blob: e5e301550e8a72ce7897fce6729bd2a82f844ea0 [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);
65static struct net_device_stats *lec_get_stats(struct net_device *dev);
66static void lec_init(struct net_device *dev);
Chas Williamsd44f7742006-09-29 17:11:14 -070067static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070068 const unsigned char *mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static int lec_arp_remove(struct lec_priv *priv,
Chas Williamsd44f7742006-09-29 17:11:14 -070070 struct lec_arp_table *to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* LANE2 functions */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070072static void lane2_associate_ind(struct net_device *dev, const u8 *mac_address,
73 const u8 *tlvs, u32 sizeoftlvs);
74static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -070075 u8 **tlvs, u32 *sizeoftlvs);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070076static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
77 const u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070079static int lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 unsigned long permanent);
81static void lec_arp_check_empties(struct lec_priv *priv,
82 struct atm_vcc *vcc, struct sk_buff *skb);
83static void lec_arp_destroy(struct lec_priv *priv);
84static void lec_arp_init(struct lec_priv *priv);
Chas Williamsd44f7742006-09-29 17:11:14 -070085static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070086 const unsigned char *mac_to_find,
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 int is_rdesc,
88 struct lec_arp_table **ret_entry);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070089static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
90 const unsigned char *atm_addr, unsigned long remoteflag,
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 unsigned int targetless_le_arp);
92static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
93static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
94static void lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070095 const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 unsigned long tran_id);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070097static void lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 struct atm_vcc *vcc,
Chas Williamsd44f7742006-09-29 17:11:14 -070099 void (*old_push) (struct atm_vcc *vcc,
100 struct sk_buff *skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
102
Chas Williams33a9c2d2006-09-29 17:16:48 -0700103/* must be done under lec_arp_lock */
104static inline void lec_arp_hold(struct lec_arp_table *entry)
105{
106 atomic_inc(&entry->usage);
107}
108
109static inline void lec_arp_put(struct lec_arp_table *entry)
110{
111 if (atomic_dec_and_test(&entry->usage))
112 kfree(entry);
113}
114
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116static struct lane2_ops lane2_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700117 lane2_resolve, /* resolve, spec 3.1.3 */
118 lane2_associate_req, /* associate_req, spec 3.1.4 */
119 NULL /* associate indicator, spec 3.1.5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120};
121
Chas Williamsd44f7742006-09-29 17:11:14 -0700122static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124/* Device structures */
125static struct net_device *dev_lec[MAX_LEC_ITF];
126
127#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
128static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
129{
Chas Williamsd44f7742006-09-29 17:11:14 -0700130 struct ethhdr *eth;
131 char *buff;
132 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Chas Williamsd44f7742006-09-29 17:11:14 -0700134 /*
135 * Check if this is a BPDU. If so, ask zeppelin to send
136 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
137 * as the Config BPDU has
138 */
139 eth = (struct ethhdr *)skb->data;
140 buff = skb->data + skb->dev->hard_header_len;
141 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 struct sock *sk;
Chas Williamsd44f7742006-09-29 17:11:14 -0700143 struct sk_buff *skb2;
144 struct atmlec_msg *mesg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Chas Williamsd44f7742006-09-29 17:11:14 -0700146 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
147 if (skb2 == NULL)
148 return;
149 skb2->len = sizeof(struct atmlec_msg);
150 mesg = (struct atmlec_msg *)skb2->data;
151 mesg->type = l_topology_change;
152 buff += 4;
153 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Wang Chen524ad0a2008-11-12 23:39:10 -0800155 priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700156 atm_force_charge(priv->lecd, skb2->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 sk = sk_atm(priv->lecd);
Chas Williamsd44f7742006-09-29 17:11:14 -0700158 skb_queue_tail(&sk->sk_receive_queue, skb2);
159 sk->sk_data_ready(sk, skb2->len);
160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Chas Williamsd44f7742006-09-29 17:11:14 -0700162 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
165
166/*
167 * Modelled after tr_type_trans
168 * All multicast and ARE or STE frames go to BUS.
169 * Non source routed frames go by destination address.
170 * Last hop source routed frames go by destination address.
171 * Not last hop source routed frames go by _next_ route descriptor.
172 * Returns pointer to destination MAC address or fills in rdesc
173 * and returns NULL.
174 */
175#ifdef CONFIG_TR
176static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
177{
Chas Williamsd44f7742006-09-29 17:11:14 -0700178 struct trh_hdr *trh;
Eric Dumazet5c17d5f2008-01-15 03:29:50 -0800179 unsigned int riflen, num_rdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Chas Williamsd44f7742006-09-29 17:11:14 -0700181 trh = (struct trh_hdr *)packet;
182 if (trh->daddr[0] & (uint8_t) 0x80)
183 return bus_mac; /* multicast */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Chas Williamsd44f7742006-09-29 17:11:14 -0700185 if (trh->saddr[0] & TR_RII) {
186 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
187 if ((ntohs(trh->rcf) >> 13) != 0)
188 return bus_mac; /* ARE or STE */
189 } else
190 return trh->daddr; /* not source routed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Chas Williamsd44f7742006-09-29 17:11:14 -0700192 if (riflen < 6)
193 return trh->daddr; /* last hop, source routed */
194
195 /* riflen is 6 or more, packet has more than one route descriptor */
196 num_rdsc = (riflen / 2) - 1;
197 memset(rdesc, 0, ETH_ALEN);
198 /* offset 4 comes from LAN destination field in LE control frames */
199 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
Al Viro30d492d2006-11-14 21:11:29 -0800200 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700201 else {
Al Viro30d492d2006-11-14 21:11:29 -0800202 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700203 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
204 }
205
206 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
208#endif /* CONFIG_TR */
209
210/*
211 * Open/initialize the netdevice. This is called (in the current kernel)
212 * sometime after booting when the 'ifconfig' program is run.
213 *
214 * This routine should set everything up anew at each open, even
215 * registers that "should" only need to be set once at boot, so that
216 * there is non-reboot way to recover if something goes wrong.
217 */
218
Chas Williamsd44f7742006-09-29 17:11:14 -0700219static int lec_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Wang Chen524ad0a2008-11-12 23:39:10 -0800221 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 netif_start_queue(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700224 memset(&priv->stats, 0, sizeof(struct net_device_stats));
225
226 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
229static __inline__ void
230lec_send(struct atm_vcc *vcc, struct sk_buff *skb, struct lec_priv *priv)
231{
232 ATM_SKB(skb)->vcc = vcc;
233 ATM_SKB(skb)->atm_options = vcc->atm_options;
234
235 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
236 if (vcc->send(vcc, skb) < 0) {
237 priv->stats.tx_dropped++;
238 return;
239 }
240
241 priv->stats.tx_packets++;
242 priv->stats.tx_bytes += skb->len;
243}
244
Chas Williamsd44f7742006-09-29 17:11:14 -0700245static void lec_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
247 printk(KERN_INFO "%s: tx timeout\n", dev->name);
248 dev->trans_start = jiffies;
249 netif_wake_queue(dev);
250}
251
Chas Williamsd44f7742006-09-29 17:11:14 -0700252static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
Chas Williamsd44f7742006-09-29 17:11:14 -0700254 struct sk_buff *skb2;
Wang Chen524ad0a2008-11-12 23:39:10 -0800255 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700256 struct lecdatahdr_8023 *lec_h;
257 struct atm_vcc *vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700259 unsigned char *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 int min_frame_size;
261#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700262 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700264 int is_rdesc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700266 char buf[300];
267 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268#endif /* DUMP_PACKETS >0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Stephen Hemminger52240062007-08-28 15:22:09 -0700270 pr_debug("lec_start_xmit called\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700271 if (!priv->lecd) {
272 printk("%s:No lecd attached\n", dev->name);
273 priv->stats.tx_errors++;
274 netif_stop_queue(dev);
275 return -EUNATCH;
276 }
277
Stephen Hemminger52240062007-08-28 15:22:09 -0700278 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700279 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700280 (long)skb_end_pointer(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700282 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
283 lec_handle_bridge(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#endif
285
Chas Williamsd44f7742006-09-29 17:11:14 -0700286 /* Make sure we have room for lec_id */
287 if (skb_headroom(skb) < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Stephen Hemminger52240062007-08-28 15:22:09 -0700289 pr_debug("lec_start_xmit: reallocating skb\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700290 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
291 kfree_skb(skb);
292 if (skb2 == NULL)
293 return 0;
294 skb = skb2;
295 }
296 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Chas Williamsd44f7742006-09-29 17:11:14 -0700298 /* Put le header to place, works for TokenRing too */
299 lec_h = (struct lecdatahdr_8023 *)skb->data;
300 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700303 /*
304 * Ugly. Use this to realign Token Ring packets for
305 * e.g. PCA-200E driver.
306 */
307 if (priv->is_trdev) {
308 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
309 kfree_skb(skb);
310 if (skb2 == NULL)
311 return 0;
312 skb = skb2;
313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314#endif
315
316#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700317 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
318 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700320 for (i = 0; i < skb->len && i < 99; i++) {
321 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700324 for (i = 0; i < skb->len && i < 30; i++) {
325 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700328 if (i == skb->len)
329 printk("%s\n", buf);
330 else
331 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#endif /* DUMP_PACKETS > 0 */
333
Chas Williamsd44f7742006-09-29 17:11:14 -0700334 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700336 if (priv->is_trdev)
337 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 else
339#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700340 min_frame_size = LEC_MINIMUM_8023_SIZE;
341 if (skb->len < min_frame_size) {
342 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
343 skb2 = skb_copy_expand(skb, 0,
344 min_frame_size - skb->truesize,
345 GFP_ATOMIC);
346 dev_kfree_skb(skb);
347 if (skb2 == NULL) {
348 priv->stats.tx_dropped++;
349 return 0;
350 }
351 skb = skb2;
352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700354 }
355
356 /* Send to right vcc */
357 is_rdesc = 0;
358 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700360 if (priv->is_trdev) {
361 dst = get_tr_dst(skb->data + 2, rdesc);
362 if (dst == NULL) {
363 dst = rdesc;
364 is_rdesc = 1;
365 }
366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700368 entry = NULL;
369 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
Andrew Morton58c14a82007-09-26 22:31:19 -0700370 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700371 vcc, vcc ? vcc->flags : 0, entry);
372 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
373 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700374 pr_debug("%s:lec_start_xmit: queuing packet, ",
Chas Williamsd44f7742006-09-29 17:11:14 -0700375 dev->name);
Johannes Berge1749612008-10-27 15:59:26 -0700376 pr_debug("MAC address %pM\n", lec_h->h_dest);
Chas Williamsd44f7742006-09-29 17:11:14 -0700377 skb_queue_tail(&entry->tx_wait, skb);
378 } else {
Stephen Hemminger52240062007-08-28 15:22:09 -0700379 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700380 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
381 dev->name);
Johannes Berge1749612008-10-27 15:59:26 -0700382 pr_debug("MAC address %pM\n", lec_h->h_dest);
Chas Williamsd44f7742006-09-29 17:11:14 -0700383 priv->stats.tx_dropped++;
384 dev_kfree_skb(skb);
385 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700386 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700387 }
388#if DUMP_PACKETS > 0
389 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700391
392 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700393 pr_debug("lec.c: emptying tx queue, ");
Johannes Berge1749612008-10-27 15:59:26 -0700394 pr_debug("MAC address %pM\n", lec_h->h_dest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 lec_send(vcc, skb2, priv);
Chas Williamsd44f7742006-09-29 17:11:14 -0700396 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 lec_send(vcc, skb, priv);
399
400 if (!atm_may_send(vcc, 0)) {
401 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
402
403 vpriv->xoff = 1;
404 netif_stop_queue(dev);
405
406 /*
407 * vcc->pop() might have occurred in between, making
408 * the vcc usuable again. Since xmit is serialized,
409 * this is the only situation we have to re-test.
410 */
411
412 if (atm_may_send(vcc, 0))
413 netif_wake_queue(dev);
414 }
415
Chas Williams6656e3c2006-09-29 17:17:17 -0700416out:
417 if (entry)
418 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 dev->trans_start = jiffies;
Chas Williamsd44f7742006-09-29 17:11:14 -0700420 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421}
422
423/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700424static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425{
Chas Williamsd44f7742006-09-29 17:11:14 -0700426 netif_stop_queue(dev);
427 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428}
429
430/*
431 * Get the current statistics.
432 * This may be called with the card open or closed.
433 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700434static struct net_device_stats *lec_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
Wang Chen524ad0a2008-11-12 23:39:10 -0800436 return &((struct lec_priv *)netdev_priv(dev))->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438
Chas Williamsd44f7742006-09-29 17:11:14 -0700439static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
441 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700442 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800443 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700444 struct atmlec_msg *mesg;
445 struct lec_arp_table *entry;
446 int i;
447 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700450 mesg = (struct atmlec_msg *)skb->data;
451 tmp = skb->data;
452 tmp += sizeof(struct atmlec_msg);
Stephen Hemminger52240062007-08-28 15:22:09 -0700453 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700454 switch (mesg->type) {
455 case l_set_mac_addr:
456 for (i = 0; i < 6; i++) {
457 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
458 }
459 break;
460 case l_del_mac_addr:
461 for (i = 0; i < 6; i++) {
462 dev->dev_addr[i] = 0;
463 }
464 break;
465 case l_addr_delete:
466 lec_addr_delete(priv, mesg->content.normal.atm_addr,
467 mesg->content.normal.flag);
468 break;
469 case l_topology_change:
470 priv->topology_change = mesg->content.normal.flag;
471 break;
472 case l_flush_complete:
473 lec_flush_complete(priv, mesg->content.normal.flag);
474 break;
475 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700477 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
478 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
480
Chas Williamsd44f7742006-09-29 17:11:14 -0700481 if (mesg->content.normal.no_source_le_narp)
482 break;
483 /* FALL THROUGH */
484 case l_arp_update:
485 lec_arp_update(priv, mesg->content.normal.mac_addr,
486 mesg->content.normal.atm_addr,
487 mesg->content.normal.flag,
488 mesg->content.normal.targetless_le_arp);
Stephen Hemminger52240062007-08-28 15:22:09 -0700489 pr_debug("lec: in l_arp_update\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700490 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700491 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700492 mesg->sizeoftlvs);
493 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
494 tmp, mesg->sizeoftlvs);
495 }
496 break;
497 case l_config:
498 priv->maximum_unknown_frame_count =
499 mesg->content.config.maximum_unknown_frame_count;
500 priv->max_unknown_frame_time =
501 (mesg->content.config.max_unknown_frame_time * HZ);
502 priv->max_retry_count = mesg->content.config.max_retry_count;
503 priv->aging_time = (mesg->content.config.aging_time * HZ);
504 priv->forward_delay_time =
505 (mesg->content.config.forward_delay_time * HZ);
506 priv->arp_response_time =
507 (mesg->content.config.arp_response_time * HZ);
508 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
509 priv->path_switching_delay =
510 (mesg->content.config.path_switching_delay * HZ);
511 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 priv->lane2_ops = NULL;
513 if (priv->lane_version > 1)
514 priv->lane2_ops = &lane2_ops;
515 if (dev->change_mtu(dev, mesg->content.config.mtu))
516 printk("%s: change_mtu to %d failed\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700517 mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700519 break;
520 case l_flush_tran_id:
521 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
522 mesg->content.normal.flag);
523 break;
524 case l_set_lecid:
525 priv->lecid =
526 (unsigned short)(0xffff & mesg->content.normal.flag);
527 break;
528 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700530 {
531 struct net_bridge_fdb_entry *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Johannes Berge1749612008-10-27 15:59:26 -0700533 pr_debug("%s: bridge zeppelin asks about %pM\n",
534 dev->name, mesg->content.proxy.mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Chas Williamsd44f7742006-09-29 17:11:14 -0700536 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
537 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Chas Williamsd44f7742006-09-29 17:11:14 -0700539 f = br_fdb_get_hook(dev->br_port->br,
540 mesg->content.proxy.mac_addr);
541 if (f != NULL && f->dst->dev != dev
542 && f->dst->state == BR_STATE_FORWARDING) {
543 /* hit from bridge table, send LE_ARP_RESPONSE */
544 struct sk_buff *skb2;
545 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Stephen Hemminger52240062007-08-28 15:22:09 -0700547 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700548 ("%s: entry found, responding to zeppelin\n",
549 dev->name);
550 skb2 =
551 alloc_skb(sizeof(struct atmlec_msg),
552 GFP_ATOMIC);
553 if (skb2 == NULL) {
554 br_fdb_put_hook(f);
555 break;
556 }
557 skb2->len = sizeof(struct atmlec_msg);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300558 skb_copy_to_linear_data(skb2, mesg,
559 sizeof(*mesg));
Chas Williamsd44f7742006-09-29 17:11:14 -0700560 atm_force_charge(priv->lecd, skb2->truesize);
561 sk = sk_atm(priv->lecd);
562 skb_queue_tail(&sk->sk_receive_queue, skb2);
563 sk->sk_data_ready(sk, skb2->len);
564 }
565 if (f != NULL)
566 br_fdb_put_hook(f);
567 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700569 break;
570 default:
571 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
572 dev_kfree_skb(skb);
573 return -EINVAL;
574 }
575 dev_kfree_skb(skb);
576 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
578
Chas Williamsd44f7742006-09-29 17:11:14 -0700579static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
Chas Williamsd44f7742006-09-29 17:11:14 -0700581 struct sk_buff *skb;
582 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800583 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Chas Williamsd44f7742006-09-29 17:11:14 -0700585 priv->lecd = NULL;
586 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Chas Williamsd44f7742006-09-29 17:11:14 -0700588 netif_stop_queue(dev);
589 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Chas Williamsd44f7742006-09-29 17:11:14 -0700591 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700593 dev->name);
594 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
595 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700597 }
598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700600 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601}
602
603static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700604 .close = lec_atm_close,
605 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606};
607
608static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700609 .ops = &lecdev_ops,
610 .type = "lec",
611 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700612 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613};
614
615/*
616 * LANE2: new argument struct sk_buff *data contains
617 * the LE_ARP based TLVs introduced in the LANE2 spec
618 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700619static int
620send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700621 const unsigned char *mac_addr, const unsigned char *atm_addr,
Chas Williamsd44f7742006-09-29 17:11:14 -0700622 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
624 struct sock *sk;
625 struct sk_buff *skb;
626 struct atmlec_msg *mesg;
627
628 if (!priv || !priv->lecd) {
629 return -1;
630 }
631 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
632 if (!skb)
633 return -1;
634 skb->len = sizeof(struct atmlec_msg);
635 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700636 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700638 if (data != NULL)
639 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 if (mac_addr)
641 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700642 else
643 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 if (atm_addr)
645 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
646
Chas Williamsd44f7742006-09-29 17:11:14 -0700647 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 sk = sk_atm(priv->lecd);
649 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700650 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Chas Williamsd44f7742006-09-29 17:11:14 -0700652 if (data != NULL) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700653 pr_debug("lec: about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700654 atm_force_charge(priv->lecd, data->truesize);
655 skb_queue_tail(&sk->sk_receive_queue, data);
656 sk->sk_data_ready(sk, skb->len);
657 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Chas Williamsd44f7742006-09-29 17:11:14 -0700659 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660}
661
662/* shamelessly stolen from drivers/net/net_init.c */
663static int lec_change_mtu(struct net_device *dev, int new_mtu)
664{
Chas Williamsd44f7742006-09-29 17:11:14 -0700665 if ((new_mtu < 68) || (new_mtu > 18190))
666 return -EINVAL;
667 dev->mtu = new_mtu;
668 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669}
670
671static void lec_set_multicast_list(struct net_device *dev)
672{
Chas Williamsd44f7742006-09-29 17:11:14 -0700673 /*
674 * by default, all multicast frames arrive over the bus.
675 * eventually support selective multicast service
676 */
677 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
Chas Williamsd44f7742006-09-29 17:11:14 -0700680static void lec_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681{
Chas Williamsd44f7742006-09-29 17:11:14 -0700682 dev->change_mtu = lec_change_mtu;
683 dev->open = lec_open;
684 dev->stop = lec_close;
685 dev->hard_start_xmit = lec_start_xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 dev->tx_timeout = lec_tx_timeout;
687
Chas Williamsd44f7742006-09-29 17:11:14 -0700688 dev->get_stats = lec_get_stats;
689 dev->set_multicast_list = lec_set_multicast_list;
690 dev->do_ioctl = NULL;
691 printk("%s: Initialized!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692}
693
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700694static const unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700695 0xff,
696 0x00,
697 0x01,
698 0x01
699};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
Scott Talbert4a7097f2005-09-29 17:30:54 -0700701#define LEC_DATA_DIRECT_8023 2
702#define LEC_DATA_DIRECT_8025 3
703
704static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700705{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700706 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
707 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700708}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700709
Chas Williamsd44f7742006-09-29 17:11:14 -0700710static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700712 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700713 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800714 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716#if DUMP_PACKETS >0
Chas Williamsd44f7742006-09-29 17:11:14 -0700717 int i = 0;
718 char buf[300];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Chas Williamsd44f7742006-09-29 17:11:14 -0700720 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
721 vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700723 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700724 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700725 lec_vcc_close(priv, vcc);
726 return;
727 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700729 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
730 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700732 for (i = 0; i < skb->len && i < 99; i++) {
733 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700736 for (i = 0; i < skb->len && i < 30; i++) {
737 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
738 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700740 if (i == skb->len)
741 printk("%s\n", buf);
742 else
743 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700745 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 struct sock *sk = sk_atm(vcc);
747
Stephen Hemminger52240062007-08-28 15:22:09 -0700748 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700749 skb_queue_tail(&sk->sk_receive_queue, skb);
750 sk->sk_data_ready(sk, skb->len);
751 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700752 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700753 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Chas Williamsd44f7742006-09-29 17:11:14 -0700755 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800756 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700757 !priv->lecd || !(dev->flags & IFF_UP)) {
758 /*
759 * Probably looping back, or if lecd is missing,
760 * lecd has gone down
761 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700762 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700763 dev_kfree_skb(skb);
764 return;
765 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700767 if (priv->is_trdev)
768 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
769 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700771 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700772
Chas Williamsd44f7742006-09-29 17:11:14 -0700773 /*
774 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700775 * the LE_ARP cache entry, delete the LE_ARP cache entry.
776 */
777 spin_lock_irqsave(&priv->lec_arp_lock, flags);
778 if (lec_is_data_direct(vcc)) {
779#ifdef CONFIG_TR
780 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700781 src =
782 ((struct lecdatahdr_8025 *)skb->data)->
783 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700784 else
785#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700786 src =
787 ((struct lecdatahdr_8023 *)skb->data)->
788 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700789 entry = lec_arp_find(priv, src);
790 if (entry && entry->vcc != vcc) {
791 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700792 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700793 }
794 }
795 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Chas Williamsd44f7742006-09-29 17:11:14 -0700797 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
798 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700800 dev_kfree_skb(skb);
801 return;
802 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700803 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700804 lec_arp_check_empties(priv, vcc, skb);
805 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700806 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700808 if (priv->is_trdev)
809 skb->protocol = tr_type_trans(skb, dev);
810 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700812 skb->protocol = eth_type_trans(skb, dev);
813 priv->stats.rx_packets++;
814 priv->stats.rx_bytes += skb->len;
815 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
816 netif_rx(skb);
817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819
Chas Williamsd44f7742006-09-29 17:11:14 -0700820static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
822 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
823 struct net_device *dev = skb->dev;
824
825 if (vpriv == NULL) {
826 printk("lec_pop(): vpriv = NULL!?!?!?\n");
827 return;
828 }
829
830 vpriv->old_pop(vcc, skb);
831
832 if (vpriv->xoff && atm_may_send(vcc, 0)) {
833 vpriv->xoff = 0;
834 if (netif_running(dev) && netif_queue_stopped(dev))
835 netif_wake_queue(dev);
836 }
837}
838
Chas Williamsd44f7742006-09-29 17:11:14 -0700839static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840{
841 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700842 int bytes_left;
843 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
Chas Williamsd44f7742006-09-29 17:11:14 -0700845 /* Lecd must be up in this case */
846 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
847 if (bytes_left != 0) {
848 printk
849 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
850 bytes_left);
851 }
852 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
853 !dev_lec[ioc_data.dev_num])
854 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
856 return -ENOMEM;
857 vpriv->xoff = 0;
858 vpriv->old_pop = vcc->pop;
859 vcc->user_back = vpriv;
860 vcc->pop = lec_pop;
Wang Chen524ad0a2008-11-12 23:39:10 -0800861 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
Chas Williamsd44f7742006-09-29 17:11:14 -0700862 &ioc_data, vcc, vcc->push);
863 vcc->proto_data = dev_lec[ioc_data.dev_num];
864 vcc->push = lec_push;
865 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866}
867
Chas Williamsd44f7742006-09-29 17:11:14 -0700868static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869{
Chas Williamsd44f7742006-09-29 17:11:14 -0700870 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
871 return -EINVAL;
872 vcc->proto_data = dev_lec[arg];
Wang Chen524ad0a2008-11-12 23:39:10 -0800873 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
874 vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875}
876
877/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700878static int lecd_attach(struct atm_vcc *vcc, int arg)
879{
880 int i;
881 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
Chas Williamsd44f7742006-09-29 17:11:14 -0700883 if (arg < 0)
884 i = 0;
885 else
886 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700888 if (arg >= MAX_LEC_ITF)
889 return -EINVAL;
890#else /* Reserve the top NUM_TR_DEVS for TR */
891 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
892 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700894 if (!dev_lec[i]) {
895 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Chas Williamsd44f7742006-09-29 17:11:14 -0700897 is_trdev = 0;
898 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
899 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
Chas Williamsd44f7742006-09-29 17:11:14 -0700901 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700903 if (is_trdev)
904 dev_lec[i] = alloc_trdev(size);
905 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700907 dev_lec[i] = alloc_etherdev(size);
908 if (!dev_lec[i])
909 return -ENOMEM;
910 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
911 if (register_netdev(dev_lec[i])) {
912 free_netdev(dev_lec[i]);
913 return -EINVAL;
914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Wang Chen524ad0a2008-11-12 23:39:10 -0800916 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700917 priv->is_trdev = is_trdev;
918 lec_init(dev_lec[i]);
919 } else {
Wang Chen524ad0a2008-11-12 23:39:10 -0800920 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700921 if (priv->lecd)
922 return -EADDRINUSE;
923 }
924 lec_arp_init(priv);
925 priv->itfnum = i; /* LANE2 addition */
926 priv->lecd = vcc;
927 vcc->dev = &lecatm_dev;
928 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Chas Williamsd44f7742006-09-29 17:11:14 -0700930 vcc->proto_data = dev_lec[i];
931 set_bit(ATM_VF_META, &vcc->flags);
932 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Chas Williamsd44f7742006-09-29 17:11:14 -0700934 /* Set default values to these variables */
935 priv->maximum_unknown_frame_count = 1;
936 priv->max_unknown_frame_time = (1 * HZ);
937 priv->vcc_timeout_period = (1200 * HZ);
938 priv->max_retry_count = 1;
939 priv->aging_time = (300 * HZ);
940 priv->forward_delay_time = (15 * HZ);
941 priv->topology_change = 0;
942 priv->arp_response_time = (1 * HZ);
943 priv->flush_timeout = (4 * HZ);
944 priv->path_switching_delay = (6 * HZ);
945
946 if (dev_lec[i]->flags & IFF_UP) {
947 netif_start_queue(dev_lec[i]);
948 }
949 __module_get(THIS_MODULE);
950 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951}
952
953#ifdef CONFIG_PROC_FS
Chas Williamsd44f7742006-09-29 17:11:14 -0700954static char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
956 static char *lec_arp_status_string[] = {
957 "ESI_UNKNOWN ",
958 "ESI_ARP_PENDING ",
959 "ESI_VC_PENDING ",
960 "<Undefined> ",
961 "ESI_FLUSH_PENDING ",
962 "ESI_FORWARD_DIRECT"
963 };
964
965 if (status > ESI_FORWARD_DIRECT)
966 status = 3; /* ESI_UNDEFINED */
967 return lec_arp_status_string[status];
968}
969
970static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
971{
972 int i;
973
974 for (i = 0; i < ETH_ALEN; i++)
975 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
976 seq_printf(seq, " ");
977 for (i = 0; i < ATM_ESA_LEN; i++)
978 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
979 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
980 entry->flags & 0xffff);
981 if (entry->vcc)
982 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
983 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700984 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 if (entry->recv_vcc) {
986 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
987 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -0700988 }
989 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990}
991
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992struct lec_state {
993 unsigned long flags;
994 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -0700995 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 struct net_device *dev;
997 int itf;
998 int arp_table;
999 int misc_table;
1000};
1001
Chas Williamsd0732f62006-09-29 17:14:27 -07001002static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 loff_t *l)
1004{
Chas Williamsd0732f62006-09-29 17:14:27 -07001005 struct hlist_node *e = state->node;
1006 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
1008 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -07001009 e = tbl->first;
Joe Perches2e1e9842008-04-10 03:33:03 -07001010 if (e == SEQ_START_TOKEN) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001011 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 --*l;
1013 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001014
1015 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 if (--*l < 0)
1017 break;
1018 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001019 state->node = e;
1020
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 return (*l < 0) ? state : NULL;
1022}
1023
1024static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -07001025 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026{
1027 void *v = NULL;
1028 int p;
1029
1030 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001031 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 if (v)
1033 break;
1034 }
1035 state->arp_table = p;
1036 return v;
1037}
1038
1039static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1040 struct lec_priv *priv)
1041{
Chas Williamsd0732f62006-09-29 17:14:27 -07001042 struct hlist_head *lec_misc_tables[] = {
1043 &priv->lec_arp_empty_ones,
1044 &priv->lec_no_forward,
1045 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 };
1047 void *v = NULL;
1048 int q;
1049
1050 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1051 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1052 if (v)
1053 break;
1054 }
1055 state->misc_table = q;
1056 return v;
1057}
1058
1059static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1060 struct lec_priv *priv)
1061{
1062 if (!state->locked) {
1063 state->locked = priv;
1064 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1065 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001066 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1068 state->locked = NULL;
1069 /* Partial state reset for the next time we get called */
1070 state->arp_table = state->misc_table = 0;
1071 }
1072 return state->locked;
1073}
1074
1075static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1076{
1077 struct net_device *dev;
1078 void *v;
1079
1080 dev = state->dev ? state->dev : dev_lec[state->itf];
Wang Chen524ad0a2008-11-12 23:39:10 -08001081 v = (dev && netdev_priv(dev)) ?
1082 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 if (!v && dev) {
1084 dev_put(dev);
1085 /* Partial state reset for the next time we get called */
1086 dev = NULL;
1087 }
1088 state->dev = dev;
1089 return v;
1090}
1091
1092static void *lec_get_idx(struct lec_state *state, loff_t l)
1093{
1094 void *v = NULL;
1095
1096 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1097 v = lec_itf_walk(state, &l);
1098 if (v)
1099 break;
1100 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001101 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102}
1103
1104static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1105{
1106 struct lec_state *state = seq->private;
1107
1108 state->itf = 0;
1109 state->dev = NULL;
1110 state->locked = NULL;
1111 state->arp_table = 0;
1112 state->misc_table = 0;
Joe Perches2e1e9842008-04-10 03:33:03 -07001113 state->node = SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Joe Perches2e1e9842008-04-10 03:33:03 -07001115 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
1118static void lec_seq_stop(struct seq_file *seq, void *v)
1119{
1120 struct lec_state *state = seq->private;
1121
1122 if (state->dev) {
1123 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1124 state->flags);
1125 dev_put(state->dev);
1126 }
1127}
1128
1129static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1130{
1131 struct lec_state *state = seq->private;
1132
1133 v = lec_get_idx(state, 1);
1134 *pos += !!PTR_ERR(v);
1135 return v;
1136}
1137
1138static int lec_seq_show(struct seq_file *seq, void *v)
1139{
Chas Williamsd44f7742006-09-29 17:11:14 -07001140 static char lec_banner[] = "Itf MAC ATM destination"
1141 " Status Flags "
1142 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
Joe Perches2e1e9842008-04-10 03:33:03 -07001144 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 seq_puts(seq, lec_banner);
1146 else {
1147 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001148 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001149 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
1151 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001152 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 }
1154 return 0;
1155}
1156
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001157static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001158 .start = lec_seq_start,
1159 .next = lec_seq_next,
1160 .stop = lec_seq_stop,
1161 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162};
1163
1164static int lec_seq_open(struct inode *inode, struct file *file)
1165{
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001166 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167}
1168
Arjan van de Ven9a321442007-02-12 00:55:35 -08001169static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001170 .owner = THIS_MODULE,
1171 .open = lec_seq_open,
1172 .read = seq_read,
1173 .llseek = seq_lseek,
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001174 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175};
1176#endif
1177
1178static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1179{
1180 struct atm_vcc *vcc = ATM_SD(sock);
1181 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001182
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001184 case ATMLEC_CTRL:
1185 case ATMLEC_MCAST:
1186 case ATMLEC_DATA:
1187 if (!capable(CAP_NET_ADMIN))
1188 return -EPERM;
1189 break;
1190 default:
1191 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 }
1193
1194 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001195 case ATMLEC_CTRL:
1196 err = lecd_attach(vcc, (int)arg);
1197 if (err >= 0)
1198 sock->state = SS_CONNECTED;
1199 break;
1200 case ATMLEC_MCAST:
1201 err = lec_mcast_attach(vcc, (int)arg);
1202 break;
1203 case ATMLEC_DATA:
1204 err = lec_vcc_attach(vcc, (void __user *)arg);
1205 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 }
1207
1208 return err;
1209}
1210
1211static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001212 .owner = THIS_MODULE,
1213 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214};
1215
1216static int __init lane_module_init(void)
1217{
1218#ifdef CONFIG_PROC_FS
1219 struct proc_dir_entry *p;
1220
Wang Chen16e297b2008-02-28 13:55:45 -08001221 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Wang Chendbee0d32008-03-23 21:45:36 -07001222 if (!p) {
1223 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n");
1224 return -ENOMEM;
1225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226#endif
1227
1228 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001229 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1230 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231}
1232
1233static void __exit lane_module_cleanup(void)
1234{
Chas Williamsd44f7742006-09-29 17:11:14 -07001235 int i;
1236 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
1238 remove_proc_entry("lec", atm_proc_root);
1239
1240 deregister_atm_ioctl(&lane_ioctl_ops);
1241
Chas Williamsd44f7742006-09-29 17:11:14 -07001242 for (i = 0; i < MAX_LEC_ITF; i++) {
1243 if (dev_lec[i] != NULL) {
Wang Chen524ad0a2008-11-12 23:39:10 -08001244 priv = netdev_priv(dev_lec[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001246 free_netdev(dev_lec[i]);
1247 dev_lec[i] = NULL;
1248 }
1249 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Chas Williamsd44f7742006-09-29 17:11:14 -07001251 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252}
1253
1254module_init(lane_module_init);
1255module_exit(lane_module_cleanup);
1256
1257/*
1258 * LANE2: 3.1.3, LE_RESOLVE.request
1259 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1260 * If sizeoftlvs == NULL the default TLVs associated with with this
1261 * lec will be used.
1262 * If dst_mac == NULL, targetless LE_ARP will be sent
1263 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001264static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001265 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266{
1267 unsigned long flags;
Wang Chen524ad0a2008-11-12 23:39:10 -08001268 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001269 struct lec_arp_table *table;
1270 struct sk_buff *skb;
1271 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
Chas Williamsd44f7742006-09-29 17:11:14 -07001273 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001275 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001277 if (table == NULL)
1278 return -1;
1279
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001280 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001281 if (*tlvs == NULL)
1282 return -1;
1283
Chas Williamsd44f7742006-09-29 17:11:14 -07001284 *sizeoftlvs = table->sizeoftlvs;
1285
1286 return 0;
1287 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289 if (sizeoftlvs == NULL)
1290 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001291
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 else {
1293 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1294 if (skb == NULL)
1295 return -1;
1296 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001297 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1299 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001300 return retval;
1301}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
1303/*
1304 * LANE2: 3.1.4, LE_ASSOCIATE.request
1305 * Associate the *tlvs with the *lan_dst address.
1306 * Will overwrite any previous association
1307 * Returns 1 for success, 0 for failure (out of memory)
1308 *
1309 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001310static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1311 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312{
Chas Williamsd44f7742006-09-29 17:11:14 -07001313 int retval;
1314 struct sk_buff *skb;
Wang Chen524ad0a2008-11-12 23:39:10 -08001315 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
Chas Williamsd44f7742006-09-29 17:11:14 -07001317 if (compare_ether_addr(lan_dst, dev->dev_addr))
1318 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
Chas Williamsd44f7742006-09-29 17:11:14 -07001320 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001322 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001323 if (priv->tlvs == NULL)
1324 return (0);
1325 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Chas Williamsd44f7742006-09-29 17:11:14 -07001327 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1328 if (skb == NULL)
1329 return 0;
1330 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001331 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001332 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1333 if (retval != 0)
1334 printk("lec.c: lane2_associate_req() failed\n");
1335 /*
1336 * If the previous association has changed we must
1337 * somehow notify other LANE entities about the change
1338 */
1339 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340}
1341
1342/*
1343 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1344 *
1345 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001346static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1347 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348{
1349#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001350 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351#endif
Wang Chen524ad0a2008-11-12 23:39:10 -08001352 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001353#if 0 /*
1354 * Why have the TLVs in LE_ARP entries
1355 * since we do not use them? When you
1356 * uncomment this code, make sure the
1357 * TLVs get freed when entry is killed
1358 */
1359 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
Chas Williamsd44f7742006-09-29 17:11:14 -07001361 if (entry == NULL)
1362 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Chas Williamsd44f7742006-09-29 17:11:14 -07001364 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001366 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001367 if (entry->tlvs == NULL)
1368 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001369 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370#endif
1371#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001372 printk("lec.c: lane2_associate_ind()\n");
1373 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1374 while (i < sizeoftlvs)
1375 printk("%02x ", tlvs[i++]);
1376
1377 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378#endif
1379
Chas Williamsd44f7742006-09-29 17:11:14 -07001380 /* tell MPOA about the TLVs we saw */
1381 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1382 priv->lane2_ops->associate_indicator(dev, mac_addr,
1383 tlvs, sizeoftlvs);
1384 }
1385 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386}
1387
1388/*
1389 * Here starts what used to lec_arpc.c
1390 *
1391 * lec_arpc.c was added here when making
1392 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 */
1394
1395#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396#include <linux/timer.h>
1397#include <asm/param.h>
1398#include <asm/atomic.h>
1399#include <linux/inetdevice.h>
1400#include <net/route.h>
1401
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402#if 0
Stephen Hemminger52240062007-08-28 15:22:09 -07001403#define pr_debug(format,args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404/*
Stephen Hemminger52240062007-08-28 15:22:09 -07001405#define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406*/
1407#endif
1408#define DEBUG_ARP_TABLE 0
1409
1410#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1411
David Howellsc4028952006-11-22 14:57:56 +00001412static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413static void lec_arp_expire_arp(unsigned long data);
1414
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001415/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 * Arp table funcs
1417 */
1418
1419#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1420
1421/*
1422 * Initialization of arp-cache
1423 */
Chas Williams1fa99612006-09-29 17:11:47 -07001424static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425{
Chas Williams1fa99612006-09-29 17:11:47 -07001426 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
Chas Williams1fa99612006-09-29 17:11:47 -07001428 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001429 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001430 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001431 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1432 INIT_HLIST_HEAD(&priv->lec_no_forward);
1433 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001435 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001436 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437}
1438
Chas Williams1fa99612006-09-29 17:11:47 -07001439static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440{
Chas Williams1fa99612006-09-29 17:11:47 -07001441 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 struct atm_vcc *vcc = entry->vcc;
1443 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001444 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
Chas Williams1fa99612006-09-29 17:11:47 -07001446 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 if (vpriv->xoff)
1448 netif_wake_queue(dev);
1449 kfree(vpriv);
1450 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001451 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001453 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001454 }
1455 if (entry->recv_vcc) {
1456 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001458 entry->recv_vcc = NULL;
1459 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460}
1461
1462/*
1463 * Insert entry to lec_arp_table
1464 * LANE2: Add to the end of the list to satisfy 8.1.13
1465 */
Chas Williams1fa99612006-09-29 17:11:47 -07001466static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001467lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468{
Chas Williamsd0732f62006-09-29 17:14:27 -07001469 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
Chas Williamsd0732f62006-09-29 17:14:27 -07001471 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1472 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001473
Stephen Hemminger52240062007-08-28 15:22:09 -07001474 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 -07001475 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1476 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1477 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478}
1479
1480/*
1481 * Remove entry from lec_arp_table
1482 */
Chas Williams1fa99612006-09-29 17:11:47 -07001483static int
1484lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485{
Chas Williamsd0732f62006-09-29 17:14:27 -07001486 struct hlist_node *node;
1487 struct lec_arp_table *entry;
1488 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
Chas Williams1fa99612006-09-29 17:11:47 -07001490 if (!to_remove) {
1491 return -1;
1492 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001493
1494 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001495 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Chas Williamsd0732f62006-09-29 17:14:27 -07001497 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001498 if (to_remove->status >= ESI_FLUSH_PENDING) {
1499 /*
1500 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1501 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001502 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1503 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1504 if (memcmp(to_remove->atm_addr,
1505 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001506 remove_vcc = 0;
1507 break;
1508 }
1509 }
1510 }
1511 if (remove_vcc)
1512 lec_arp_clear_vccs(to_remove);
1513 }
1514 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1515
Stephen Hemminger52240062007-08-28 15:22:09 -07001516 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 -07001517 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1518 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1519 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1520 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521}
1522
1523#if DEBUG_ARP_TABLE
Chas Williams1fa99612006-09-29 17:11:47 -07001524static char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525{
Chas Williams1fa99612006-09-29 17:11:47 -07001526 switch (st) {
1527 case ESI_UNKNOWN:
1528 return "ESI_UNKNOWN";
1529 case ESI_ARP_PENDING:
1530 return "ESI_ARP_PENDING";
1531 case ESI_VC_PENDING:
1532 return "ESI_VC_PENDING";
1533 case ESI_FLUSH_PENDING:
1534 return "ESI_FLUSH_PENDING";
1535 case ESI_FORWARD_DIRECT:
1536 return "ESI_FORWARD_DIRECT";
1537 default:
1538 return "<UNKNOWN>";
1539 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
Chas Williams1fa99612006-09-29 17:11:47 -07001542static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543{
Chas Williamsd0732f62006-09-29 17:14:27 -07001544 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001545 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001546 char buf[256];
1547 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
Chas Williams1fa99612006-09-29 17:11:47 -07001549 printk("Dump %p:\n", priv);
1550 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001551 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1552 offset = 0;
1553 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001554 offset += sprintf(buf + offset, "Mac:");
1555 for (j = 0; j < ETH_ALEN; j++) {
1556 offset += sprintf(buf + offset,
1557 "%2.2x ",
1558 rulla->mac_addr[j] & 0xff);
1559 }
1560 offset += sprintf(buf + offset, "Atm:");
1561 for (j = 0; j < ATM_ESA_LEN; j++) {
1562 offset += sprintf(buf + offset,
1563 "%2.2x ",
1564 rulla->atm_addr[j] & 0xff);
1565 }
1566 offset += sprintf(buf + offset,
1567 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1568 rulla->vcc ? rulla->vcc->vpi : 0,
1569 rulla->vcc ? rulla->vcc->vci : 0,
1570 rulla->recv_vcc ? rulla->recv_vcc->
1571 vpi : 0,
1572 rulla->recv_vcc ? rulla->recv_vcc->
1573 vci : 0, rulla->last_used,
1574 rulla->timestamp, rulla->no_tries);
1575 offset +=
1576 sprintf(buf + offset,
1577 "Flags:%x, Packets_flooded:%x, Status: %s ",
1578 rulla->flags, rulla->packets_flooded,
1579 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001580 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001581 }
Chas Williams1fa99612006-09-29 17:11:47 -07001582 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001583
1584 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001585 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001586 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001587 offset = 0;
1588 offset += sprintf(buf + offset, "Mac:");
1589 for (j = 0; j < ETH_ALEN; j++) {
1590 offset += sprintf(buf + offset, "%2.2x ",
1591 rulla->mac_addr[j] & 0xff);
1592 }
1593 offset += sprintf(buf + offset, "Atm:");
1594 for (j = 0; j < ATM_ESA_LEN; j++) {
1595 offset += sprintf(buf + offset, "%2.2x ",
1596 rulla->atm_addr[j] & 0xff);
1597 }
1598 offset += sprintf(buf + offset,
1599 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1600 rulla->vcc ? rulla->vcc->vpi : 0,
1601 rulla->vcc ? rulla->vcc->vci : 0,
1602 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1603 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1604 rulla->last_used,
1605 rulla->timestamp, rulla->no_tries);
1606 offset += sprintf(buf + offset,
1607 "Flags:%x, Packets_flooded:%x, Status: %s ",
1608 rulla->flags, rulla->packets_flooded,
1609 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001610 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001611 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001612
1613 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001614 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001615 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001616 offset = 0;
1617 offset += sprintf(buf + offset, "Mac:");
1618 for (j = 0; j < ETH_ALEN; j++) {
1619 offset += sprintf(buf + offset, "%2.2x ",
1620 rulla->mac_addr[j] & 0xff);
1621 }
1622 offset += sprintf(buf + offset, "Atm:");
1623 for (j = 0; j < ATM_ESA_LEN; j++) {
1624 offset += sprintf(buf + offset, "%2.2x ",
1625 rulla->atm_addr[j] & 0xff);
1626 }
1627 offset += sprintf(buf + offset,
1628 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1629 rulla->vcc ? rulla->vcc->vpi : 0,
1630 rulla->vcc ? rulla->vcc->vci : 0,
1631 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1632 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1633 rulla->last_used,
1634 rulla->timestamp, rulla->no_tries);
1635 offset += sprintf(buf + offset,
1636 "Flags:%x, Packets_flooded:%x, Status: %s ",
1637 rulla->flags, rulla->packets_flooded,
1638 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001639 printk("%s", buf);
1640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
Chas Williamsd0732f62006-09-29 17:14:27 -07001642 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001643 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001644 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001645 offset = 0;
1646 offset += sprintf(buf + offset, "Mac:");
1647 for (j = 0; j < ETH_ALEN; j++) {
1648 offset += sprintf(buf + offset, "%2.2x ",
1649 rulla->mac_addr[j] & 0xff);
1650 }
1651 offset += sprintf(buf + offset, "Atm:");
1652 for (j = 0; j < ATM_ESA_LEN; j++) {
1653 offset += sprintf(buf + offset, "%2.2x ",
1654 rulla->atm_addr[j] & 0xff);
1655 }
1656 offset += sprintf(buf + offset,
1657 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1658 rulla->vcc ? rulla->vcc->vpi : 0,
1659 rulla->vcc ? rulla->vcc->vci : 0,
1660 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1661 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1662 rulla->last_used,
1663 rulla->timestamp, rulla->no_tries);
1664 offset += sprintf(buf + offset,
1665 "Flags:%x, Packets_flooded:%x, Status: %s ",
1666 rulla->flags, rulla->packets_flooded,
1667 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001668 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671}
Chas Williamsd0732f62006-09-29 17:14:27 -07001672#else
1673#define dump_arp_table(priv) do { } while (0)
1674#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
1676/*
1677 * Destruction of arp-cache
1678 */
Chas Williams1fa99612006-09-29 17:11:47 -07001679static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680{
1681 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001682 struct hlist_node *node, *next;
1683 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001684 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
Chas Williams987e46b2006-09-29 17:15:59 -07001686 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001687
1688 /*
1689 * Remove all entries
1690 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
1692 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001693 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001694 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001695 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001696 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001697 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001698 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001699 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001700
1701 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, 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_arp_empty_ones);
1708
1709 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001710 del_timer_sync(&entry->timer);
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->lec_no_forward);
1716
1717 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001718 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1719 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001720 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001721 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001722 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001723 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001724 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1726}
1727
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001728/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 * Find entry by mac_address
1730 */
Chas Williams1fa99612006-09-29 17:11:47 -07001731static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001732 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733{
Chas Williamsd0732f62006-09-29 17:14:27 -07001734 struct hlist_node *node;
1735 struct hlist_head *head;
1736 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
Stephen Hemminger52240062007-08-28 15:22:09 -07001738 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 -07001739 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1740 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
Chas Williams1fa99612006-09-29 17:11:47 -07001741
Chas Williamsd0732f62006-09-29 17:14:27 -07001742 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1743 hlist_for_each_entry(entry, node, head, next) {
1744 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1745 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001746 }
Chas Williams1fa99612006-09-29 17:11:47 -07001747 }
1748 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749}
1750
Chas Williams1fa99612006-09-29 17:11:47 -07001751static struct lec_arp_table *make_entry(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001752 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753{
Chas Williams1fa99612006-09-29 17:11:47 -07001754 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
Chas Williams1fa99612006-09-29 17:11:47 -07001756 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1757 if (!to_return) {
1758 printk("LEC: Arp entry kmalloc failed\n");
1759 return NULL;
1760 }
1761 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001762 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001763 setup_timer(&to_return->timer, lec_arp_expire_arp,
1764 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001765 to_return->last_used = jiffies;
1766 to_return->priv = priv;
1767 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001768 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001769 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770}
1771
Chas Williams1fa99612006-09-29 17:11:47 -07001772/* Arp sent timer expired */
1773static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
Chas Williams1fa99612006-09-29 17:11:47 -07001775 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776
Chas Williams1fa99612006-09-29 17:11:47 -07001777 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
Stephen Hemminger52240062007-08-28 15:22:09 -07001779 pr_debug("lec_arp_expire_arp\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001780 if (entry->status == ESI_ARP_PENDING) {
1781 if (entry->no_tries <= entry->priv->max_retry_count) {
1782 if (entry->is_rdesc)
1783 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1784 entry->mac_addr, NULL, NULL);
1785 else
1786 send_to_lecd(entry->priv, l_arp_xmt,
1787 entry->mac_addr, NULL, NULL);
1788 entry->no_tries++;
1789 }
1790 mod_timer(&entry->timer, jiffies + (1 * HZ));
1791 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792}
1793
Chas Williams1fa99612006-09-29 17:11:47 -07001794/* Unknown/unused vcc expire, remove associated entry */
1795static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796{
1797 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001798 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1799 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800
Chas Williams1fa99612006-09-29 17:11:47 -07001801 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802
Stephen Hemminger52240062007-08-28 15:22:09 -07001803 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001804 to_remove, priv,
1805 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1806 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
1808 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001809 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1811
Chas Williams1fa99612006-09-29 17:11:47 -07001812 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001813 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814}
1815
1816/*
1817 * Expire entries.
1818 * 1. Re-set timer
1819 * 2. For each entry, delete entries that have aged past the age limit.
1820 * 3. For each entry, depending on the status of the entry, perform
1821 * the following maintenance.
1822 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1823 * tick_count is above the max_unknown_frame_time, clear
1824 * the tick_count to zero and clear the packets_flooded counter
1825 * to zero. This supports the packet rate limit per address
1826 * while flooding unknowns.
1827 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1828 * than or equal to the path_switching_delay, change the status
1829 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1830 * regardless of the progress of the flush protocol.
1831 */
David Howellsc4028952006-11-22 14:57:56 +00001832static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833{
1834 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001835 struct lec_priv *priv =
1836 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001837 struct hlist_node *node, *next;
1838 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001839 unsigned long now;
1840 unsigned long time_to_check;
1841 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
Stephen Hemminger52240062007-08-28 15:22:09 -07001843 pr_debug("lec_arp_check_expire %p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001845restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001847 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001848 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001849 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 priv->topology_change)
1851 time_to_check = priv->forward_delay_time;
1852 else
1853 time_to_check = priv->aging_time;
1854
Stephen Hemminger52240062007-08-28 15:22:09 -07001855 pr_debug("About to expire: %lx - %lx > %lx\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001856 now, entry->last_used, time_to_check);
1857 if (time_after(now, entry->last_used + time_to_check)
1858 && !(entry->flags & LEC_PERMANENT_FLAG)
1859 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 /* Remove entry */
Stephen Hemminger52240062007-08-28 15:22:09 -07001861 pr_debug("LEC:Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001863 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 } else {
1865 /* Something else */
1866 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001867 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001869 entry->timestamp +
1870 priv->
1871 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 entry->timestamp = jiffies;
1873 entry->packets_flooded = 0;
1874 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001875 send_to_lecd(priv, l_svc_setup,
1876 entry->mac_addr,
1877 entry->atm_addr,
1878 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 }
Chas Williams1fa99612006-09-29 17:11:47 -07001880 if (entry->status == ESI_FLUSH_PENDING
1881 &&
1882 time_after_eq(now, entry->timestamp +
1883 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001885 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
Chas Williams6656e3c2006-09-29 17:17:17 -07001887 lec_arp_hold(entry);
1888 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1889 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1890 lec_send(vcc, skb, entry->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001892 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001893 lec_arp_put(entry);
1894 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 }
1897 }
1898 }
1899 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1900
Chas Williams987e46b2006-09-29 17:15:59 -07001901 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902}
Chas Williams1fa99612006-09-29 17:11:47 -07001903
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904/*
1905 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001906 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 */
Chas Williams1fa99612006-09-29 17:11:47 -07001908static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001909 const unsigned char *mac_to_find, int is_rdesc,
Chas Williams1fa99612006-09-29 17:11:47 -07001910 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911{
1912 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001913 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 struct atm_vcc *found;
1915
Chas Williams1fa99612006-09-29 17:11:47 -07001916 if (mac_to_find[0] & 0x01) {
1917 switch (priv->lane_version) {
1918 case 1:
1919 return priv->mcast_vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07001920 case 2: /* LANE2 wants arp for multicast addresses */
1921 if (!compare_ether_addr(mac_to_find, bus_mac))
1922 return priv->mcast_vcc;
1923 break;
1924 default:
1925 break;
1926 }
1927 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928
1929 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001930 entry = lec_arp_find(priv, mac_to_find);
1931
1932 if (entry) {
1933 if (entry->status == ESI_FORWARD_DIRECT) {
1934 /* Connection Ok */
1935 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001936 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001937 *ret_entry = entry;
1938 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001940 }
1941 /*
1942 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001943 * so another LE_ARP request can be made for this frame.
1944 */
1945 if (entry->status == ESI_ARP_PENDING) {
1946 entry->no_tries = 0;
1947 }
Chas Williams1fa99612006-09-29 17:11:47 -07001948 /*
1949 * Data direct VC not yet set up, check to see if the unknown
1950 * frame count is greater than the limit. If the limit has
1951 * not been reached, allow the caller to send packet to
1952 * BUS.
1953 */
1954 if (entry->status != ESI_FLUSH_PENDING &&
1955 entry->packets_flooded <
1956 priv->maximum_unknown_frame_count) {
1957 entry->packets_flooded++;
Stephen Hemminger52240062007-08-28 15:22:09 -07001958 pr_debug("LEC_ARP: Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001959 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001961 }
1962 /*
1963 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 * or BUS flood limit was reached for an entry which is
1965 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1966 */
Chas Williams6656e3c2006-09-29 17:17:17 -07001967 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001968 *ret_entry = entry;
Stephen Hemminger52240062007-08-28 15:22:09 -07001969 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
Chas Williams1fa99612006-09-29 17:11:47 -07001970 entry->vcc);
1971 found = NULL;
1972 } else {
1973 /* No matching entry was found */
1974 entry = make_entry(priv, mac_to_find);
Stephen Hemminger52240062007-08-28 15:22:09 -07001975 pr_debug("LEC_ARP: Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001976 if (!entry) {
1977 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001979 }
1980 lec_arp_add(priv, entry);
1981 /* We want arp-request(s) to be sent */
1982 entry->packets_flooded = 1;
1983 entry->status = ESI_ARP_PENDING;
1984 entry->no_tries = 1;
1985 entry->last_used = entry->timestamp = jiffies;
1986 entry->is_rdesc = is_rdesc;
1987 if (entry->is_rdesc)
1988 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1989 NULL);
1990 else
1991 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1992 entry->timer.expires = jiffies + (1 * HZ);
1993 entry->timer.function = lec_arp_expire_arp;
1994 add_timer(&entry->timer);
1995 found = priv->mcast_vcc;
1996 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
1998out:
1999 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2000 return found;
2001}
2002
2003static int
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002004lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07002005 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006{
2007 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002008 struct hlist_node *node, *next;
2009 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002010 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
Stephen Hemminger52240062007-08-28 15:22:09 -07002012 pr_debug("lec_addr_delete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002014 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002015 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002016 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2017 && (permanent ||
2018 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002020 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002021 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002023 return 0;
2024 }
2025 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002027 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028}
2029
2030/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002031 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 */
2033static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002034lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
2035 const unsigned char *atm_addr, unsigned long remoteflag,
Chas Williams1fa99612006-09-29 17:11:47 -07002036 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037{
2038 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002039 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07002040 struct lec_arp_table *entry, *tmp;
2041 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042
Stephen Hemminger52240062007-08-28 15:22:09 -07002043 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2044 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 -07002045 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2046 mac_addr[4], mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047
2048 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002049 entry = lec_arp_find(priv, mac_addr);
2050 if (entry == NULL && targetless_le_arp)
2051 goto out; /*
2052 * LANE2: ignore targetless LE_ARPs for which
2053 * we have no entry in the cache. 7.1.30
2054 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002055 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2056 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2057 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2058 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002059 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002060 tmp = lec_arp_find(priv, mac_addr);
2061 if (tmp) {
2062 del_timer(&tmp->timer);
2063 tmp->status = ESI_FORWARD_DIRECT;
2064 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2065 tmp->vcc = entry->vcc;
2066 tmp->old_push = entry->old_push;
2067 tmp->last_used = jiffies;
2068 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002069 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002070 entry = tmp;
2071 } else {
2072 entry->status = ESI_FORWARD_DIRECT;
2073 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2074 entry->last_used = jiffies;
2075 lec_arp_add(priv, entry);
2076 }
2077 if (remoteflag)
2078 entry->flags |= LEC_REMOTE_FLAG;
2079 else
2080 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002081 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002082 dump_arp_table(priv);
2083 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002084 }
Chas Williams1fa99612006-09-29 17:11:47 -07002085 }
2086 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002087
Chas Williams1fa99612006-09-29 17:11:47 -07002088 entry = lec_arp_find(priv, mac_addr);
2089 if (!entry) {
2090 entry = make_entry(priv, mac_addr);
2091 if (!entry)
2092 goto out;
2093 entry->status = ESI_UNKNOWN;
2094 lec_arp_add(priv, entry);
2095 /* Temporary, changes before end of function */
2096 }
2097 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2098 del_timer(&entry->timer);
2099 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002100 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002101 if (entry != tmp &&
2102 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2103 /* Vcc to this host exists */
2104 if (tmp->status > ESI_VC_PENDING) {
2105 /*
2106 * ESI_FLUSH_PENDING,
2107 * ESI_FORWARD_DIRECT
2108 */
2109 entry->vcc = tmp->vcc;
2110 entry->old_push = tmp->old_push;
2111 }
2112 entry->status = tmp->status;
2113 break;
2114 }
2115 }
2116 }
2117 if (remoteflag)
2118 entry->flags |= LEC_REMOTE_FLAG;
2119 else
2120 entry->flags &= ~LEC_REMOTE_FLAG;
2121 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2122 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002123 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002124 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002125 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002126 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127out:
2128 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2129}
2130
2131/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002132 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 */
2134static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002135lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002136 struct atm_vcc *vcc,
2137 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138{
2139 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002140 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002141 struct lec_arp_table *entry;
2142 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
2144 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002145 if (ioc_data->receive == 2) {
2146 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147
Stephen Hemminger52240062007-08-28 15:22:09 -07002148 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002150 entry = lec_arp_find(priv, bus_mac);
2151 if (!entry) {
2152 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002154 }
2155 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2156 entry->recv_vcc = vcc;
2157 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002159 entry = make_entry(priv, bus_mac);
2160 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002162 del_timer(&entry->timer);
2163 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2164 entry->recv_vcc = vcc;
2165 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002166 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002167 goto out;
2168 } else if (ioc_data->receive == 1) {
2169 /*
2170 * Vcc which we don't want to make default vcc,
2171 * attach it anyway.
2172 */
Stephen Hemminger52240062007-08-28 15:22:09 -07002173 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002174 ("LEC_ARP:Attaching data direct, not default: "
2175 "%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",
2176 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2177 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2178 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2179 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2180 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2181 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2182 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2183 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2184 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2185 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2186 entry = make_entry(priv, bus_mac);
2187 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002189 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2190 memset(entry->mac_addr, 0, ETH_ALEN);
2191 entry->recv_vcc = vcc;
2192 entry->old_recv_push = old_push;
2193 entry->status = ESI_UNKNOWN;
2194 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2195 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002196 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002197 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 dump_arp_table(priv);
2199 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002200 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002201 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002202 ("LEC_ARP:Attaching data direct, default: "
2203 "%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",
2204 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2205 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2206 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2207 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2208 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2209 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2210 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2211 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2212 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2213 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2214 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002215 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002216 if (memcmp
2217 (ioc_data->atm_addr, entry->atm_addr,
2218 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002219 pr_debug("LEC_ARP: Attaching data direct\n");
2220 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07002221 entry->vcc ? entry->vcc->vci : 0,
2222 entry->recv_vcc ? entry->recv_vcc->
2223 vci : 0);
2224 found_entry = 1;
2225 del_timer(&entry->timer);
2226 entry->vcc = vcc;
2227 entry->old_push = old_push;
2228 if (entry->status == ESI_VC_PENDING) {
2229 if (priv->maximum_unknown_frame_count
2230 == 0)
2231 entry->status =
2232 ESI_FORWARD_DIRECT;
2233 else {
2234 entry->timestamp = jiffies;
2235 entry->status =
2236 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002238 send_to_lecd(priv, l_flush_xmt,
2239 NULL,
2240 entry->atm_addr,
2241 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002243 }
2244 } else {
2245 /*
2246 * They were forming a connection
2247 * to us, and we to them. Our
2248 * ATM address is numerically lower
2249 * than theirs, so we make connection
2250 * we formed into default VCC (8.1.11).
2251 * Connection they made gets torn
2252 * down. This might confuse some
2253 * clients. Can be changed if
2254 * someone reports trouble...
2255 */
2256 ;
2257 }
2258 }
2259 }
2260 }
2261 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002262 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002263 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002265 }
2266 /*
2267 * Not found, snatch address from first data packet that arrives
2268 * from this vcc
2269 */
2270 entry = make_entry(priv, bus_mac);
2271 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002273 entry->vcc = vcc;
2274 entry->old_push = old_push;
2275 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2276 memset(entry->mac_addr, 0, ETH_ALEN);
2277 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002278 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002279 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2280 entry->timer.function = lec_arp_expire_vcc;
2281 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002282 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 dump_arp_table(priv);
2284out:
2285 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2286}
2287
Chas Williams1fa99612006-09-29 17:11:47 -07002288static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289{
2290 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002291 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002292 struct lec_arp_table *entry;
2293 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
Stephen Hemminger52240062007-08-28 15:22:09 -07002295 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002296restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002297 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2298 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002299 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002300 if (entry->flush_tran_id == tran_id
2301 && entry->status == ESI_FLUSH_PENDING) {
2302 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002303 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002304
Chas Williams6656e3c2006-09-29 17:17:17 -07002305 lec_arp_hold(entry);
2306 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2307 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2308 lec_send(vcc, skb, entry->priv);
2309 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002310 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002311 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002312 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002313 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002314 }
2315 }
2316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002318 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319}
2320
2321static void
2322lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002323 const unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324{
2325 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002326 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002327 struct lec_arp_table *entry;
2328 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329
2330 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002331 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002332 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002333 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2334 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002335 pr_debug("Set flush transaction id to %lx for %p\n",
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002336 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002337 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002338 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2340}
2341
Chas Williams1fa99612006-09-29 17:11:47 -07002342static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343{
2344 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002345 unsigned char mac_addr[] = {
2346 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2347 };
2348 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 struct lec_vcc_priv *vpriv;
2350 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002351
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2353 return -ENOMEM;
2354 vpriv->xoff = 0;
2355 vpriv->old_pop = vcc->pop;
2356 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002357 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002359 to_add = make_entry(priv, mac_addr);
2360 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 vcc->pop = vpriv->old_pop;
2362 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002363 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002365 }
2366 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2367 to_add->status = ESI_FORWARD_DIRECT;
2368 to_add->flags |= LEC_PERMANENT_FLAG;
2369 to_add->vcc = vcc;
2370 to_add->old_push = vcc->push;
2371 vcc->push = lec_push;
2372 priv->mcast_vcc = vcc;
2373 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374out:
2375 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002376 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377}
2378
Chas Williams1fa99612006-09-29 17:11:47 -07002379static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380{
2381 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002382 struct hlist_node *node, *next;
2383 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002384 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385
Stephen Hemminger52240062007-08-28 15:22:09 -07002386 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002387 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002388
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002390
Chas Williams1fa99612006-09-29 17:11:47 -07002391 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002392 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002393 if (vcc == entry->vcc) {
2394 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002395 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002396 if (priv->mcast_vcc == vcc) {
2397 priv->mcast_vcc = NULL;
2398 }
2399 }
2400 }
2401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
Chas Williamsd0732f62006-09-29 17:14:27 -07002403 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2404 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002405 lec_arp_clear_vccs(entry);
2406 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002407 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002408 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002409 }
Chas Williams1fa99612006-09-29 17:11:47 -07002410 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
Chas Williamsd0732f62006-09-29 17:14:27 -07002412 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002413 if (entry->recv_vcc == vcc) {
2414 lec_arp_clear_vccs(entry);
2415 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002416 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002417 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002418 }
Chas Williams1fa99612006-09-29 17:11:47 -07002419 }
2420
Chas Williamsd0732f62006-09-29 17:14:27 -07002421 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002422 if (entry->recv_vcc == vcc) {
2423 lec_arp_clear_vccs(entry);
2424 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002425 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002426 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002427 }
Chas Williams1fa99612006-09-29 17:11:47 -07002428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
2430 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2431 dump_arp_table(priv);
2432}
2433
2434static void
2435lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002436 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437{
Chas Williams1fa99612006-09-29 17:11:47 -07002438 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002439 struct hlist_node *node, *next;
2440 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002441 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2442 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002444 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
Chas Williams1fa99612006-09-29 17:11:47 -07002446 if (priv->is_trdev)
2447 src = tr_hdr->h_source;
2448 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002450 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451
2452 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002453 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2454 if (vcc == entry->vcc) {
2455 del_timer(&entry->timer);
2456 memcpy(entry->mac_addr, src, ETH_ALEN);
2457 entry->status = ESI_FORWARD_DIRECT;
2458 entry->last_used = jiffies;
2459 /* We might have got an entry */
2460 if ((tmp = lec_arp_find(priv, src))) {
2461 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002462 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002463 }
2464 hlist_del(&entry->next);
2465 lec_arp_add(priv, entry);
2466 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002467 }
Chas Williams1fa99612006-09-29 17:11:47 -07002468 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002469 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470out:
2471 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2472}
Chas Williams1fa99612006-09-29 17:11:47 -07002473
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474MODULE_LICENSE("GPL");