blob: 199b6bb79f429aadeaf6a26ad6c3b65d200d1644 [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)
37#include <linux/if_bridge.h>
38#include "../bridge/br_private.h"
39
Chas Williamsd44f7742006-09-29 17:11:14 -070040static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#endif
42
43/* Modular too */
44#include <linux/module.h>
45#include <linux/init.h>
46
47#include "lec.h"
48#include "lec_arpc.h"
49#include "resources.h"
50
Chas Williamsd44f7742006-09-29 17:11:14 -070051#define DUMP_PACKETS 0 /*
52 * 0 = None,
53 * 1 = 30 first bytes
54 * 2 = Whole packet
55 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Chas Williamsd44f7742006-09-29 17:11:14 -070057#define LEC_UNRES_QUE_LEN 8 /*
58 * number of tx packets to queue for a
59 * single destination while waiting for SVC
60 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62static int lec_open(struct net_device *dev);
63static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev);
64static int lec_close(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065static void lec_init(struct net_device *dev);
Chas Williamsd44f7742006-09-29 17:11:14 -070066static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070067 const unsigned char *mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068static int lec_arp_remove(struct lec_priv *priv,
Chas Williamsd44f7742006-09-29 17:11:14 -070069 struct lec_arp_table *to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070/* LANE2 functions */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070071static void lane2_associate_ind(struct net_device *dev, const u8 *mac_address,
72 const u8 *tlvs, u32 sizeoftlvs);
73static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -070074 u8 **tlvs, u32 *sizeoftlvs);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070075static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
76 const u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070078static int lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 unsigned long permanent);
80static void lec_arp_check_empties(struct lec_priv *priv,
81 struct atm_vcc *vcc, struct sk_buff *skb);
82static void lec_arp_destroy(struct lec_priv *priv);
83static void lec_arp_init(struct lec_priv *priv);
Chas Williamsd44f7742006-09-29 17:11:14 -070084static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070085 const unsigned char *mac_to_find,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 int is_rdesc,
87 struct lec_arp_table **ret_entry);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070088static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
89 const unsigned char *atm_addr, unsigned long remoteflag,
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 unsigned int targetless_le_arp);
91static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
92static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
93static void lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070094 const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 unsigned long tran_id);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070096static void lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 struct atm_vcc *vcc,
Chas Williamsd44f7742006-09-29 17:11:14 -070098 void (*old_push) (struct atm_vcc *vcc,
99 struct sk_buff *skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
101
Chas Williams33a9c2d2006-09-29 17:16:48 -0700102/* must be done under lec_arp_lock */
103static inline void lec_arp_hold(struct lec_arp_table *entry)
104{
105 atomic_inc(&entry->usage);
106}
107
108static inline void lec_arp_put(struct lec_arp_table *entry)
109{
110 if (atomic_dec_and_test(&entry->usage))
111 kfree(entry);
112}
113
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115static struct lane2_ops lane2_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700116 lane2_resolve, /* resolve, spec 3.1.3 */
117 lane2_associate_req, /* associate_req, spec 3.1.4 */
118 NULL /* associate indicator, spec 3.1.5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119};
120
Chas Williamsd44f7742006-09-29 17:11:14 -0700121static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123/* Device structures */
124static struct net_device *dev_lec[MAX_LEC_ITF];
125
126#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
127static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
128{
Chas Williamsd44f7742006-09-29 17:11:14 -0700129 struct ethhdr *eth;
130 char *buff;
131 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Chas Williamsd44f7742006-09-29 17:11:14 -0700133 /*
134 * Check if this is a BPDU. If so, ask zeppelin to send
135 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
136 * as the Config BPDU has
137 */
138 eth = (struct ethhdr *)skb->data;
139 buff = skb->data + skb->dev->hard_header_len;
140 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 struct sock *sk;
Chas Williamsd44f7742006-09-29 17:11:14 -0700142 struct sk_buff *skb2;
143 struct atmlec_msg *mesg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Chas Williamsd44f7742006-09-29 17:11:14 -0700145 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
146 if (skb2 == NULL)
147 return;
148 skb2->len = sizeof(struct atmlec_msg);
149 mesg = (struct atmlec_msg *)skb2->data;
150 mesg->type = l_topology_change;
151 buff += 4;
152 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Wang Chen524ad0a2008-11-12 23:39:10 -0800154 priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700155 atm_force_charge(priv->lecd, skb2->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 sk = sk_atm(priv->lecd);
Chas Williamsd44f7742006-09-29 17:11:14 -0700157 skb_queue_tail(&sk->sk_receive_queue, skb2);
158 sk->sk_data_ready(sk, skb2->len);
159 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Chas Williamsd44f7742006-09-29 17:11:14 -0700161 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
164
165/*
166 * Modelled after tr_type_trans
167 * All multicast and ARE or STE frames go to BUS.
168 * Non source routed frames go by destination address.
169 * Last hop source routed frames go by destination address.
170 * Not last hop source routed frames go by _next_ route descriptor.
171 * Returns pointer to destination MAC address or fills in rdesc
172 * and returns NULL.
173 */
174#ifdef CONFIG_TR
175static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
176{
Chas Williamsd44f7742006-09-29 17:11:14 -0700177 struct trh_hdr *trh;
Eric Dumazet5c17d5f2008-01-15 03:29:50 -0800178 unsigned int riflen, num_rdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Chas Williamsd44f7742006-09-29 17:11:14 -0700180 trh = (struct trh_hdr *)packet;
181 if (trh->daddr[0] & (uint8_t) 0x80)
182 return bus_mac; /* multicast */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Chas Williamsd44f7742006-09-29 17:11:14 -0700184 if (trh->saddr[0] & TR_RII) {
185 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
186 if ((ntohs(trh->rcf) >> 13) != 0)
187 return bus_mac; /* ARE or STE */
188 } else
189 return trh->daddr; /* not source routed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Chas Williamsd44f7742006-09-29 17:11:14 -0700191 if (riflen < 6)
192 return trh->daddr; /* last hop, source routed */
193
194 /* riflen is 6 or more, packet has more than one route descriptor */
195 num_rdsc = (riflen / 2) - 1;
196 memset(rdesc, 0, ETH_ALEN);
197 /* offset 4 comes from LAN destination field in LE control frames */
198 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
Al Viro30d492d2006-11-14 21:11:29 -0800199 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700200 else {
Al Viro30d492d2006-11-14 21:11:29 -0800201 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700202 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
203 }
204
205 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206}
207#endif /* CONFIG_TR */
208
209/*
210 * Open/initialize the netdevice. This is called (in the current kernel)
211 * sometime after booting when the 'ifconfig' program is run.
212 *
213 * This routine should set everything up anew at each open, even
214 * registers that "should" only need to be set once at boot, so that
215 * there is non-reboot way to recover if something goes wrong.
216 */
217
Chas Williamsd44f7742006-09-29 17:11:14 -0700218static int lec_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 netif_start_queue(dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000221 memset(&dev->stats, 0, sizeof(struct net_device_stats));
Chas Williamsd44f7742006-09-29 17:11:14 -0700222
223 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224}
225
Stephen Hemminger162619e2009-01-09 13:01:01 +0000226static void
227lec_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
Stephen Hemminger162619e2009-01-09 13:01:01 +0000229 struct net_device *dev = skb->dev;
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 ATM_SKB(skb)->vcc = vcc;
232 ATM_SKB(skb)->atm_options = vcc->atm_options;
233
234 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
235 if (vcc->send(vcc, skb) < 0) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000236 dev->stats.tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 return;
238 }
239
Stephen Hemminger162619e2009-01-09 13:01:01 +0000240 dev->stats.tx_packets++;
241 dev->stats.tx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242}
243
Chas Williamsd44f7742006-09-29 17:11:14 -0700244static void lec_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
246 printk(KERN_INFO "%s: tx timeout\n", dev->name);
247 dev->trans_start = jiffies;
248 netif_wake_queue(dev);
249}
250
Chas Williamsd44f7742006-09-29 17:11:14 -0700251static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Chas Williamsd44f7742006-09-29 17:11:14 -0700253 struct sk_buff *skb2;
Wang Chen524ad0a2008-11-12 23:39:10 -0800254 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700255 struct lecdatahdr_8023 *lec_h;
256 struct atm_vcc *vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700258 unsigned char *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 int min_frame_size;
260#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700261 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700263 int is_rdesc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700265 char buf[300];
266 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267#endif /* DUMP_PACKETS >0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Stephen Hemminger52240062007-08-28 15:22:09 -0700269 pr_debug("lec_start_xmit called\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700270 if (!priv->lecd) {
271 printk("%s:No lecd attached\n", dev->name);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000272 dev->stats.tx_errors++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700273 netif_stop_queue(dev);
274 return -EUNATCH;
275 }
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)
292 return 0;
293 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)
310 return 0;
311 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++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700348 return 0;
349 }
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;
Chas Williamsd44f7742006-09-29 17:11:14 -0700419 return 0;
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 {
521 struct net_bridge_fdb_entry *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Johannes Berge1749612008-10-27 15:59:26 -0700523 pr_debug("%s: bridge zeppelin asks about %pM\n",
524 dev->name, mesg->content.proxy.mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Chas Williamsd44f7742006-09-29 17:11:14 -0700526 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
527 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Chas Williamsd44f7742006-09-29 17:11:14 -0700529 f = br_fdb_get_hook(dev->br_port->br,
530 mesg->content.proxy.mac_addr);
531 if (f != NULL && f->dst->dev != dev
532 && f->dst->state == BR_STATE_FORWARDING) {
533 /* hit from bridge table, send LE_ARP_RESPONSE */
534 struct sk_buff *skb2;
535 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Stephen Hemminger52240062007-08-28 15:22:09 -0700537 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700538 ("%s: entry found, responding to zeppelin\n",
539 dev->name);
540 skb2 =
541 alloc_skb(sizeof(struct atmlec_msg),
542 GFP_ATOMIC);
543 if (skb2 == NULL) {
544 br_fdb_put_hook(f);
545 break;
546 }
547 skb2->len = sizeof(struct atmlec_msg);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300548 skb_copy_to_linear_data(skb2, mesg,
549 sizeof(*mesg));
Chas Williamsd44f7742006-09-29 17:11:14 -0700550 atm_force_charge(priv->lecd, skb2->truesize);
551 sk = sk_atm(priv->lecd);
552 skb_queue_tail(&sk->sk_receive_queue, skb2);
553 sk->sk_data_ready(sk, skb2->len);
554 }
555 if (f != NULL)
556 br_fdb_put_hook(f);
557 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700559 break;
560 default:
561 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
562 dev_kfree_skb(skb);
563 return -EINVAL;
564 }
565 dev_kfree_skb(skb);
566 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567}
568
Chas Williamsd44f7742006-09-29 17:11:14 -0700569static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
Chas Williamsd44f7742006-09-29 17:11:14 -0700571 struct sk_buff *skb;
572 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800573 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Chas Williamsd44f7742006-09-29 17:11:14 -0700575 priv->lecd = NULL;
576 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Chas Williamsd44f7742006-09-29 17:11:14 -0700578 netif_stop_queue(dev);
579 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Chas Williamsd44f7742006-09-29 17:11:14 -0700581 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700583 dev->name);
584 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
585 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700587 }
588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700590 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591}
592
593static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700594 .close = lec_atm_close,
595 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596};
597
598static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700599 .ops = &lecdev_ops,
600 .type = "lec",
601 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700602 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603};
604
605/*
606 * LANE2: new argument struct sk_buff *data contains
607 * the LE_ARP based TLVs introduced in the LANE2 spec
608 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700609static int
610send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700611 const unsigned char *mac_addr, const unsigned char *atm_addr,
Chas Williamsd44f7742006-09-29 17:11:14 -0700612 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
614 struct sock *sk;
615 struct sk_buff *skb;
616 struct atmlec_msg *mesg;
617
618 if (!priv || !priv->lecd) {
619 return -1;
620 }
621 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
622 if (!skb)
623 return -1;
624 skb->len = sizeof(struct atmlec_msg);
625 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700626 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700628 if (data != NULL)
629 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 if (mac_addr)
631 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700632 else
633 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 if (atm_addr)
635 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
636
Chas Williamsd44f7742006-09-29 17:11:14 -0700637 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 sk = sk_atm(priv->lecd);
639 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700640 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Chas Williamsd44f7742006-09-29 17:11:14 -0700642 if (data != NULL) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700643 pr_debug("lec: about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700644 atm_force_charge(priv->lecd, data->truesize);
645 skb_queue_tail(&sk->sk_receive_queue, data);
646 sk->sk_data_ready(sk, skb->len);
647 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
Chas Williamsd44f7742006-09-29 17:11:14 -0700649 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}
651
652/* shamelessly stolen from drivers/net/net_init.c */
653static int lec_change_mtu(struct net_device *dev, int new_mtu)
654{
Chas Williamsd44f7742006-09-29 17:11:14 -0700655 if ((new_mtu < 68) || (new_mtu > 18190))
656 return -EINVAL;
657 dev->mtu = new_mtu;
658 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659}
660
661static void lec_set_multicast_list(struct net_device *dev)
662{
Chas Williamsd44f7742006-09-29 17:11:14 -0700663 /*
664 * by default, all multicast frames arrive over the bus.
665 * eventually support selective multicast service
666 */
667 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668}
669
Stephen Hemminger004b3222009-01-09 13:01:02 +0000670static const struct net_device_ops lec_netdev_ops = {
671 .ndo_open = lec_open,
672 .ndo_stop = lec_close,
673 .ndo_start_xmit = lec_start_xmit,
674 .ndo_change_mtu = lec_change_mtu,
675 .ndo_tx_timeout = lec_tx_timeout,
676 .ndo_set_multicast_list = lec_set_multicast_list,
677};
678
679
Chas Williamsd44f7742006-09-29 17:11:14 -0700680static void lec_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681{
Stephen Hemminger004b3222009-01-09 13:01:02 +0000682 dev->netdev_ops = &lec_netdev_ops;
Chas Williamsd44f7742006-09-29 17:11:14 -0700683 printk("%s: Initialized!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684}
685
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700686static const unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700687 0xff,
688 0x00,
689 0x01,
690 0x01
691};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Scott Talbert4a7097f2005-09-29 17:30:54 -0700693#define LEC_DATA_DIRECT_8023 2
694#define LEC_DATA_DIRECT_8025 3
695
696static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700697{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700698 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
699 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700700}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700701
Chas Williamsd44f7742006-09-29 17:11:14 -0700702static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700704 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700705 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800706 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
708#if DUMP_PACKETS >0
Chas Williamsd44f7742006-09-29 17:11:14 -0700709 int i = 0;
710 char buf[300];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Chas Williamsd44f7742006-09-29 17:11:14 -0700712 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
713 vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700715 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700716 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700717 lec_vcc_close(priv, vcc);
718 return;
719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700721 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
722 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700724 for (i = 0; i < skb->len && i < 99; i++) {
725 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
726 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700728 for (i = 0; i < skb->len && i < 30; i++) {
729 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
730 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700732 if (i == skb->len)
733 printk("%s\n", buf);
734 else
735 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700737 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 struct sock *sk = sk_atm(vcc);
739
Stephen Hemminger52240062007-08-28 15:22:09 -0700740 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700741 skb_queue_tail(&sk->sk_receive_queue, skb);
742 sk->sk_data_ready(sk, skb->len);
743 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700744 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700745 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Chas Williamsd44f7742006-09-29 17:11:14 -0700747 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800748 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700749 !priv->lecd || !(dev->flags & IFF_UP)) {
750 /*
751 * Probably looping back, or if lecd is missing,
752 * lecd has gone down
753 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700754 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700755 dev_kfree_skb(skb);
756 return;
757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700759 if (priv->is_trdev)
760 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
761 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700763 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700764
Chas Williamsd44f7742006-09-29 17:11:14 -0700765 /*
766 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700767 * the LE_ARP cache entry, delete the LE_ARP cache entry.
768 */
769 spin_lock_irqsave(&priv->lec_arp_lock, flags);
770 if (lec_is_data_direct(vcc)) {
771#ifdef CONFIG_TR
772 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700773 src =
774 ((struct lecdatahdr_8025 *)skb->data)->
775 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700776 else
777#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700778 src =
779 ((struct lecdatahdr_8023 *)skb->data)->
780 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700781 entry = lec_arp_find(priv, src);
782 if (entry && entry->vcc != vcc) {
783 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700784 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700785 }
786 }
787 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Chas Williamsd44f7742006-09-29 17:11:14 -0700789 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
790 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700792 dev_kfree_skb(skb);
793 return;
794 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700795 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700796 lec_arp_check_empties(priv, vcc, skb);
797 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700798 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700800 if (priv->is_trdev)
801 skb->protocol = tr_type_trans(skb, dev);
802 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700804 skb->protocol = eth_type_trans(skb, dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000805 dev->stats.rx_packets++;
806 dev->stats.rx_bytes += skb->len;
Chas Williamsd44f7742006-09-29 17:11:14 -0700807 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
808 netif_rx(skb);
809 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810}
811
Chas Williamsd44f7742006-09-29 17:11:14 -0700812static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
814 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
815 struct net_device *dev = skb->dev;
816
817 if (vpriv == NULL) {
818 printk("lec_pop(): vpriv = NULL!?!?!?\n");
819 return;
820 }
821
822 vpriv->old_pop(vcc, skb);
823
824 if (vpriv->xoff && atm_may_send(vcc, 0)) {
825 vpriv->xoff = 0;
826 if (netif_running(dev) && netif_queue_stopped(dev))
827 netif_wake_queue(dev);
828 }
829}
830
Chas Williamsd44f7742006-09-29 17:11:14 -0700831static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
833 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700834 int bytes_left;
835 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Chas Williamsd44f7742006-09-29 17:11:14 -0700837 /* Lecd must be up in this case */
838 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
839 if (bytes_left != 0) {
840 printk
841 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
842 bytes_left);
843 }
844 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
845 !dev_lec[ioc_data.dev_num])
846 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
848 return -ENOMEM;
849 vpriv->xoff = 0;
850 vpriv->old_pop = vcc->pop;
851 vcc->user_back = vpriv;
852 vcc->pop = lec_pop;
Wang Chen524ad0a2008-11-12 23:39:10 -0800853 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
Chas Williamsd44f7742006-09-29 17:11:14 -0700854 &ioc_data, vcc, vcc->push);
855 vcc->proto_data = dev_lec[ioc_data.dev_num];
856 vcc->push = lec_push;
857 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858}
859
Chas Williamsd44f7742006-09-29 17:11:14 -0700860static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
Chas Williamsd44f7742006-09-29 17:11:14 -0700862 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
863 return -EINVAL;
864 vcc->proto_data = dev_lec[arg];
Wang Chen524ad0a2008-11-12 23:39:10 -0800865 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
866 vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867}
868
869/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700870static int lecd_attach(struct atm_vcc *vcc, int arg)
871{
872 int i;
873 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Chas Williamsd44f7742006-09-29 17:11:14 -0700875 if (arg < 0)
876 i = 0;
877 else
878 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700880 if (arg >= MAX_LEC_ITF)
881 return -EINVAL;
882#else /* Reserve the top NUM_TR_DEVS for TR */
883 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
884 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700886 if (!dev_lec[i]) {
887 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
Chas Williamsd44f7742006-09-29 17:11:14 -0700889 is_trdev = 0;
890 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
891 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Chas Williamsd44f7742006-09-29 17:11:14 -0700893 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700895 if (is_trdev)
896 dev_lec[i] = alloc_trdev(size);
897 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700899 dev_lec[i] = alloc_etherdev(size);
900 if (!dev_lec[i])
901 return -ENOMEM;
902 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
903 if (register_netdev(dev_lec[i])) {
904 free_netdev(dev_lec[i]);
905 return -EINVAL;
906 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Wang Chen524ad0a2008-11-12 23:39:10 -0800908 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700909 priv->is_trdev = is_trdev;
910 lec_init(dev_lec[i]);
911 } else {
Wang Chen524ad0a2008-11-12 23:39:10 -0800912 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700913 if (priv->lecd)
914 return -EADDRINUSE;
915 }
916 lec_arp_init(priv);
917 priv->itfnum = i; /* LANE2 addition */
918 priv->lecd = vcc;
919 vcc->dev = &lecatm_dev;
920 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Chas Williamsd44f7742006-09-29 17:11:14 -0700922 vcc->proto_data = dev_lec[i];
923 set_bit(ATM_VF_META, &vcc->flags);
924 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Chas Williamsd44f7742006-09-29 17:11:14 -0700926 /* Set default values to these variables */
927 priv->maximum_unknown_frame_count = 1;
928 priv->max_unknown_frame_time = (1 * HZ);
929 priv->vcc_timeout_period = (1200 * HZ);
930 priv->max_retry_count = 1;
931 priv->aging_time = (300 * HZ);
932 priv->forward_delay_time = (15 * HZ);
933 priv->topology_change = 0;
934 priv->arp_response_time = (1 * HZ);
935 priv->flush_timeout = (4 * HZ);
936 priv->path_switching_delay = (6 * HZ);
937
938 if (dev_lec[i]->flags & IFF_UP) {
939 netif_start_queue(dev_lec[i]);
940 }
941 __module_get(THIS_MODULE);
942 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943}
944
945#ifdef CONFIG_PROC_FS
Chas Williamsd44f7742006-09-29 17:11:14 -0700946static char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947{
948 static char *lec_arp_status_string[] = {
949 "ESI_UNKNOWN ",
950 "ESI_ARP_PENDING ",
951 "ESI_VC_PENDING ",
952 "<Undefined> ",
953 "ESI_FLUSH_PENDING ",
954 "ESI_FORWARD_DIRECT"
955 };
956
957 if (status > ESI_FORWARD_DIRECT)
958 status = 3; /* ESI_UNDEFINED */
959 return lec_arp_status_string[status];
960}
961
962static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
963{
964 int i;
965
966 for (i = 0; i < ETH_ALEN; i++)
967 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
968 seq_printf(seq, " ");
969 for (i = 0; i < ATM_ESA_LEN; i++)
970 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
971 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
972 entry->flags & 0xffff);
973 if (entry->vcc)
974 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
975 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700976 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 if (entry->recv_vcc) {
978 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
979 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -0700980 }
981 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982}
983
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984struct lec_state {
985 unsigned long flags;
986 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -0700987 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 struct net_device *dev;
989 int itf;
990 int arp_table;
991 int misc_table;
992};
993
Chas Williamsd0732f62006-09-29 17:14:27 -0700994static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 loff_t *l)
996{
Chas Williamsd0732f62006-09-29 17:14:27 -0700997 struct hlist_node *e = state->node;
998 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
1000 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -07001001 e = tbl->first;
Joe Perches2e1e9842008-04-10 03:33:03 -07001002 if (e == SEQ_START_TOKEN) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001003 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 --*l;
1005 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001006
1007 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 if (--*l < 0)
1009 break;
1010 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001011 state->node = e;
1012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 return (*l < 0) ? state : NULL;
1014}
1015
1016static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -07001017 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018{
1019 void *v = NULL;
1020 int p;
1021
1022 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001023 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 if (v)
1025 break;
1026 }
1027 state->arp_table = p;
1028 return v;
1029}
1030
1031static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1032 struct lec_priv *priv)
1033{
Chas Williamsd0732f62006-09-29 17:14:27 -07001034 struct hlist_head *lec_misc_tables[] = {
1035 &priv->lec_arp_empty_ones,
1036 &priv->lec_no_forward,
1037 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 };
1039 void *v = NULL;
1040 int q;
1041
1042 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1043 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1044 if (v)
1045 break;
1046 }
1047 state->misc_table = q;
1048 return v;
1049}
1050
1051static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1052 struct lec_priv *priv)
1053{
1054 if (!state->locked) {
1055 state->locked = priv;
1056 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1057 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001058 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1060 state->locked = NULL;
1061 /* Partial state reset for the next time we get called */
1062 state->arp_table = state->misc_table = 0;
1063 }
1064 return state->locked;
1065}
1066
1067static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1068{
1069 struct net_device *dev;
1070 void *v;
1071
1072 dev = state->dev ? state->dev : dev_lec[state->itf];
Wang Chen524ad0a2008-11-12 23:39:10 -08001073 v = (dev && netdev_priv(dev)) ?
1074 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 if (!v && dev) {
1076 dev_put(dev);
1077 /* Partial state reset for the next time we get called */
1078 dev = NULL;
1079 }
1080 state->dev = dev;
1081 return v;
1082}
1083
1084static void *lec_get_idx(struct lec_state *state, loff_t l)
1085{
1086 void *v = NULL;
1087
1088 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1089 v = lec_itf_walk(state, &l);
1090 if (v)
1091 break;
1092 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001093 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094}
1095
1096static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1097{
1098 struct lec_state *state = seq->private;
1099
1100 state->itf = 0;
1101 state->dev = NULL;
1102 state->locked = NULL;
1103 state->arp_table = 0;
1104 state->misc_table = 0;
Joe Perches2e1e9842008-04-10 03:33:03 -07001105 state->node = SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
Joe Perches2e1e9842008-04-10 03:33:03 -07001107 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108}
1109
1110static void lec_seq_stop(struct seq_file *seq, void *v)
1111{
1112 struct lec_state *state = seq->private;
1113
1114 if (state->dev) {
1115 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1116 state->flags);
1117 dev_put(state->dev);
1118 }
1119}
1120
1121static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1122{
1123 struct lec_state *state = seq->private;
1124
1125 v = lec_get_idx(state, 1);
1126 *pos += !!PTR_ERR(v);
1127 return v;
1128}
1129
1130static int lec_seq_show(struct seq_file *seq, void *v)
1131{
Chas Williamsd44f7742006-09-29 17:11:14 -07001132 static char lec_banner[] = "Itf MAC ATM destination"
1133 " Status Flags "
1134 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Joe Perches2e1e9842008-04-10 03:33:03 -07001136 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 seq_puts(seq, lec_banner);
1138 else {
1139 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001140 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001141 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
1143 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001144 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 }
1146 return 0;
1147}
1148
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001149static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001150 .start = lec_seq_start,
1151 .next = lec_seq_next,
1152 .stop = lec_seq_stop,
1153 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154};
1155
1156static int lec_seq_open(struct inode *inode, struct file *file)
1157{
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001158 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159}
1160
Arjan van de Ven9a321442007-02-12 00:55:35 -08001161static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001162 .owner = THIS_MODULE,
1163 .open = lec_seq_open,
1164 .read = seq_read,
1165 .llseek = seq_lseek,
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001166 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167};
1168#endif
1169
1170static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1171{
1172 struct atm_vcc *vcc = ATM_SD(sock);
1173 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001174
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001176 case ATMLEC_CTRL:
1177 case ATMLEC_MCAST:
1178 case ATMLEC_DATA:
1179 if (!capable(CAP_NET_ADMIN))
1180 return -EPERM;
1181 break;
1182 default:
1183 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 }
1185
1186 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001187 case ATMLEC_CTRL:
1188 err = lecd_attach(vcc, (int)arg);
1189 if (err >= 0)
1190 sock->state = SS_CONNECTED;
1191 break;
1192 case ATMLEC_MCAST:
1193 err = lec_mcast_attach(vcc, (int)arg);
1194 break;
1195 case ATMLEC_DATA:
1196 err = lec_vcc_attach(vcc, (void __user *)arg);
1197 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 }
1199
1200 return err;
1201}
1202
1203static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001204 .owner = THIS_MODULE,
1205 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206};
1207
1208static int __init lane_module_init(void)
1209{
1210#ifdef CONFIG_PROC_FS
1211 struct proc_dir_entry *p;
1212
Wang Chen16e297b2008-02-28 13:55:45 -08001213 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Wang Chendbee0d32008-03-23 21:45:36 -07001214 if (!p) {
1215 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n");
1216 return -ENOMEM;
1217 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218#endif
1219
1220 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001221 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1222 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223}
1224
1225static void __exit lane_module_cleanup(void)
1226{
Chas Williamsd44f7742006-09-29 17:11:14 -07001227 int i;
1228 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 remove_proc_entry("lec", atm_proc_root);
1231
1232 deregister_atm_ioctl(&lane_ioctl_ops);
1233
Chas Williamsd44f7742006-09-29 17:11:14 -07001234 for (i = 0; i < MAX_LEC_ITF; i++) {
1235 if (dev_lec[i] != NULL) {
Wang Chen524ad0a2008-11-12 23:39:10 -08001236 priv = netdev_priv(dev_lec[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001238 free_netdev(dev_lec[i]);
1239 dev_lec[i] = NULL;
1240 }
1241 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
Chas Williamsd44f7742006-09-29 17:11:14 -07001243 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244}
1245
1246module_init(lane_module_init);
1247module_exit(lane_module_cleanup);
1248
1249/*
1250 * LANE2: 3.1.3, LE_RESOLVE.request
1251 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1252 * If sizeoftlvs == NULL the default TLVs associated with with this
1253 * lec will be used.
1254 * If dst_mac == NULL, targetless LE_ARP will be sent
1255 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001256static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001257 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
1259 unsigned long flags;
Wang Chen524ad0a2008-11-12 23:39:10 -08001260 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001261 struct lec_arp_table *table;
1262 struct sk_buff *skb;
1263 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Chas Williamsd44f7742006-09-29 17:11:14 -07001265 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001267 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001269 if (table == NULL)
1270 return -1;
1271
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001272 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001273 if (*tlvs == NULL)
1274 return -1;
1275
Chas Williamsd44f7742006-09-29 17:11:14 -07001276 *sizeoftlvs = table->sizeoftlvs;
1277
1278 return 0;
1279 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
1281 if (sizeoftlvs == NULL)
1282 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001283
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 else {
1285 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1286 if (skb == NULL)
1287 return -1;
1288 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001289 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1291 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001292 return retval;
1293}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
1295/*
1296 * LANE2: 3.1.4, LE_ASSOCIATE.request
1297 * Associate the *tlvs with the *lan_dst address.
1298 * Will overwrite any previous association
1299 * Returns 1 for success, 0 for failure (out of memory)
1300 *
1301 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001302static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1303 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304{
Chas Williamsd44f7742006-09-29 17:11:14 -07001305 int retval;
1306 struct sk_buff *skb;
Wang Chen524ad0a2008-11-12 23:39:10 -08001307 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Chas Williamsd44f7742006-09-29 17:11:14 -07001309 if (compare_ether_addr(lan_dst, dev->dev_addr))
1310 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Chas Williamsd44f7742006-09-29 17:11:14 -07001312 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001314 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001315 if (priv->tlvs == NULL)
1316 return (0);
1317 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Chas Williamsd44f7742006-09-29 17:11:14 -07001319 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1320 if (skb == NULL)
1321 return 0;
1322 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001323 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001324 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1325 if (retval != 0)
1326 printk("lec.c: lane2_associate_req() failed\n");
1327 /*
1328 * If the previous association has changed we must
1329 * somehow notify other LANE entities about the change
1330 */
1331 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332}
1333
1334/*
1335 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1336 *
1337 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001338static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1339 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340{
1341#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001342 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343#endif
Wang Chen524ad0a2008-11-12 23:39:10 -08001344 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001345#if 0 /*
1346 * Why have the TLVs in LE_ARP entries
1347 * since we do not use them? When you
1348 * uncomment this code, make sure the
1349 * TLVs get freed when entry is killed
1350 */
1351 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Chas Williamsd44f7742006-09-29 17:11:14 -07001353 if (entry == NULL)
1354 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
Chas Williamsd44f7742006-09-29 17:11:14 -07001356 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001358 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001359 if (entry->tlvs == NULL)
1360 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001361 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362#endif
1363#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001364 printk("lec.c: lane2_associate_ind()\n");
1365 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1366 while (i < sizeoftlvs)
1367 printk("%02x ", tlvs[i++]);
1368
1369 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370#endif
1371
Chas Williamsd44f7742006-09-29 17:11:14 -07001372 /* tell MPOA about the TLVs we saw */
1373 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1374 priv->lane2_ops->associate_indicator(dev, mac_addr,
1375 tlvs, sizeoftlvs);
1376 }
1377 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378}
1379
1380/*
1381 * Here starts what used to lec_arpc.c
1382 *
1383 * lec_arpc.c was added here when making
1384 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 */
1386
1387#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388#include <linux/timer.h>
1389#include <asm/param.h>
1390#include <asm/atomic.h>
1391#include <linux/inetdevice.h>
1392#include <net/route.h>
1393
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394#if 0
Stephen Hemminger52240062007-08-28 15:22:09 -07001395#define pr_debug(format,args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396/*
Stephen Hemminger52240062007-08-28 15:22:09 -07001397#define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398*/
1399#endif
1400#define DEBUG_ARP_TABLE 0
1401
1402#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1403
David Howellsc4028952006-11-22 14:57:56 +00001404static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405static void lec_arp_expire_arp(unsigned long data);
1406
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001407/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 * Arp table funcs
1409 */
1410
1411#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1412
1413/*
1414 * Initialization of arp-cache
1415 */
Chas Williams1fa99612006-09-29 17:11:47 -07001416static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417{
Chas Williams1fa99612006-09-29 17:11:47 -07001418 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Chas Williams1fa99612006-09-29 17:11:47 -07001420 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001421 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001422 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001423 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1424 INIT_HLIST_HEAD(&priv->lec_no_forward);
1425 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001427 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001428 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429}
1430
Chas Williams1fa99612006-09-29 17:11:47 -07001431static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432{
Chas Williams1fa99612006-09-29 17:11:47 -07001433 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 struct atm_vcc *vcc = entry->vcc;
1435 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001436 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Chas Williams1fa99612006-09-29 17:11:47 -07001438 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 if (vpriv->xoff)
1440 netif_wake_queue(dev);
1441 kfree(vpriv);
1442 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001443 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001445 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001446 }
1447 if (entry->recv_vcc) {
1448 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001450 entry->recv_vcc = NULL;
1451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452}
1453
1454/*
1455 * Insert entry to lec_arp_table
1456 * LANE2: Add to the end of the list to satisfy 8.1.13
1457 */
Chas Williams1fa99612006-09-29 17:11:47 -07001458static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001459lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
Chas Williamsd0732f62006-09-29 17:14:27 -07001461 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Chas Williamsd0732f62006-09-29 17:14:27 -07001463 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1464 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001465
Stephen Hemminger52240062007-08-28 15:22:09 -07001466 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 -07001467 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1468 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1469 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470}
1471
1472/*
1473 * Remove entry from lec_arp_table
1474 */
Chas Williams1fa99612006-09-29 17:11:47 -07001475static int
1476lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477{
Chas Williamsd0732f62006-09-29 17:14:27 -07001478 struct hlist_node *node;
1479 struct lec_arp_table *entry;
1480 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Chas Williams1fa99612006-09-29 17:11:47 -07001482 if (!to_remove) {
1483 return -1;
1484 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001485
1486 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001487 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
Chas Williamsd0732f62006-09-29 17:14:27 -07001489 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001490 if (to_remove->status >= ESI_FLUSH_PENDING) {
1491 /*
1492 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1493 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001494 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1495 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1496 if (memcmp(to_remove->atm_addr,
1497 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001498 remove_vcc = 0;
1499 break;
1500 }
1501 }
1502 }
1503 if (remove_vcc)
1504 lec_arp_clear_vccs(to_remove);
1505 }
1506 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1507
Stephen Hemminger52240062007-08-28 15:22:09 -07001508 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 -07001509 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1510 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1511 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1512 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513}
1514
1515#if DEBUG_ARP_TABLE
Chas Williams1fa99612006-09-29 17:11:47 -07001516static char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517{
Chas Williams1fa99612006-09-29 17:11:47 -07001518 switch (st) {
1519 case ESI_UNKNOWN:
1520 return "ESI_UNKNOWN";
1521 case ESI_ARP_PENDING:
1522 return "ESI_ARP_PENDING";
1523 case ESI_VC_PENDING:
1524 return "ESI_VC_PENDING";
1525 case ESI_FLUSH_PENDING:
1526 return "ESI_FLUSH_PENDING";
1527 case ESI_FORWARD_DIRECT:
1528 return "ESI_FORWARD_DIRECT";
1529 default:
1530 return "<UNKNOWN>";
1531 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Chas Williams1fa99612006-09-29 17:11:47 -07001534static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535{
Chas Williamsd0732f62006-09-29 17:14:27 -07001536 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001537 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001538 char buf[256];
1539 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
Chas Williams1fa99612006-09-29 17:11:47 -07001541 printk("Dump %p:\n", priv);
1542 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001543 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1544 offset = 0;
1545 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001546 offset += sprintf(buf + offset, "Mac:");
1547 for (j = 0; j < ETH_ALEN; j++) {
1548 offset += sprintf(buf + offset,
1549 "%2.2x ",
1550 rulla->mac_addr[j] & 0xff);
1551 }
1552 offset += sprintf(buf + offset, "Atm:");
1553 for (j = 0; j < ATM_ESA_LEN; j++) {
1554 offset += sprintf(buf + offset,
1555 "%2.2x ",
1556 rulla->atm_addr[j] & 0xff);
1557 }
1558 offset += sprintf(buf + offset,
1559 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1560 rulla->vcc ? rulla->vcc->vpi : 0,
1561 rulla->vcc ? rulla->vcc->vci : 0,
1562 rulla->recv_vcc ? rulla->recv_vcc->
1563 vpi : 0,
1564 rulla->recv_vcc ? rulla->recv_vcc->
1565 vci : 0, rulla->last_used,
1566 rulla->timestamp, rulla->no_tries);
1567 offset +=
1568 sprintf(buf + offset,
1569 "Flags:%x, Packets_flooded:%x, Status: %s ",
1570 rulla->flags, rulla->packets_flooded,
1571 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001572 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001573 }
Chas Williams1fa99612006-09-29 17:11:47 -07001574 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001575
1576 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001577 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001578 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001579 offset = 0;
1580 offset += sprintf(buf + offset, "Mac:");
1581 for (j = 0; j < ETH_ALEN; j++) {
1582 offset += sprintf(buf + offset, "%2.2x ",
1583 rulla->mac_addr[j] & 0xff);
1584 }
1585 offset += sprintf(buf + offset, "Atm:");
1586 for (j = 0; j < ATM_ESA_LEN; j++) {
1587 offset += sprintf(buf + offset, "%2.2x ",
1588 rulla->atm_addr[j] & 0xff);
1589 }
1590 offset += sprintf(buf + offset,
1591 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1592 rulla->vcc ? rulla->vcc->vpi : 0,
1593 rulla->vcc ? rulla->vcc->vci : 0,
1594 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1595 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1596 rulla->last_used,
1597 rulla->timestamp, rulla->no_tries);
1598 offset += sprintf(buf + offset,
1599 "Flags:%x, Packets_flooded:%x, Status: %s ",
1600 rulla->flags, rulla->packets_flooded,
1601 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001602 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001603 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001604
1605 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001606 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001607 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001608 offset = 0;
1609 offset += sprintf(buf + offset, "Mac:");
1610 for (j = 0; j < ETH_ALEN; j++) {
1611 offset += sprintf(buf + offset, "%2.2x ",
1612 rulla->mac_addr[j] & 0xff);
1613 }
1614 offset += sprintf(buf + offset, "Atm:");
1615 for (j = 0; j < ATM_ESA_LEN; j++) {
1616 offset += sprintf(buf + offset, "%2.2x ",
1617 rulla->atm_addr[j] & 0xff);
1618 }
1619 offset += sprintf(buf + offset,
1620 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1621 rulla->vcc ? rulla->vcc->vpi : 0,
1622 rulla->vcc ? rulla->vcc->vci : 0,
1623 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1624 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1625 rulla->last_used,
1626 rulla->timestamp, rulla->no_tries);
1627 offset += sprintf(buf + offset,
1628 "Flags:%x, Packets_flooded:%x, Status: %s ",
1629 rulla->flags, rulla->packets_flooded,
1630 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001631 printk("%s", buf);
1632 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
Chas Williamsd0732f62006-09-29 17:14:27 -07001634 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001635 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001636 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001637 offset = 0;
1638 offset += sprintf(buf + offset, "Mac:");
1639 for (j = 0; j < ETH_ALEN; j++) {
1640 offset += sprintf(buf + offset, "%2.2x ",
1641 rulla->mac_addr[j] & 0xff);
1642 }
1643 offset += sprintf(buf + offset, "Atm:");
1644 for (j = 0; j < ATM_ESA_LEN; j++) {
1645 offset += sprintf(buf + offset, "%2.2x ",
1646 rulla->atm_addr[j] & 0xff);
1647 }
1648 offset += sprintf(buf + offset,
1649 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1650 rulla->vcc ? rulla->vcc->vpi : 0,
1651 rulla->vcc ? rulla->vcc->vci : 0,
1652 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1653 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1654 rulla->last_used,
1655 rulla->timestamp, rulla->no_tries);
1656 offset += sprintf(buf + offset,
1657 "Flags:%x, Packets_flooded:%x, Status: %s ",
1658 rulla->flags, rulla->packets_flooded,
1659 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001660 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663}
Chas Williamsd0732f62006-09-29 17:14:27 -07001664#else
1665#define dump_arp_table(priv) do { } while (0)
1666#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
1668/*
1669 * Destruction of arp-cache
1670 */
Chas Williams1fa99612006-09-29 17:11:47 -07001671static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672{
1673 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001674 struct hlist_node *node, *next;
1675 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001676 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
Chas Williams987e46b2006-09-29 17:15:59 -07001678 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001679
1680 /*
1681 * Remove all entries
1682 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
1684 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001685 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001686 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001687 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001688 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001689 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001690 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001691 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001692
1693 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001694 del_timer_sync(&entry->timer);
1695 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001696 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001697 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001698 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001699 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1700
1701 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001702 del_timer_sync(&entry->timer);
1703 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001704 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001705 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001706 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001707 INIT_HLIST_HEAD(&priv->lec_no_forward);
1708
1709 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001710 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1711 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001712 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001713 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001714 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001715 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001716 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1718}
1719
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001720/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 * Find entry by mac_address
1722 */
Chas Williams1fa99612006-09-29 17:11:47 -07001723static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001724 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725{
Chas Williamsd0732f62006-09-29 17:14:27 -07001726 struct hlist_node *node;
1727 struct hlist_head *head;
1728 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
Stephen Hemminger52240062007-08-28 15:22:09 -07001730 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 -07001731 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1732 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
Chas Williams1fa99612006-09-29 17:11:47 -07001733
Chas Williamsd0732f62006-09-29 17:14:27 -07001734 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1735 hlist_for_each_entry(entry, node, head, next) {
1736 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1737 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001738 }
Chas Williams1fa99612006-09-29 17:11:47 -07001739 }
1740 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741}
1742
Chas Williams1fa99612006-09-29 17:11:47 -07001743static struct lec_arp_table *make_entry(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001744 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745{
Chas Williams1fa99612006-09-29 17:11:47 -07001746 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
Chas Williams1fa99612006-09-29 17:11:47 -07001748 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1749 if (!to_return) {
1750 printk("LEC: Arp entry kmalloc failed\n");
1751 return NULL;
1752 }
1753 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001754 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001755 setup_timer(&to_return->timer, lec_arp_expire_arp,
1756 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001757 to_return->last_used = jiffies;
1758 to_return->priv = priv;
1759 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001760 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001761 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762}
1763
Chas Williams1fa99612006-09-29 17:11:47 -07001764/* Arp sent timer expired */
1765static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766{
Chas Williams1fa99612006-09-29 17:11:47 -07001767 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
Chas Williams1fa99612006-09-29 17:11:47 -07001769 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
Stephen Hemminger52240062007-08-28 15:22:09 -07001771 pr_debug("lec_arp_expire_arp\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001772 if (entry->status == ESI_ARP_PENDING) {
1773 if (entry->no_tries <= entry->priv->max_retry_count) {
1774 if (entry->is_rdesc)
1775 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1776 entry->mac_addr, NULL, NULL);
1777 else
1778 send_to_lecd(entry->priv, l_arp_xmt,
1779 entry->mac_addr, NULL, NULL);
1780 entry->no_tries++;
1781 }
1782 mod_timer(&entry->timer, jiffies + (1 * HZ));
1783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784}
1785
Chas Williams1fa99612006-09-29 17:11:47 -07001786/* Unknown/unused vcc expire, remove associated entry */
1787static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788{
1789 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001790 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1791 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
Chas Williams1fa99612006-09-29 17:11:47 -07001793 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
Stephen Hemminger52240062007-08-28 15:22:09 -07001795 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001796 to_remove, priv,
1797 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1798 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799
1800 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001801 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1803
Chas Williams1fa99612006-09-29 17:11:47 -07001804 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001805 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806}
1807
1808/*
1809 * Expire entries.
1810 * 1. Re-set timer
1811 * 2. For each entry, delete entries that have aged past the age limit.
1812 * 3. For each entry, depending on the status of the entry, perform
1813 * the following maintenance.
1814 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1815 * tick_count is above the max_unknown_frame_time, clear
1816 * the tick_count to zero and clear the packets_flooded counter
1817 * to zero. This supports the packet rate limit per address
1818 * while flooding unknowns.
1819 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1820 * than or equal to the path_switching_delay, change the status
1821 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1822 * regardless of the progress of the flush protocol.
1823 */
David Howellsc4028952006-11-22 14:57:56 +00001824static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825{
1826 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001827 struct lec_priv *priv =
1828 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001829 struct hlist_node *node, *next;
1830 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001831 unsigned long now;
1832 unsigned long time_to_check;
1833 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
Stephen Hemminger52240062007-08-28 15:22:09 -07001835 pr_debug("lec_arp_check_expire %p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001837restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001839 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001840 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001841 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 priv->topology_change)
1843 time_to_check = priv->forward_delay_time;
1844 else
1845 time_to_check = priv->aging_time;
1846
Stephen Hemminger52240062007-08-28 15:22:09 -07001847 pr_debug("About to expire: %lx - %lx > %lx\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001848 now, entry->last_used, time_to_check);
1849 if (time_after(now, entry->last_used + time_to_check)
1850 && !(entry->flags & LEC_PERMANENT_FLAG)
1851 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 /* Remove entry */
Stephen Hemminger52240062007-08-28 15:22:09 -07001853 pr_debug("LEC:Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001855 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 } else {
1857 /* Something else */
1858 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001859 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001861 entry->timestamp +
1862 priv->
1863 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 entry->timestamp = jiffies;
1865 entry->packets_flooded = 0;
1866 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001867 send_to_lecd(priv, l_svc_setup,
1868 entry->mac_addr,
1869 entry->atm_addr,
1870 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 }
Chas Williams1fa99612006-09-29 17:11:47 -07001872 if (entry->status == ESI_FLUSH_PENDING
1873 &&
1874 time_after_eq(now, entry->timestamp +
1875 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001877 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
Chas Williams6656e3c2006-09-29 17:17:17 -07001879 lec_arp_hold(entry);
1880 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1881 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
Stephen Hemminger162619e2009-01-09 13:01:01 +00001882 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001884 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001885 lec_arp_put(entry);
1886 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 }
1889 }
1890 }
1891 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1892
Chas Williams987e46b2006-09-29 17:15:59 -07001893 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894}
Chas Williams1fa99612006-09-29 17:11:47 -07001895
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896/*
1897 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001898 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 */
Chas Williams1fa99612006-09-29 17:11:47 -07001900static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001901 const unsigned char *mac_to_find, int is_rdesc,
Chas Williams1fa99612006-09-29 17:11:47 -07001902 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903{
1904 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001905 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 struct atm_vcc *found;
1907
Chas Williams1fa99612006-09-29 17:11:47 -07001908 if (mac_to_find[0] & 0x01) {
1909 switch (priv->lane_version) {
1910 case 1:
1911 return priv->mcast_vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07001912 case 2: /* LANE2 wants arp for multicast addresses */
1913 if (!compare_ether_addr(mac_to_find, bus_mac))
1914 return priv->mcast_vcc;
1915 break;
1916 default:
1917 break;
1918 }
1919 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
1921 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001922 entry = lec_arp_find(priv, mac_to_find);
1923
1924 if (entry) {
1925 if (entry->status == ESI_FORWARD_DIRECT) {
1926 /* Connection Ok */
1927 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001928 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001929 *ret_entry = entry;
1930 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001932 }
1933 /*
1934 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001935 * so another LE_ARP request can be made for this frame.
1936 */
1937 if (entry->status == ESI_ARP_PENDING) {
1938 entry->no_tries = 0;
1939 }
Chas Williams1fa99612006-09-29 17:11:47 -07001940 /*
1941 * Data direct VC not yet set up, check to see if the unknown
1942 * frame count is greater than the limit. If the limit has
1943 * not been reached, allow the caller to send packet to
1944 * BUS.
1945 */
1946 if (entry->status != ESI_FLUSH_PENDING &&
1947 entry->packets_flooded <
1948 priv->maximum_unknown_frame_count) {
1949 entry->packets_flooded++;
Stephen Hemminger52240062007-08-28 15:22:09 -07001950 pr_debug("LEC_ARP: Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001951 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001953 }
1954 /*
1955 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 * or BUS flood limit was reached for an entry which is
1957 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1958 */
Chas Williams6656e3c2006-09-29 17:17:17 -07001959 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001960 *ret_entry = entry;
Stephen Hemminger52240062007-08-28 15:22:09 -07001961 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
Chas Williams1fa99612006-09-29 17:11:47 -07001962 entry->vcc);
1963 found = NULL;
1964 } else {
1965 /* No matching entry was found */
1966 entry = make_entry(priv, mac_to_find);
Stephen Hemminger52240062007-08-28 15:22:09 -07001967 pr_debug("LEC_ARP: Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001968 if (!entry) {
1969 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001971 }
1972 lec_arp_add(priv, entry);
1973 /* We want arp-request(s) to be sent */
1974 entry->packets_flooded = 1;
1975 entry->status = ESI_ARP_PENDING;
1976 entry->no_tries = 1;
1977 entry->last_used = entry->timestamp = jiffies;
1978 entry->is_rdesc = is_rdesc;
1979 if (entry->is_rdesc)
1980 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1981 NULL);
1982 else
1983 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1984 entry->timer.expires = jiffies + (1 * HZ);
1985 entry->timer.function = lec_arp_expire_arp;
1986 add_timer(&entry->timer);
1987 found = priv->mcast_vcc;
1988 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
1990out:
1991 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1992 return found;
1993}
1994
1995static int
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001996lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07001997 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998{
1999 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002000 struct hlist_node *node, *next;
2001 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002002 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
Stephen Hemminger52240062007-08-28 15:22:09 -07002004 pr_debug("lec_addr_delete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002006 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002007 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002008 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2009 && (permanent ||
2010 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002012 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002013 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002015 return 0;
2016 }
2017 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002019 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020}
2021
2022/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002023 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 */
2025static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002026lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
2027 const unsigned char *atm_addr, unsigned long remoteflag,
Chas Williams1fa99612006-09-29 17:11:47 -07002028 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029{
2030 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002031 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07002032 struct lec_arp_table *entry, *tmp;
2033 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
Stephen Hemminger52240062007-08-28 15:22:09 -07002035 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2036 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 -07002037 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2038 mac_addr[4], mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039
2040 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002041 entry = lec_arp_find(priv, mac_addr);
2042 if (entry == NULL && targetless_le_arp)
2043 goto out; /*
2044 * LANE2: ignore targetless LE_ARPs for which
2045 * we have no entry in the cache. 7.1.30
2046 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002047 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2048 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2049 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2050 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002051 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002052 tmp = lec_arp_find(priv, mac_addr);
2053 if (tmp) {
2054 del_timer(&tmp->timer);
2055 tmp->status = ESI_FORWARD_DIRECT;
2056 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2057 tmp->vcc = entry->vcc;
2058 tmp->old_push = entry->old_push;
2059 tmp->last_used = jiffies;
2060 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002061 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002062 entry = tmp;
2063 } else {
2064 entry->status = ESI_FORWARD_DIRECT;
2065 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2066 entry->last_used = jiffies;
2067 lec_arp_add(priv, entry);
2068 }
2069 if (remoteflag)
2070 entry->flags |= LEC_REMOTE_FLAG;
2071 else
2072 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002073 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002074 dump_arp_table(priv);
2075 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002076 }
Chas Williams1fa99612006-09-29 17:11:47 -07002077 }
2078 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002079
Chas Williams1fa99612006-09-29 17:11:47 -07002080 entry = lec_arp_find(priv, mac_addr);
2081 if (!entry) {
2082 entry = make_entry(priv, mac_addr);
2083 if (!entry)
2084 goto out;
2085 entry->status = ESI_UNKNOWN;
2086 lec_arp_add(priv, entry);
2087 /* Temporary, changes before end of function */
2088 }
2089 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2090 del_timer(&entry->timer);
2091 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002092 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002093 if (entry != tmp &&
2094 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2095 /* Vcc to this host exists */
2096 if (tmp->status > ESI_VC_PENDING) {
2097 /*
2098 * ESI_FLUSH_PENDING,
2099 * ESI_FORWARD_DIRECT
2100 */
2101 entry->vcc = tmp->vcc;
2102 entry->old_push = tmp->old_push;
2103 }
2104 entry->status = tmp->status;
2105 break;
2106 }
2107 }
2108 }
2109 if (remoteflag)
2110 entry->flags |= LEC_REMOTE_FLAG;
2111 else
2112 entry->flags &= ~LEC_REMOTE_FLAG;
2113 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2114 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002115 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002116 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002117 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002118 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119out:
2120 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2121}
2122
2123/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002124 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 */
2126static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002127lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002128 struct atm_vcc *vcc,
2129 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130{
2131 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002132 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002133 struct lec_arp_table *entry;
2134 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135
2136 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002137 if (ioc_data->receive == 2) {
2138 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
Stephen Hemminger52240062007-08-28 15:22:09 -07002140 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002142 entry = lec_arp_find(priv, bus_mac);
2143 if (!entry) {
2144 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002146 }
2147 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2148 entry->recv_vcc = vcc;
2149 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002151 entry = make_entry(priv, bus_mac);
2152 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002154 del_timer(&entry->timer);
2155 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2156 entry->recv_vcc = vcc;
2157 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002158 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002159 goto out;
2160 } else if (ioc_data->receive == 1) {
2161 /*
2162 * Vcc which we don't want to make default vcc,
2163 * attach it anyway.
2164 */
Stephen Hemminger52240062007-08-28 15:22:09 -07002165 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002166 ("LEC_ARP:Attaching data direct, not default: "
2167 "%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",
2168 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2169 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2170 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2171 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2172 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2173 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2174 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2175 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2176 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2177 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2178 entry = make_entry(priv, bus_mac);
2179 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002181 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2182 memset(entry->mac_addr, 0, ETH_ALEN);
2183 entry->recv_vcc = vcc;
2184 entry->old_recv_push = old_push;
2185 entry->status = ESI_UNKNOWN;
2186 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2187 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002188 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002189 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 dump_arp_table(priv);
2191 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002192 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002193 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002194 ("LEC_ARP:Attaching data direct, default: "
2195 "%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",
2196 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2197 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2198 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2199 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2200 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2201 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2202 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2203 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2204 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2205 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2206 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002207 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002208 if (memcmp
2209 (ioc_data->atm_addr, entry->atm_addr,
2210 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002211 pr_debug("LEC_ARP: Attaching data direct\n");
2212 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07002213 entry->vcc ? entry->vcc->vci : 0,
2214 entry->recv_vcc ? entry->recv_vcc->
2215 vci : 0);
2216 found_entry = 1;
2217 del_timer(&entry->timer);
2218 entry->vcc = vcc;
2219 entry->old_push = old_push;
2220 if (entry->status == ESI_VC_PENDING) {
2221 if (priv->maximum_unknown_frame_count
2222 == 0)
2223 entry->status =
2224 ESI_FORWARD_DIRECT;
2225 else {
2226 entry->timestamp = jiffies;
2227 entry->status =
2228 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002230 send_to_lecd(priv, l_flush_xmt,
2231 NULL,
2232 entry->atm_addr,
2233 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002235 }
2236 } else {
2237 /*
2238 * They were forming a connection
2239 * to us, and we to them. Our
2240 * ATM address is numerically lower
2241 * than theirs, so we make connection
2242 * we formed into default VCC (8.1.11).
2243 * Connection they made gets torn
2244 * down. This might confuse some
2245 * clients. Can be changed if
2246 * someone reports trouble...
2247 */
2248 ;
2249 }
2250 }
2251 }
2252 }
2253 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002254 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002255 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002257 }
2258 /*
2259 * Not found, snatch address from first data packet that arrives
2260 * from this vcc
2261 */
2262 entry = make_entry(priv, bus_mac);
2263 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002265 entry->vcc = vcc;
2266 entry->old_push = old_push;
2267 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2268 memset(entry->mac_addr, 0, ETH_ALEN);
2269 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002270 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002271 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2272 entry->timer.function = lec_arp_expire_vcc;
2273 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002274 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 dump_arp_table(priv);
2276out:
2277 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2278}
2279
Chas Williams1fa99612006-09-29 17:11:47 -07002280static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281{
2282 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002283 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002284 struct lec_arp_table *entry;
2285 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286
Stephen Hemminger52240062007-08-28 15:22:09 -07002287 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002288restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002289 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2290 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002291 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002292 if (entry->flush_tran_id == tran_id
2293 && entry->status == ESI_FLUSH_PENDING) {
2294 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002295 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002296
Chas Williams6656e3c2006-09-29 17:17:17 -07002297 lec_arp_hold(entry);
2298 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2299 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
Stephen Hemminger162619e2009-01-09 13:01:01 +00002300 lec_send(vcc, skb);
Chas Williams6656e3c2006-09-29 17:17:17 -07002301 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002302 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002303 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002304 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002305 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002306 }
2307 }
2308 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002310 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311}
2312
2313static void
2314lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002315 const unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316{
2317 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002318 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002319 struct lec_arp_table *entry;
2320 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
2322 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002323 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002324 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002325 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2326 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002327 pr_debug("Set flush transaction id to %lx for %p\n",
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002328 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002329 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2332}
2333
Chas Williams1fa99612006-09-29 17:11:47 -07002334static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335{
2336 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002337 unsigned char mac_addr[] = {
2338 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2339 };
2340 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 struct lec_vcc_priv *vpriv;
2342 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002343
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2345 return -ENOMEM;
2346 vpriv->xoff = 0;
2347 vpriv->old_pop = vcc->pop;
2348 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002349 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002351 to_add = make_entry(priv, mac_addr);
2352 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 vcc->pop = vpriv->old_pop;
2354 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002355 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002357 }
2358 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2359 to_add->status = ESI_FORWARD_DIRECT;
2360 to_add->flags |= LEC_PERMANENT_FLAG;
2361 to_add->vcc = vcc;
2362 to_add->old_push = vcc->push;
2363 vcc->push = lec_push;
2364 priv->mcast_vcc = vcc;
2365 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366out:
2367 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002368 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369}
2370
Chas Williams1fa99612006-09-29 17:11:47 -07002371static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372{
2373 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002374 struct hlist_node *node, *next;
2375 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002376 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377
Stephen Hemminger52240062007-08-28 15:22:09 -07002378 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002379 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002380
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002382
Chas Williams1fa99612006-09-29 17:11:47 -07002383 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002384 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002385 if (vcc == entry->vcc) {
2386 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002387 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002388 if (priv->mcast_vcc == vcc) {
2389 priv->mcast_vcc = NULL;
2390 }
2391 }
2392 }
2393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
Chas Williamsd0732f62006-09-29 17:14:27 -07002395 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2396 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002397 lec_arp_clear_vccs(entry);
2398 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002399 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002400 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002401 }
Chas Williams1fa99612006-09-29 17:11:47 -07002402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403
Chas Williamsd0732f62006-09-29 17:14:27 -07002404 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002405 if (entry->recv_vcc == vcc) {
2406 lec_arp_clear_vccs(entry);
2407 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002408 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002409 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002410 }
Chas Williams1fa99612006-09-29 17:11:47 -07002411 }
2412
Chas Williamsd0732f62006-09-29 17:14:27 -07002413 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002414 if (entry->recv_vcc == vcc) {
2415 lec_arp_clear_vccs(entry);
2416 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002417 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002418 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002419 }
Chas Williams1fa99612006-09-29 17:11:47 -07002420 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421
2422 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2423 dump_arp_table(priv);
2424}
2425
2426static void
2427lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002428 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429{
Chas Williams1fa99612006-09-29 17:11:47 -07002430 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002431 struct hlist_node *node, *next;
2432 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002433 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2434 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002436 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437
Chas Williams1fa99612006-09-29 17:11:47 -07002438 if (priv->is_trdev)
2439 src = tr_hdr->h_source;
2440 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002442 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443
2444 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002445 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2446 if (vcc == entry->vcc) {
2447 del_timer(&entry->timer);
2448 memcpy(entry->mac_addr, src, ETH_ALEN);
2449 entry->status = ESI_FORWARD_DIRECT;
2450 entry->last_used = jiffies;
2451 /* We might have got an entry */
2452 if ((tmp = lec_arp_find(priv, src))) {
2453 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002454 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002455 }
2456 hlist_del(&entry->next);
2457 lec_arp_add(priv, entry);
2458 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002459 }
Chas Williams1fa99612006-09-29 17:11:47 -07002460 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002461 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462out:
2463 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2464}
Chas Williams1fa99612006-09-29 17:11:47 -07002465
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466MODULE_LICENSE("GPL");