blob: 8e723c2654cb82f50f4376291be41ce49d988de9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002 * lec.c: Lan Emulation driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Chas Williamsd44f7742006-09-29 17:11:14 -07004 * Marko Kiiskila <mkiiskila@yahoo.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/kernel.h>
8#include <linux/bitops.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -08009#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11/* We are ethernet device */
12#include <linux/if_ether.h>
13#include <linux/netdevice.h>
14#include <linux/etherdevice.h>
15#include <net/sock.h>
16#include <linux/skbuff.h>
17#include <linux/ip.h>
18#include <asm/byteorder.h>
19#include <asm/uaccess.h>
20#include <net/arp.h>
21#include <net/dst.h>
22#include <linux/proc_fs.h>
23#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/seq_file.h>
25
26/* TokenRing if needed */
27#ifdef CONFIG_TR
28#include <linux/trdevice.h>
29#endif
30
31/* And atm device */
32#include <linux/atmdev.h>
33#include <linux/atmlec.h>
34
35/* Proxy LEC knows about bridging */
36#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include "../bridge/br_private.h"
38
Chas Williamsd44f7742006-09-29 17:11:14 -070039static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#endif
41
42/* Modular too */
43#include <linux/module.h>
44#include <linux/init.h>
45
46#include "lec.h"
47#include "lec_arpc.h"
48#include "resources.h"
49
Chas Williamsd44f7742006-09-29 17:11:14 -070050#define DUMP_PACKETS 0 /*
51 * 0 = None,
52 * 1 = 30 first bytes
53 * 2 = Whole packet
54 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Chas Williamsd44f7742006-09-29 17:11:14 -070056#define LEC_UNRES_QUE_LEN 8 /*
57 * number of tx packets to queue for a
58 * single destination while waiting for SVC
59 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61static int lec_open(struct net_device *dev);
62static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev);
63static int lec_close(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static void lec_init(struct net_device *dev);
Chas Williamsd44f7742006-09-29 17:11:14 -070065static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070066 const unsigned char *mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067static int lec_arp_remove(struct lec_priv *priv,
Chas Williamsd44f7742006-09-29 17:11:14 -070068 struct lec_arp_table *to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/* LANE2 functions */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070070static void lane2_associate_ind(struct net_device *dev, const u8 *mac_address,
71 const u8 *tlvs, u32 sizeoftlvs);
72static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -070073 u8 **tlvs, u32 *sizeoftlvs);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070074static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
75 const u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070077static int lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 unsigned long permanent);
79static void lec_arp_check_empties(struct lec_priv *priv,
80 struct atm_vcc *vcc, struct sk_buff *skb);
81static void lec_arp_destroy(struct lec_priv *priv);
82static void lec_arp_init(struct lec_priv *priv);
Chas Williamsd44f7742006-09-29 17:11:14 -070083static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070084 const unsigned char *mac_to_find,
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 int is_rdesc,
86 struct lec_arp_table **ret_entry);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070087static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
88 const unsigned char *atm_addr, unsigned long remoteflag,
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 unsigned int targetless_le_arp);
90static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
91static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
92static void lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070093 const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 unsigned long tran_id);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070095static void lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 struct atm_vcc *vcc,
Chas Williamsd44f7742006-09-29 17:11:14 -070097 void (*old_push) (struct atm_vcc *vcc,
98 struct sk_buff *skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -070099static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
100
Chas Williams33a9c2d2006-09-29 17:16:48 -0700101/* must be done under lec_arp_lock */
102static inline void lec_arp_hold(struct lec_arp_table *entry)
103{
104 atomic_inc(&entry->usage);
105}
106
107static inline void lec_arp_put(struct lec_arp_table *entry)
108{
109 if (atomic_dec_and_test(&entry->usage))
110 kfree(entry);
111}
112
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114static struct lane2_ops lane2_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700115 lane2_resolve, /* resolve, spec 3.1.3 */
116 lane2_associate_req, /* associate_req, spec 3.1.4 */
117 NULL /* associate indicator, spec 3.1.5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118};
119
Chas Williamsd44f7742006-09-29 17:11:14 -0700120static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122/* Device structures */
123static struct net_device *dev_lec[MAX_LEC_ITF];
124
125#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
126static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
127{
Chas Williamsd44f7742006-09-29 17:11:14 -0700128 struct ethhdr *eth;
129 char *buff;
130 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Chas Williamsd44f7742006-09-29 17:11:14 -0700132 /*
133 * Check if this is a BPDU. If so, ask zeppelin to send
134 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
135 * as the Config BPDU has
136 */
137 eth = (struct ethhdr *)skb->data;
138 buff = skb->data + skb->dev->hard_header_len;
139 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 struct sock *sk;
Chas Williamsd44f7742006-09-29 17:11:14 -0700141 struct sk_buff *skb2;
142 struct atmlec_msg *mesg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Chas Williamsd44f7742006-09-29 17:11:14 -0700144 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
145 if (skb2 == NULL)
146 return;
147 skb2->len = sizeof(struct atmlec_msg);
148 mesg = (struct atmlec_msg *)skb2->data;
149 mesg->type = l_topology_change;
150 buff += 4;
151 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Wang Chen524ad0a2008-11-12 23:39:10 -0800153 priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700154 atm_force_charge(priv->lecd, skb2->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 sk = sk_atm(priv->lecd);
Chas Williamsd44f7742006-09-29 17:11:14 -0700156 skb_queue_tail(&sk->sk_receive_queue, skb2);
157 sk->sk_data_ready(sk, skb2->len);
158 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Chas Williamsd44f7742006-09-29 17:11:14 -0700160 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
162#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
163
164/*
165 * Modelled after tr_type_trans
166 * All multicast and ARE or STE frames go to BUS.
167 * Non source routed frames go by destination address.
168 * Last hop source routed frames go by destination address.
169 * Not last hop source routed frames go by _next_ route descriptor.
170 * Returns pointer to destination MAC address or fills in rdesc
171 * and returns NULL.
172 */
173#ifdef CONFIG_TR
174static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
175{
Chas Williamsd44f7742006-09-29 17:11:14 -0700176 struct trh_hdr *trh;
Eric Dumazet5c17d5f2008-01-15 03:29:50 -0800177 unsigned int riflen, num_rdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Chas Williamsd44f7742006-09-29 17:11:14 -0700179 trh = (struct trh_hdr *)packet;
180 if (trh->daddr[0] & (uint8_t) 0x80)
181 return bus_mac; /* multicast */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Chas Williamsd44f7742006-09-29 17:11:14 -0700183 if (trh->saddr[0] & TR_RII) {
184 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
185 if ((ntohs(trh->rcf) >> 13) != 0)
186 return bus_mac; /* ARE or STE */
187 } else
188 return trh->daddr; /* not source routed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Chas Williamsd44f7742006-09-29 17:11:14 -0700190 if (riflen < 6)
191 return trh->daddr; /* last hop, source routed */
192
193 /* riflen is 6 or more, packet has more than one route descriptor */
194 num_rdsc = (riflen / 2) - 1;
195 memset(rdesc, 0, ETH_ALEN);
196 /* offset 4 comes from LAN destination field in LE control frames */
197 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
Al Viro30d492d2006-11-14 21:11:29 -0800198 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700199 else {
Al Viro30d492d2006-11-14 21:11:29 -0800200 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700201 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
202 }
203
204 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206#endif /* CONFIG_TR */
207
208/*
209 * Open/initialize the netdevice. This is called (in the current kernel)
210 * sometime after booting when the 'ifconfig' program is run.
211 *
212 * This routine should set everything up anew at each open, even
213 * registers that "should" only need to be set once at boot, so that
214 * there is non-reboot way to recover if something goes wrong.
215 */
216
Chas Williamsd44f7742006-09-29 17:11:14 -0700217static int lec_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 netif_start_queue(dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000220 memset(&dev->stats, 0, sizeof(struct net_device_stats));
Chas Williamsd44f7742006-09-29 17:11:14 -0700221
222 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
Stephen Hemminger162619e2009-01-09 13:01:01 +0000225static void
226lec_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
Stephen Hemminger162619e2009-01-09 13:01:01 +0000228 struct net_device *dev = skb->dev;
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 ATM_SKB(skb)->vcc = vcc;
231 ATM_SKB(skb)->atm_options = vcc->atm_options;
232
233 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
234 if (vcc->send(vcc, skb) < 0) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000235 dev->stats.tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return;
237 }
238
Stephen Hemminger162619e2009-01-09 13:01:01 +0000239 dev->stats.tx_packets++;
240 dev->stats.tx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241}
242
Chas Williamsd44f7742006-09-29 17:11:14 -0700243static void lec_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 printk(KERN_INFO "%s: tx timeout\n", dev->name);
246 dev->trans_start = jiffies;
247 netif_wake_queue(dev);
248}
249
Chas Williamsd44f7742006-09-29 17:11:14 -0700250static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
Chas Williamsd44f7742006-09-29 17:11:14 -0700252 struct sk_buff *skb2;
Wang Chen524ad0a2008-11-12 23:39:10 -0800253 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700254 struct lecdatahdr_8023 *lec_h;
255 struct atm_vcc *vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700257 unsigned char *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 int min_frame_size;
259#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700260 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700262 int is_rdesc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700264 char buf[300];
265 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266#endif /* DUMP_PACKETS >0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Stephen Hemminger52240062007-08-28 15:22:09 -0700268 pr_debug("lec_start_xmit called\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700269 if (!priv->lecd) {
270 printk("%s:No lecd attached\n", dev->name);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000271 dev->stats.tx_errors++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700272 netif_stop_queue(dev);
Patrick McHardy81fbbf62009-06-12 05:34:37 +0000273 kfree_skb(skb);
274 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700275 }
276
Stephen Hemminger52240062007-08-28 15:22:09 -0700277 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700278 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700279 (long)skb_end_pointer(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700281 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
282 lec_handle_bridge(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283#endif
284
Chas Williamsd44f7742006-09-29 17:11:14 -0700285 /* Make sure we have room for lec_id */
286 if (skb_headroom(skb) < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Stephen Hemminger52240062007-08-28 15:22:09 -0700288 pr_debug("lec_start_xmit: reallocating skb\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700289 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
290 kfree_skb(skb);
291 if (skb2 == NULL)
Patrick McHardy6ed10652009-06-23 06:03:08 +0000292 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700293 skb = skb2;
294 }
295 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Chas Williamsd44f7742006-09-29 17:11:14 -0700297 /* Put le header to place, works for TokenRing too */
298 lec_h = (struct lecdatahdr_8023 *)skb->data;
299 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700302 /*
303 * Ugly. Use this to realign Token Ring packets for
304 * e.g. PCA-200E driver.
305 */
306 if (priv->is_trdev) {
307 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
308 kfree_skb(skb);
309 if (skb2 == NULL)
Patrick McHardy6ed10652009-06-23 06:03:08 +0000310 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700311 skb = skb2;
312 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313#endif
314
315#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700316 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
317 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700319 for (i = 0; i < skb->len && i < 99; i++) {
320 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700323 for (i = 0; i < skb->len && i < 30; i++) {
324 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700327 if (i == skb->len)
328 printk("%s\n", buf);
329 else
330 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331#endif /* DUMP_PACKETS > 0 */
332
Chas Williamsd44f7742006-09-29 17:11:14 -0700333 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700335 if (priv->is_trdev)
336 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 else
338#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700339 min_frame_size = LEC_MINIMUM_8023_SIZE;
340 if (skb->len < min_frame_size) {
341 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
342 skb2 = skb_copy_expand(skb, 0,
343 min_frame_size - skb->truesize,
344 GFP_ATOMIC);
345 dev_kfree_skb(skb);
346 if (skb2 == NULL) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000347 dev->stats.tx_dropped++;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000348 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700349 }
350 skb = skb2;
351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700353 }
354
355 /* Send to right vcc */
356 is_rdesc = 0;
357 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700359 if (priv->is_trdev) {
360 dst = get_tr_dst(skb->data + 2, rdesc);
361 if (dst == NULL) {
362 dst = rdesc;
363 is_rdesc = 1;
364 }
365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700367 entry = NULL;
368 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
Andrew Morton58c14a82007-09-26 22:31:19 -0700369 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700370 vcc, vcc ? vcc->flags : 0, entry);
371 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
372 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700373 pr_debug("%s:lec_start_xmit: queuing packet, ",
Chas Williamsd44f7742006-09-29 17:11:14 -0700374 dev->name);
Johannes Berge1749612008-10-27 15:59:26 -0700375 pr_debug("MAC address %pM\n", lec_h->h_dest);
Chas Williamsd44f7742006-09-29 17:11:14 -0700376 skb_queue_tail(&entry->tx_wait, skb);
377 } else {
Stephen Hemminger52240062007-08-28 15:22:09 -0700378 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700379 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
380 dev->name);
Johannes Berge1749612008-10-27 15:59:26 -0700381 pr_debug("MAC address %pM\n", lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000382 dev->stats.tx_dropped++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700383 dev_kfree_skb(skb);
384 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700385 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700386 }
387#if DUMP_PACKETS > 0
388 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700390
391 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700392 pr_debug("lec.c: emptying tx queue, ");
Johannes Berge1749612008-10-27 15:59:26 -0700393 pr_debug("MAC address %pM\n", lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000394 lec_send(vcc, skb2);
Chas Williamsd44f7742006-09-29 17:11:14 -0700395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Stephen Hemminger162619e2009-01-09 13:01:01 +0000397 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 if (!atm_may_send(vcc, 0)) {
400 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
401
402 vpriv->xoff = 1;
403 netif_stop_queue(dev);
404
405 /*
406 * vcc->pop() might have occurred in between, making
407 * the vcc usuable again. Since xmit is serialized,
408 * this is the only situation we have to re-test.
409 */
410
411 if (atm_may_send(vcc, 0))
412 netif_wake_queue(dev);
413 }
414
Chas Williams6656e3c2006-09-29 17:17:17 -0700415out:
416 if (entry)
417 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 dev->trans_start = jiffies;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000419 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
422/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700423static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
Chas Williamsd44f7742006-09-29 17:11:14 -0700425 netif_stop_queue(dev);
426 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
Chas Williamsd44f7742006-09-29 17:11:14 -0700429static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
431 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700432 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800433 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700434 struct atmlec_msg *mesg;
435 struct lec_arp_table *entry;
436 int i;
437 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
439 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700440 mesg = (struct atmlec_msg *)skb->data;
441 tmp = skb->data;
442 tmp += sizeof(struct atmlec_msg);
Stephen Hemminger52240062007-08-28 15:22:09 -0700443 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700444 switch (mesg->type) {
445 case l_set_mac_addr:
446 for (i = 0; i < 6; i++) {
447 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
448 }
449 break;
450 case l_del_mac_addr:
451 for (i = 0; i < 6; i++) {
452 dev->dev_addr[i] = 0;
453 }
454 break;
455 case l_addr_delete:
456 lec_addr_delete(priv, mesg->content.normal.atm_addr,
457 mesg->content.normal.flag);
458 break;
459 case l_topology_change:
460 priv->topology_change = mesg->content.normal.flag;
461 break;
462 case l_flush_complete:
463 lec_flush_complete(priv, mesg->content.normal.flag);
464 break;
465 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700467 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
468 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
470
Chas Williamsd44f7742006-09-29 17:11:14 -0700471 if (mesg->content.normal.no_source_le_narp)
472 break;
473 /* FALL THROUGH */
474 case l_arp_update:
475 lec_arp_update(priv, mesg->content.normal.mac_addr,
476 mesg->content.normal.atm_addr,
477 mesg->content.normal.flag,
478 mesg->content.normal.targetless_le_arp);
Stephen Hemminger52240062007-08-28 15:22:09 -0700479 pr_debug("lec: in l_arp_update\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700480 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700481 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700482 mesg->sizeoftlvs);
483 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
484 tmp, mesg->sizeoftlvs);
485 }
486 break;
487 case l_config:
488 priv->maximum_unknown_frame_count =
489 mesg->content.config.maximum_unknown_frame_count;
490 priv->max_unknown_frame_time =
491 (mesg->content.config.max_unknown_frame_time * HZ);
492 priv->max_retry_count = mesg->content.config.max_retry_count;
493 priv->aging_time = (mesg->content.config.aging_time * HZ);
494 priv->forward_delay_time =
495 (mesg->content.config.forward_delay_time * HZ);
496 priv->arp_response_time =
497 (mesg->content.config.arp_response_time * HZ);
498 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
499 priv->path_switching_delay =
500 (mesg->content.config.path_switching_delay * HZ);
501 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 priv->lane2_ops = NULL;
503 if (priv->lane_version > 1)
504 priv->lane2_ops = &lane2_ops;
Stephen Hemminger1f1900f2009-03-21 13:37:28 -0700505 if (dev_set_mtu(dev, mesg->content.config.mtu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 printk("%s: change_mtu to %d failed\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700507 mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700509 break;
510 case l_flush_tran_id:
511 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
512 mesg->content.normal.flag);
513 break;
514 case l_set_lecid:
515 priv->lecid =
516 (unsigned short)(0xffff & mesg->content.normal.flag);
517 break;
518 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700520 {
Johannes Berge1749612008-10-27 15:59:26 -0700521 pr_debug("%s: bridge zeppelin asks about %pM\n",
522 dev->name, mesg->content.proxy.mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Michał Mirosławda678292009-06-05 05:35:28 +0000524 if (br_fdb_test_addr_hook == NULL)
Chas Williamsd44f7742006-09-29 17:11:14 -0700525 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Michał Mirosławda678292009-06-05 05:35:28 +0000527 if (br_fdb_test_addr_hook(dev,
528 mesg->content.proxy.mac_addr)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700529 /* hit from bridge table, send LE_ARP_RESPONSE */
530 struct sk_buff *skb2;
531 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Stephen Hemminger52240062007-08-28 15:22:09 -0700533 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700534 ("%s: entry found, responding to zeppelin\n",
535 dev->name);
536 skb2 =
537 alloc_skb(sizeof(struct atmlec_msg),
538 GFP_ATOMIC);
Michał Mirosławda678292009-06-05 05:35:28 +0000539 if (skb2 == NULL)
Chas Williamsd44f7742006-09-29 17:11:14 -0700540 break;
Chas Williamsd44f7742006-09-29 17:11:14 -0700541 skb2->len = sizeof(struct atmlec_msg);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300542 skb_copy_to_linear_data(skb2, mesg,
543 sizeof(*mesg));
Chas Williamsd44f7742006-09-29 17:11:14 -0700544 atm_force_charge(priv->lecd, skb2->truesize);
545 sk = sk_atm(priv->lecd);
546 skb_queue_tail(&sk->sk_receive_queue, skb2);
547 sk->sk_data_ready(sk, skb2->len);
548 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700549 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700551 break;
552 default:
553 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
554 dev_kfree_skb(skb);
555 return -EINVAL;
556 }
557 dev_kfree_skb(skb);
558 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559}
560
Chas Williamsd44f7742006-09-29 17:11:14 -0700561static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562{
Chas Williamsd44f7742006-09-29 17:11:14 -0700563 struct sk_buff *skb;
564 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800565 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Chas Williamsd44f7742006-09-29 17:11:14 -0700567 priv->lecd = NULL;
568 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Chas Williamsd44f7742006-09-29 17:11:14 -0700570 netif_stop_queue(dev);
571 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Chas Williamsd44f7742006-09-29 17:11:14 -0700573 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700575 dev->name);
576 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
577 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700579 }
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700582 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583}
584
585static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700586 .close = lec_atm_close,
587 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588};
589
590static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700591 .ops = &lecdev_ops,
592 .type = "lec",
593 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700594 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595};
596
597/*
598 * LANE2: new argument struct sk_buff *data contains
599 * the LE_ARP based TLVs introduced in the LANE2 spec
600 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700601static int
602send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700603 const unsigned char *mac_addr, const unsigned char *atm_addr,
Chas Williamsd44f7742006-09-29 17:11:14 -0700604 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605{
606 struct sock *sk;
607 struct sk_buff *skb;
608 struct atmlec_msg *mesg;
609
610 if (!priv || !priv->lecd) {
611 return -1;
612 }
613 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
614 if (!skb)
615 return -1;
616 skb->len = sizeof(struct atmlec_msg);
617 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700618 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700620 if (data != NULL)
621 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 if (mac_addr)
623 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700624 else
625 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 if (atm_addr)
627 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
628
Chas Williamsd44f7742006-09-29 17:11:14 -0700629 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 sk = sk_atm(priv->lecd);
631 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700632 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Chas Williamsd44f7742006-09-29 17:11:14 -0700634 if (data != NULL) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700635 pr_debug("lec: about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700636 atm_force_charge(priv->lecd, data->truesize);
637 skb_queue_tail(&sk->sk_receive_queue, data);
638 sk->sk_data_ready(sk, skb->len);
639 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
Chas Williamsd44f7742006-09-29 17:11:14 -0700641 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642}
643
644/* shamelessly stolen from drivers/net/net_init.c */
645static int lec_change_mtu(struct net_device *dev, int new_mtu)
646{
Chas Williamsd44f7742006-09-29 17:11:14 -0700647 if ((new_mtu < 68) || (new_mtu > 18190))
648 return -EINVAL;
649 dev->mtu = new_mtu;
650 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651}
652
653static void lec_set_multicast_list(struct net_device *dev)
654{
Chas Williamsd44f7742006-09-29 17:11:14 -0700655 /*
656 * by default, all multicast frames arrive over the bus.
657 * eventually support selective multicast service
658 */
659 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660}
661
Stephen Hemminger004b3222009-01-09 13:01:02 +0000662static const struct net_device_ops lec_netdev_ops = {
663 .ndo_open = lec_open,
664 .ndo_stop = lec_close,
665 .ndo_start_xmit = lec_start_xmit,
666 .ndo_change_mtu = lec_change_mtu,
667 .ndo_tx_timeout = lec_tx_timeout,
668 .ndo_set_multicast_list = lec_set_multicast_list,
669};
670
671
Chas Williamsd44f7742006-09-29 17:11:14 -0700672static void lec_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673{
Stephen Hemminger004b3222009-01-09 13:01:02 +0000674 dev->netdev_ops = &lec_netdev_ops;
Chas Williamsd44f7742006-09-29 17:11:14 -0700675 printk("%s: Initialized!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676}
677
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700678static const unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700679 0xff,
680 0x00,
681 0x01,
682 0x01
683};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Scott Talbert4a7097f2005-09-29 17:30:54 -0700685#define LEC_DATA_DIRECT_8023 2
686#define LEC_DATA_DIRECT_8025 3
687
688static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700689{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700690 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
691 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700692}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700693
Chas Williamsd44f7742006-09-29 17:11:14 -0700694static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700696 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700697 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800698 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700#if DUMP_PACKETS >0
Chas Williamsd44f7742006-09-29 17:11:14 -0700701 int i = 0;
702 char buf[300];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Chas Williamsd44f7742006-09-29 17:11:14 -0700704 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
705 vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700707 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700708 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700709 lec_vcc_close(priv, vcc);
710 return;
711 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700713 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
714 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700716 for (i = 0; i < skb->len && i < 99; i++) {
717 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
718 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700720 for (i = 0; i < skb->len && i < 30; i++) {
721 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
722 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700724 if (i == skb->len)
725 printk("%s\n", buf);
726 else
727 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700729 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 struct sock *sk = sk_atm(vcc);
731
Stephen Hemminger52240062007-08-28 15:22:09 -0700732 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700733 skb_queue_tail(&sk->sk_receive_queue, skb);
734 sk->sk_data_ready(sk, skb->len);
735 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700736 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700737 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
Chas Williamsd44f7742006-09-29 17:11:14 -0700739 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800740 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700741 !priv->lecd || !(dev->flags & IFF_UP)) {
742 /*
743 * Probably looping back, or if lecd is missing,
744 * lecd has gone down
745 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700746 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700747 dev_kfree_skb(skb);
748 return;
749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700751 if (priv->is_trdev)
752 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
753 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700755 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700756
Chas Williamsd44f7742006-09-29 17:11:14 -0700757 /*
758 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700759 * the LE_ARP cache entry, delete the LE_ARP cache entry.
760 */
761 spin_lock_irqsave(&priv->lec_arp_lock, flags);
762 if (lec_is_data_direct(vcc)) {
763#ifdef CONFIG_TR
764 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700765 src =
766 ((struct lecdatahdr_8025 *)skb->data)->
767 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700768 else
769#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700770 src =
771 ((struct lecdatahdr_8023 *)skb->data)->
772 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700773 entry = lec_arp_find(priv, src);
774 if (entry && entry->vcc != vcc) {
775 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700776 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700777 }
778 }
779 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
Chas Williamsd44f7742006-09-29 17:11:14 -0700781 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
782 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700784 dev_kfree_skb(skb);
785 return;
786 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700787 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700788 lec_arp_check_empties(priv, vcc, skb);
789 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700790 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700792 if (priv->is_trdev)
793 skb->protocol = tr_type_trans(skb, dev);
794 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700796 skb->protocol = eth_type_trans(skb, dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000797 dev->stats.rx_packets++;
798 dev->stats.rx_bytes += skb->len;
Chas Williamsd44f7742006-09-29 17:11:14 -0700799 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
800 netif_rx(skb);
801 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802}
803
Chas Williamsd44f7742006-09-29 17:11:14 -0700804static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805{
806 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
807 struct net_device *dev = skb->dev;
808
809 if (vpriv == NULL) {
810 printk("lec_pop(): vpriv = NULL!?!?!?\n");
811 return;
812 }
813
814 vpriv->old_pop(vcc, skb);
815
816 if (vpriv->xoff && atm_may_send(vcc, 0)) {
817 vpriv->xoff = 0;
818 if (netif_running(dev) && netif_queue_stopped(dev))
819 netif_wake_queue(dev);
820 }
821}
822
Chas Williamsd44f7742006-09-29 17:11:14 -0700823static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824{
825 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700826 int bytes_left;
827 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Chas Williamsd44f7742006-09-29 17:11:14 -0700829 /* Lecd must be up in this case */
830 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
831 if (bytes_left != 0) {
832 printk
833 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
834 bytes_left);
835 }
836 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
837 !dev_lec[ioc_data.dev_num])
838 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
840 return -ENOMEM;
841 vpriv->xoff = 0;
842 vpriv->old_pop = vcc->pop;
843 vcc->user_back = vpriv;
844 vcc->pop = lec_pop;
Wang Chen524ad0a2008-11-12 23:39:10 -0800845 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
Chas Williamsd44f7742006-09-29 17:11:14 -0700846 &ioc_data, vcc, vcc->push);
847 vcc->proto_data = dev_lec[ioc_data.dev_num];
848 vcc->push = lec_push;
849 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850}
851
Chas Williamsd44f7742006-09-29 17:11:14 -0700852static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853{
Chas Williamsd44f7742006-09-29 17:11:14 -0700854 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
855 return -EINVAL;
856 vcc->proto_data = dev_lec[arg];
Wang Chen524ad0a2008-11-12 23:39:10 -0800857 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
858 vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859}
860
861/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700862static int lecd_attach(struct atm_vcc *vcc, int arg)
863{
864 int i;
865 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Chas Williamsd44f7742006-09-29 17:11:14 -0700867 if (arg < 0)
868 i = 0;
869 else
870 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700872 if (arg >= MAX_LEC_ITF)
873 return -EINVAL;
874#else /* Reserve the top NUM_TR_DEVS for TR */
875 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
876 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700878 if (!dev_lec[i]) {
879 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
Chas Williamsd44f7742006-09-29 17:11:14 -0700881 is_trdev = 0;
882 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
883 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
Chas Williamsd44f7742006-09-29 17:11:14 -0700885 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700887 if (is_trdev)
888 dev_lec[i] = alloc_trdev(size);
889 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700891 dev_lec[i] = alloc_etherdev(size);
892 if (!dev_lec[i])
893 return -ENOMEM;
894 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
895 if (register_netdev(dev_lec[i])) {
896 free_netdev(dev_lec[i]);
897 return -EINVAL;
898 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Wang Chen524ad0a2008-11-12 23:39:10 -0800900 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700901 priv->is_trdev = is_trdev;
902 lec_init(dev_lec[i]);
903 } else {
Wang Chen524ad0a2008-11-12 23:39:10 -0800904 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700905 if (priv->lecd)
906 return -EADDRINUSE;
907 }
908 lec_arp_init(priv);
909 priv->itfnum = i; /* LANE2 addition */
910 priv->lecd = vcc;
911 vcc->dev = &lecatm_dev;
912 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Chas Williamsd44f7742006-09-29 17:11:14 -0700914 vcc->proto_data = dev_lec[i];
915 set_bit(ATM_VF_META, &vcc->flags);
916 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Chas Williamsd44f7742006-09-29 17:11:14 -0700918 /* Set default values to these variables */
919 priv->maximum_unknown_frame_count = 1;
920 priv->max_unknown_frame_time = (1 * HZ);
921 priv->vcc_timeout_period = (1200 * HZ);
922 priv->max_retry_count = 1;
923 priv->aging_time = (300 * HZ);
924 priv->forward_delay_time = (15 * HZ);
925 priv->topology_change = 0;
926 priv->arp_response_time = (1 * HZ);
927 priv->flush_timeout = (4 * HZ);
928 priv->path_switching_delay = (6 * HZ);
929
930 if (dev_lec[i]->flags & IFF_UP) {
931 netif_start_queue(dev_lec[i]);
932 }
933 __module_get(THIS_MODULE);
934 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935}
936
937#ifdef CONFIG_PROC_FS
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700938static const char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700940 static const char *const lec_arp_status_string[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 "ESI_UNKNOWN ",
942 "ESI_ARP_PENDING ",
943 "ESI_VC_PENDING ",
944 "<Undefined> ",
945 "ESI_FLUSH_PENDING ",
946 "ESI_FORWARD_DIRECT"
947 };
948
949 if (status > ESI_FORWARD_DIRECT)
950 status = 3; /* ESI_UNDEFINED */
951 return lec_arp_status_string[status];
952}
953
954static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
955{
956 int i;
957
958 for (i = 0; i < ETH_ALEN; i++)
959 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
960 seq_printf(seq, " ");
961 for (i = 0; i < ATM_ESA_LEN; i++)
962 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
963 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
964 entry->flags & 0xffff);
965 if (entry->vcc)
966 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
967 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700968 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 if (entry->recv_vcc) {
970 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
971 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -0700972 }
973 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974}
975
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976struct lec_state {
977 unsigned long flags;
978 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -0700979 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 struct net_device *dev;
981 int itf;
982 int arp_table;
983 int misc_table;
984};
985
Chas Williamsd0732f62006-09-29 17:14:27 -0700986static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 loff_t *l)
988{
Chas Williamsd0732f62006-09-29 17:14:27 -0700989 struct hlist_node *e = state->node;
990 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
992 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -0700993 e = tbl->first;
Joe Perches2e1e9842008-04-10 03:33:03 -0700994 if (e == SEQ_START_TOKEN) {
Chas Williamsd0732f62006-09-29 17:14:27 -0700995 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 --*l;
997 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700998
999 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 if (--*l < 0)
1001 break;
1002 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001003 state->node = e;
1004
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 return (*l < 0) ? state : NULL;
1006}
1007
1008static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -07001009 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010{
1011 void *v = NULL;
1012 int p;
1013
1014 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001015 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 if (v)
1017 break;
1018 }
1019 state->arp_table = p;
1020 return v;
1021}
1022
1023static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1024 struct lec_priv *priv)
1025{
Chas Williamsd0732f62006-09-29 17:14:27 -07001026 struct hlist_head *lec_misc_tables[] = {
1027 &priv->lec_arp_empty_ones,
1028 &priv->lec_no_forward,
1029 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 };
1031 void *v = NULL;
1032 int q;
1033
1034 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1035 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1036 if (v)
1037 break;
1038 }
1039 state->misc_table = q;
1040 return v;
1041}
1042
1043static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1044 struct lec_priv *priv)
1045{
1046 if (!state->locked) {
1047 state->locked = priv;
1048 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1049 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001050 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1052 state->locked = NULL;
1053 /* Partial state reset for the next time we get called */
1054 state->arp_table = state->misc_table = 0;
1055 }
1056 return state->locked;
1057}
1058
1059static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1060{
1061 struct net_device *dev;
1062 void *v;
1063
1064 dev = state->dev ? state->dev : dev_lec[state->itf];
Wang Chen524ad0a2008-11-12 23:39:10 -08001065 v = (dev && netdev_priv(dev)) ?
1066 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 if (!v && dev) {
1068 dev_put(dev);
1069 /* Partial state reset for the next time we get called */
1070 dev = NULL;
1071 }
1072 state->dev = dev;
1073 return v;
1074}
1075
1076static void *lec_get_idx(struct lec_state *state, loff_t l)
1077{
1078 void *v = NULL;
1079
1080 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1081 v = lec_itf_walk(state, &l);
1082 if (v)
1083 break;
1084 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001085 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086}
1087
1088static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1089{
1090 struct lec_state *state = seq->private;
1091
1092 state->itf = 0;
1093 state->dev = NULL;
1094 state->locked = NULL;
1095 state->arp_table = 0;
1096 state->misc_table = 0;
Joe Perches2e1e9842008-04-10 03:33:03 -07001097 state->node = SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Joe Perches2e1e9842008-04-10 03:33:03 -07001099 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100}
1101
1102static void lec_seq_stop(struct seq_file *seq, void *v)
1103{
1104 struct lec_state *state = seq->private;
1105
1106 if (state->dev) {
1107 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1108 state->flags);
1109 dev_put(state->dev);
1110 }
1111}
1112
1113static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1114{
1115 struct lec_state *state = seq->private;
1116
1117 v = lec_get_idx(state, 1);
1118 *pos += !!PTR_ERR(v);
1119 return v;
1120}
1121
1122static int lec_seq_show(struct seq_file *seq, void *v)
1123{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001124 static const char lec_banner[] =
1125 "Itf MAC ATM destination"
Chas Williamsd44f7742006-09-29 17:11:14 -07001126 " Status Flags "
1127 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Joe Perches2e1e9842008-04-10 03:33:03 -07001129 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 seq_puts(seq, lec_banner);
1131 else {
1132 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001133 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001134 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
1136 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001137 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 }
1139 return 0;
1140}
1141
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001142static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001143 .start = lec_seq_start,
1144 .next = lec_seq_next,
1145 .stop = lec_seq_stop,
1146 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147};
1148
1149static int lec_seq_open(struct inode *inode, struct file *file)
1150{
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001151 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
Arjan van de Ven9a321442007-02-12 00:55:35 -08001154static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001155 .owner = THIS_MODULE,
1156 .open = lec_seq_open,
1157 .read = seq_read,
1158 .llseek = seq_lseek,
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001159 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160};
1161#endif
1162
1163static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1164{
1165 struct atm_vcc *vcc = ATM_SD(sock);
1166 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001167
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001169 case ATMLEC_CTRL:
1170 case ATMLEC_MCAST:
1171 case ATMLEC_DATA:
1172 if (!capable(CAP_NET_ADMIN))
1173 return -EPERM;
1174 break;
1175 default:
1176 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 }
1178
1179 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001180 case ATMLEC_CTRL:
1181 err = lecd_attach(vcc, (int)arg);
1182 if (err >= 0)
1183 sock->state = SS_CONNECTED;
1184 break;
1185 case ATMLEC_MCAST:
1186 err = lec_mcast_attach(vcc, (int)arg);
1187 break;
1188 case ATMLEC_DATA:
1189 err = lec_vcc_attach(vcc, (void __user *)arg);
1190 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 }
1192
1193 return err;
1194}
1195
1196static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001197 .owner = THIS_MODULE,
1198 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199};
1200
1201static int __init lane_module_init(void)
1202{
1203#ifdef CONFIG_PROC_FS
1204 struct proc_dir_entry *p;
1205
Wang Chen16e297b2008-02-28 13:55:45 -08001206 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Wang Chendbee0d32008-03-23 21:45:36 -07001207 if (!p) {
1208 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n");
1209 return -ENOMEM;
1210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211#endif
1212
1213 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001214 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1215 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216}
1217
1218static void __exit lane_module_cleanup(void)
1219{
Chas Williamsd44f7742006-09-29 17:11:14 -07001220 int i;
1221 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
1223 remove_proc_entry("lec", atm_proc_root);
1224
1225 deregister_atm_ioctl(&lane_ioctl_ops);
1226
Chas Williamsd44f7742006-09-29 17:11:14 -07001227 for (i = 0; i < MAX_LEC_ITF; i++) {
1228 if (dev_lec[i] != NULL) {
Wang Chen524ad0a2008-11-12 23:39:10 -08001229 priv = netdev_priv(dev_lec[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001231 free_netdev(dev_lec[i]);
1232 dev_lec[i] = NULL;
1233 }
1234 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
Chas Williamsd44f7742006-09-29 17:11:14 -07001236 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237}
1238
1239module_init(lane_module_init);
1240module_exit(lane_module_cleanup);
1241
1242/*
1243 * LANE2: 3.1.3, LE_RESOLVE.request
1244 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1245 * If sizeoftlvs == NULL the default TLVs associated with with this
1246 * lec will be used.
1247 * If dst_mac == NULL, targetless LE_ARP will be sent
1248 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001249static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001250 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251{
1252 unsigned long flags;
Wang Chen524ad0a2008-11-12 23:39:10 -08001253 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001254 struct lec_arp_table *table;
1255 struct sk_buff *skb;
1256 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Chas Williamsd44f7742006-09-29 17:11:14 -07001258 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001260 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001262 if (table == NULL)
1263 return -1;
1264
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001265 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001266 if (*tlvs == NULL)
1267 return -1;
1268
Chas Williamsd44f7742006-09-29 17:11:14 -07001269 *sizeoftlvs = table->sizeoftlvs;
1270
1271 return 0;
1272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
1274 if (sizeoftlvs == NULL)
1275 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001276
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 else {
1278 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1279 if (skb == NULL)
1280 return -1;
1281 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001282 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1284 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001285 return retval;
1286}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
1288/*
1289 * LANE2: 3.1.4, LE_ASSOCIATE.request
1290 * Associate the *tlvs with the *lan_dst address.
1291 * Will overwrite any previous association
1292 * Returns 1 for success, 0 for failure (out of memory)
1293 *
1294 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001295static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1296 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297{
Chas Williamsd44f7742006-09-29 17:11:14 -07001298 int retval;
1299 struct sk_buff *skb;
Wang Chen524ad0a2008-11-12 23:39:10 -08001300 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
Chas Williamsd44f7742006-09-29 17:11:14 -07001302 if (compare_ether_addr(lan_dst, dev->dev_addr))
1303 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Chas Williamsd44f7742006-09-29 17:11:14 -07001305 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001307 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001308 if (priv->tlvs == NULL)
1309 return (0);
1310 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Chas Williamsd44f7742006-09-29 17:11:14 -07001312 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1313 if (skb == NULL)
1314 return 0;
1315 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001316 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001317 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1318 if (retval != 0)
1319 printk("lec.c: lane2_associate_req() failed\n");
1320 /*
1321 * If the previous association has changed we must
1322 * somehow notify other LANE entities about the change
1323 */
1324 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325}
1326
1327/*
1328 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1329 *
1330 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001331static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1332 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333{
1334#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001335 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336#endif
Wang Chen524ad0a2008-11-12 23:39:10 -08001337 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001338#if 0 /*
1339 * Why have the TLVs in LE_ARP entries
1340 * since we do not use them? When you
1341 * uncomment this code, make sure the
1342 * TLVs get freed when entry is killed
1343 */
1344 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Chas Williamsd44f7742006-09-29 17:11:14 -07001346 if (entry == NULL)
1347 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Chas Williamsd44f7742006-09-29 17:11:14 -07001349 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001351 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001352 if (entry->tlvs == NULL)
1353 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001354 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355#endif
1356#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001357 printk("lec.c: lane2_associate_ind()\n");
1358 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1359 while (i < sizeoftlvs)
1360 printk("%02x ", tlvs[i++]);
1361
1362 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363#endif
1364
Chas Williamsd44f7742006-09-29 17:11:14 -07001365 /* tell MPOA about the TLVs we saw */
1366 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1367 priv->lane2_ops->associate_indicator(dev, mac_addr,
1368 tlvs, sizeoftlvs);
1369 }
1370 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371}
1372
1373/*
1374 * Here starts what used to lec_arpc.c
1375 *
1376 * lec_arpc.c was added here when making
1377 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 */
1379
1380#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381#include <linux/timer.h>
1382#include <asm/param.h>
1383#include <asm/atomic.h>
1384#include <linux/inetdevice.h>
1385#include <net/route.h>
1386
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387#if 0
Stephen Hemminger52240062007-08-28 15:22:09 -07001388#define pr_debug(format,args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389/*
Stephen Hemminger52240062007-08-28 15:22:09 -07001390#define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391*/
1392#endif
1393#define DEBUG_ARP_TABLE 0
1394
1395#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1396
David Howellsc4028952006-11-22 14:57:56 +00001397static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398static void lec_arp_expire_arp(unsigned long data);
1399
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001400/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 * Arp table funcs
1402 */
1403
1404#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1405
1406/*
1407 * Initialization of arp-cache
1408 */
Chas Williams1fa99612006-09-29 17:11:47 -07001409static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410{
Chas Williams1fa99612006-09-29 17:11:47 -07001411 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
Chas Williams1fa99612006-09-29 17:11:47 -07001413 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001414 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001415 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001416 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1417 INIT_HLIST_HEAD(&priv->lec_no_forward);
1418 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001420 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001421 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422}
1423
Chas Williams1fa99612006-09-29 17:11:47 -07001424static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425{
Chas Williams1fa99612006-09-29 17:11:47 -07001426 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 struct atm_vcc *vcc = entry->vcc;
1428 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001429 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Chas Williams1fa99612006-09-29 17:11:47 -07001431 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 if (vpriv->xoff)
1433 netif_wake_queue(dev);
1434 kfree(vpriv);
1435 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001436 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001438 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001439 }
1440 if (entry->recv_vcc) {
1441 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001443 entry->recv_vcc = NULL;
1444 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445}
1446
1447/*
1448 * Insert entry to lec_arp_table
1449 * LANE2: Add to the end of the list to satisfy 8.1.13
1450 */
Chas Williams1fa99612006-09-29 17:11:47 -07001451static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001452lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453{
Chas Williamsd0732f62006-09-29 17:14:27 -07001454 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Chas Williamsd0732f62006-09-29 17:14:27 -07001456 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1457 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001458
Stephen Hemminger52240062007-08-28 15:22:09 -07001459 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 -07001460 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1461 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1462 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463}
1464
1465/*
1466 * Remove entry from lec_arp_table
1467 */
Chas Williams1fa99612006-09-29 17:11:47 -07001468static int
1469lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470{
Chas Williamsd0732f62006-09-29 17:14:27 -07001471 struct hlist_node *node;
1472 struct lec_arp_table *entry;
1473 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Chas Williams1fa99612006-09-29 17:11:47 -07001475 if (!to_remove) {
1476 return -1;
1477 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001478
1479 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001480 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Chas Williamsd0732f62006-09-29 17:14:27 -07001482 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001483 if (to_remove->status >= ESI_FLUSH_PENDING) {
1484 /*
1485 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1486 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001487 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1488 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1489 if (memcmp(to_remove->atm_addr,
1490 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001491 remove_vcc = 0;
1492 break;
1493 }
1494 }
1495 }
1496 if (remove_vcc)
1497 lec_arp_clear_vccs(to_remove);
1498 }
1499 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1500
Stephen Hemminger52240062007-08-28 15:22:09 -07001501 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 -07001502 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1503 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1504 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1505 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506}
1507
1508#if DEBUG_ARP_TABLE
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001509static const char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510{
Chas Williams1fa99612006-09-29 17:11:47 -07001511 switch (st) {
1512 case ESI_UNKNOWN:
1513 return "ESI_UNKNOWN";
1514 case ESI_ARP_PENDING:
1515 return "ESI_ARP_PENDING";
1516 case ESI_VC_PENDING:
1517 return "ESI_VC_PENDING";
1518 case ESI_FLUSH_PENDING:
1519 return "ESI_FLUSH_PENDING";
1520 case ESI_FORWARD_DIRECT:
1521 return "ESI_FORWARD_DIRECT";
1522 default:
1523 return "<UNKNOWN>";
1524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
Chas Williams1fa99612006-09-29 17:11:47 -07001527static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528{
Chas Williamsd0732f62006-09-29 17:14:27 -07001529 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001530 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001531 char buf[256];
1532 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Chas Williams1fa99612006-09-29 17:11:47 -07001534 printk("Dump %p:\n", priv);
1535 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001536 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1537 offset = 0;
1538 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001539 offset += sprintf(buf + offset, "Mac:");
1540 for (j = 0; j < ETH_ALEN; j++) {
1541 offset += sprintf(buf + offset,
1542 "%2.2x ",
1543 rulla->mac_addr[j] & 0xff);
1544 }
1545 offset += sprintf(buf + offset, "Atm:");
1546 for (j = 0; j < ATM_ESA_LEN; j++) {
1547 offset += sprintf(buf + offset,
1548 "%2.2x ",
1549 rulla->atm_addr[j] & 0xff);
1550 }
1551 offset += sprintf(buf + offset,
1552 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1553 rulla->vcc ? rulla->vcc->vpi : 0,
1554 rulla->vcc ? rulla->vcc->vci : 0,
1555 rulla->recv_vcc ? rulla->recv_vcc->
1556 vpi : 0,
1557 rulla->recv_vcc ? rulla->recv_vcc->
1558 vci : 0, rulla->last_used,
1559 rulla->timestamp, rulla->no_tries);
1560 offset +=
1561 sprintf(buf + offset,
1562 "Flags:%x, Packets_flooded:%x, Status: %s ",
1563 rulla->flags, rulla->packets_flooded,
1564 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001565 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001566 }
Chas Williams1fa99612006-09-29 17:11:47 -07001567 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001568
1569 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001570 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001571 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001572 offset = 0;
1573 offset += sprintf(buf + offset, "Mac:");
1574 for (j = 0; j < ETH_ALEN; j++) {
1575 offset += sprintf(buf + offset, "%2.2x ",
1576 rulla->mac_addr[j] & 0xff);
1577 }
1578 offset += sprintf(buf + offset, "Atm:");
1579 for (j = 0; j < ATM_ESA_LEN; j++) {
1580 offset += sprintf(buf + offset, "%2.2x ",
1581 rulla->atm_addr[j] & 0xff);
1582 }
1583 offset += sprintf(buf + offset,
1584 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1585 rulla->vcc ? rulla->vcc->vpi : 0,
1586 rulla->vcc ? rulla->vcc->vci : 0,
1587 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1588 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1589 rulla->last_used,
1590 rulla->timestamp, rulla->no_tries);
1591 offset += sprintf(buf + offset,
1592 "Flags:%x, Packets_flooded:%x, Status: %s ",
1593 rulla->flags, rulla->packets_flooded,
1594 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001595 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001596 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001597
1598 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001599 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001600 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001601 offset = 0;
1602 offset += sprintf(buf + offset, "Mac:");
1603 for (j = 0; j < ETH_ALEN; j++) {
1604 offset += sprintf(buf + offset, "%2.2x ",
1605 rulla->mac_addr[j] & 0xff);
1606 }
1607 offset += sprintf(buf + offset, "Atm:");
1608 for (j = 0; j < ATM_ESA_LEN; j++) {
1609 offset += sprintf(buf + offset, "%2.2x ",
1610 rulla->atm_addr[j] & 0xff);
1611 }
1612 offset += sprintf(buf + offset,
1613 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1614 rulla->vcc ? rulla->vcc->vpi : 0,
1615 rulla->vcc ? rulla->vcc->vci : 0,
1616 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1617 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1618 rulla->last_used,
1619 rulla->timestamp, rulla->no_tries);
1620 offset += sprintf(buf + offset,
1621 "Flags:%x, Packets_flooded:%x, Status: %s ",
1622 rulla->flags, rulla->packets_flooded,
1623 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001624 printk("%s", buf);
1625 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
Chas Williamsd0732f62006-09-29 17:14:27 -07001627 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001628 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001629 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001630 offset = 0;
1631 offset += sprintf(buf + offset, "Mac:");
1632 for (j = 0; j < ETH_ALEN; j++) {
1633 offset += sprintf(buf + offset, "%2.2x ",
1634 rulla->mac_addr[j] & 0xff);
1635 }
1636 offset += sprintf(buf + offset, "Atm:");
1637 for (j = 0; j < ATM_ESA_LEN; j++) {
1638 offset += sprintf(buf + offset, "%2.2x ",
1639 rulla->atm_addr[j] & 0xff);
1640 }
1641 offset += sprintf(buf + offset,
1642 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1643 rulla->vcc ? rulla->vcc->vpi : 0,
1644 rulla->vcc ? rulla->vcc->vci : 0,
1645 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1646 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1647 rulla->last_used,
1648 rulla->timestamp, rulla->no_tries);
1649 offset += sprintf(buf + offset,
1650 "Flags:%x, Packets_flooded:%x, Status: %s ",
1651 rulla->flags, rulla->packets_flooded,
1652 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001653 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656}
Chas Williamsd0732f62006-09-29 17:14:27 -07001657#else
1658#define dump_arp_table(priv) do { } while (0)
1659#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
1661/*
1662 * Destruction of arp-cache
1663 */
Chas Williams1fa99612006-09-29 17:11:47 -07001664static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665{
1666 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001667 struct hlist_node *node, *next;
1668 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001669 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
Chas Williams987e46b2006-09-29 17:15:59 -07001671 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001672
1673 /*
1674 * Remove all entries
1675 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
1677 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001678 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001679 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001680 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001681 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001682 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001683 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001684 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001685
1686 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001687 del_timer_sync(&entry->timer);
1688 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001689 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001690 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001691 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001692 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1693
1694 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001695 del_timer_sync(&entry->timer);
1696 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001697 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001698 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001699 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001700 INIT_HLIST_HEAD(&priv->lec_no_forward);
1701
1702 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001703 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1704 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001705 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001706 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001707 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001708 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001709 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1711}
1712
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001713/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 * Find entry by mac_address
1715 */
Chas Williams1fa99612006-09-29 17:11:47 -07001716static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001717 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718{
Chas Williamsd0732f62006-09-29 17:14:27 -07001719 struct hlist_node *node;
1720 struct hlist_head *head;
1721 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
Stephen Hemminger52240062007-08-28 15:22:09 -07001723 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 -07001724 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1725 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
Chas Williams1fa99612006-09-29 17:11:47 -07001726
Chas Williamsd0732f62006-09-29 17:14:27 -07001727 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1728 hlist_for_each_entry(entry, node, head, next) {
1729 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1730 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001731 }
Chas Williams1fa99612006-09-29 17:11:47 -07001732 }
1733 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734}
1735
Chas Williams1fa99612006-09-29 17:11:47 -07001736static struct lec_arp_table *make_entry(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001737 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738{
Chas Williams1fa99612006-09-29 17:11:47 -07001739 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Chas Williams1fa99612006-09-29 17:11:47 -07001741 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1742 if (!to_return) {
1743 printk("LEC: Arp entry kmalloc failed\n");
1744 return NULL;
1745 }
1746 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001747 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001748 setup_timer(&to_return->timer, lec_arp_expire_arp,
1749 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001750 to_return->last_used = jiffies;
1751 to_return->priv = priv;
1752 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001753 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001754 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755}
1756
Chas Williams1fa99612006-09-29 17:11:47 -07001757/* Arp sent timer expired */
1758static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759{
Chas Williams1fa99612006-09-29 17:11:47 -07001760 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
Chas Williams1fa99612006-09-29 17:11:47 -07001762 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
Stephen Hemminger52240062007-08-28 15:22:09 -07001764 pr_debug("lec_arp_expire_arp\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001765 if (entry->status == ESI_ARP_PENDING) {
1766 if (entry->no_tries <= entry->priv->max_retry_count) {
1767 if (entry->is_rdesc)
1768 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1769 entry->mac_addr, NULL, NULL);
1770 else
1771 send_to_lecd(entry->priv, l_arp_xmt,
1772 entry->mac_addr, NULL, NULL);
1773 entry->no_tries++;
1774 }
1775 mod_timer(&entry->timer, jiffies + (1 * HZ));
1776 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777}
1778
Chas Williams1fa99612006-09-29 17:11:47 -07001779/* Unknown/unused vcc expire, remove associated entry */
1780static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781{
1782 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001783 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1784 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785
Chas Williams1fa99612006-09-29 17:11:47 -07001786 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
Stephen Hemminger52240062007-08-28 15:22:09 -07001788 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001789 to_remove, priv,
1790 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1791 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
1793 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001794 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1796
Chas Williams1fa99612006-09-29 17:11:47 -07001797 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001798 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799}
1800
1801/*
1802 * Expire entries.
1803 * 1. Re-set timer
1804 * 2. For each entry, delete entries that have aged past the age limit.
1805 * 3. For each entry, depending on the status of the entry, perform
1806 * the following maintenance.
1807 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1808 * tick_count is above the max_unknown_frame_time, clear
1809 * the tick_count to zero and clear the packets_flooded counter
1810 * to zero. This supports the packet rate limit per address
1811 * while flooding unknowns.
1812 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1813 * than or equal to the path_switching_delay, change the status
1814 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1815 * regardless of the progress of the flush protocol.
1816 */
David Howellsc4028952006-11-22 14:57:56 +00001817static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818{
1819 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001820 struct lec_priv *priv =
1821 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001822 struct hlist_node *node, *next;
1823 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001824 unsigned long now;
1825 unsigned long time_to_check;
1826 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
Stephen Hemminger52240062007-08-28 15:22:09 -07001828 pr_debug("lec_arp_check_expire %p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001830restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001832 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001833 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001834 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 priv->topology_change)
1836 time_to_check = priv->forward_delay_time;
1837 else
1838 time_to_check = priv->aging_time;
1839
Stephen Hemminger52240062007-08-28 15:22:09 -07001840 pr_debug("About to expire: %lx - %lx > %lx\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001841 now, entry->last_used, time_to_check);
1842 if (time_after(now, entry->last_used + time_to_check)
1843 && !(entry->flags & LEC_PERMANENT_FLAG)
1844 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 /* Remove entry */
Stephen Hemminger52240062007-08-28 15:22:09 -07001846 pr_debug("LEC:Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001848 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 } else {
1850 /* Something else */
1851 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001852 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001854 entry->timestamp +
1855 priv->
1856 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 entry->timestamp = jiffies;
1858 entry->packets_flooded = 0;
1859 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001860 send_to_lecd(priv, l_svc_setup,
1861 entry->mac_addr,
1862 entry->atm_addr,
1863 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 }
Chas Williams1fa99612006-09-29 17:11:47 -07001865 if (entry->status == ESI_FLUSH_PENDING
1866 &&
1867 time_after_eq(now, entry->timestamp +
1868 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001870 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871
Chas Williams6656e3c2006-09-29 17:17:17 -07001872 lec_arp_hold(entry);
1873 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1874 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
Stephen Hemminger162619e2009-01-09 13:01:01 +00001875 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001877 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001878 lec_arp_put(entry);
1879 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 }
1882 }
1883 }
1884 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1885
Chas Williams987e46b2006-09-29 17:15:59 -07001886 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887}
Chas Williams1fa99612006-09-29 17:11:47 -07001888
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889/*
1890 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001891 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 */
Chas Williams1fa99612006-09-29 17:11:47 -07001893static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001894 const unsigned char *mac_to_find, int is_rdesc,
Chas Williams1fa99612006-09-29 17:11:47 -07001895 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896{
1897 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001898 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 struct atm_vcc *found;
1900
Chas Williams1fa99612006-09-29 17:11:47 -07001901 if (mac_to_find[0] & 0x01) {
1902 switch (priv->lane_version) {
1903 case 1:
1904 return priv->mcast_vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07001905 case 2: /* LANE2 wants arp for multicast addresses */
1906 if (!compare_ether_addr(mac_to_find, bus_mac))
1907 return priv->mcast_vcc;
1908 break;
1909 default:
1910 break;
1911 }
1912 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
1914 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001915 entry = lec_arp_find(priv, mac_to_find);
1916
1917 if (entry) {
1918 if (entry->status == ESI_FORWARD_DIRECT) {
1919 /* Connection Ok */
1920 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001921 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001922 *ret_entry = entry;
1923 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001925 }
1926 /*
1927 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001928 * so another LE_ARP request can be made for this frame.
1929 */
1930 if (entry->status == ESI_ARP_PENDING) {
1931 entry->no_tries = 0;
1932 }
Chas Williams1fa99612006-09-29 17:11:47 -07001933 /*
1934 * Data direct VC not yet set up, check to see if the unknown
1935 * frame count is greater than the limit. If the limit has
1936 * not been reached, allow the caller to send packet to
1937 * BUS.
1938 */
1939 if (entry->status != ESI_FLUSH_PENDING &&
1940 entry->packets_flooded <
1941 priv->maximum_unknown_frame_count) {
1942 entry->packets_flooded++;
Stephen Hemminger52240062007-08-28 15:22:09 -07001943 pr_debug("LEC_ARP: Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001944 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001946 }
1947 /*
1948 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 * or BUS flood limit was reached for an entry which is
1950 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1951 */
Chas Williams6656e3c2006-09-29 17:17:17 -07001952 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001953 *ret_entry = entry;
Stephen Hemminger52240062007-08-28 15:22:09 -07001954 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
Chas Williams1fa99612006-09-29 17:11:47 -07001955 entry->vcc);
1956 found = NULL;
1957 } else {
1958 /* No matching entry was found */
1959 entry = make_entry(priv, mac_to_find);
Stephen Hemminger52240062007-08-28 15:22:09 -07001960 pr_debug("LEC_ARP: Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001961 if (!entry) {
1962 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001964 }
1965 lec_arp_add(priv, entry);
1966 /* We want arp-request(s) to be sent */
1967 entry->packets_flooded = 1;
1968 entry->status = ESI_ARP_PENDING;
1969 entry->no_tries = 1;
1970 entry->last_used = entry->timestamp = jiffies;
1971 entry->is_rdesc = is_rdesc;
1972 if (entry->is_rdesc)
1973 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1974 NULL);
1975 else
1976 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1977 entry->timer.expires = jiffies + (1 * HZ);
1978 entry->timer.function = lec_arp_expire_arp;
1979 add_timer(&entry->timer);
1980 found = priv->mcast_vcc;
1981 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982
1983out:
1984 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1985 return found;
1986}
1987
1988static int
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001989lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07001990 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991{
1992 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001993 struct hlist_node *node, *next;
1994 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001995 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
Stephen Hemminger52240062007-08-28 15:22:09 -07001997 pr_debug("lec_addr_delete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001999 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002000 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002001 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2002 && (permanent ||
2003 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002005 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002006 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002008 return 0;
2009 }
2010 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002012 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013}
2014
2015/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002016 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 */
2018static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002019lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
2020 const unsigned char *atm_addr, unsigned long remoteflag,
Chas Williams1fa99612006-09-29 17:11:47 -07002021 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022{
2023 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002024 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07002025 struct lec_arp_table *entry, *tmp;
2026 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027
Stephen Hemminger52240062007-08-28 15:22:09 -07002028 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2029 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 -07002030 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2031 mac_addr[4], mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032
2033 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002034 entry = lec_arp_find(priv, mac_addr);
2035 if (entry == NULL && targetless_le_arp)
2036 goto out; /*
2037 * LANE2: ignore targetless LE_ARPs for which
2038 * we have no entry in the cache. 7.1.30
2039 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002040 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2041 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2042 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2043 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002044 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002045 tmp = lec_arp_find(priv, mac_addr);
2046 if (tmp) {
2047 del_timer(&tmp->timer);
2048 tmp->status = ESI_FORWARD_DIRECT;
2049 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2050 tmp->vcc = entry->vcc;
2051 tmp->old_push = entry->old_push;
2052 tmp->last_used = jiffies;
2053 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002054 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002055 entry = tmp;
2056 } else {
2057 entry->status = ESI_FORWARD_DIRECT;
2058 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2059 entry->last_used = jiffies;
2060 lec_arp_add(priv, entry);
2061 }
2062 if (remoteflag)
2063 entry->flags |= LEC_REMOTE_FLAG;
2064 else
2065 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002066 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002067 dump_arp_table(priv);
2068 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002069 }
Chas Williams1fa99612006-09-29 17:11:47 -07002070 }
2071 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002072
Chas Williams1fa99612006-09-29 17:11:47 -07002073 entry = lec_arp_find(priv, mac_addr);
2074 if (!entry) {
2075 entry = make_entry(priv, mac_addr);
2076 if (!entry)
2077 goto out;
2078 entry->status = ESI_UNKNOWN;
2079 lec_arp_add(priv, entry);
2080 /* Temporary, changes before end of function */
2081 }
2082 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2083 del_timer(&entry->timer);
2084 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002085 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002086 if (entry != tmp &&
2087 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2088 /* Vcc to this host exists */
2089 if (tmp->status > ESI_VC_PENDING) {
2090 /*
2091 * ESI_FLUSH_PENDING,
2092 * ESI_FORWARD_DIRECT
2093 */
2094 entry->vcc = tmp->vcc;
2095 entry->old_push = tmp->old_push;
2096 }
2097 entry->status = tmp->status;
2098 break;
2099 }
2100 }
2101 }
2102 if (remoteflag)
2103 entry->flags |= LEC_REMOTE_FLAG;
2104 else
2105 entry->flags &= ~LEC_REMOTE_FLAG;
2106 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2107 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002108 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002109 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002110 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002111 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112out:
2113 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2114}
2115
2116/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002117 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 */
2119static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002120lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002121 struct atm_vcc *vcc,
2122 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123{
2124 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002125 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002126 struct lec_arp_table *entry;
2127 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128
2129 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002130 if (ioc_data->receive == 2) {
2131 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132
Stephen Hemminger52240062007-08-28 15:22:09 -07002133 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002135 entry = lec_arp_find(priv, bus_mac);
2136 if (!entry) {
2137 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002139 }
2140 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2141 entry->recv_vcc = vcc;
2142 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002144 entry = make_entry(priv, bus_mac);
2145 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002147 del_timer(&entry->timer);
2148 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2149 entry->recv_vcc = vcc;
2150 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002151 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002152 goto out;
2153 } else if (ioc_data->receive == 1) {
2154 /*
2155 * Vcc which we don't want to make default vcc,
2156 * attach it anyway.
2157 */
Stephen Hemminger52240062007-08-28 15:22:09 -07002158 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002159 ("LEC_ARP:Attaching data direct, not default: "
2160 "%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",
2161 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2162 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2163 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2164 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2165 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2166 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2167 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2168 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2169 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2170 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2171 entry = make_entry(priv, bus_mac);
2172 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002174 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2175 memset(entry->mac_addr, 0, ETH_ALEN);
2176 entry->recv_vcc = vcc;
2177 entry->old_recv_push = old_push;
2178 entry->status = ESI_UNKNOWN;
2179 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2180 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002181 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002182 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 dump_arp_table(priv);
2184 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002185 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002186 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002187 ("LEC_ARP:Attaching data direct, default: "
2188 "%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",
2189 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2190 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2191 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2192 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2193 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2194 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2195 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2196 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2197 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2198 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2199 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002200 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002201 if (memcmp
2202 (ioc_data->atm_addr, entry->atm_addr,
2203 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002204 pr_debug("LEC_ARP: Attaching data direct\n");
2205 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07002206 entry->vcc ? entry->vcc->vci : 0,
2207 entry->recv_vcc ? entry->recv_vcc->
2208 vci : 0);
2209 found_entry = 1;
2210 del_timer(&entry->timer);
2211 entry->vcc = vcc;
2212 entry->old_push = old_push;
2213 if (entry->status == ESI_VC_PENDING) {
2214 if (priv->maximum_unknown_frame_count
2215 == 0)
2216 entry->status =
2217 ESI_FORWARD_DIRECT;
2218 else {
2219 entry->timestamp = jiffies;
2220 entry->status =
2221 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002223 send_to_lecd(priv, l_flush_xmt,
2224 NULL,
2225 entry->atm_addr,
2226 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002228 }
2229 } else {
2230 /*
2231 * They were forming a connection
2232 * to us, and we to them. Our
2233 * ATM address is numerically lower
2234 * than theirs, so we make connection
2235 * we formed into default VCC (8.1.11).
2236 * Connection they made gets torn
2237 * down. This might confuse some
2238 * clients. Can be changed if
2239 * someone reports trouble...
2240 */
2241 ;
2242 }
2243 }
2244 }
2245 }
2246 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002247 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002248 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002250 }
2251 /*
2252 * Not found, snatch address from first data packet that arrives
2253 * from this vcc
2254 */
2255 entry = make_entry(priv, bus_mac);
2256 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002258 entry->vcc = vcc;
2259 entry->old_push = old_push;
2260 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2261 memset(entry->mac_addr, 0, ETH_ALEN);
2262 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002263 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002264 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2265 entry->timer.function = lec_arp_expire_vcc;
2266 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002267 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 dump_arp_table(priv);
2269out:
2270 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2271}
2272
Chas Williams1fa99612006-09-29 17:11:47 -07002273static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274{
2275 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002276 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002277 struct lec_arp_table *entry;
2278 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279
Stephen Hemminger52240062007-08-28 15:22:09 -07002280 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002281restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002282 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2283 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002284 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002285 if (entry->flush_tran_id == tran_id
2286 && entry->status == ESI_FLUSH_PENDING) {
2287 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002288 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002289
Chas Williams6656e3c2006-09-29 17:17:17 -07002290 lec_arp_hold(entry);
2291 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2292 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
Stephen Hemminger162619e2009-01-09 13:01:01 +00002293 lec_send(vcc, skb);
Chas Williams6656e3c2006-09-29 17:17:17 -07002294 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002295 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002296 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002297 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002298 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002299 }
2300 }
2301 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002303 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304}
2305
2306static void
2307lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002308 const unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309{
2310 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002311 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002312 struct lec_arp_table *entry;
2313 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314
2315 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002316 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002317 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002318 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2319 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002320 pr_debug("Set flush transaction id to %lx for %p\n",
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002321 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002322 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2325}
2326
Chas Williams1fa99612006-09-29 17:11:47 -07002327static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328{
2329 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002330 unsigned char mac_addr[] = {
2331 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2332 };
2333 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 struct lec_vcc_priv *vpriv;
2335 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002336
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2338 return -ENOMEM;
2339 vpriv->xoff = 0;
2340 vpriv->old_pop = vcc->pop;
2341 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002342 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002344 to_add = make_entry(priv, mac_addr);
2345 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 vcc->pop = vpriv->old_pop;
2347 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002348 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002350 }
2351 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2352 to_add->status = ESI_FORWARD_DIRECT;
2353 to_add->flags |= LEC_PERMANENT_FLAG;
2354 to_add->vcc = vcc;
2355 to_add->old_push = vcc->push;
2356 vcc->push = lec_push;
2357 priv->mcast_vcc = vcc;
2358 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359out:
2360 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002361 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362}
2363
Chas Williams1fa99612006-09-29 17:11:47 -07002364static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365{
2366 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002367 struct hlist_node *node, *next;
2368 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002369 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370
Stephen Hemminger52240062007-08-28 15:22:09 -07002371 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002372 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002373
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002375
Chas Williams1fa99612006-09-29 17:11:47 -07002376 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002377 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002378 if (vcc == entry->vcc) {
2379 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002380 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002381 if (priv->mcast_vcc == vcc) {
2382 priv->mcast_vcc = NULL;
2383 }
2384 }
2385 }
2386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387
Chas Williamsd0732f62006-09-29 17:14:27 -07002388 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2389 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002390 lec_arp_clear_vccs(entry);
2391 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002392 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002393 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002394 }
Chas Williams1fa99612006-09-29 17:11:47 -07002395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396
Chas Williamsd0732f62006-09-29 17:14:27 -07002397 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002398 if (entry->recv_vcc == vcc) {
2399 lec_arp_clear_vccs(entry);
2400 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002401 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002402 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002403 }
Chas Williams1fa99612006-09-29 17:11:47 -07002404 }
2405
Chas Williamsd0732f62006-09-29 17:14:27 -07002406 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002407 if (entry->recv_vcc == vcc) {
2408 lec_arp_clear_vccs(entry);
2409 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002410 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002411 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002412 }
Chas Williams1fa99612006-09-29 17:11:47 -07002413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414
2415 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2416 dump_arp_table(priv);
2417}
2418
2419static void
2420lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002421 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422{
Chas Williams1fa99612006-09-29 17:11:47 -07002423 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002424 struct hlist_node *node, *next;
2425 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002426 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2427 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002429 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430
Chas Williams1fa99612006-09-29 17:11:47 -07002431 if (priv->is_trdev)
2432 src = tr_hdr->h_source;
2433 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002435 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436
2437 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002438 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2439 if (vcc == entry->vcc) {
2440 del_timer(&entry->timer);
2441 memcpy(entry->mac_addr, src, ETH_ALEN);
2442 entry->status = ESI_FORWARD_DIRECT;
2443 entry->last_used = jiffies;
2444 /* We might have got an entry */
2445 if ((tmp = lec_arp_find(priv, src))) {
2446 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002447 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002448 }
2449 hlist_del(&entry->next);
2450 lec_arp_add(priv, entry);
2451 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002452 }
Chas Williams1fa99612006-09-29 17:11:47 -07002453 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002454 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455out:
2456 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2457}
Chas Williams1fa99612006-09-29 17:11:47 -07002458
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459MODULE_LICENSE("GPL");