blob: 42749b7b917cc7d97e3f97bd147e398543b4c3b7 [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);
Stephen Hemminger3c805a22009-08-31 19:50:42 +000062static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
63 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static int lec_close(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
Stephen Hemminger3c805a22009-08-31 19:50:42 +0000250static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
251 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Chas Williamsd44f7742006-09-29 17:11:14 -0700253 struct sk_buff *skb2;
Wang Chen524ad0a2008-11-12 23:39:10 -0800254 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700255 struct lecdatahdr_8023 *lec_h;
256 struct atm_vcc *vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700258 unsigned char *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 int min_frame_size;
260#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700261 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700263 int is_rdesc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700265 char buf[300];
266 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267#endif /* DUMP_PACKETS >0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Stephen Hemminger52240062007-08-28 15:22:09 -0700269 pr_debug("lec_start_xmit called\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700270 if (!priv->lecd) {
271 printk("%s:No lecd attached\n", dev->name);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000272 dev->stats.tx_errors++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700273 netif_stop_queue(dev);
Patrick McHardy81fbbf62009-06-12 05:34:37 +0000274 kfree_skb(skb);
275 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700276 }
277
Stephen Hemminger52240062007-08-28 15:22:09 -0700278 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700279 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700280 (long)skb_end_pointer(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700282 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
283 lec_handle_bridge(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#endif
285
Chas Williamsd44f7742006-09-29 17:11:14 -0700286 /* Make sure we have room for lec_id */
287 if (skb_headroom(skb) < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Stephen Hemminger52240062007-08-28 15:22:09 -0700289 pr_debug("lec_start_xmit: reallocating skb\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700290 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
291 kfree_skb(skb);
292 if (skb2 == NULL)
Patrick McHardy6ed10652009-06-23 06:03:08 +0000293 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700294 skb = skb2;
295 }
296 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Chas Williamsd44f7742006-09-29 17:11:14 -0700298 /* Put le header to place, works for TokenRing too */
299 lec_h = (struct lecdatahdr_8023 *)skb->data;
300 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700303 /*
304 * Ugly. Use this to realign Token Ring packets for
305 * e.g. PCA-200E driver.
306 */
307 if (priv->is_trdev) {
308 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
309 kfree_skb(skb);
310 if (skb2 == NULL)
Patrick McHardy6ed10652009-06-23 06:03:08 +0000311 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700312 skb = skb2;
313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314#endif
315
316#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700317 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
318 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700320 for (i = 0; i < skb->len && i < 99; i++) {
321 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700324 for (i = 0; i < skb->len && i < 30; i++) {
325 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700328 if (i == skb->len)
329 printk("%s\n", buf);
330 else
331 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#endif /* DUMP_PACKETS > 0 */
333
Chas Williamsd44f7742006-09-29 17:11:14 -0700334 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700336 if (priv->is_trdev)
337 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 else
339#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700340 min_frame_size = LEC_MINIMUM_8023_SIZE;
341 if (skb->len < min_frame_size) {
342 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
343 skb2 = skb_copy_expand(skb, 0,
344 min_frame_size - skb->truesize,
345 GFP_ATOMIC);
346 dev_kfree_skb(skb);
347 if (skb2 == NULL) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000348 dev->stats.tx_dropped++;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000349 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700350 }
351 skb = skb2;
352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700354 }
355
356 /* Send to right vcc */
357 is_rdesc = 0;
358 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700360 if (priv->is_trdev) {
361 dst = get_tr_dst(skb->data + 2, rdesc);
362 if (dst == NULL) {
363 dst = rdesc;
364 is_rdesc = 1;
365 }
366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700368 entry = NULL;
369 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
Andrew Morton58c14a82007-09-26 22:31:19 -0700370 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700371 vcc, vcc ? vcc->flags : 0, entry);
372 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
373 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700374 pr_debug("%s:lec_start_xmit: queuing packet, ",
Chas Williamsd44f7742006-09-29 17:11:14 -0700375 dev->name);
Johannes Berge1749612008-10-27 15:59:26 -0700376 pr_debug("MAC address %pM\n", lec_h->h_dest);
Chas Williamsd44f7742006-09-29 17:11:14 -0700377 skb_queue_tail(&entry->tx_wait, skb);
378 } else {
Stephen Hemminger52240062007-08-28 15:22:09 -0700379 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700380 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
381 dev->name);
Johannes Berge1749612008-10-27 15:59:26 -0700382 pr_debug("MAC address %pM\n", lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000383 dev->stats.tx_dropped++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700384 dev_kfree_skb(skb);
385 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700386 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700387 }
388#if DUMP_PACKETS > 0
389 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700391
392 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700393 pr_debug("lec.c: emptying tx queue, ");
Johannes Berge1749612008-10-27 15:59:26 -0700394 pr_debug("MAC address %pM\n", lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000395 lec_send(vcc, skb2);
Chas Williamsd44f7742006-09-29 17:11:14 -0700396 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Stephen Hemminger162619e2009-01-09 13:01:01 +0000398 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 if (!atm_may_send(vcc, 0)) {
401 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
402
403 vpriv->xoff = 1;
404 netif_stop_queue(dev);
405
406 /*
407 * vcc->pop() might have occurred in between, making
408 * the vcc usuable again. Since xmit is serialized,
409 * this is the only situation we have to re-test.
410 */
411
412 if (atm_may_send(vcc, 0))
413 netif_wake_queue(dev);
414 }
415
Chas Williams6656e3c2006-09-29 17:17:17 -0700416out:
417 if (entry)
418 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 dev->trans_start = jiffies;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000420 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421}
422
423/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700424static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425{
Chas Williamsd44f7742006-09-29 17:11:14 -0700426 netif_stop_queue(dev);
427 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428}
429
Chas Williamsd44f7742006-09-29 17:11:14 -0700430static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
432 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700433 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800434 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700435 struct atmlec_msg *mesg;
436 struct lec_arp_table *entry;
437 int i;
438 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700441 mesg = (struct atmlec_msg *)skb->data;
442 tmp = skb->data;
443 tmp += sizeof(struct atmlec_msg);
Stephen Hemminger52240062007-08-28 15:22:09 -0700444 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700445 switch (mesg->type) {
446 case l_set_mac_addr:
447 for (i = 0; i < 6; i++) {
448 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
449 }
450 break;
451 case l_del_mac_addr:
452 for (i = 0; i < 6; i++) {
453 dev->dev_addr[i] = 0;
454 }
455 break;
456 case l_addr_delete:
457 lec_addr_delete(priv, mesg->content.normal.atm_addr,
458 mesg->content.normal.flag);
459 break;
460 case l_topology_change:
461 priv->topology_change = mesg->content.normal.flag;
462 break;
463 case l_flush_complete:
464 lec_flush_complete(priv, mesg->content.normal.flag);
465 break;
466 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700468 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
469 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
471
Chas Williamsd44f7742006-09-29 17:11:14 -0700472 if (mesg->content.normal.no_source_le_narp)
473 break;
474 /* FALL THROUGH */
475 case l_arp_update:
476 lec_arp_update(priv, mesg->content.normal.mac_addr,
477 mesg->content.normal.atm_addr,
478 mesg->content.normal.flag,
479 mesg->content.normal.targetless_le_arp);
Stephen Hemminger52240062007-08-28 15:22:09 -0700480 pr_debug("lec: in l_arp_update\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700481 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700482 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700483 mesg->sizeoftlvs);
484 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
485 tmp, mesg->sizeoftlvs);
486 }
487 break;
488 case l_config:
489 priv->maximum_unknown_frame_count =
490 mesg->content.config.maximum_unknown_frame_count;
491 priv->max_unknown_frame_time =
492 (mesg->content.config.max_unknown_frame_time * HZ);
493 priv->max_retry_count = mesg->content.config.max_retry_count;
494 priv->aging_time = (mesg->content.config.aging_time * HZ);
495 priv->forward_delay_time =
496 (mesg->content.config.forward_delay_time * HZ);
497 priv->arp_response_time =
498 (mesg->content.config.arp_response_time * HZ);
499 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
500 priv->path_switching_delay =
501 (mesg->content.config.path_switching_delay * HZ);
502 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 priv->lane2_ops = NULL;
504 if (priv->lane_version > 1)
505 priv->lane2_ops = &lane2_ops;
Stephen Hemminger1f1900f2009-03-21 13:37:28 -0700506 if (dev_set_mtu(dev, mesg->content.config.mtu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 printk("%s: change_mtu to %d failed\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700508 mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700510 break;
511 case l_flush_tran_id:
512 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
513 mesg->content.normal.flag);
514 break;
515 case l_set_lecid:
516 priv->lecid =
517 (unsigned short)(0xffff & mesg->content.normal.flag);
518 break;
519 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700521 {
Johannes Berge1749612008-10-27 15:59:26 -0700522 pr_debug("%s: bridge zeppelin asks about %pM\n",
523 dev->name, mesg->content.proxy.mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Michał Mirosławda678292009-06-05 05:35:28 +0000525 if (br_fdb_test_addr_hook == NULL)
Chas Williamsd44f7742006-09-29 17:11:14 -0700526 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Michał Mirosławda678292009-06-05 05:35:28 +0000528 if (br_fdb_test_addr_hook(dev,
529 mesg->content.proxy.mac_addr)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700530 /* hit from bridge table, send LE_ARP_RESPONSE */
531 struct sk_buff *skb2;
532 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Stephen Hemminger52240062007-08-28 15:22:09 -0700534 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700535 ("%s: entry found, responding to zeppelin\n",
536 dev->name);
537 skb2 =
538 alloc_skb(sizeof(struct atmlec_msg),
539 GFP_ATOMIC);
Michał Mirosławda678292009-06-05 05:35:28 +0000540 if (skb2 == NULL)
Chas Williamsd44f7742006-09-29 17:11:14 -0700541 break;
Chas Williamsd44f7742006-09-29 17:11:14 -0700542 skb2->len = sizeof(struct atmlec_msg);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300543 skb_copy_to_linear_data(skb2, mesg,
544 sizeof(*mesg));
Chas Williamsd44f7742006-09-29 17:11:14 -0700545 atm_force_charge(priv->lecd, skb2->truesize);
546 sk = sk_atm(priv->lecd);
547 skb_queue_tail(&sk->sk_receive_queue, skb2);
548 sk->sk_data_ready(sk, skb2->len);
549 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700550 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700552 break;
553 default:
554 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
555 dev_kfree_skb(skb);
556 return -EINVAL;
557 }
558 dev_kfree_skb(skb);
559 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560}
561
Chas Williamsd44f7742006-09-29 17:11:14 -0700562static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563{
Chas Williamsd44f7742006-09-29 17:11:14 -0700564 struct sk_buff *skb;
565 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800566 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Chas Williamsd44f7742006-09-29 17:11:14 -0700568 priv->lecd = NULL;
569 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Chas Williamsd44f7742006-09-29 17:11:14 -0700571 netif_stop_queue(dev);
572 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Chas Williamsd44f7742006-09-29 17:11:14 -0700574 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700576 dev->name);
577 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
578 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700580 }
581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700583 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584}
585
586static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700587 .close = lec_atm_close,
588 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589};
590
591static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700592 .ops = &lecdev_ops,
593 .type = "lec",
594 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700595 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596};
597
598/*
599 * LANE2: new argument struct sk_buff *data contains
600 * the LE_ARP based TLVs introduced in the LANE2 spec
601 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700602static int
603send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700604 const unsigned char *mac_addr, const unsigned char *atm_addr,
Chas Williamsd44f7742006-09-29 17:11:14 -0700605 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606{
607 struct sock *sk;
608 struct sk_buff *skb;
609 struct atmlec_msg *mesg;
610
611 if (!priv || !priv->lecd) {
612 return -1;
613 }
614 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
615 if (!skb)
616 return -1;
617 skb->len = sizeof(struct atmlec_msg);
618 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700619 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700621 if (data != NULL)
622 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 if (mac_addr)
624 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700625 else
626 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 if (atm_addr)
628 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
629
Chas Williamsd44f7742006-09-29 17:11:14 -0700630 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 sk = sk_atm(priv->lecd);
632 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700633 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Chas Williamsd44f7742006-09-29 17:11:14 -0700635 if (data != NULL) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700636 pr_debug("lec: about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700637 atm_force_charge(priv->lecd, data->truesize);
638 skb_queue_tail(&sk->sk_receive_queue, data);
639 sk->sk_data_ready(sk, skb->len);
640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Chas Williamsd44f7742006-09-29 17:11:14 -0700642 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643}
644
645/* shamelessly stolen from drivers/net/net_init.c */
646static int lec_change_mtu(struct net_device *dev, int new_mtu)
647{
Chas Williamsd44f7742006-09-29 17:11:14 -0700648 if ((new_mtu < 68) || (new_mtu > 18190))
649 return -EINVAL;
650 dev->mtu = new_mtu;
651 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652}
653
654static void lec_set_multicast_list(struct net_device *dev)
655{
Chas Williamsd44f7742006-09-29 17:11:14 -0700656 /*
657 * by default, all multicast frames arrive over the bus.
658 * eventually support selective multicast service
659 */
660 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661}
662
Stephen Hemminger004b3222009-01-09 13:01:02 +0000663static const struct net_device_ops lec_netdev_ops = {
664 .ndo_open = lec_open,
665 .ndo_stop = lec_close,
666 .ndo_start_xmit = lec_start_xmit,
667 .ndo_change_mtu = lec_change_mtu,
668 .ndo_tx_timeout = lec_tx_timeout,
669 .ndo_set_multicast_list = lec_set_multicast_list,
670};
671
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700672static const unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700673 0xff,
674 0x00,
675 0x01,
676 0x01
677};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Scott Talbert4a7097f2005-09-29 17:30:54 -0700679#define LEC_DATA_DIRECT_8023 2
680#define LEC_DATA_DIRECT_8025 3
681
682static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700683{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700684 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
685 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700686}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700687
Chas Williamsd44f7742006-09-29 17:11:14 -0700688static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700690 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700691 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800692 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
694#if DUMP_PACKETS >0
Chas Williamsd44f7742006-09-29 17:11:14 -0700695 int i = 0;
696 char buf[300];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Chas Williamsd44f7742006-09-29 17:11:14 -0700698 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
699 vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700701 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700702 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700703 lec_vcc_close(priv, vcc);
704 return;
705 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700707 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
708 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700710 for (i = 0; i < skb->len && i < 99; i++) {
711 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700714 for (i = 0; i < skb->len && i < 30; i++) {
715 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
716 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700718 if (i == skb->len)
719 printk("%s\n", buf);
720 else
721 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700723 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 struct sock *sk = sk_atm(vcc);
725
Stephen Hemminger52240062007-08-28 15:22:09 -0700726 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700727 skb_queue_tail(&sk->sk_receive_queue, skb);
728 sk->sk_data_ready(sk, skb->len);
729 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700730 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700731 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Chas Williamsd44f7742006-09-29 17:11:14 -0700733 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800734 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700735 !priv->lecd || !(dev->flags & IFF_UP)) {
736 /*
737 * Probably looping back, or if lecd is missing,
738 * lecd has gone down
739 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700740 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700741 dev_kfree_skb(skb);
742 return;
743 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700745 if (priv->is_trdev)
746 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
747 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700749 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700750
Chas Williamsd44f7742006-09-29 17:11:14 -0700751 /*
752 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700753 * the LE_ARP cache entry, delete the LE_ARP cache entry.
754 */
755 spin_lock_irqsave(&priv->lec_arp_lock, flags);
756 if (lec_is_data_direct(vcc)) {
757#ifdef CONFIG_TR
758 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700759 src =
760 ((struct lecdatahdr_8025 *)skb->data)->
761 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700762 else
763#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700764 src =
765 ((struct lecdatahdr_8023 *)skb->data)->
766 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700767 entry = lec_arp_find(priv, src);
768 if (entry && entry->vcc != vcc) {
769 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700770 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700771 }
772 }
773 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Chas Williamsd44f7742006-09-29 17:11:14 -0700775 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
776 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700778 dev_kfree_skb(skb);
779 return;
780 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700781 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700782 lec_arp_check_empties(priv, vcc, skb);
783 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700784 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700786 if (priv->is_trdev)
787 skb->protocol = tr_type_trans(skb, dev);
788 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700790 skb->protocol = eth_type_trans(skb, dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000791 dev->stats.rx_packets++;
792 dev->stats.rx_bytes += skb->len;
Chas Williamsd44f7742006-09-29 17:11:14 -0700793 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
794 netif_rx(skb);
795 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796}
797
Chas Williamsd44f7742006-09-29 17:11:14 -0700798static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799{
800 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
801 struct net_device *dev = skb->dev;
802
803 if (vpriv == NULL) {
804 printk("lec_pop(): vpriv = NULL!?!?!?\n");
805 return;
806 }
807
808 vpriv->old_pop(vcc, skb);
809
810 if (vpriv->xoff && atm_may_send(vcc, 0)) {
811 vpriv->xoff = 0;
812 if (netif_running(dev) && netif_queue_stopped(dev))
813 netif_wake_queue(dev);
814 }
815}
816
Chas Williamsd44f7742006-09-29 17:11:14 -0700817static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818{
819 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700820 int bytes_left;
821 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Chas Williamsd44f7742006-09-29 17:11:14 -0700823 /* Lecd must be up in this case */
824 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
825 if (bytes_left != 0) {
826 printk
827 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
828 bytes_left);
829 }
830 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
831 !dev_lec[ioc_data.dev_num])
832 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
834 return -ENOMEM;
835 vpriv->xoff = 0;
836 vpriv->old_pop = vcc->pop;
837 vcc->user_back = vpriv;
838 vcc->pop = lec_pop;
Wang Chen524ad0a2008-11-12 23:39:10 -0800839 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
Chas Williamsd44f7742006-09-29 17:11:14 -0700840 &ioc_data, vcc, vcc->push);
841 vcc->proto_data = dev_lec[ioc_data.dev_num];
842 vcc->push = lec_push;
843 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844}
845
Chas Williamsd44f7742006-09-29 17:11:14 -0700846static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847{
Chas Williamsd44f7742006-09-29 17:11:14 -0700848 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
849 return -EINVAL;
850 vcc->proto_data = dev_lec[arg];
Wang Chen524ad0a2008-11-12 23:39:10 -0800851 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
852 vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853}
854
855/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700856static int lecd_attach(struct atm_vcc *vcc, int arg)
857{
858 int i;
859 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Chas Williamsd44f7742006-09-29 17:11:14 -0700861 if (arg < 0)
862 i = 0;
863 else
864 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700866 if (arg >= MAX_LEC_ITF)
867 return -EINVAL;
868#else /* Reserve the top NUM_TR_DEVS for TR */
869 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
870 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700872 if (!dev_lec[i]) {
873 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Chas Williamsd44f7742006-09-29 17:11:14 -0700875 is_trdev = 0;
876 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
877 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Chas Williamsd44f7742006-09-29 17:11:14 -0700879 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700881 if (is_trdev)
882 dev_lec[i] = alloc_trdev(size);
883 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700885 dev_lec[i] = alloc_etherdev(size);
886 if (!dev_lec[i])
887 return -ENOMEM;
chas williams - CONTRACTOReb044582009-12-04 05:19:30 +0000888 dev_lec[i]->netdev_ops = &lec_netdev_ops;
Chas Williamsd44f7742006-09-29 17:11:14 -0700889 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
890 if (register_netdev(dev_lec[i])) {
891 free_netdev(dev_lec[i]);
892 return -EINVAL;
893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
Wang Chen524ad0a2008-11-12 23:39:10 -0800895 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700896 priv->is_trdev = is_trdev;
Chas Williamsd44f7742006-09-29 17:11:14 -0700897 } else {
Wang Chen524ad0a2008-11-12 23:39:10 -0800898 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700899 if (priv->lecd)
900 return -EADDRINUSE;
901 }
902 lec_arp_init(priv);
903 priv->itfnum = i; /* LANE2 addition */
904 priv->lecd = vcc;
905 vcc->dev = &lecatm_dev;
906 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Chas Williamsd44f7742006-09-29 17:11:14 -0700908 vcc->proto_data = dev_lec[i];
909 set_bit(ATM_VF_META, &vcc->flags);
910 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Chas Williamsd44f7742006-09-29 17:11:14 -0700912 /* Set default values to these variables */
913 priv->maximum_unknown_frame_count = 1;
914 priv->max_unknown_frame_time = (1 * HZ);
915 priv->vcc_timeout_period = (1200 * HZ);
916 priv->max_retry_count = 1;
917 priv->aging_time = (300 * HZ);
918 priv->forward_delay_time = (15 * HZ);
919 priv->topology_change = 0;
920 priv->arp_response_time = (1 * HZ);
921 priv->flush_timeout = (4 * HZ);
922 priv->path_switching_delay = (6 * HZ);
923
924 if (dev_lec[i]->flags & IFF_UP) {
925 netif_start_queue(dev_lec[i]);
926 }
927 __module_get(THIS_MODULE);
928 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929}
930
931#ifdef CONFIG_PROC_FS
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700932static const char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700934 static const char *const lec_arp_status_string[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 "ESI_UNKNOWN ",
936 "ESI_ARP_PENDING ",
937 "ESI_VC_PENDING ",
938 "<Undefined> ",
939 "ESI_FLUSH_PENDING ",
940 "ESI_FORWARD_DIRECT"
941 };
942
943 if (status > ESI_FORWARD_DIRECT)
944 status = 3; /* ESI_UNDEFINED */
945 return lec_arp_status_string[status];
946}
947
948static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
949{
950 int i;
951
952 for (i = 0; i < ETH_ALEN; i++)
953 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
954 seq_printf(seq, " ");
955 for (i = 0; i < ATM_ESA_LEN; i++)
956 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
957 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
958 entry->flags & 0xffff);
959 if (entry->vcc)
960 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
961 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700962 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 if (entry->recv_vcc) {
964 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
965 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -0700966 }
967 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968}
969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970struct lec_state {
971 unsigned long flags;
972 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -0700973 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 struct net_device *dev;
975 int itf;
976 int arp_table;
977 int misc_table;
978};
979
Chas Williamsd0732f62006-09-29 17:14:27 -0700980static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 loff_t *l)
982{
Chas Williamsd0732f62006-09-29 17:14:27 -0700983 struct hlist_node *e = state->node;
984 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
986 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -0700987 e = tbl->first;
Joe Perches2e1e9842008-04-10 03:33:03 -0700988 if (e == SEQ_START_TOKEN) {
Chas Williamsd0732f62006-09-29 17:14:27 -0700989 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 --*l;
991 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700992
993 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 if (--*l < 0)
995 break;
996 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700997 state->node = e;
998
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 return (*l < 0) ? state : NULL;
1000}
1001
1002static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -07001003 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004{
1005 void *v = NULL;
1006 int p;
1007
1008 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001009 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 if (v)
1011 break;
1012 }
1013 state->arp_table = p;
1014 return v;
1015}
1016
1017static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1018 struct lec_priv *priv)
1019{
Chas Williamsd0732f62006-09-29 17:14:27 -07001020 struct hlist_head *lec_misc_tables[] = {
1021 &priv->lec_arp_empty_ones,
1022 &priv->lec_no_forward,
1023 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 };
1025 void *v = NULL;
1026 int q;
1027
1028 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1029 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1030 if (v)
1031 break;
1032 }
1033 state->misc_table = q;
1034 return v;
1035}
1036
1037static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1038 struct lec_priv *priv)
1039{
1040 if (!state->locked) {
1041 state->locked = priv;
1042 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1043 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001044 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1046 state->locked = NULL;
1047 /* Partial state reset for the next time we get called */
1048 state->arp_table = state->misc_table = 0;
1049 }
1050 return state->locked;
1051}
1052
1053static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1054{
1055 struct net_device *dev;
1056 void *v;
1057
1058 dev = state->dev ? state->dev : dev_lec[state->itf];
Wang Chen524ad0a2008-11-12 23:39:10 -08001059 v = (dev && netdev_priv(dev)) ?
1060 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 if (!v && dev) {
1062 dev_put(dev);
1063 /* Partial state reset for the next time we get called */
1064 dev = NULL;
1065 }
1066 state->dev = dev;
1067 return v;
1068}
1069
1070static void *lec_get_idx(struct lec_state *state, loff_t l)
1071{
1072 void *v = NULL;
1073
1074 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1075 v = lec_itf_walk(state, &l);
1076 if (v)
1077 break;
1078 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001079 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080}
1081
1082static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1083{
1084 struct lec_state *state = seq->private;
1085
1086 state->itf = 0;
1087 state->dev = NULL;
1088 state->locked = NULL;
1089 state->arp_table = 0;
1090 state->misc_table = 0;
Joe Perches2e1e9842008-04-10 03:33:03 -07001091 state->node = SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Joe Perches2e1e9842008-04-10 03:33:03 -07001093 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094}
1095
1096static void lec_seq_stop(struct seq_file *seq, void *v)
1097{
1098 struct lec_state *state = seq->private;
1099
1100 if (state->dev) {
1101 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1102 state->flags);
1103 dev_put(state->dev);
1104 }
1105}
1106
1107static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1108{
1109 struct lec_state *state = seq->private;
1110
1111 v = lec_get_idx(state, 1);
1112 *pos += !!PTR_ERR(v);
1113 return v;
1114}
1115
1116static int lec_seq_show(struct seq_file *seq, void *v)
1117{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001118 static const char lec_banner[] =
1119 "Itf MAC ATM destination"
Chas Williamsd44f7742006-09-29 17:11:14 -07001120 " Status Flags "
1121 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
Joe Perches2e1e9842008-04-10 03:33:03 -07001123 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 seq_puts(seq, lec_banner);
1125 else {
1126 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001127 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001128 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001131 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 }
1133 return 0;
1134}
1135
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001136static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001137 .start = lec_seq_start,
1138 .next = lec_seq_next,
1139 .stop = lec_seq_stop,
1140 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141};
1142
1143static int lec_seq_open(struct inode *inode, struct file *file)
1144{
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001145 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146}
1147
Arjan van de Ven9a321442007-02-12 00:55:35 -08001148static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001149 .owner = THIS_MODULE,
1150 .open = lec_seq_open,
1151 .read = seq_read,
1152 .llseek = seq_lseek,
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001153 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154};
1155#endif
1156
1157static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1158{
1159 struct atm_vcc *vcc = ATM_SD(sock);
1160 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001161
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001163 case ATMLEC_CTRL:
1164 case ATMLEC_MCAST:
1165 case ATMLEC_DATA:
1166 if (!capable(CAP_NET_ADMIN))
1167 return -EPERM;
1168 break;
1169 default:
1170 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 }
1172
1173 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001174 case ATMLEC_CTRL:
1175 err = lecd_attach(vcc, (int)arg);
1176 if (err >= 0)
1177 sock->state = SS_CONNECTED;
1178 break;
1179 case ATMLEC_MCAST:
1180 err = lec_mcast_attach(vcc, (int)arg);
1181 break;
1182 case ATMLEC_DATA:
1183 err = lec_vcc_attach(vcc, (void __user *)arg);
1184 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 }
1186
1187 return err;
1188}
1189
1190static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001191 .owner = THIS_MODULE,
1192 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193};
1194
1195static int __init lane_module_init(void)
1196{
1197#ifdef CONFIG_PROC_FS
1198 struct proc_dir_entry *p;
1199
Wang Chen16e297b2008-02-28 13:55:45 -08001200 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Wang Chendbee0d32008-03-23 21:45:36 -07001201 if (!p) {
1202 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n");
1203 return -ENOMEM;
1204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205#endif
1206
1207 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001208 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1209 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210}
1211
1212static void __exit lane_module_cleanup(void)
1213{
Chas Williamsd44f7742006-09-29 17:11:14 -07001214 int i;
1215 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
1217 remove_proc_entry("lec", atm_proc_root);
1218
1219 deregister_atm_ioctl(&lane_ioctl_ops);
1220
Chas Williamsd44f7742006-09-29 17:11:14 -07001221 for (i = 0; i < MAX_LEC_ITF; i++) {
1222 if (dev_lec[i] != NULL) {
Wang Chen524ad0a2008-11-12 23:39:10 -08001223 priv = netdev_priv(dev_lec[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001225 free_netdev(dev_lec[i]);
1226 dev_lec[i] = NULL;
1227 }
1228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
Chas Williamsd44f7742006-09-29 17:11:14 -07001230 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231}
1232
1233module_init(lane_module_init);
1234module_exit(lane_module_cleanup);
1235
1236/*
1237 * LANE2: 3.1.3, LE_RESOLVE.request
1238 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1239 * If sizeoftlvs == NULL the default TLVs associated with with this
1240 * lec will be used.
1241 * If dst_mac == NULL, targetless LE_ARP will be sent
1242 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001243static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001244 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245{
1246 unsigned long flags;
Wang Chen524ad0a2008-11-12 23:39:10 -08001247 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001248 struct lec_arp_table *table;
1249 struct sk_buff *skb;
1250 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Chas Williamsd44f7742006-09-29 17:11:14 -07001252 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001254 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001256 if (table == NULL)
1257 return -1;
1258
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001259 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001260 if (*tlvs == NULL)
1261 return -1;
1262
Chas Williamsd44f7742006-09-29 17:11:14 -07001263 *sizeoftlvs = table->sizeoftlvs;
1264
1265 return 0;
1266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 if (sizeoftlvs == NULL)
1269 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001270
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 else {
1272 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1273 if (skb == NULL)
1274 return -1;
1275 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001276 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1278 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001279 return retval;
1280}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
1282/*
1283 * LANE2: 3.1.4, LE_ASSOCIATE.request
1284 * Associate the *tlvs with the *lan_dst address.
1285 * Will overwrite any previous association
1286 * Returns 1 for success, 0 for failure (out of memory)
1287 *
1288 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001289static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1290 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291{
Chas Williamsd44f7742006-09-29 17:11:14 -07001292 int retval;
1293 struct sk_buff *skb;
Wang Chen524ad0a2008-11-12 23:39:10 -08001294 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Chas Williamsd44f7742006-09-29 17:11:14 -07001296 if (compare_ether_addr(lan_dst, dev->dev_addr))
1297 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
Chas Williamsd44f7742006-09-29 17:11:14 -07001299 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001301 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001302 if (priv->tlvs == NULL)
1303 return (0);
1304 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Chas Williamsd44f7742006-09-29 17:11:14 -07001306 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1307 if (skb == NULL)
1308 return 0;
1309 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001310 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001311 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1312 if (retval != 0)
1313 printk("lec.c: lane2_associate_req() failed\n");
1314 /*
1315 * If the previous association has changed we must
1316 * somehow notify other LANE entities about the change
1317 */
1318 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319}
1320
1321/*
1322 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1323 *
1324 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001325static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1326 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
1328#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001329 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330#endif
Wang Chen524ad0a2008-11-12 23:39:10 -08001331 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001332#if 0 /*
1333 * Why have the TLVs in LE_ARP entries
1334 * since we do not use them? When you
1335 * uncomment this code, make sure the
1336 * TLVs get freed when entry is killed
1337 */
1338 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Chas Williamsd44f7742006-09-29 17:11:14 -07001340 if (entry == NULL)
1341 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Chas Williamsd44f7742006-09-29 17:11:14 -07001343 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001345 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001346 if (entry->tlvs == NULL)
1347 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001348 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349#endif
1350#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001351 printk("lec.c: lane2_associate_ind()\n");
1352 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1353 while (i < sizeoftlvs)
1354 printk("%02x ", tlvs[i++]);
1355
1356 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357#endif
1358
Chas Williamsd44f7742006-09-29 17:11:14 -07001359 /* tell MPOA about the TLVs we saw */
1360 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1361 priv->lane2_ops->associate_indicator(dev, mac_addr,
1362 tlvs, sizeoftlvs);
1363 }
1364 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365}
1366
1367/*
1368 * Here starts what used to lec_arpc.c
1369 *
1370 * lec_arpc.c was added here when making
1371 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 */
1373
1374#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375#include <linux/timer.h>
1376#include <asm/param.h>
1377#include <asm/atomic.h>
1378#include <linux/inetdevice.h>
1379#include <net/route.h>
1380
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381#if 0
Stephen Hemminger52240062007-08-28 15:22:09 -07001382#define pr_debug(format,args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383/*
Stephen Hemminger52240062007-08-28 15:22:09 -07001384#define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385*/
1386#endif
1387#define DEBUG_ARP_TABLE 0
1388
1389#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1390
David Howellsc4028952006-11-22 14:57:56 +00001391static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392static void lec_arp_expire_arp(unsigned long data);
1393
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001394/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 * Arp table funcs
1396 */
1397
1398#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1399
1400/*
1401 * Initialization of arp-cache
1402 */
Chas Williams1fa99612006-09-29 17:11:47 -07001403static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404{
Chas Williams1fa99612006-09-29 17:11:47 -07001405 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Chas Williams1fa99612006-09-29 17:11:47 -07001407 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001408 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001409 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001410 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1411 INIT_HLIST_HEAD(&priv->lec_no_forward);
1412 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001414 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001415 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416}
1417
Chas Williams1fa99612006-09-29 17:11:47 -07001418static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419{
Chas Williams1fa99612006-09-29 17:11:47 -07001420 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 struct atm_vcc *vcc = entry->vcc;
1422 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001423 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
Chas Williams1fa99612006-09-29 17:11:47 -07001425 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 if (vpriv->xoff)
1427 netif_wake_queue(dev);
1428 kfree(vpriv);
1429 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001430 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001432 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001433 }
1434 if (entry->recv_vcc) {
1435 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001437 entry->recv_vcc = NULL;
1438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439}
1440
1441/*
1442 * Insert entry to lec_arp_table
1443 * LANE2: Add to the end of the list to satisfy 8.1.13
1444 */
Chas Williams1fa99612006-09-29 17:11:47 -07001445static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001446lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447{
Chas Williamsd0732f62006-09-29 17:14:27 -07001448 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
Chas Williamsd0732f62006-09-29 17:14:27 -07001450 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1451 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001452
Stephen Hemminger52240062007-08-28 15:22:09 -07001453 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 -07001454 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1455 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1456 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457}
1458
1459/*
1460 * Remove entry from lec_arp_table
1461 */
Chas Williams1fa99612006-09-29 17:11:47 -07001462static int
1463lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464{
Chas Williamsd0732f62006-09-29 17:14:27 -07001465 struct hlist_node *node;
1466 struct lec_arp_table *entry;
1467 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Chas Williams1fa99612006-09-29 17:11:47 -07001469 if (!to_remove) {
1470 return -1;
1471 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001472
1473 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001474 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
Chas Williamsd0732f62006-09-29 17:14:27 -07001476 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001477 if (to_remove->status >= ESI_FLUSH_PENDING) {
1478 /*
1479 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1480 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001481 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1482 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1483 if (memcmp(to_remove->atm_addr,
1484 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001485 remove_vcc = 0;
1486 break;
1487 }
1488 }
1489 }
1490 if (remove_vcc)
1491 lec_arp_clear_vccs(to_remove);
1492 }
1493 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1494
Stephen Hemminger52240062007-08-28 15:22:09 -07001495 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 -07001496 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1497 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1498 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1499 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500}
1501
1502#if DEBUG_ARP_TABLE
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001503static const char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504{
Chas Williams1fa99612006-09-29 17:11:47 -07001505 switch (st) {
1506 case ESI_UNKNOWN:
1507 return "ESI_UNKNOWN";
1508 case ESI_ARP_PENDING:
1509 return "ESI_ARP_PENDING";
1510 case ESI_VC_PENDING:
1511 return "ESI_VC_PENDING";
1512 case ESI_FLUSH_PENDING:
1513 return "ESI_FLUSH_PENDING";
1514 case ESI_FORWARD_DIRECT:
1515 return "ESI_FORWARD_DIRECT";
1516 default:
1517 return "<UNKNOWN>";
1518 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Chas Williams1fa99612006-09-29 17:11:47 -07001521static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522{
Chas Williamsd0732f62006-09-29 17:14:27 -07001523 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001524 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001525 char buf[256];
1526 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
Chas Williams1fa99612006-09-29 17:11:47 -07001528 printk("Dump %p:\n", priv);
1529 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001530 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1531 offset = 0;
1532 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001533 offset += sprintf(buf + offset, "Mac:");
1534 for (j = 0; j < ETH_ALEN; j++) {
1535 offset += sprintf(buf + offset,
1536 "%2.2x ",
1537 rulla->mac_addr[j] & 0xff);
1538 }
1539 offset += sprintf(buf + offset, "Atm:");
1540 for (j = 0; j < ATM_ESA_LEN; j++) {
1541 offset += sprintf(buf + offset,
1542 "%2.2x ",
1543 rulla->atm_addr[j] & 0xff);
1544 }
1545 offset += sprintf(buf + offset,
1546 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1547 rulla->vcc ? rulla->vcc->vpi : 0,
1548 rulla->vcc ? rulla->vcc->vci : 0,
1549 rulla->recv_vcc ? rulla->recv_vcc->
1550 vpi : 0,
1551 rulla->recv_vcc ? rulla->recv_vcc->
1552 vci : 0, rulla->last_used,
1553 rulla->timestamp, rulla->no_tries);
1554 offset +=
1555 sprintf(buf + offset,
1556 "Flags:%x, Packets_flooded:%x, Status: %s ",
1557 rulla->flags, rulla->packets_flooded,
1558 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001559 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001560 }
Chas Williams1fa99612006-09-29 17:11:47 -07001561 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001562
1563 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001564 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001565 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001566 offset = 0;
1567 offset += sprintf(buf + offset, "Mac:");
1568 for (j = 0; j < ETH_ALEN; j++) {
1569 offset += sprintf(buf + offset, "%2.2x ",
1570 rulla->mac_addr[j] & 0xff);
1571 }
1572 offset += sprintf(buf + offset, "Atm:");
1573 for (j = 0; j < ATM_ESA_LEN; j++) {
1574 offset += sprintf(buf + offset, "%2.2x ",
1575 rulla->atm_addr[j] & 0xff);
1576 }
1577 offset += sprintf(buf + offset,
1578 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1579 rulla->vcc ? rulla->vcc->vpi : 0,
1580 rulla->vcc ? rulla->vcc->vci : 0,
1581 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1582 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1583 rulla->last_used,
1584 rulla->timestamp, rulla->no_tries);
1585 offset += sprintf(buf + offset,
1586 "Flags:%x, Packets_flooded:%x, Status: %s ",
1587 rulla->flags, rulla->packets_flooded,
1588 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001589 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001590 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001591
1592 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001593 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001594 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001595 offset = 0;
1596 offset += sprintf(buf + offset, "Mac:");
1597 for (j = 0; j < ETH_ALEN; j++) {
1598 offset += sprintf(buf + offset, "%2.2x ",
1599 rulla->mac_addr[j] & 0xff);
1600 }
1601 offset += sprintf(buf + offset, "Atm:");
1602 for (j = 0; j < ATM_ESA_LEN; j++) {
1603 offset += sprintf(buf + offset, "%2.2x ",
1604 rulla->atm_addr[j] & 0xff);
1605 }
1606 offset += sprintf(buf + offset,
1607 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1608 rulla->vcc ? rulla->vcc->vpi : 0,
1609 rulla->vcc ? rulla->vcc->vci : 0,
1610 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1611 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1612 rulla->last_used,
1613 rulla->timestamp, rulla->no_tries);
1614 offset += sprintf(buf + offset,
1615 "Flags:%x, Packets_flooded:%x, Status: %s ",
1616 rulla->flags, rulla->packets_flooded,
1617 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001618 printk("%s", buf);
1619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
Chas Williamsd0732f62006-09-29 17:14:27 -07001621 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001622 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001623 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001624 offset = 0;
1625 offset += sprintf(buf + offset, "Mac:");
1626 for (j = 0; j < ETH_ALEN; j++) {
1627 offset += sprintf(buf + offset, "%2.2x ",
1628 rulla->mac_addr[j] & 0xff);
1629 }
1630 offset += sprintf(buf + offset, "Atm:");
1631 for (j = 0; j < ATM_ESA_LEN; j++) {
1632 offset += sprintf(buf + offset, "%2.2x ",
1633 rulla->atm_addr[j] & 0xff);
1634 }
1635 offset += sprintf(buf + offset,
1636 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1637 rulla->vcc ? rulla->vcc->vpi : 0,
1638 rulla->vcc ? rulla->vcc->vci : 0,
1639 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1640 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1641 rulla->last_used,
1642 rulla->timestamp, rulla->no_tries);
1643 offset += sprintf(buf + offset,
1644 "Flags:%x, Packets_flooded:%x, Status: %s ",
1645 rulla->flags, rulla->packets_flooded,
1646 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001647 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650}
Chas Williamsd0732f62006-09-29 17:14:27 -07001651#else
1652#define dump_arp_table(priv) do { } while (0)
1653#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
1655/*
1656 * Destruction of arp-cache
1657 */
Chas Williams1fa99612006-09-29 17:11:47 -07001658static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659{
1660 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001661 struct hlist_node *node, *next;
1662 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001663 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
Chas Williams987e46b2006-09-29 17:15:59 -07001665 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001666
1667 /*
1668 * Remove all entries
1669 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
1671 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001672 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001673 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001674 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001675 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001676 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001677 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001678 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001679
1680 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001681 del_timer_sync(&entry->timer);
1682 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001683 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001684 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001685 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001686 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1687
1688 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001689 del_timer_sync(&entry->timer);
1690 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001691 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001692 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001693 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001694 INIT_HLIST_HEAD(&priv->lec_no_forward);
1695
1696 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001697 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1698 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001699 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001700 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001701 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001702 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001703 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1705}
1706
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001707/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 * Find entry by mac_address
1709 */
Chas Williams1fa99612006-09-29 17:11:47 -07001710static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001711 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712{
Chas Williamsd0732f62006-09-29 17:14:27 -07001713 struct hlist_node *node;
1714 struct hlist_head *head;
1715 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Stephen Hemminger52240062007-08-28 15:22:09 -07001717 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 -07001718 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1719 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
Chas Williams1fa99612006-09-29 17:11:47 -07001720
Chas Williamsd0732f62006-09-29 17:14:27 -07001721 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1722 hlist_for_each_entry(entry, node, head, next) {
1723 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1724 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001725 }
Chas Williams1fa99612006-09-29 17:11:47 -07001726 }
1727 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728}
1729
Chas Williams1fa99612006-09-29 17:11:47 -07001730static struct lec_arp_table *make_entry(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001731 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732{
Chas Williams1fa99612006-09-29 17:11:47 -07001733 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
Chas Williams1fa99612006-09-29 17:11:47 -07001735 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1736 if (!to_return) {
1737 printk("LEC: Arp entry kmalloc failed\n");
1738 return NULL;
1739 }
1740 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001741 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001742 setup_timer(&to_return->timer, lec_arp_expire_arp,
1743 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001744 to_return->last_used = jiffies;
1745 to_return->priv = priv;
1746 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001747 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001748 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749}
1750
Chas Williams1fa99612006-09-29 17:11:47 -07001751/* Arp sent timer expired */
1752static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753{
Chas Williams1fa99612006-09-29 17:11:47 -07001754 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
Chas Williams1fa99612006-09-29 17:11:47 -07001756 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
Stephen Hemminger52240062007-08-28 15:22:09 -07001758 pr_debug("lec_arp_expire_arp\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001759 if (entry->status == ESI_ARP_PENDING) {
1760 if (entry->no_tries <= entry->priv->max_retry_count) {
1761 if (entry->is_rdesc)
1762 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1763 entry->mac_addr, NULL, NULL);
1764 else
1765 send_to_lecd(entry->priv, l_arp_xmt,
1766 entry->mac_addr, NULL, NULL);
1767 entry->no_tries++;
1768 }
1769 mod_timer(&entry->timer, jiffies + (1 * HZ));
1770 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771}
1772
Chas Williams1fa99612006-09-29 17:11:47 -07001773/* Unknown/unused vcc expire, remove associated entry */
1774static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775{
1776 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001777 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1778 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
Chas Williams1fa99612006-09-29 17:11:47 -07001780 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
Stephen Hemminger52240062007-08-28 15:22:09 -07001782 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001783 to_remove, priv,
1784 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1785 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
1787 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001788 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1790
Chas Williams1fa99612006-09-29 17:11:47 -07001791 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001792 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793}
1794
1795/*
1796 * Expire entries.
1797 * 1. Re-set timer
1798 * 2. For each entry, delete entries that have aged past the age limit.
1799 * 3. For each entry, depending on the status of the entry, perform
1800 * the following maintenance.
1801 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1802 * tick_count is above the max_unknown_frame_time, clear
1803 * the tick_count to zero and clear the packets_flooded counter
1804 * to zero. This supports the packet rate limit per address
1805 * while flooding unknowns.
1806 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1807 * than or equal to the path_switching_delay, change the status
1808 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1809 * regardless of the progress of the flush protocol.
1810 */
David Howellsc4028952006-11-22 14:57:56 +00001811static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812{
1813 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001814 struct lec_priv *priv =
1815 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001816 struct hlist_node *node, *next;
1817 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001818 unsigned long now;
1819 unsigned long time_to_check;
1820 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821
Stephen Hemminger52240062007-08-28 15:22:09 -07001822 pr_debug("lec_arp_check_expire %p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001824restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001826 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001827 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001828 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 priv->topology_change)
1830 time_to_check = priv->forward_delay_time;
1831 else
1832 time_to_check = priv->aging_time;
1833
Stephen Hemminger52240062007-08-28 15:22:09 -07001834 pr_debug("About to expire: %lx - %lx > %lx\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001835 now, entry->last_used, time_to_check);
1836 if (time_after(now, entry->last_used + time_to_check)
1837 && !(entry->flags & LEC_PERMANENT_FLAG)
1838 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 /* Remove entry */
Stephen Hemminger52240062007-08-28 15:22:09 -07001840 pr_debug("LEC:Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001842 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 } else {
1844 /* Something else */
1845 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001846 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001848 entry->timestamp +
1849 priv->
1850 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 entry->timestamp = jiffies;
1852 entry->packets_flooded = 0;
1853 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001854 send_to_lecd(priv, l_svc_setup,
1855 entry->mac_addr,
1856 entry->atm_addr,
1857 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 }
Chas Williams1fa99612006-09-29 17:11:47 -07001859 if (entry->status == ESI_FLUSH_PENDING
1860 &&
1861 time_after_eq(now, entry->timestamp +
1862 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001864 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
Chas Williams6656e3c2006-09-29 17:17:17 -07001866 lec_arp_hold(entry);
1867 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1868 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
Stephen Hemminger162619e2009-01-09 13:01:01 +00001869 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001871 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001872 lec_arp_put(entry);
1873 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 }
1876 }
1877 }
1878 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1879
Chas Williams987e46b2006-09-29 17:15:59 -07001880 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881}
Chas Williams1fa99612006-09-29 17:11:47 -07001882
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883/*
1884 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001885 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 */
Chas Williams1fa99612006-09-29 17:11:47 -07001887static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001888 const unsigned char *mac_to_find, int is_rdesc,
Chas Williams1fa99612006-09-29 17:11:47 -07001889 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890{
1891 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001892 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 struct atm_vcc *found;
1894
Chas Williams1fa99612006-09-29 17:11:47 -07001895 if (mac_to_find[0] & 0x01) {
1896 switch (priv->lane_version) {
1897 case 1:
1898 return priv->mcast_vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07001899 case 2: /* LANE2 wants arp for multicast addresses */
1900 if (!compare_ether_addr(mac_to_find, bus_mac))
1901 return priv->mcast_vcc;
1902 break;
1903 default:
1904 break;
1905 }
1906 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
1908 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001909 entry = lec_arp_find(priv, mac_to_find);
1910
1911 if (entry) {
1912 if (entry->status == ESI_FORWARD_DIRECT) {
1913 /* Connection Ok */
1914 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001915 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001916 *ret_entry = entry;
1917 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001919 }
1920 /*
1921 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001922 * so another LE_ARP request can be made for this frame.
1923 */
1924 if (entry->status == ESI_ARP_PENDING) {
1925 entry->no_tries = 0;
1926 }
Chas Williams1fa99612006-09-29 17:11:47 -07001927 /*
1928 * Data direct VC not yet set up, check to see if the unknown
1929 * frame count is greater than the limit. If the limit has
1930 * not been reached, allow the caller to send packet to
1931 * BUS.
1932 */
1933 if (entry->status != ESI_FLUSH_PENDING &&
1934 entry->packets_flooded <
1935 priv->maximum_unknown_frame_count) {
1936 entry->packets_flooded++;
Stephen Hemminger52240062007-08-28 15:22:09 -07001937 pr_debug("LEC_ARP: Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001938 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001940 }
1941 /*
1942 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 * or BUS flood limit was reached for an entry which is
1944 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1945 */
Chas Williams6656e3c2006-09-29 17:17:17 -07001946 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001947 *ret_entry = entry;
Stephen Hemminger52240062007-08-28 15:22:09 -07001948 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
Chas Williams1fa99612006-09-29 17:11:47 -07001949 entry->vcc);
1950 found = NULL;
1951 } else {
1952 /* No matching entry was found */
1953 entry = make_entry(priv, mac_to_find);
Stephen Hemminger52240062007-08-28 15:22:09 -07001954 pr_debug("LEC_ARP: Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001955 if (!entry) {
1956 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001958 }
1959 lec_arp_add(priv, entry);
1960 /* We want arp-request(s) to be sent */
1961 entry->packets_flooded = 1;
1962 entry->status = ESI_ARP_PENDING;
1963 entry->no_tries = 1;
1964 entry->last_used = entry->timestamp = jiffies;
1965 entry->is_rdesc = is_rdesc;
1966 if (entry->is_rdesc)
1967 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1968 NULL);
1969 else
1970 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1971 entry->timer.expires = jiffies + (1 * HZ);
1972 entry->timer.function = lec_arp_expire_arp;
1973 add_timer(&entry->timer);
1974 found = priv->mcast_vcc;
1975 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976
1977out:
1978 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1979 return found;
1980}
1981
1982static int
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001983lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07001984 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985{
1986 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001987 struct hlist_node *node, *next;
1988 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001989 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
Stephen Hemminger52240062007-08-28 15:22:09 -07001991 pr_debug("lec_addr_delete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001993 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001994 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001995 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
1996 && (permanent ||
1997 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001999 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002000 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002002 return 0;
2003 }
2004 }
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 -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007}
2008
2009/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002010 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 */
2012static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002013lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
2014 const unsigned char *atm_addr, unsigned long remoteflag,
Chas Williams1fa99612006-09-29 17:11:47 -07002015 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016{
2017 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002018 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07002019 struct lec_arp_table *entry, *tmp;
2020 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021
Stephen Hemminger52240062007-08-28 15:22:09 -07002022 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2023 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 -07002024 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2025 mac_addr[4], mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
2027 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002028 entry = lec_arp_find(priv, mac_addr);
2029 if (entry == NULL && targetless_le_arp)
2030 goto out; /*
2031 * LANE2: ignore targetless LE_ARPs for which
2032 * we have no entry in the cache. 7.1.30
2033 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002034 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2035 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2036 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2037 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002038 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002039 tmp = lec_arp_find(priv, mac_addr);
2040 if (tmp) {
2041 del_timer(&tmp->timer);
2042 tmp->status = ESI_FORWARD_DIRECT;
2043 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2044 tmp->vcc = entry->vcc;
2045 tmp->old_push = entry->old_push;
2046 tmp->last_used = jiffies;
2047 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002048 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002049 entry = tmp;
2050 } else {
2051 entry->status = ESI_FORWARD_DIRECT;
2052 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2053 entry->last_used = jiffies;
2054 lec_arp_add(priv, entry);
2055 }
2056 if (remoteflag)
2057 entry->flags |= LEC_REMOTE_FLAG;
2058 else
2059 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002060 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002061 dump_arp_table(priv);
2062 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002063 }
Chas Williams1fa99612006-09-29 17:11:47 -07002064 }
2065 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002066
Chas Williams1fa99612006-09-29 17:11:47 -07002067 entry = lec_arp_find(priv, mac_addr);
2068 if (!entry) {
2069 entry = make_entry(priv, mac_addr);
2070 if (!entry)
2071 goto out;
2072 entry->status = ESI_UNKNOWN;
2073 lec_arp_add(priv, entry);
2074 /* Temporary, changes before end of function */
2075 }
2076 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2077 del_timer(&entry->timer);
2078 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002079 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002080 if (entry != tmp &&
2081 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2082 /* Vcc to this host exists */
2083 if (tmp->status > ESI_VC_PENDING) {
2084 /*
2085 * ESI_FLUSH_PENDING,
2086 * ESI_FORWARD_DIRECT
2087 */
2088 entry->vcc = tmp->vcc;
2089 entry->old_push = tmp->old_push;
2090 }
2091 entry->status = tmp->status;
2092 break;
2093 }
2094 }
2095 }
2096 if (remoteflag)
2097 entry->flags |= LEC_REMOTE_FLAG;
2098 else
2099 entry->flags &= ~LEC_REMOTE_FLAG;
2100 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2101 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002102 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002103 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002104 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002105 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106out:
2107 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2108}
2109
2110/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002111 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 */
2113static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002114lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002115 struct atm_vcc *vcc,
2116 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117{
2118 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002119 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002120 struct lec_arp_table *entry;
2121 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
2123 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002124 if (ioc_data->receive == 2) {
2125 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
Stephen Hemminger52240062007-08-28 15:22:09 -07002127 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002129 entry = lec_arp_find(priv, bus_mac);
2130 if (!entry) {
2131 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002133 }
2134 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2135 entry->recv_vcc = vcc;
2136 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002138 entry = make_entry(priv, bus_mac);
2139 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002141 del_timer(&entry->timer);
2142 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2143 entry->recv_vcc = vcc;
2144 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002145 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002146 goto out;
2147 } else if (ioc_data->receive == 1) {
2148 /*
2149 * Vcc which we don't want to make default vcc,
2150 * attach it anyway.
2151 */
Stephen Hemminger52240062007-08-28 15:22:09 -07002152 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002153 ("LEC_ARP:Attaching data direct, not default: "
2154 "%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",
2155 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2156 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2157 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2158 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2159 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2160 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2161 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2162 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2163 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2164 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2165 entry = make_entry(priv, bus_mac);
2166 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002168 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2169 memset(entry->mac_addr, 0, ETH_ALEN);
2170 entry->recv_vcc = vcc;
2171 entry->old_recv_push = old_push;
2172 entry->status = ESI_UNKNOWN;
2173 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2174 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002175 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002176 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 dump_arp_table(priv);
2178 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002179 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002180 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002181 ("LEC_ARP:Attaching data direct, default: "
2182 "%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",
2183 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2184 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2185 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2186 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2187 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2188 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2189 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2190 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2191 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2192 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2193 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002194 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002195 if (memcmp
2196 (ioc_data->atm_addr, entry->atm_addr,
2197 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002198 pr_debug("LEC_ARP: Attaching data direct\n");
2199 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07002200 entry->vcc ? entry->vcc->vci : 0,
2201 entry->recv_vcc ? entry->recv_vcc->
2202 vci : 0);
2203 found_entry = 1;
2204 del_timer(&entry->timer);
2205 entry->vcc = vcc;
2206 entry->old_push = old_push;
2207 if (entry->status == ESI_VC_PENDING) {
2208 if (priv->maximum_unknown_frame_count
2209 == 0)
2210 entry->status =
2211 ESI_FORWARD_DIRECT;
2212 else {
2213 entry->timestamp = jiffies;
2214 entry->status =
2215 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002217 send_to_lecd(priv, l_flush_xmt,
2218 NULL,
2219 entry->atm_addr,
2220 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002222 }
2223 } else {
2224 /*
2225 * They were forming a connection
2226 * to us, and we to them. Our
2227 * ATM address is numerically lower
2228 * than theirs, so we make connection
2229 * we formed into default VCC (8.1.11).
2230 * Connection they made gets torn
2231 * down. This might confuse some
2232 * clients. Can be changed if
2233 * someone reports trouble...
2234 */
2235 ;
2236 }
2237 }
2238 }
2239 }
2240 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002241 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002242 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002244 }
2245 /*
2246 * Not found, snatch address from first data packet that arrives
2247 * from this vcc
2248 */
2249 entry = make_entry(priv, bus_mac);
2250 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002252 entry->vcc = vcc;
2253 entry->old_push = old_push;
2254 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2255 memset(entry->mac_addr, 0, ETH_ALEN);
2256 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002257 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002258 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2259 entry->timer.function = lec_arp_expire_vcc;
2260 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002261 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 dump_arp_table(priv);
2263out:
2264 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2265}
2266
Chas Williams1fa99612006-09-29 17:11:47 -07002267static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268{
2269 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002270 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002271 struct lec_arp_table *entry;
2272 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273
Stephen Hemminger52240062007-08-28 15:22:09 -07002274 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002275restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002276 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2277 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002278 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002279 if (entry->flush_tran_id == tran_id
2280 && entry->status == ESI_FLUSH_PENDING) {
2281 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002282 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002283
Chas Williams6656e3c2006-09-29 17:17:17 -07002284 lec_arp_hold(entry);
2285 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2286 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
Stephen Hemminger162619e2009-01-09 13:01:01 +00002287 lec_send(vcc, skb);
Chas Williams6656e3c2006-09-29 17:17:17 -07002288 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002289 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002290 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002291 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002292 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002293 }
2294 }
2295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002297 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298}
2299
2300static void
2301lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002302 const unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303{
2304 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002305 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002306 struct lec_arp_table *entry;
2307 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308
2309 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002310 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002311 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002312 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2313 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002314 pr_debug("Set flush transaction id to %lx for %p\n",
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002315 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002316 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002317 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2319}
2320
Chas Williams1fa99612006-09-29 17:11:47 -07002321static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322{
2323 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002324 unsigned char mac_addr[] = {
2325 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2326 };
2327 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 struct lec_vcc_priv *vpriv;
2329 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002330
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2332 return -ENOMEM;
2333 vpriv->xoff = 0;
2334 vpriv->old_pop = vcc->pop;
2335 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002336 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002338 to_add = make_entry(priv, mac_addr);
2339 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 vcc->pop = vpriv->old_pop;
2341 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002342 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002344 }
2345 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2346 to_add->status = ESI_FORWARD_DIRECT;
2347 to_add->flags |= LEC_PERMANENT_FLAG;
2348 to_add->vcc = vcc;
2349 to_add->old_push = vcc->push;
2350 vcc->push = lec_push;
2351 priv->mcast_vcc = vcc;
2352 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353out:
2354 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002355 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356}
2357
Chas Williams1fa99612006-09-29 17:11:47 -07002358static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359{
2360 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002361 struct hlist_node *node, *next;
2362 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002363 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
Stephen Hemminger52240062007-08-28 15:22:09 -07002365 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002366 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002367
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002369
Chas Williams1fa99612006-09-29 17:11:47 -07002370 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002371 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002372 if (vcc == entry->vcc) {
2373 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002374 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002375 if (priv->mcast_vcc == vcc) {
2376 priv->mcast_vcc = NULL;
2377 }
2378 }
2379 }
2380 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
Chas Williamsd0732f62006-09-29 17:14:27 -07002382 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2383 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002384 lec_arp_clear_vccs(entry);
2385 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002386 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002387 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002388 }
Chas Williams1fa99612006-09-29 17:11:47 -07002389 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390
Chas Williamsd0732f62006-09-29 17:14:27 -07002391 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002392 if (entry->recv_vcc == vcc) {
2393 lec_arp_clear_vccs(entry);
2394 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002395 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002396 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002397 }
Chas Williams1fa99612006-09-29 17:11:47 -07002398 }
2399
Chas Williamsd0732f62006-09-29 17:14:27 -07002400 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002401 if (entry->recv_vcc == vcc) {
2402 lec_arp_clear_vccs(entry);
2403 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002404 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002405 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002406 }
Chas Williams1fa99612006-09-29 17:11:47 -07002407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408
2409 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2410 dump_arp_table(priv);
2411}
2412
2413static void
2414lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002415 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416{
Chas Williams1fa99612006-09-29 17:11:47 -07002417 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002418 struct hlist_node *node, *next;
2419 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002420 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2421 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002423 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
Chas Williams1fa99612006-09-29 17:11:47 -07002425 if (priv->is_trdev)
2426 src = tr_hdr->h_source;
2427 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002429 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430
2431 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002432 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2433 if (vcc == entry->vcc) {
2434 del_timer(&entry->timer);
2435 memcpy(entry->mac_addr, src, ETH_ALEN);
2436 entry->status = ESI_FORWARD_DIRECT;
2437 entry->last_used = jiffies;
2438 /* We might have got an entry */
2439 if ((tmp = lec_arp_find(priv, src))) {
2440 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002441 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002442 }
2443 hlist_del(&entry->next);
2444 lec_arp_add(priv, entry);
2445 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002446 }
Chas Williams1fa99612006-09-29 17:11:47 -07002447 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002448 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449out:
2450 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2451}
Chas Williams1fa99612006-09-29 17:11:47 -07002452
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453MODULE_LICENSE("GPL");