blob: 75b9d59553fc8723b2249fcf183f9ef2298bdb73 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002 * lec.c: Lan Emulation driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Chas Williamsd44f7742006-09-29 17:11:14 -07004 * Marko Kiiskila <mkiiskila@yahoo.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/kernel.h>
8#include <linux/bitops.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -08009#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11/* We are ethernet device */
12#include <linux/if_ether.h>
13#include <linux/netdevice.h>
14#include <linux/etherdevice.h>
15#include <net/sock.h>
16#include <linux/skbuff.h>
17#include <linux/ip.h>
18#include <asm/byteorder.h>
19#include <asm/uaccess.h>
20#include <net/arp.h>
21#include <net/dst.h>
22#include <linux/proc_fs.h>
23#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/seq_file.h>
25
26/* TokenRing if needed */
27#ifdef CONFIG_TR
28#include <linux/trdevice.h>
29#endif
30
31/* And atm device */
32#include <linux/atmdev.h>
33#include <linux/atmlec.h>
34
35/* Proxy LEC knows about bridging */
36#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include "../bridge/br_private.h"
38
Chas Williamsd44f7742006-09-29 17:11:14 -070039static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#endif
41
42/* Modular too */
43#include <linux/module.h>
44#include <linux/init.h>
45
46#include "lec.h"
47#include "lec_arpc.h"
48#include "resources.h"
49
Chas Williamsd44f7742006-09-29 17:11:14 -070050#define DUMP_PACKETS 0 /*
51 * 0 = None,
52 * 1 = 30 first bytes
53 * 2 = Whole packet
54 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Chas Williamsd44f7742006-09-29 17:11:14 -070056#define LEC_UNRES_QUE_LEN 8 /*
57 * number of tx packets to queue for a
58 * single destination while waiting for SVC
59 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61static int lec_open(struct net_device *dev);
62static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev);
63static int lec_close(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static void lec_init(struct net_device *dev);
Chas Williamsd44f7742006-09-29 17:11:14 -070065static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070066 const unsigned char *mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067static int lec_arp_remove(struct lec_priv *priv,
Chas Williamsd44f7742006-09-29 17:11:14 -070068 struct lec_arp_table *to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/* LANE2 functions */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070070static void lane2_associate_ind(struct net_device *dev, const u8 *mac_address,
71 const u8 *tlvs, u32 sizeoftlvs);
72static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -070073 u8 **tlvs, u32 *sizeoftlvs);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070074static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
75 const u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070077static int lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 unsigned long permanent);
79static void lec_arp_check_empties(struct lec_priv *priv,
80 struct atm_vcc *vcc, struct sk_buff *skb);
81static void lec_arp_destroy(struct lec_priv *priv);
82static void lec_arp_init(struct lec_priv *priv);
Chas Williamsd44f7742006-09-29 17:11:14 -070083static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070084 const unsigned char *mac_to_find,
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 int is_rdesc,
86 struct lec_arp_table **ret_entry);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070087static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
88 const unsigned char *atm_addr, unsigned long remoteflag,
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 unsigned int targetless_le_arp);
90static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
91static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
92static void lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070093 const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 unsigned long tran_id);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070095static void lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 struct atm_vcc *vcc,
Chas Williamsd44f7742006-09-29 17:11:14 -070097 void (*old_push) (struct atm_vcc *vcc,
98 struct sk_buff *skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -070099static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
100
Chas Williams33a9c2d2006-09-29 17:16:48 -0700101/* must be done under lec_arp_lock */
102static inline void lec_arp_hold(struct lec_arp_table *entry)
103{
104 atomic_inc(&entry->usage);
105}
106
107static inline void lec_arp_put(struct lec_arp_table *entry)
108{
109 if (atomic_dec_and_test(&entry->usage))
110 kfree(entry);
111}
112
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114static struct lane2_ops lane2_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700115 lane2_resolve, /* resolve, spec 3.1.3 */
116 lane2_associate_req, /* associate_req, spec 3.1.4 */
117 NULL /* associate indicator, spec 3.1.5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118};
119
Chas Williamsd44f7742006-09-29 17:11:14 -0700120static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122/* Device structures */
123static struct net_device *dev_lec[MAX_LEC_ITF];
124
125#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
126static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
127{
Chas Williamsd44f7742006-09-29 17:11:14 -0700128 struct ethhdr *eth;
129 char *buff;
130 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Chas Williamsd44f7742006-09-29 17:11:14 -0700132 /*
133 * Check if this is a BPDU. If so, ask zeppelin to send
134 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
135 * as the Config BPDU has
136 */
137 eth = (struct ethhdr *)skb->data;
138 buff = skb->data + skb->dev->hard_header_len;
139 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 struct sock *sk;
Chas Williamsd44f7742006-09-29 17:11:14 -0700141 struct sk_buff *skb2;
142 struct atmlec_msg *mesg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Chas Williamsd44f7742006-09-29 17:11:14 -0700144 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
145 if (skb2 == NULL)
146 return;
147 skb2->len = sizeof(struct atmlec_msg);
148 mesg = (struct atmlec_msg *)skb2->data;
149 mesg->type = l_topology_change;
150 buff += 4;
151 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Wang Chen524ad0a2008-11-12 23:39:10 -0800153 priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700154 atm_force_charge(priv->lecd, skb2->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 sk = sk_atm(priv->lecd);
Chas Williamsd44f7742006-09-29 17:11:14 -0700156 skb_queue_tail(&sk->sk_receive_queue, skb2);
157 sk->sk_data_ready(sk, skb2->len);
158 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Chas Williamsd44f7742006-09-29 17:11:14 -0700160 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
162#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
163
164/*
165 * Modelled after tr_type_trans
166 * All multicast and ARE or STE frames go to BUS.
167 * Non source routed frames go by destination address.
168 * Last hop source routed frames go by destination address.
169 * Not last hop source routed frames go by _next_ route descriptor.
170 * Returns pointer to destination MAC address or fills in rdesc
171 * and returns NULL.
172 */
173#ifdef CONFIG_TR
174static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
175{
Chas Williamsd44f7742006-09-29 17:11:14 -0700176 struct trh_hdr *trh;
Eric Dumazet5c17d5f2008-01-15 03:29:50 -0800177 unsigned int riflen, num_rdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Chas Williamsd44f7742006-09-29 17:11:14 -0700179 trh = (struct trh_hdr *)packet;
180 if (trh->daddr[0] & (uint8_t) 0x80)
181 return bus_mac; /* multicast */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Chas Williamsd44f7742006-09-29 17:11:14 -0700183 if (trh->saddr[0] & TR_RII) {
184 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
185 if ((ntohs(trh->rcf) >> 13) != 0)
186 return bus_mac; /* ARE or STE */
187 } else
188 return trh->daddr; /* not source routed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Chas Williamsd44f7742006-09-29 17:11:14 -0700190 if (riflen < 6)
191 return trh->daddr; /* last hop, source routed */
192
193 /* riflen is 6 or more, packet has more than one route descriptor */
194 num_rdsc = (riflen / 2) - 1;
195 memset(rdesc, 0, ETH_ALEN);
196 /* offset 4 comes from LAN destination field in LE control frames */
197 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
Al Viro30d492d2006-11-14 21:11:29 -0800198 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700199 else {
Al Viro30d492d2006-11-14 21:11:29 -0800200 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700201 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
202 }
203
204 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206#endif /* CONFIG_TR */
207
208/*
209 * Open/initialize the netdevice. This is called (in the current kernel)
210 * sometime after booting when the 'ifconfig' program is run.
211 *
212 * This routine should set everything up anew at each open, even
213 * registers that "should" only need to be set once at boot, so that
214 * there is non-reboot way to recover if something goes wrong.
215 */
216
Chas Williamsd44f7742006-09-29 17:11:14 -0700217static int lec_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 netif_start_queue(dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000220 memset(&dev->stats, 0, sizeof(struct net_device_stats));
Chas Williamsd44f7742006-09-29 17:11:14 -0700221
222 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
Stephen Hemminger162619e2009-01-09 13:01:01 +0000225static void
226lec_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
Stephen Hemminger162619e2009-01-09 13:01:01 +0000228 struct net_device *dev = skb->dev;
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 ATM_SKB(skb)->vcc = vcc;
231 ATM_SKB(skb)->atm_options = vcc->atm_options;
232
233 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
234 if (vcc->send(vcc, skb) < 0) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000235 dev->stats.tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return;
237 }
238
Stephen Hemminger162619e2009-01-09 13:01:01 +0000239 dev->stats.tx_packets++;
240 dev->stats.tx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241}
242
Chas Williamsd44f7742006-09-29 17:11:14 -0700243static void lec_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 printk(KERN_INFO "%s: tx timeout\n", dev->name);
246 dev->trans_start = jiffies;
247 netif_wake_queue(dev);
248}
249
Chas Williamsd44f7742006-09-29 17:11:14 -0700250static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
Chas Williamsd44f7742006-09-29 17:11:14 -0700252 struct sk_buff *skb2;
Wang Chen524ad0a2008-11-12 23:39:10 -0800253 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700254 struct lecdatahdr_8023 *lec_h;
255 struct atm_vcc *vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700257 unsigned char *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 int min_frame_size;
259#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700260 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700262 int is_rdesc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700264 char buf[300];
265 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266#endif /* DUMP_PACKETS >0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Stephen Hemminger52240062007-08-28 15:22:09 -0700268 pr_debug("lec_start_xmit called\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700269 if (!priv->lecd) {
270 printk("%s:No lecd attached\n", dev->name);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000271 dev->stats.tx_errors++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700272 netif_stop_queue(dev);
273 return -EUNATCH;
274 }
275
Stephen Hemminger52240062007-08-28 15:22:09 -0700276 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700277 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700278 (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) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Stephen Hemminger52240062007-08-28 15:22:09 -0700287 pr_debug("lec_start_xmit: reallocating skb\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700288 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
289 kfree_skb(skb);
290 if (skb2 == NULL)
291 return 0;
292 skb = skb2;
293 }
294 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Chas Williamsd44f7742006-09-29 17:11:14 -0700296 /* Put le header to place, works for TokenRing too */
297 lec_h = (struct lecdatahdr_8023 *)skb->data;
298 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700301 /*
302 * Ugly. Use this to realign Token Ring packets for
303 * e.g. PCA-200E driver.
304 */
305 if (priv->is_trdev) {
306 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
307 kfree_skb(skb);
308 if (skb2 == NULL)
309 return 0;
310 skb = skb2;
311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312#endif
313
314#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700315 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
316 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700318 for (i = 0; i < skb->len && i < 99; i++) {
319 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700322 for (i = 0; i < skb->len && i < 30; i++) {
323 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700326 if (i == skb->len)
327 printk("%s\n", buf);
328 else
329 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330#endif /* DUMP_PACKETS > 0 */
331
Chas Williamsd44f7742006-09-29 17:11:14 -0700332 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700334 if (priv->is_trdev)
335 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 else
337#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700338 min_frame_size = LEC_MINIMUM_8023_SIZE;
339 if (skb->len < min_frame_size) {
340 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
341 skb2 = skb_copy_expand(skb, 0,
342 min_frame_size - skb->truesize,
343 GFP_ATOMIC);
344 dev_kfree_skb(skb);
345 if (skb2 == NULL) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000346 dev->stats.tx_dropped++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700347 return 0;
348 }
349 skb = skb2;
350 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700352 }
353
354 /* Send to right vcc */
355 is_rdesc = 0;
356 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700358 if (priv->is_trdev) {
359 dst = get_tr_dst(skb->data + 2, rdesc);
360 if (dst == NULL) {
361 dst = rdesc;
362 is_rdesc = 1;
363 }
364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700366 entry = NULL;
367 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
Andrew Morton58c14a82007-09-26 22:31:19 -0700368 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700369 vcc, vcc ? vcc->flags : 0, entry);
370 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
371 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700372 pr_debug("%s:lec_start_xmit: queuing packet, ",
Chas Williamsd44f7742006-09-29 17:11:14 -0700373 dev->name);
Johannes Berge1749612008-10-27 15:59:26 -0700374 pr_debug("MAC address %pM\n", lec_h->h_dest);
Chas Williamsd44f7742006-09-29 17:11:14 -0700375 skb_queue_tail(&entry->tx_wait, skb);
376 } else {
Stephen Hemminger52240062007-08-28 15:22:09 -0700377 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700378 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
379 dev->name);
Johannes Berge1749612008-10-27 15:59:26 -0700380 pr_debug("MAC address %pM\n", lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000381 dev->stats.tx_dropped++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700382 dev_kfree_skb(skb);
383 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700384 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700385 }
386#if DUMP_PACKETS > 0
387 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700389
390 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700391 pr_debug("lec.c: emptying tx queue, ");
Johannes Berge1749612008-10-27 15:59:26 -0700392 pr_debug("MAC address %pM\n", lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000393 lec_send(vcc, skb2);
Chas Williamsd44f7742006-09-29 17:11:14 -0700394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Stephen Hemminger162619e2009-01-09 13:01:01 +0000396 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 if (!atm_may_send(vcc, 0)) {
399 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
400
401 vpriv->xoff = 1;
402 netif_stop_queue(dev);
403
404 /*
405 * vcc->pop() might have occurred in between, making
406 * the vcc usuable again. Since xmit is serialized,
407 * this is the only situation we have to re-test.
408 */
409
410 if (atm_may_send(vcc, 0))
411 netif_wake_queue(dev);
412 }
413
Chas Williams6656e3c2006-09-29 17:17:17 -0700414out:
415 if (entry)
416 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 dev->trans_start = jiffies;
Chas Williamsd44f7742006-09-29 17:11:14 -0700418 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419}
420
421/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700422static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
Chas Williamsd44f7742006-09-29 17:11:14 -0700424 netif_stop_queue(dev);
425 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426}
427
Chas Williamsd44f7742006-09-29 17:11:14 -0700428static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
430 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700431 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800432 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700433 struct atmlec_msg *mesg;
434 struct lec_arp_table *entry;
435 int i;
436 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700439 mesg = (struct atmlec_msg *)skb->data;
440 tmp = skb->data;
441 tmp += sizeof(struct atmlec_msg);
Stephen Hemminger52240062007-08-28 15:22:09 -0700442 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700443 switch (mesg->type) {
444 case l_set_mac_addr:
445 for (i = 0; i < 6; i++) {
446 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
447 }
448 break;
449 case l_del_mac_addr:
450 for (i = 0; i < 6; i++) {
451 dev->dev_addr[i] = 0;
452 }
453 break;
454 case l_addr_delete:
455 lec_addr_delete(priv, mesg->content.normal.atm_addr,
456 mesg->content.normal.flag);
457 break;
458 case l_topology_change:
459 priv->topology_change = mesg->content.normal.flag;
460 break;
461 case l_flush_complete:
462 lec_flush_complete(priv, mesg->content.normal.flag);
463 break;
464 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700466 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
467 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
469
Chas Williamsd44f7742006-09-29 17:11:14 -0700470 if (mesg->content.normal.no_source_le_narp)
471 break;
472 /* FALL THROUGH */
473 case l_arp_update:
474 lec_arp_update(priv, mesg->content.normal.mac_addr,
475 mesg->content.normal.atm_addr,
476 mesg->content.normal.flag,
477 mesg->content.normal.targetless_le_arp);
Stephen Hemminger52240062007-08-28 15:22:09 -0700478 pr_debug("lec: in l_arp_update\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700479 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700480 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700481 mesg->sizeoftlvs);
482 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
483 tmp, mesg->sizeoftlvs);
484 }
485 break;
486 case l_config:
487 priv->maximum_unknown_frame_count =
488 mesg->content.config.maximum_unknown_frame_count;
489 priv->max_unknown_frame_time =
490 (mesg->content.config.max_unknown_frame_time * HZ);
491 priv->max_retry_count = mesg->content.config.max_retry_count;
492 priv->aging_time = (mesg->content.config.aging_time * HZ);
493 priv->forward_delay_time =
494 (mesg->content.config.forward_delay_time * HZ);
495 priv->arp_response_time =
496 (mesg->content.config.arp_response_time * HZ);
497 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
498 priv->path_switching_delay =
499 (mesg->content.config.path_switching_delay * HZ);
500 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 priv->lane2_ops = NULL;
502 if (priv->lane_version > 1)
503 priv->lane2_ops = &lane2_ops;
Stephen Hemminger1f1900f2009-03-21 13:37:28 -0700504 if (dev_set_mtu(dev, mesg->content.config.mtu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 printk("%s: change_mtu to %d failed\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700506 mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700508 break;
509 case l_flush_tran_id:
510 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
511 mesg->content.normal.flag);
512 break;
513 case l_set_lecid:
514 priv->lecid =
515 (unsigned short)(0xffff & mesg->content.normal.flag);
516 break;
517 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700519 {
Johannes Berge1749612008-10-27 15:59:26 -0700520 pr_debug("%s: bridge zeppelin asks about %pM\n",
521 dev->name, mesg->content.proxy.mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Michał Mirosławda678292009-06-05 05:35:28 +0000523 if (br_fdb_test_addr_hook == NULL)
Chas Williamsd44f7742006-09-29 17:11:14 -0700524 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Michał Mirosławda678292009-06-05 05:35:28 +0000526 if (br_fdb_test_addr_hook(dev,
527 mesg->content.proxy.mac_addr)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700528 /* hit from bridge table, send LE_ARP_RESPONSE */
529 struct sk_buff *skb2;
530 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Stephen Hemminger52240062007-08-28 15:22:09 -0700532 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700533 ("%s: entry found, responding to zeppelin\n",
534 dev->name);
535 skb2 =
536 alloc_skb(sizeof(struct atmlec_msg),
537 GFP_ATOMIC);
Michał Mirosławda678292009-06-05 05:35:28 +0000538 if (skb2 == NULL)
Chas Williamsd44f7742006-09-29 17:11:14 -0700539 break;
Chas Williamsd44f7742006-09-29 17:11:14 -0700540 skb2->len = sizeof(struct atmlec_msg);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300541 skb_copy_to_linear_data(skb2, mesg,
542 sizeof(*mesg));
Chas Williamsd44f7742006-09-29 17:11:14 -0700543 atm_force_charge(priv->lecd, skb2->truesize);
544 sk = sk_atm(priv->lecd);
545 skb_queue_tail(&sk->sk_receive_queue, skb2);
546 sk->sk_data_ready(sk, skb2->len);
547 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700550 break;
551 default:
552 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
553 dev_kfree_skb(skb);
554 return -EINVAL;
555 }
556 dev_kfree_skb(skb);
557 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558}
559
Chas Williamsd44f7742006-09-29 17:11:14 -0700560static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561{
Chas Williamsd44f7742006-09-29 17:11:14 -0700562 struct sk_buff *skb;
563 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800564 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Chas Williamsd44f7742006-09-29 17:11:14 -0700566 priv->lecd = NULL;
567 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Chas Williamsd44f7742006-09-29 17:11:14 -0700569 netif_stop_queue(dev);
570 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
Chas Williamsd44f7742006-09-29 17:11:14 -0700572 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700574 dev->name);
575 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
576 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700578 }
579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700581 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582}
583
584static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700585 .close = lec_atm_close,
586 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587};
588
589static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700590 .ops = &lecdev_ops,
591 .type = "lec",
592 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700593 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594};
595
596/*
597 * LANE2: new argument struct sk_buff *data contains
598 * the LE_ARP based TLVs introduced in the LANE2 spec
599 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700600static int
601send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700602 const unsigned char *mac_addr, const unsigned char *atm_addr,
Chas Williamsd44f7742006-09-29 17:11:14 -0700603 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
605 struct sock *sk;
606 struct sk_buff *skb;
607 struct atmlec_msg *mesg;
608
609 if (!priv || !priv->lecd) {
610 return -1;
611 }
612 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
613 if (!skb)
614 return -1;
615 skb->len = sizeof(struct atmlec_msg);
616 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700617 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700619 if (data != NULL)
620 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 if (mac_addr)
622 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700623 else
624 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 if (atm_addr)
626 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
627
Chas Williamsd44f7742006-09-29 17:11:14 -0700628 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 sk = sk_atm(priv->lecd);
630 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700631 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Chas Williamsd44f7742006-09-29 17:11:14 -0700633 if (data != NULL) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700634 pr_debug("lec: about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700635 atm_force_charge(priv->lecd, data->truesize);
636 skb_queue_tail(&sk->sk_receive_queue, data);
637 sk->sk_data_ready(sk, skb->len);
638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
Chas Williamsd44f7742006-09-29 17:11:14 -0700640 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641}
642
643/* shamelessly stolen from drivers/net/net_init.c */
644static int lec_change_mtu(struct net_device *dev, int new_mtu)
645{
Chas Williamsd44f7742006-09-29 17:11:14 -0700646 if ((new_mtu < 68) || (new_mtu > 18190))
647 return -EINVAL;
648 dev->mtu = new_mtu;
649 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}
651
652static void lec_set_multicast_list(struct net_device *dev)
653{
Chas Williamsd44f7742006-09-29 17:11:14 -0700654 /*
655 * by default, all multicast frames arrive over the bus.
656 * eventually support selective multicast service
657 */
658 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659}
660
Stephen Hemminger004b3222009-01-09 13:01:02 +0000661static const struct net_device_ops lec_netdev_ops = {
662 .ndo_open = lec_open,
663 .ndo_stop = lec_close,
664 .ndo_start_xmit = lec_start_xmit,
665 .ndo_change_mtu = lec_change_mtu,
666 .ndo_tx_timeout = lec_tx_timeout,
667 .ndo_set_multicast_list = lec_set_multicast_list,
668};
669
670
Chas Williamsd44f7742006-09-29 17:11:14 -0700671static void lec_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672{
Stephen Hemminger004b3222009-01-09 13:01:02 +0000673 dev->netdev_ops = &lec_netdev_ops;
Chas Williamsd44f7742006-09-29 17:11:14 -0700674 printk("%s: Initialized!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675}
676
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700677static const unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700678 0xff,
679 0x00,
680 0x01,
681 0x01
682};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Scott Talbert4a7097f2005-09-29 17:30:54 -0700684#define LEC_DATA_DIRECT_8023 2
685#define LEC_DATA_DIRECT_8025 3
686
687static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700688{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700689 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
690 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700691}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700692
Chas Williamsd44f7742006-09-29 17:11:14 -0700693static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700695 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700696 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800697 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699#if DUMP_PACKETS >0
Chas Williamsd44f7742006-09-29 17:11:14 -0700700 int i = 0;
701 char buf[300];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Chas Williamsd44f7742006-09-29 17:11:14 -0700703 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
704 vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700706 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700707 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700708 lec_vcc_close(priv, vcc);
709 return;
710 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700712 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
713 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700715 for (i = 0; i < skb->len && i < 99; i++) {
716 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
717 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700719 for (i = 0; i < skb->len && i < 30; i++) {
720 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
721 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700723 if (i == skb->len)
724 printk("%s\n", buf);
725 else
726 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700728 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 struct sock *sk = sk_atm(vcc);
730
Stephen Hemminger52240062007-08-28 15:22:09 -0700731 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700732 skb_queue_tail(&sk->sk_receive_queue, skb);
733 sk->sk_data_ready(sk, skb->len);
734 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700735 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700736 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
Chas Williamsd44f7742006-09-29 17:11:14 -0700738 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800739 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700740 !priv->lecd || !(dev->flags & IFF_UP)) {
741 /*
742 * Probably looping back, or if lecd is missing,
743 * lecd has gone down
744 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700745 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700746 dev_kfree_skb(skb);
747 return;
748 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700750 if (priv->is_trdev)
751 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
752 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700754 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700755
Chas Williamsd44f7742006-09-29 17:11:14 -0700756 /*
757 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700758 * the LE_ARP cache entry, delete the LE_ARP cache entry.
759 */
760 spin_lock_irqsave(&priv->lec_arp_lock, flags);
761 if (lec_is_data_direct(vcc)) {
762#ifdef CONFIG_TR
763 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700764 src =
765 ((struct lecdatahdr_8025 *)skb->data)->
766 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700767 else
768#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700769 src =
770 ((struct lecdatahdr_8023 *)skb->data)->
771 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700772 entry = lec_arp_find(priv, src);
773 if (entry && entry->vcc != vcc) {
774 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700775 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700776 }
777 }
778 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Chas Williamsd44f7742006-09-29 17:11:14 -0700780 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
781 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700783 dev_kfree_skb(skb);
784 return;
785 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700786 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700787 lec_arp_check_empties(priv, vcc, skb);
788 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700789 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700791 if (priv->is_trdev)
792 skb->protocol = tr_type_trans(skb, dev);
793 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700795 skb->protocol = eth_type_trans(skb, dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000796 dev->stats.rx_packets++;
797 dev->stats.rx_bytes += skb->len;
Chas Williamsd44f7742006-09-29 17:11:14 -0700798 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
799 netif_rx(skb);
800 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801}
802
Chas Williamsd44f7742006-09-29 17:11:14 -0700803static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804{
805 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
806 struct net_device *dev = skb->dev;
807
808 if (vpriv == NULL) {
809 printk("lec_pop(): vpriv = NULL!?!?!?\n");
810 return;
811 }
812
813 vpriv->old_pop(vcc, skb);
814
815 if (vpriv->xoff && atm_may_send(vcc, 0)) {
816 vpriv->xoff = 0;
817 if (netif_running(dev) && netif_queue_stopped(dev))
818 netif_wake_queue(dev);
819 }
820}
821
Chas Williamsd44f7742006-09-29 17:11:14 -0700822static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
824 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700825 int bytes_left;
826 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Chas Williamsd44f7742006-09-29 17:11:14 -0700828 /* Lecd must be up in this case */
829 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
830 if (bytes_left != 0) {
831 printk
832 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
833 bytes_left);
834 }
835 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
836 !dev_lec[ioc_data.dev_num])
837 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
839 return -ENOMEM;
840 vpriv->xoff = 0;
841 vpriv->old_pop = vcc->pop;
842 vcc->user_back = vpriv;
843 vcc->pop = lec_pop;
Wang Chen524ad0a2008-11-12 23:39:10 -0800844 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
Chas Williamsd44f7742006-09-29 17:11:14 -0700845 &ioc_data, vcc, vcc->push);
846 vcc->proto_data = dev_lec[ioc_data.dev_num];
847 vcc->push = lec_push;
848 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849}
850
Chas Williamsd44f7742006-09-29 17:11:14 -0700851static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
Chas Williamsd44f7742006-09-29 17:11:14 -0700853 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
854 return -EINVAL;
855 vcc->proto_data = dev_lec[arg];
Wang Chen524ad0a2008-11-12 23:39:10 -0800856 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
857 vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858}
859
860/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700861static int lecd_attach(struct atm_vcc *vcc, int arg)
862{
863 int i;
864 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Chas Williamsd44f7742006-09-29 17:11:14 -0700866 if (arg < 0)
867 i = 0;
868 else
869 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700871 if (arg >= MAX_LEC_ITF)
872 return -EINVAL;
873#else /* Reserve the top NUM_TR_DEVS for TR */
874 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
875 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700877 if (!dev_lec[i]) {
878 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
Chas Williamsd44f7742006-09-29 17:11:14 -0700880 is_trdev = 0;
881 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
882 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
Chas Williamsd44f7742006-09-29 17:11:14 -0700884 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700886 if (is_trdev)
887 dev_lec[i] = alloc_trdev(size);
888 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700890 dev_lec[i] = alloc_etherdev(size);
891 if (!dev_lec[i])
892 return -ENOMEM;
893 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
894 if (register_netdev(dev_lec[i])) {
895 free_netdev(dev_lec[i]);
896 return -EINVAL;
897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Wang Chen524ad0a2008-11-12 23:39:10 -0800899 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700900 priv->is_trdev = is_trdev;
901 lec_init(dev_lec[i]);
902 } else {
Wang Chen524ad0a2008-11-12 23:39:10 -0800903 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700904 if (priv->lecd)
905 return -EADDRINUSE;
906 }
907 lec_arp_init(priv);
908 priv->itfnum = i; /* LANE2 addition */
909 priv->lecd = vcc;
910 vcc->dev = &lecatm_dev;
911 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Chas Williamsd44f7742006-09-29 17:11:14 -0700913 vcc->proto_data = dev_lec[i];
914 set_bit(ATM_VF_META, &vcc->flags);
915 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Chas Williamsd44f7742006-09-29 17:11:14 -0700917 /* Set default values to these variables */
918 priv->maximum_unknown_frame_count = 1;
919 priv->max_unknown_frame_time = (1 * HZ);
920 priv->vcc_timeout_period = (1200 * HZ);
921 priv->max_retry_count = 1;
922 priv->aging_time = (300 * HZ);
923 priv->forward_delay_time = (15 * HZ);
924 priv->topology_change = 0;
925 priv->arp_response_time = (1 * HZ);
926 priv->flush_timeout = (4 * HZ);
927 priv->path_switching_delay = (6 * HZ);
928
929 if (dev_lec[i]->flags & IFF_UP) {
930 netif_start_queue(dev_lec[i]);
931 }
932 __module_get(THIS_MODULE);
933 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934}
935
936#ifdef CONFIG_PROC_FS
Chas Williamsd44f7742006-09-29 17:11:14 -0700937static char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938{
939 static char *lec_arp_status_string[] = {
940 "ESI_UNKNOWN ",
941 "ESI_ARP_PENDING ",
942 "ESI_VC_PENDING ",
943 "<Undefined> ",
944 "ESI_FLUSH_PENDING ",
945 "ESI_FORWARD_DIRECT"
946 };
947
948 if (status > ESI_FORWARD_DIRECT)
949 status = 3; /* ESI_UNDEFINED */
950 return lec_arp_status_string[status];
951}
952
953static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
954{
955 int i;
956
957 for (i = 0; i < ETH_ALEN; i++)
958 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
959 seq_printf(seq, " ");
960 for (i = 0; i < ATM_ESA_LEN; i++)
961 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
962 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
963 entry->flags & 0xffff);
964 if (entry->vcc)
965 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
966 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700967 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 if (entry->recv_vcc) {
969 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
970 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -0700971 }
972 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973}
974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975struct lec_state {
976 unsigned long flags;
977 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -0700978 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 struct net_device *dev;
980 int itf;
981 int arp_table;
982 int misc_table;
983};
984
Chas Williamsd0732f62006-09-29 17:14:27 -0700985static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 loff_t *l)
987{
Chas Williamsd0732f62006-09-29 17:14:27 -0700988 struct hlist_node *e = state->node;
989 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
991 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -0700992 e = tbl->first;
Joe Perches2e1e9842008-04-10 03:33:03 -0700993 if (e == SEQ_START_TOKEN) {
Chas Williamsd0732f62006-09-29 17:14:27 -0700994 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 --*l;
996 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700997
998 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 if (--*l < 0)
1000 break;
1001 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001002 state->node = e;
1003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 return (*l < 0) ? state : NULL;
1005}
1006
1007static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -07001008 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009{
1010 void *v = NULL;
1011 int p;
1012
1013 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001014 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 if (v)
1016 break;
1017 }
1018 state->arp_table = p;
1019 return v;
1020}
1021
1022static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1023 struct lec_priv *priv)
1024{
Chas Williamsd0732f62006-09-29 17:14:27 -07001025 struct hlist_head *lec_misc_tables[] = {
1026 &priv->lec_arp_empty_ones,
1027 &priv->lec_no_forward,
1028 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 };
1030 void *v = NULL;
1031 int q;
1032
1033 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1034 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1035 if (v)
1036 break;
1037 }
1038 state->misc_table = q;
1039 return v;
1040}
1041
1042static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1043 struct lec_priv *priv)
1044{
1045 if (!state->locked) {
1046 state->locked = priv;
1047 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1048 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001049 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1051 state->locked = NULL;
1052 /* Partial state reset for the next time we get called */
1053 state->arp_table = state->misc_table = 0;
1054 }
1055 return state->locked;
1056}
1057
1058static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1059{
1060 struct net_device *dev;
1061 void *v;
1062
1063 dev = state->dev ? state->dev : dev_lec[state->itf];
Wang Chen524ad0a2008-11-12 23:39:10 -08001064 v = (dev && netdev_priv(dev)) ?
1065 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 if (!v && dev) {
1067 dev_put(dev);
1068 /* Partial state reset for the next time we get called */
1069 dev = NULL;
1070 }
1071 state->dev = dev;
1072 return v;
1073}
1074
1075static void *lec_get_idx(struct lec_state *state, loff_t l)
1076{
1077 void *v = NULL;
1078
1079 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1080 v = lec_itf_walk(state, &l);
1081 if (v)
1082 break;
1083 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001084 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085}
1086
1087static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1088{
1089 struct lec_state *state = seq->private;
1090
1091 state->itf = 0;
1092 state->dev = NULL;
1093 state->locked = NULL;
1094 state->arp_table = 0;
1095 state->misc_table = 0;
Joe Perches2e1e9842008-04-10 03:33:03 -07001096 state->node = SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Joe Perches2e1e9842008-04-10 03:33:03 -07001098 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099}
1100
1101static void lec_seq_stop(struct seq_file *seq, void *v)
1102{
1103 struct lec_state *state = seq->private;
1104
1105 if (state->dev) {
1106 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1107 state->flags);
1108 dev_put(state->dev);
1109 }
1110}
1111
1112static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1113{
1114 struct lec_state *state = seq->private;
1115
1116 v = lec_get_idx(state, 1);
1117 *pos += !!PTR_ERR(v);
1118 return v;
1119}
1120
1121static int lec_seq_show(struct seq_file *seq, void *v)
1122{
Chas Williamsd44f7742006-09-29 17:11:14 -07001123 static char lec_banner[] = "Itf MAC ATM destination"
1124 " Status Flags "
1125 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Joe Perches2e1e9842008-04-10 03:33:03 -07001127 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 seq_puts(seq, lec_banner);
1129 else {
1130 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001131 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001132 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
1134 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001135 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 }
1137 return 0;
1138}
1139
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001140static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001141 .start = lec_seq_start,
1142 .next = lec_seq_next,
1143 .stop = lec_seq_stop,
1144 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145};
1146
1147static int lec_seq_open(struct inode *inode, struct file *file)
1148{
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001149 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150}
1151
Arjan van de Ven9a321442007-02-12 00:55:35 -08001152static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001153 .owner = THIS_MODULE,
1154 .open = lec_seq_open,
1155 .read = seq_read,
1156 .llseek = seq_lseek,
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001157 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158};
1159#endif
1160
1161static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1162{
1163 struct atm_vcc *vcc = ATM_SD(sock);
1164 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001165
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001167 case ATMLEC_CTRL:
1168 case ATMLEC_MCAST:
1169 case ATMLEC_DATA:
1170 if (!capable(CAP_NET_ADMIN))
1171 return -EPERM;
1172 break;
1173 default:
1174 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 }
1176
1177 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001178 case ATMLEC_CTRL:
1179 err = lecd_attach(vcc, (int)arg);
1180 if (err >= 0)
1181 sock->state = SS_CONNECTED;
1182 break;
1183 case ATMLEC_MCAST:
1184 err = lec_mcast_attach(vcc, (int)arg);
1185 break;
1186 case ATMLEC_DATA:
1187 err = lec_vcc_attach(vcc, (void __user *)arg);
1188 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 }
1190
1191 return err;
1192}
1193
1194static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001195 .owner = THIS_MODULE,
1196 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197};
1198
1199static int __init lane_module_init(void)
1200{
1201#ifdef CONFIG_PROC_FS
1202 struct proc_dir_entry *p;
1203
Wang Chen16e297b2008-02-28 13:55:45 -08001204 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Wang Chendbee0d32008-03-23 21:45:36 -07001205 if (!p) {
1206 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n");
1207 return -ENOMEM;
1208 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209#endif
1210
1211 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001212 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1213 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214}
1215
1216static void __exit lane_module_cleanup(void)
1217{
Chas Williamsd44f7742006-09-29 17:11:14 -07001218 int i;
1219 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
1221 remove_proc_entry("lec", atm_proc_root);
1222
1223 deregister_atm_ioctl(&lane_ioctl_ops);
1224
Chas Williamsd44f7742006-09-29 17:11:14 -07001225 for (i = 0; i < MAX_LEC_ITF; i++) {
1226 if (dev_lec[i] != NULL) {
Wang Chen524ad0a2008-11-12 23:39:10 -08001227 priv = netdev_priv(dev_lec[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001229 free_netdev(dev_lec[i]);
1230 dev_lec[i] = NULL;
1231 }
1232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Chas Williamsd44f7742006-09-29 17:11:14 -07001234 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235}
1236
1237module_init(lane_module_init);
1238module_exit(lane_module_cleanup);
1239
1240/*
1241 * LANE2: 3.1.3, LE_RESOLVE.request
1242 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1243 * If sizeoftlvs == NULL the default TLVs associated with with this
1244 * lec will be used.
1245 * If dst_mac == NULL, targetless LE_ARP will be sent
1246 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001247static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001248 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
1250 unsigned long flags;
Wang Chen524ad0a2008-11-12 23:39:10 -08001251 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001252 struct lec_arp_table *table;
1253 struct sk_buff *skb;
1254 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
Chas Williamsd44f7742006-09-29 17:11:14 -07001256 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001258 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001260 if (table == NULL)
1261 return -1;
1262
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001263 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001264 if (*tlvs == NULL)
1265 return -1;
1266
Chas Williamsd44f7742006-09-29 17:11:14 -07001267 *sizeoftlvs = table->sizeoftlvs;
1268
1269 return 0;
1270 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
1272 if (sizeoftlvs == NULL)
1273 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001274
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 else {
1276 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1277 if (skb == NULL)
1278 return -1;
1279 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001280 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1282 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001283 return retval;
1284}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
1286/*
1287 * LANE2: 3.1.4, LE_ASSOCIATE.request
1288 * Associate the *tlvs with the *lan_dst address.
1289 * Will overwrite any previous association
1290 * Returns 1 for success, 0 for failure (out of memory)
1291 *
1292 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001293static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1294 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295{
Chas Williamsd44f7742006-09-29 17:11:14 -07001296 int retval;
1297 struct sk_buff *skb;
Wang Chen524ad0a2008-11-12 23:39:10 -08001298 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
Chas Williamsd44f7742006-09-29 17:11:14 -07001300 if (compare_ether_addr(lan_dst, dev->dev_addr))
1301 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
Chas Williamsd44f7742006-09-29 17:11:14 -07001303 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001305 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001306 if (priv->tlvs == NULL)
1307 return (0);
1308 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
Chas Williamsd44f7742006-09-29 17:11:14 -07001310 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1311 if (skb == NULL)
1312 return 0;
1313 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001314 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001315 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1316 if (retval != 0)
1317 printk("lec.c: lane2_associate_req() failed\n");
1318 /*
1319 * If the previous association has changed we must
1320 * somehow notify other LANE entities about the change
1321 */
1322 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323}
1324
1325/*
1326 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1327 *
1328 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001329static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1330 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331{
1332#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001333 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334#endif
Wang Chen524ad0a2008-11-12 23:39:10 -08001335 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001336#if 0 /*
1337 * Why have the TLVs in LE_ARP entries
1338 * since we do not use them? When you
1339 * uncomment this code, make sure the
1340 * TLVs get freed when entry is killed
1341 */
1342 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Chas Williamsd44f7742006-09-29 17:11:14 -07001344 if (entry == NULL)
1345 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
Chas Williamsd44f7742006-09-29 17:11:14 -07001347 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001349 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001350 if (entry->tlvs == NULL)
1351 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001352 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353#endif
1354#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001355 printk("lec.c: lane2_associate_ind()\n");
1356 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1357 while (i < sizeoftlvs)
1358 printk("%02x ", tlvs[i++]);
1359
1360 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361#endif
1362
Chas Williamsd44f7742006-09-29 17:11:14 -07001363 /* tell MPOA about the TLVs we saw */
1364 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1365 priv->lane2_ops->associate_indicator(dev, mac_addr,
1366 tlvs, sizeoftlvs);
1367 }
1368 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369}
1370
1371/*
1372 * Here starts what used to lec_arpc.c
1373 *
1374 * lec_arpc.c was added here when making
1375 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 */
1377
1378#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379#include <linux/timer.h>
1380#include <asm/param.h>
1381#include <asm/atomic.h>
1382#include <linux/inetdevice.h>
1383#include <net/route.h>
1384
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385#if 0
Stephen Hemminger52240062007-08-28 15:22:09 -07001386#define pr_debug(format,args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387/*
Stephen Hemminger52240062007-08-28 15:22:09 -07001388#define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389*/
1390#endif
1391#define DEBUG_ARP_TABLE 0
1392
1393#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1394
David Howellsc4028952006-11-22 14:57:56 +00001395static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396static void lec_arp_expire_arp(unsigned long data);
1397
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001398/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 * Arp table funcs
1400 */
1401
1402#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1403
1404/*
1405 * Initialization of arp-cache
1406 */
Chas Williams1fa99612006-09-29 17:11:47 -07001407static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408{
Chas Williams1fa99612006-09-29 17:11:47 -07001409 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Chas Williams1fa99612006-09-29 17:11:47 -07001411 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001412 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001413 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001414 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1415 INIT_HLIST_HEAD(&priv->lec_no_forward);
1416 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001418 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001419 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420}
1421
Chas Williams1fa99612006-09-29 17:11:47 -07001422static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423{
Chas Williams1fa99612006-09-29 17:11:47 -07001424 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 struct atm_vcc *vcc = entry->vcc;
1426 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001427 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Chas Williams1fa99612006-09-29 17:11:47 -07001429 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 if (vpriv->xoff)
1431 netif_wake_queue(dev);
1432 kfree(vpriv);
1433 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001434 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001436 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001437 }
1438 if (entry->recv_vcc) {
1439 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001441 entry->recv_vcc = NULL;
1442 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443}
1444
1445/*
1446 * Insert entry to lec_arp_table
1447 * LANE2: Add to the end of the list to satisfy 8.1.13
1448 */
Chas Williams1fa99612006-09-29 17:11:47 -07001449static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001450lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451{
Chas Williamsd0732f62006-09-29 17:14:27 -07001452 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
Chas Williamsd0732f62006-09-29 17:14:27 -07001454 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1455 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001456
Stephen Hemminger52240062007-08-28 15:22:09 -07001457 pr_debug("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
Chas Williamsd0732f62006-09-29 17:14:27 -07001458 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1459 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1460 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461}
1462
1463/*
1464 * Remove entry from lec_arp_table
1465 */
Chas Williams1fa99612006-09-29 17:11:47 -07001466static int
1467lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468{
Chas Williamsd0732f62006-09-29 17:14:27 -07001469 struct hlist_node *node;
1470 struct lec_arp_table *entry;
1471 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Chas Williams1fa99612006-09-29 17:11:47 -07001473 if (!to_remove) {
1474 return -1;
1475 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001476
1477 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001478 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Chas Williamsd0732f62006-09-29 17:14:27 -07001480 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001481 if (to_remove->status >= ESI_FLUSH_PENDING) {
1482 /*
1483 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1484 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001485 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1486 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1487 if (memcmp(to_remove->atm_addr,
1488 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001489 remove_vcc = 0;
1490 break;
1491 }
1492 }
1493 }
1494 if (remove_vcc)
1495 lec_arp_clear_vccs(to_remove);
1496 }
1497 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1498
Stephen Hemminger52240062007-08-28 15:22:09 -07001499 pr_debug("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001500 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1501 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1502 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1503 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504}
1505
1506#if DEBUG_ARP_TABLE
Chas Williams1fa99612006-09-29 17:11:47 -07001507static char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Chas Williams1fa99612006-09-29 17:11:47 -07001509 switch (st) {
1510 case ESI_UNKNOWN:
1511 return "ESI_UNKNOWN";
1512 case ESI_ARP_PENDING:
1513 return "ESI_ARP_PENDING";
1514 case ESI_VC_PENDING:
1515 return "ESI_VC_PENDING";
1516 case ESI_FLUSH_PENDING:
1517 return "ESI_FLUSH_PENDING";
1518 case ESI_FORWARD_DIRECT:
1519 return "ESI_FORWARD_DIRECT";
1520 default:
1521 return "<UNKNOWN>";
1522 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524
Chas Williams1fa99612006-09-29 17:11:47 -07001525static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
Chas Williamsd0732f62006-09-29 17:14:27 -07001527 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001528 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001529 char buf[256];
1530 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Chas Williams1fa99612006-09-29 17:11:47 -07001532 printk("Dump %p:\n", priv);
1533 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001534 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1535 offset = 0;
1536 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001537 offset += sprintf(buf + offset, "Mac:");
1538 for (j = 0; j < ETH_ALEN; j++) {
1539 offset += sprintf(buf + offset,
1540 "%2.2x ",
1541 rulla->mac_addr[j] & 0xff);
1542 }
1543 offset += sprintf(buf + offset, "Atm:");
1544 for (j = 0; j < ATM_ESA_LEN; j++) {
1545 offset += sprintf(buf + offset,
1546 "%2.2x ",
1547 rulla->atm_addr[j] & 0xff);
1548 }
1549 offset += sprintf(buf + offset,
1550 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1551 rulla->vcc ? rulla->vcc->vpi : 0,
1552 rulla->vcc ? rulla->vcc->vci : 0,
1553 rulla->recv_vcc ? rulla->recv_vcc->
1554 vpi : 0,
1555 rulla->recv_vcc ? rulla->recv_vcc->
1556 vci : 0, rulla->last_used,
1557 rulla->timestamp, rulla->no_tries);
1558 offset +=
1559 sprintf(buf + offset,
1560 "Flags:%x, Packets_flooded:%x, Status: %s ",
1561 rulla->flags, rulla->packets_flooded,
1562 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001563 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001564 }
Chas Williams1fa99612006-09-29 17:11:47 -07001565 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001566
1567 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001568 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001569 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001570 offset = 0;
1571 offset += sprintf(buf + offset, "Mac:");
1572 for (j = 0; j < ETH_ALEN; j++) {
1573 offset += sprintf(buf + offset, "%2.2x ",
1574 rulla->mac_addr[j] & 0xff);
1575 }
1576 offset += sprintf(buf + offset, "Atm:");
1577 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));
Chas Williamsd0732f62006-09-29 17:14:27 -07001593 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001594 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001595
1596 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001597 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001598 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001599 offset = 0;
1600 offset += sprintf(buf + offset, "Mac:");
1601 for (j = 0; j < ETH_ALEN; j++) {
1602 offset += sprintf(buf + offset, "%2.2x ",
1603 rulla->mac_addr[j] & 0xff);
1604 }
1605 offset += sprintf(buf + offset, "Atm:");
1606 for (j = 0; j < ATM_ESA_LEN; j++) {
1607 offset += sprintf(buf + offset, "%2.2x ",
1608 rulla->atm_addr[j] & 0xff);
1609 }
1610 offset += sprintf(buf + offset,
1611 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1612 rulla->vcc ? rulla->vcc->vpi : 0,
1613 rulla->vcc ? rulla->vcc->vci : 0,
1614 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1615 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1616 rulla->last_used,
1617 rulla->timestamp, rulla->no_tries);
1618 offset += sprintf(buf + offset,
1619 "Flags:%x, Packets_flooded:%x, Status: %s ",
1620 rulla->flags, rulla->packets_flooded,
1621 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001622 printk("%s", buf);
1623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
Chas Williamsd0732f62006-09-29 17:14:27 -07001625 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001626 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001627 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001628 offset = 0;
1629 offset += sprintf(buf + offset, "Mac:");
1630 for (j = 0; j < ETH_ALEN; j++) {
1631 offset += sprintf(buf + offset, "%2.2x ",
1632 rulla->mac_addr[j] & 0xff);
1633 }
1634 offset += sprintf(buf + offset, "Atm:");
1635 for (j = 0; j < ATM_ESA_LEN; j++) {
1636 offset += sprintf(buf + offset, "%2.2x ",
1637 rulla->atm_addr[j] & 0xff);
1638 }
1639 offset += sprintf(buf + offset,
1640 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1641 rulla->vcc ? rulla->vcc->vpi : 0,
1642 rulla->vcc ? rulla->vcc->vci : 0,
1643 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1644 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1645 rulla->last_used,
1646 rulla->timestamp, rulla->no_tries);
1647 offset += sprintf(buf + offset,
1648 "Flags:%x, Packets_flooded:%x, Status: %s ",
1649 rulla->flags, rulla->packets_flooded,
1650 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001651 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001652 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654}
Chas Williamsd0732f62006-09-29 17:14:27 -07001655#else
1656#define dump_arp_table(priv) do { } while (0)
1657#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
1659/*
1660 * Destruction of arp-cache
1661 */
Chas Williams1fa99612006-09-29 17:11:47 -07001662static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663{
1664 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001665 struct hlist_node *node, *next;
1666 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001667 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
Chas Williams987e46b2006-09-29 17:15:59 -07001669 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001670
1671 /*
1672 * Remove all entries
1673 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
1675 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001676 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001677 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001678 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001679 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001680 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001681 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001682 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001683
1684 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001685 del_timer_sync(&entry->timer);
1686 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001687 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001688 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001689 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001690 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1691
1692 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001693 del_timer_sync(&entry->timer);
1694 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001695 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001696 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001697 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001698 INIT_HLIST_HEAD(&priv->lec_no_forward);
1699
1700 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001701 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1702 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001703 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001704 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001705 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001706 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001707 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1709}
1710
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001711/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 * Find entry by mac_address
1713 */
Chas Williams1fa99612006-09-29 17:11:47 -07001714static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001715 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716{
Chas Williamsd0732f62006-09-29 17:14:27 -07001717 struct hlist_node *node;
1718 struct hlist_head *head;
1719 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
Stephen Hemminger52240062007-08-28 15:22:09 -07001721 pr_debug("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001722 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1723 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
Chas Williams1fa99612006-09-29 17:11:47 -07001724
Chas Williamsd0732f62006-09-29 17:14:27 -07001725 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1726 hlist_for_each_entry(entry, node, head, next) {
1727 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1728 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001729 }
Chas Williams1fa99612006-09-29 17:11:47 -07001730 }
1731 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
1733
Chas Williams1fa99612006-09-29 17:11:47 -07001734static struct lec_arp_table *make_entry(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001735 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736{
Chas Williams1fa99612006-09-29 17:11:47 -07001737 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
Chas Williams1fa99612006-09-29 17:11:47 -07001739 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1740 if (!to_return) {
1741 printk("LEC: Arp entry kmalloc failed\n");
1742 return NULL;
1743 }
1744 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001745 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001746 setup_timer(&to_return->timer, lec_arp_expire_arp,
1747 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001748 to_return->last_used = jiffies;
1749 to_return->priv = priv;
1750 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001751 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001752 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753}
1754
Chas Williams1fa99612006-09-29 17:11:47 -07001755/* Arp sent timer expired */
1756static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757{
Chas Williams1fa99612006-09-29 17:11:47 -07001758 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
Chas Williams1fa99612006-09-29 17:11:47 -07001760 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
Stephen Hemminger52240062007-08-28 15:22:09 -07001762 pr_debug("lec_arp_expire_arp\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001763 if (entry->status == ESI_ARP_PENDING) {
1764 if (entry->no_tries <= entry->priv->max_retry_count) {
1765 if (entry->is_rdesc)
1766 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1767 entry->mac_addr, NULL, NULL);
1768 else
1769 send_to_lecd(entry->priv, l_arp_xmt,
1770 entry->mac_addr, NULL, NULL);
1771 entry->no_tries++;
1772 }
1773 mod_timer(&entry->timer, jiffies + (1 * HZ));
1774 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775}
1776
Chas Williams1fa99612006-09-29 17:11:47 -07001777/* Unknown/unused vcc expire, remove associated entry */
1778static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779{
1780 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001781 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1782 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
Chas Williams1fa99612006-09-29 17:11:47 -07001784 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785
Stephen Hemminger52240062007-08-28 15:22:09 -07001786 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001787 to_remove, priv,
1788 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1789 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
1791 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001792 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1794
Chas Williams1fa99612006-09-29 17:11:47 -07001795 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001796 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797}
1798
1799/*
1800 * Expire entries.
1801 * 1. Re-set timer
1802 * 2. For each entry, delete entries that have aged past the age limit.
1803 * 3. For each entry, depending on the status of the entry, perform
1804 * the following maintenance.
1805 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1806 * tick_count is above the max_unknown_frame_time, clear
1807 * the tick_count to zero and clear the packets_flooded counter
1808 * to zero. This supports the packet rate limit per address
1809 * while flooding unknowns.
1810 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1811 * than or equal to the path_switching_delay, change the status
1812 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1813 * regardless of the progress of the flush protocol.
1814 */
David Howellsc4028952006-11-22 14:57:56 +00001815static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816{
1817 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001818 struct lec_priv *priv =
1819 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001820 struct hlist_node *node, *next;
1821 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001822 unsigned long now;
1823 unsigned long time_to_check;
1824 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825
Stephen Hemminger52240062007-08-28 15:22:09 -07001826 pr_debug("lec_arp_check_expire %p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001828restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001830 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001831 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001832 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 priv->topology_change)
1834 time_to_check = priv->forward_delay_time;
1835 else
1836 time_to_check = priv->aging_time;
1837
Stephen Hemminger52240062007-08-28 15:22:09 -07001838 pr_debug("About to expire: %lx - %lx > %lx\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001839 now, entry->last_used, time_to_check);
1840 if (time_after(now, entry->last_used + time_to_check)
1841 && !(entry->flags & LEC_PERMANENT_FLAG)
1842 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 /* Remove entry */
Stephen Hemminger52240062007-08-28 15:22:09 -07001844 pr_debug("LEC:Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001846 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 } else {
1848 /* Something else */
1849 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001850 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001852 entry->timestamp +
1853 priv->
1854 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 entry->timestamp = jiffies;
1856 entry->packets_flooded = 0;
1857 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001858 send_to_lecd(priv, l_svc_setup,
1859 entry->mac_addr,
1860 entry->atm_addr,
1861 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 }
Chas Williams1fa99612006-09-29 17:11:47 -07001863 if (entry->status == ESI_FLUSH_PENDING
1864 &&
1865 time_after_eq(now, entry->timestamp +
1866 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001868 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
Chas Williams6656e3c2006-09-29 17:17:17 -07001870 lec_arp_hold(entry);
1871 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1872 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
Stephen Hemminger162619e2009-01-09 13:01:01 +00001873 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001875 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001876 lec_arp_put(entry);
1877 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 }
1880 }
1881 }
1882 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1883
Chas Williams987e46b2006-09-29 17:15:59 -07001884 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885}
Chas Williams1fa99612006-09-29 17:11:47 -07001886
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887/*
1888 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001889 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 */
Chas Williams1fa99612006-09-29 17:11:47 -07001891static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001892 const unsigned char *mac_to_find, int is_rdesc,
Chas Williams1fa99612006-09-29 17:11:47 -07001893 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894{
1895 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001896 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 struct atm_vcc *found;
1898
Chas Williams1fa99612006-09-29 17:11:47 -07001899 if (mac_to_find[0] & 0x01) {
1900 switch (priv->lane_version) {
1901 case 1:
1902 return priv->mcast_vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07001903 case 2: /* LANE2 wants arp for multicast addresses */
1904 if (!compare_ether_addr(mac_to_find, bus_mac))
1905 return priv->mcast_vcc;
1906 break;
1907 default:
1908 break;
1909 }
1910 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911
1912 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001913 entry = lec_arp_find(priv, mac_to_find);
1914
1915 if (entry) {
1916 if (entry->status == ESI_FORWARD_DIRECT) {
1917 /* Connection Ok */
1918 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001919 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001920 *ret_entry = entry;
1921 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001923 }
1924 /*
1925 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001926 * so another LE_ARP request can be made for this frame.
1927 */
1928 if (entry->status == ESI_ARP_PENDING) {
1929 entry->no_tries = 0;
1930 }
Chas Williams1fa99612006-09-29 17:11:47 -07001931 /*
1932 * Data direct VC not yet set up, check to see if the unknown
1933 * frame count is greater than the limit. If the limit has
1934 * not been reached, allow the caller to send packet to
1935 * BUS.
1936 */
1937 if (entry->status != ESI_FLUSH_PENDING &&
1938 entry->packets_flooded <
1939 priv->maximum_unknown_frame_count) {
1940 entry->packets_flooded++;
Stephen Hemminger52240062007-08-28 15:22:09 -07001941 pr_debug("LEC_ARP: Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001942 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001944 }
1945 /*
1946 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 * or BUS flood limit was reached for an entry which is
1948 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1949 */
Chas Williams6656e3c2006-09-29 17:17:17 -07001950 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001951 *ret_entry = entry;
Stephen Hemminger52240062007-08-28 15:22:09 -07001952 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
Chas Williams1fa99612006-09-29 17:11:47 -07001953 entry->vcc);
1954 found = NULL;
1955 } else {
1956 /* No matching entry was found */
1957 entry = make_entry(priv, mac_to_find);
Stephen Hemminger52240062007-08-28 15:22:09 -07001958 pr_debug("LEC_ARP: Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001959 if (!entry) {
1960 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001962 }
1963 lec_arp_add(priv, entry);
1964 /* We want arp-request(s) to be sent */
1965 entry->packets_flooded = 1;
1966 entry->status = ESI_ARP_PENDING;
1967 entry->no_tries = 1;
1968 entry->last_used = entry->timestamp = jiffies;
1969 entry->is_rdesc = is_rdesc;
1970 if (entry->is_rdesc)
1971 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1972 NULL);
1973 else
1974 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1975 entry->timer.expires = jiffies + (1 * HZ);
1976 entry->timer.function = lec_arp_expire_arp;
1977 add_timer(&entry->timer);
1978 found = priv->mcast_vcc;
1979 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
1981out:
1982 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1983 return found;
1984}
1985
1986static int
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001987lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07001988 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989{
1990 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001991 struct hlist_node *node, *next;
1992 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001993 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
Stephen Hemminger52240062007-08-28 15:22:09 -07001995 pr_debug("lec_addr_delete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001997 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001998 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001999 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2000 && (permanent ||
2001 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002003 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002004 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002006 return 0;
2007 }
2008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002010 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011}
2012
2013/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002014 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 */
2016static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002017lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
2018 const unsigned char *atm_addr, unsigned long remoteflag,
Chas Williams1fa99612006-09-29 17:11:47 -07002019 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020{
2021 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002022 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07002023 struct lec_arp_table *entry, *tmp;
2024 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025
Stephen Hemminger52240062007-08-28 15:22:09 -07002026 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2027 pr_debug("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
Chas Williams1fa99612006-09-29 17:11:47 -07002028 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2029 mac_addr[4], mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030
2031 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002032 entry = lec_arp_find(priv, mac_addr);
2033 if (entry == NULL && targetless_le_arp)
2034 goto out; /*
2035 * LANE2: ignore targetless LE_ARPs for which
2036 * we have no entry in the cache. 7.1.30
2037 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002038 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2039 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2040 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2041 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002042 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002043 tmp = lec_arp_find(priv, mac_addr);
2044 if (tmp) {
2045 del_timer(&tmp->timer);
2046 tmp->status = ESI_FORWARD_DIRECT;
2047 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2048 tmp->vcc = entry->vcc;
2049 tmp->old_push = entry->old_push;
2050 tmp->last_used = jiffies;
2051 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002052 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002053 entry = tmp;
2054 } else {
2055 entry->status = ESI_FORWARD_DIRECT;
2056 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2057 entry->last_used = jiffies;
2058 lec_arp_add(priv, entry);
2059 }
2060 if (remoteflag)
2061 entry->flags |= LEC_REMOTE_FLAG;
2062 else
2063 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002064 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002065 dump_arp_table(priv);
2066 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002067 }
Chas Williams1fa99612006-09-29 17:11:47 -07002068 }
2069 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002070
Chas Williams1fa99612006-09-29 17:11:47 -07002071 entry = lec_arp_find(priv, mac_addr);
2072 if (!entry) {
2073 entry = make_entry(priv, mac_addr);
2074 if (!entry)
2075 goto out;
2076 entry->status = ESI_UNKNOWN;
2077 lec_arp_add(priv, entry);
2078 /* Temporary, changes before end of function */
2079 }
2080 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2081 del_timer(&entry->timer);
2082 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002083 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002084 if (entry != tmp &&
2085 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2086 /* Vcc to this host exists */
2087 if (tmp->status > ESI_VC_PENDING) {
2088 /*
2089 * ESI_FLUSH_PENDING,
2090 * ESI_FORWARD_DIRECT
2091 */
2092 entry->vcc = tmp->vcc;
2093 entry->old_push = tmp->old_push;
2094 }
2095 entry->status = tmp->status;
2096 break;
2097 }
2098 }
2099 }
2100 if (remoteflag)
2101 entry->flags |= LEC_REMOTE_FLAG;
2102 else
2103 entry->flags &= ~LEC_REMOTE_FLAG;
2104 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2105 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002106 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002107 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002108 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002109 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110out:
2111 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2112}
2113
2114/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002115 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 */
2117static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002118lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002119 struct atm_vcc *vcc,
2120 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121{
2122 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002123 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002124 struct lec_arp_table *entry;
2125 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
2127 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002128 if (ioc_data->receive == 2) {
2129 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
Stephen Hemminger52240062007-08-28 15:22:09 -07002131 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002133 entry = lec_arp_find(priv, bus_mac);
2134 if (!entry) {
2135 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002137 }
2138 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2139 entry->recv_vcc = vcc;
2140 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002142 entry = make_entry(priv, bus_mac);
2143 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002145 del_timer(&entry->timer);
2146 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2147 entry->recv_vcc = vcc;
2148 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002149 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002150 goto out;
2151 } else if (ioc_data->receive == 1) {
2152 /*
2153 * Vcc which we don't want to make default vcc,
2154 * attach it anyway.
2155 */
Stephen Hemminger52240062007-08-28 15:22:09 -07002156 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002157 ("LEC_ARP:Attaching data direct, not default: "
2158 "%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",
2159 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2160 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2161 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2162 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2163 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2164 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2165 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2166 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2167 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2168 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2169 entry = make_entry(priv, bus_mac);
2170 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002172 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2173 memset(entry->mac_addr, 0, ETH_ALEN);
2174 entry->recv_vcc = vcc;
2175 entry->old_recv_push = old_push;
2176 entry->status = ESI_UNKNOWN;
2177 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2178 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002179 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002180 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 dump_arp_table(priv);
2182 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002183 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002184 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002185 ("LEC_ARP:Attaching data direct, default: "
2186 "%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",
2187 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2188 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2189 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2190 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2191 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2192 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2193 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2194 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2195 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2196 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2197 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002198 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002199 if (memcmp
2200 (ioc_data->atm_addr, entry->atm_addr,
2201 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002202 pr_debug("LEC_ARP: Attaching data direct\n");
2203 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07002204 entry->vcc ? entry->vcc->vci : 0,
2205 entry->recv_vcc ? entry->recv_vcc->
2206 vci : 0);
2207 found_entry = 1;
2208 del_timer(&entry->timer);
2209 entry->vcc = vcc;
2210 entry->old_push = old_push;
2211 if (entry->status == ESI_VC_PENDING) {
2212 if (priv->maximum_unknown_frame_count
2213 == 0)
2214 entry->status =
2215 ESI_FORWARD_DIRECT;
2216 else {
2217 entry->timestamp = jiffies;
2218 entry->status =
2219 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002221 send_to_lecd(priv, l_flush_xmt,
2222 NULL,
2223 entry->atm_addr,
2224 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002226 }
2227 } else {
2228 /*
2229 * They were forming a connection
2230 * to us, and we to them. Our
2231 * ATM address is numerically lower
2232 * than theirs, so we make connection
2233 * we formed into default VCC (8.1.11).
2234 * Connection they made gets torn
2235 * down. This might confuse some
2236 * clients. Can be changed if
2237 * someone reports trouble...
2238 */
2239 ;
2240 }
2241 }
2242 }
2243 }
2244 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002245 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002246 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002248 }
2249 /*
2250 * Not found, snatch address from first data packet that arrives
2251 * from this vcc
2252 */
2253 entry = make_entry(priv, bus_mac);
2254 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002256 entry->vcc = vcc;
2257 entry->old_push = old_push;
2258 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2259 memset(entry->mac_addr, 0, ETH_ALEN);
2260 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002261 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002262 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2263 entry->timer.function = lec_arp_expire_vcc;
2264 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002265 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 dump_arp_table(priv);
2267out:
2268 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2269}
2270
Chas Williams1fa99612006-09-29 17:11:47 -07002271static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272{
2273 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002274 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002275 struct lec_arp_table *entry;
2276 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277
Stephen Hemminger52240062007-08-28 15:22:09 -07002278 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002279restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002280 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2281 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002282 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002283 if (entry->flush_tran_id == tran_id
2284 && entry->status == ESI_FLUSH_PENDING) {
2285 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002286 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002287
Chas Williams6656e3c2006-09-29 17:17:17 -07002288 lec_arp_hold(entry);
2289 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2290 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
Stephen Hemminger162619e2009-01-09 13:01:01 +00002291 lec_send(vcc, skb);
Chas Williams6656e3c2006-09-29 17:17:17 -07002292 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002293 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002294 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002295 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002296 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002297 }
2298 }
2299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002301 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302}
2303
2304static void
2305lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002306 const unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307{
2308 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002309 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002310 struct lec_arp_table *entry;
2311 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
2313 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002314 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002315 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002316 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2317 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002318 pr_debug("Set flush transaction id to %lx for %p\n",
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002319 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002320 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2323}
2324
Chas Williams1fa99612006-09-29 17:11:47 -07002325static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326{
2327 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002328 unsigned char mac_addr[] = {
2329 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2330 };
2331 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 struct lec_vcc_priv *vpriv;
2333 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002334
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2336 return -ENOMEM;
2337 vpriv->xoff = 0;
2338 vpriv->old_pop = vcc->pop;
2339 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002340 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002342 to_add = make_entry(priv, mac_addr);
2343 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 vcc->pop = vpriv->old_pop;
2345 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002346 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002348 }
2349 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2350 to_add->status = ESI_FORWARD_DIRECT;
2351 to_add->flags |= LEC_PERMANENT_FLAG;
2352 to_add->vcc = vcc;
2353 to_add->old_push = vcc->push;
2354 vcc->push = lec_push;
2355 priv->mcast_vcc = vcc;
2356 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357out:
2358 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002359 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360}
2361
Chas Williams1fa99612006-09-29 17:11:47 -07002362static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363{
2364 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002365 struct hlist_node *node, *next;
2366 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002367 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
Stephen Hemminger52240062007-08-28 15:22:09 -07002369 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002370 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002371
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002373
Chas Williams1fa99612006-09-29 17:11:47 -07002374 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002375 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002376 if (vcc == entry->vcc) {
2377 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002378 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002379 if (priv->mcast_vcc == vcc) {
2380 priv->mcast_vcc = NULL;
2381 }
2382 }
2383 }
2384 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385
Chas Williamsd0732f62006-09-29 17:14:27 -07002386 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2387 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002388 lec_arp_clear_vccs(entry);
2389 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002390 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002391 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002392 }
Chas Williams1fa99612006-09-29 17:11:47 -07002393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
Chas Williamsd0732f62006-09-29 17:14:27 -07002395 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002396 if (entry->recv_vcc == vcc) {
2397 lec_arp_clear_vccs(entry);
2398 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002399 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002400 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002401 }
Chas Williams1fa99612006-09-29 17:11:47 -07002402 }
2403
Chas Williamsd0732f62006-09-29 17:14:27 -07002404 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002405 if (entry->recv_vcc == vcc) {
2406 lec_arp_clear_vccs(entry);
2407 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002408 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002409 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002410 }
Chas Williams1fa99612006-09-29 17:11:47 -07002411 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412
2413 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2414 dump_arp_table(priv);
2415}
2416
2417static void
2418lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002419 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420{
Chas Williams1fa99612006-09-29 17:11:47 -07002421 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002422 struct hlist_node *node, *next;
2423 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002424 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2425 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002427 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
Chas Williams1fa99612006-09-29 17:11:47 -07002429 if (priv->is_trdev)
2430 src = tr_hdr->h_source;
2431 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002433 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434
2435 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002436 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2437 if (vcc == entry->vcc) {
2438 del_timer(&entry->timer);
2439 memcpy(entry->mac_addr, src, ETH_ALEN);
2440 entry->status = ESI_FORWARD_DIRECT;
2441 entry->last_used = jiffies;
2442 /* We might have got an entry */
2443 if ((tmp = lec_arp_find(priv, src))) {
2444 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002445 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002446 }
2447 hlist_del(&entry->next);
2448 lec_arp_add(priv, entry);
2449 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002450 }
Chas Williams1fa99612006-09-29 17:11:47 -07002451 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002452 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453out:
2454 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2455}
Chas Williams1fa99612006-09-29 17:11:47 -07002456
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457MODULE_LICENSE("GPL");