blob: e2d800d818e357c058b867e7ccd9d1af5c231087 [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,
68 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 */
Chas Williamsd44f7742006-09-29 17:11:14 -070072static void lane2_associate_ind(struct net_device *dev, u8 *mac_address,
73 u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -070075 u8 **tlvs, u32 *sizeoftlvs);
76static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
77 u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Chas Williamsd44f7742006-09-29 17:11:14 -070079static int lec_addr_delete(struct lec_priv *priv, 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,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 unsigned char *mac_to_find,
87 int is_rdesc,
88 struct lec_arp_table **ret_entry);
89static void lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
90 unsigned char *atm_addr, unsigned long remoteflag,
91 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,
95 unsigned char *atm_addr,
96 unsigned long tran_id);
97static void lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
98 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
Chas Williamsd44f7742006-09-29 17:11:14 -0700155 priv = (struct lec_priv *)dev->priv;
156 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{
Chas Williamsd44f7742006-09-29 17:11:14 -0700221 struct lec_priv *priv = (struct lec_priv *)dev->priv;
222
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;
255 struct lec_priv *priv = (struct lec_priv *)dev->priv;
256 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 */
Joe Perches0795af52007-10-03 17:59:30 -0700269 DECLARE_MAC_BUF(mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Stephen Hemminger52240062007-08-28 15:22:09 -0700271 pr_debug("lec_start_xmit called\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700272 if (!priv->lecd) {
273 printk("%s:No lecd attached\n", dev->name);
274 priv->stats.tx_errors++;
275 netif_stop_queue(dev);
276 return -EUNATCH;
277 }
278
Stephen Hemminger52240062007-08-28 15:22:09 -0700279 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700280 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700281 (long)skb_end_pointer(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700283 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
284 lec_handle_bridge(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285#endif
286
Chas Williamsd44f7742006-09-29 17:11:14 -0700287 /* Make sure we have room for lec_id */
288 if (skb_headroom(skb) < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Stephen Hemminger52240062007-08-28 15:22:09 -0700290 pr_debug("lec_start_xmit: reallocating skb\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700291 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
292 kfree_skb(skb);
293 if (skb2 == NULL)
294 return 0;
295 skb = skb2;
296 }
297 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Chas Williamsd44f7742006-09-29 17:11:14 -0700299 /* Put le header to place, works for TokenRing too */
300 lec_h = (struct lecdatahdr_8023 *)skb->data;
301 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700304 /*
305 * Ugly. Use this to realign Token Ring packets for
306 * e.g. PCA-200E driver.
307 */
308 if (priv->is_trdev) {
309 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
310 kfree_skb(skb);
311 if (skb2 == NULL)
312 return 0;
313 skb = skb2;
314 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#endif
316
317#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700318 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
319 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700321 for (i = 0; i < skb->len && i < 99; i++) {
322 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700325 for (i = 0; i < skb->len && i < 30; i++) {
326 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700329 if (i == skb->len)
330 printk("%s\n", buf);
331 else
332 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333#endif /* DUMP_PACKETS > 0 */
334
Chas Williamsd44f7742006-09-29 17:11:14 -0700335 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700337 if (priv->is_trdev)
338 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 else
340#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700341 min_frame_size = LEC_MINIMUM_8023_SIZE;
342 if (skb->len < min_frame_size) {
343 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
344 skb2 = skb_copy_expand(skb, 0,
345 min_frame_size - skb->truesize,
346 GFP_ATOMIC);
347 dev_kfree_skb(skb);
348 if (skb2 == NULL) {
349 priv->stats.tx_dropped++;
350 return 0;
351 }
352 skb = skb2;
353 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700355 }
356
357 /* Send to right vcc */
358 is_rdesc = 0;
359 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700361 if (priv->is_trdev) {
362 dst = get_tr_dst(skb->data + 2, rdesc);
363 if (dst == NULL) {
364 dst = rdesc;
365 is_rdesc = 1;
366 }
367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700369 entry = NULL;
370 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
Andrew Morton58c14a82007-09-26 22:31:19 -0700371 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700372 vcc, vcc ? vcc->flags : 0, entry);
373 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
374 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700375 pr_debug("%s:lec_start_xmit: queuing packet, ",
Chas Williamsd44f7742006-09-29 17:11:14 -0700376 dev->name);
Joe Perches0795af52007-10-03 17:59:30 -0700377 pr_debug("MAC address %s\n",
378 print_mac(mac, lec_h->h_dest));
Chas Williamsd44f7742006-09-29 17:11:14 -0700379 skb_queue_tail(&entry->tx_wait, skb);
380 } else {
Stephen Hemminger52240062007-08-28 15:22:09 -0700381 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700382 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
383 dev->name);
Joe Perches0795af52007-10-03 17:59:30 -0700384 pr_debug("MAC address %s\n",
385 print_mac(mac, lec_h->h_dest));
Chas Williamsd44f7742006-09-29 17:11:14 -0700386 priv->stats.tx_dropped++;
387 dev_kfree_skb(skb);
388 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700389 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700390 }
391#if DUMP_PACKETS > 0
392 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700394
395 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700396 pr_debug("lec.c: emptying tx queue, ");
Joe Perches0795af52007-10-03 17:59:30 -0700397 pr_debug("MAC address %s\n",
398 print_mac(mac, lec_h->h_dest));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 lec_send(vcc, skb2, priv);
Chas Williamsd44f7742006-09-29 17:11:14 -0700400 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402 lec_send(vcc, skb, priv);
403
404 if (!atm_may_send(vcc, 0)) {
405 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
406
407 vpriv->xoff = 1;
408 netif_stop_queue(dev);
409
410 /*
411 * vcc->pop() might have occurred in between, making
412 * the vcc usuable again. Since xmit is serialized,
413 * this is the only situation we have to re-test.
414 */
415
416 if (atm_may_send(vcc, 0))
417 netif_wake_queue(dev);
418 }
419
Chas Williams6656e3c2006-09-29 17:17:17 -0700420out:
421 if (entry)
422 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 dev->trans_start = jiffies;
Chas Williamsd44f7742006-09-29 17:11:14 -0700424 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
426
427/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700428static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
Chas Williamsd44f7742006-09-29 17:11:14 -0700430 netif_stop_queue(dev);
431 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
433
434/*
435 * Get the current statistics.
436 * This may be called with the card open or closed.
437 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700438static struct net_device_stats *lec_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
Chas Williamsd44f7742006-09-29 17:11:14 -0700440 return &((struct lec_priv *)dev->priv)->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441}
442
Chas Williamsd44f7742006-09-29 17:11:14 -0700443static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
445 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700446 struct net_device *dev = (struct net_device *)vcc->proto_data;
447 struct lec_priv *priv = (struct lec_priv *)dev->priv;
448 struct atmlec_msg *mesg;
449 struct lec_arp_table *entry;
450 int i;
451 char *tmp; /* FIXME */
Joe Perches0795af52007-10-03 17:59:30 -0700452 DECLARE_MAC_BUF(mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
454 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700455 mesg = (struct atmlec_msg *)skb->data;
456 tmp = skb->data;
457 tmp += sizeof(struct atmlec_msg);
Stephen Hemminger52240062007-08-28 15:22:09 -0700458 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700459 switch (mesg->type) {
460 case l_set_mac_addr:
461 for (i = 0; i < 6; i++) {
462 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
463 }
464 break;
465 case l_del_mac_addr:
466 for (i = 0; i < 6; i++) {
467 dev->dev_addr[i] = 0;
468 }
469 break;
470 case l_addr_delete:
471 lec_addr_delete(priv, mesg->content.normal.atm_addr,
472 mesg->content.normal.flag);
473 break;
474 case l_topology_change:
475 priv->topology_change = mesg->content.normal.flag;
476 break;
477 case l_flush_complete:
478 lec_flush_complete(priv, mesg->content.normal.flag);
479 break;
480 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700482 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
483 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
485
Chas Williamsd44f7742006-09-29 17:11:14 -0700486 if (mesg->content.normal.no_source_le_narp)
487 break;
488 /* FALL THROUGH */
489 case l_arp_update:
490 lec_arp_update(priv, mesg->content.normal.mac_addr,
491 mesg->content.normal.atm_addr,
492 mesg->content.normal.flag,
493 mesg->content.normal.targetless_le_arp);
Stephen Hemminger52240062007-08-28 15:22:09 -0700494 pr_debug("lec: in l_arp_update\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700495 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700496 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700497 mesg->sizeoftlvs);
498 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
499 tmp, mesg->sizeoftlvs);
500 }
501 break;
502 case l_config:
503 priv->maximum_unknown_frame_count =
504 mesg->content.config.maximum_unknown_frame_count;
505 priv->max_unknown_frame_time =
506 (mesg->content.config.max_unknown_frame_time * HZ);
507 priv->max_retry_count = mesg->content.config.max_retry_count;
508 priv->aging_time = (mesg->content.config.aging_time * HZ);
509 priv->forward_delay_time =
510 (mesg->content.config.forward_delay_time * HZ);
511 priv->arp_response_time =
512 (mesg->content.config.arp_response_time * HZ);
513 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
514 priv->path_switching_delay =
515 (mesg->content.config.path_switching_delay * HZ);
516 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 priv->lane2_ops = NULL;
518 if (priv->lane_version > 1)
519 priv->lane2_ops = &lane2_ops;
520 if (dev->change_mtu(dev, mesg->content.config.mtu))
521 printk("%s: change_mtu to %d failed\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700522 mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700524 break;
525 case l_flush_tran_id:
526 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
527 mesg->content.normal.flag);
528 break;
529 case l_set_lecid:
530 priv->lecid =
531 (unsigned short)(0xffff & mesg->content.normal.flag);
532 break;
533 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700535 {
536 struct net_bridge_fdb_entry *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Stephen Hemminger52240062007-08-28 15:22:09 -0700538 pr_debug
Joe Perches0795af52007-10-03 17:59:30 -0700539 ("%s: bridge zeppelin asks about %s\n",
540 dev->name,
541 print_mac(mac, mesg->content.proxy.mac_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
Chas Williamsd44f7742006-09-29 17:11:14 -0700543 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
544 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Chas Williamsd44f7742006-09-29 17:11:14 -0700546 f = br_fdb_get_hook(dev->br_port->br,
547 mesg->content.proxy.mac_addr);
548 if (f != NULL && f->dst->dev != dev
549 && f->dst->state == BR_STATE_FORWARDING) {
550 /* hit from bridge table, send LE_ARP_RESPONSE */
551 struct sk_buff *skb2;
552 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Stephen Hemminger52240062007-08-28 15:22:09 -0700554 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700555 ("%s: entry found, responding to zeppelin\n",
556 dev->name);
557 skb2 =
558 alloc_skb(sizeof(struct atmlec_msg),
559 GFP_ATOMIC);
560 if (skb2 == NULL) {
561 br_fdb_put_hook(f);
562 break;
563 }
564 skb2->len = sizeof(struct atmlec_msg);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300565 skb_copy_to_linear_data(skb2, mesg,
566 sizeof(*mesg));
Chas Williamsd44f7742006-09-29 17:11:14 -0700567 atm_force_charge(priv->lecd, skb2->truesize);
568 sk = sk_atm(priv->lecd);
569 skb_queue_tail(&sk->sk_receive_queue, skb2);
570 sk->sk_data_ready(sk, skb2->len);
571 }
572 if (f != NULL)
573 br_fdb_put_hook(f);
574 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700576 break;
577 default:
578 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
579 dev_kfree_skb(skb);
580 return -EINVAL;
581 }
582 dev_kfree_skb(skb);
583 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584}
585
Chas Williamsd44f7742006-09-29 17:11:14 -0700586static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587{
Chas Williamsd44f7742006-09-29 17:11:14 -0700588 struct sk_buff *skb;
589 struct net_device *dev = (struct net_device *)vcc->proto_data;
590 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Chas Williamsd44f7742006-09-29 17:11:14 -0700592 priv->lecd = NULL;
593 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Chas Williamsd44f7742006-09-29 17:11:14 -0700595 netif_stop_queue(dev);
596 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Chas Williamsd44f7742006-09-29 17:11:14 -0700598 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700600 dev->name);
601 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
602 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700604 }
605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700607 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608}
609
610static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700611 .close = lec_atm_close,
612 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613};
614
615static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700616 .ops = &lecdev_ops,
617 .type = "lec",
618 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700619 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620};
621
622/*
623 * LANE2: new argument struct sk_buff *data contains
624 * the LE_ARP based TLVs introduced in the LANE2 spec
625 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700626static int
627send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
628 unsigned char *mac_addr, unsigned char *atm_addr,
629 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630{
631 struct sock *sk;
632 struct sk_buff *skb;
633 struct atmlec_msg *mesg;
634
635 if (!priv || !priv->lecd) {
636 return -1;
637 }
638 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
639 if (!skb)
640 return -1;
641 skb->len = sizeof(struct atmlec_msg);
642 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700643 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700645 if (data != NULL)
646 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 if (mac_addr)
648 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700649 else
650 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 if (atm_addr)
652 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
653
Chas Williamsd44f7742006-09-29 17:11:14 -0700654 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 sk = sk_atm(priv->lecd);
656 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700657 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Chas Williamsd44f7742006-09-29 17:11:14 -0700659 if (data != NULL) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700660 pr_debug("lec: about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700661 atm_force_charge(priv->lecd, data->truesize);
662 skb_queue_tail(&sk->sk_receive_queue, data);
663 sk->sk_data_ready(sk, skb->len);
664 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Chas Williamsd44f7742006-09-29 17:11:14 -0700666 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667}
668
669/* shamelessly stolen from drivers/net/net_init.c */
670static int lec_change_mtu(struct net_device *dev, int new_mtu)
671{
Chas Williamsd44f7742006-09-29 17:11:14 -0700672 if ((new_mtu < 68) || (new_mtu > 18190))
673 return -EINVAL;
674 dev->mtu = new_mtu;
675 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676}
677
678static void lec_set_multicast_list(struct net_device *dev)
679{
Chas Williamsd44f7742006-09-29 17:11:14 -0700680 /*
681 * by default, all multicast frames arrive over the bus.
682 * eventually support selective multicast service
683 */
684 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685}
686
Chas Williamsd44f7742006-09-29 17:11:14 -0700687static void lec_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688{
Chas Williamsd44f7742006-09-29 17:11:14 -0700689 dev->change_mtu = lec_change_mtu;
690 dev->open = lec_open;
691 dev->stop = lec_close;
692 dev->hard_start_xmit = lec_start_xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 dev->tx_timeout = lec_tx_timeout;
694
Chas Williamsd44f7742006-09-29 17:11:14 -0700695 dev->get_stats = lec_get_stats;
696 dev->set_multicast_list = lec_set_multicast_list;
697 dev->do_ioctl = NULL;
698 printk("%s: Initialized!\n", dev->name);
699 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700}
701
702static unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700703 0xff,
704 0x00,
705 0x01,
706 0x01
707};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Scott Talbert4a7097f2005-09-29 17:30:54 -0700709#define LEC_DATA_DIRECT_8023 2
710#define LEC_DATA_DIRECT_8025 3
711
712static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700713{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700714 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
715 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700716}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700717
Chas Williamsd44f7742006-09-29 17:11:14 -0700718static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700720 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700721 struct net_device *dev = (struct net_device *)vcc->proto_data;
722 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724#if DUMP_PACKETS >0
Chas Williamsd44f7742006-09-29 17:11:14 -0700725 int i = 0;
726 char buf[300];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Chas Williamsd44f7742006-09-29 17:11:14 -0700728 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
729 vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700731 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700732 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700733 lec_vcc_close(priv, vcc);
734 return;
735 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700737 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
738 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700740 for (i = 0; i < skb->len && i < 99; i++) {
741 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
742 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700744 for (i = 0; i < skb->len && i < 30; i++) {
745 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
746 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700748 if (i == skb->len)
749 printk("%s\n", buf);
750 else
751 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700753 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 struct sock *sk = sk_atm(vcc);
755
Stephen Hemminger52240062007-08-28 15:22:09 -0700756 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700757 skb_queue_tail(&sk->sk_receive_queue, skb);
758 sk->sk_data_ready(sk, skb->len);
759 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700760 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700761 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Chas Williamsd44f7742006-09-29 17:11:14 -0700763 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800764 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700765 !priv->lecd || !(dev->flags & IFF_UP)) {
766 /*
767 * Probably looping back, or if lecd is missing,
768 * lecd has gone down
769 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700770 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700771 dev_kfree_skb(skb);
772 return;
773 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700775 if (priv->is_trdev)
776 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
777 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700779 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700780
Chas Williamsd44f7742006-09-29 17:11:14 -0700781 /*
782 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700783 * the LE_ARP cache entry, delete the LE_ARP cache entry.
784 */
785 spin_lock_irqsave(&priv->lec_arp_lock, flags);
786 if (lec_is_data_direct(vcc)) {
787#ifdef CONFIG_TR
788 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700789 src =
790 ((struct lecdatahdr_8025 *)skb->data)->
791 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700792 else
793#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700794 src =
795 ((struct lecdatahdr_8023 *)skb->data)->
796 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700797 entry = lec_arp_find(priv, src);
798 if (entry && entry->vcc != vcc) {
799 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700800 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700801 }
802 }
803 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
Chas Williamsd44f7742006-09-29 17:11:14 -0700805 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
806 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700808 dev_kfree_skb(skb);
809 return;
810 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700811 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700812 lec_arp_check_empties(priv, vcc, skb);
813 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700814 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700816 if (priv->is_trdev)
817 skb->protocol = tr_type_trans(skb, dev);
818 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700820 skb->protocol = eth_type_trans(skb, dev);
821 priv->stats.rx_packets++;
822 priv->stats.rx_bytes += skb->len;
823 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
824 netif_rx(skb);
825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826}
827
Chas Williamsd44f7742006-09-29 17:11:14 -0700828static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
830 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
831 struct net_device *dev = skb->dev;
832
833 if (vpriv == NULL) {
834 printk("lec_pop(): vpriv = NULL!?!?!?\n");
835 return;
836 }
837
838 vpriv->old_pop(vcc, skb);
839
840 if (vpriv->xoff && atm_may_send(vcc, 0)) {
841 vpriv->xoff = 0;
842 if (netif_running(dev) && netif_queue_stopped(dev))
843 netif_wake_queue(dev);
844 }
845}
846
Chas Williamsd44f7742006-09-29 17:11:14 -0700847static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848{
849 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700850 int bytes_left;
851 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
Chas Williamsd44f7742006-09-29 17:11:14 -0700853 /* Lecd must be up in this case */
854 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
855 if (bytes_left != 0) {
856 printk
857 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
858 bytes_left);
859 }
860 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
861 !dev_lec[ioc_data.dev_num])
862 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
864 return -ENOMEM;
865 vpriv->xoff = 0;
866 vpriv->old_pop = vcc->pop;
867 vcc->user_back = vpriv;
868 vcc->pop = lec_pop;
Chas Williamsd44f7742006-09-29 17:11:14 -0700869 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
870 &ioc_data, vcc, vcc->push);
871 vcc->proto_data = dev_lec[ioc_data.dev_num];
872 vcc->push = lec_push;
873 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874}
875
Chas Williamsd44f7742006-09-29 17:11:14 -0700876static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
Chas Williamsd44f7742006-09-29 17:11:14 -0700878 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
879 return -EINVAL;
880 vcc->proto_data = dev_lec[arg];
881 return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882}
883
884/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700885static int lecd_attach(struct atm_vcc *vcc, int arg)
886{
887 int i;
888 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Chas Williamsd44f7742006-09-29 17:11:14 -0700890 if (arg < 0)
891 i = 0;
892 else
893 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700895 if (arg >= MAX_LEC_ITF)
896 return -EINVAL;
897#else /* Reserve the top NUM_TR_DEVS for TR */
898 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
899 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700901 if (!dev_lec[i]) {
902 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Chas Williamsd44f7742006-09-29 17:11:14 -0700904 is_trdev = 0;
905 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
906 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Chas Williamsd44f7742006-09-29 17:11:14 -0700908 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700910 if (is_trdev)
911 dev_lec[i] = alloc_trdev(size);
912 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700914 dev_lec[i] = alloc_etherdev(size);
915 if (!dev_lec[i])
916 return -ENOMEM;
917 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
918 if (register_netdev(dev_lec[i])) {
919 free_netdev(dev_lec[i]);
920 return -EINVAL;
921 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
Chas Williamsd44f7742006-09-29 17:11:14 -0700923 priv = dev_lec[i]->priv;
924 priv->is_trdev = is_trdev;
925 lec_init(dev_lec[i]);
926 } else {
927 priv = dev_lec[i]->priv;
928 if (priv->lecd)
929 return -EADDRINUSE;
930 }
931 lec_arp_init(priv);
932 priv->itfnum = i; /* LANE2 addition */
933 priv->lecd = vcc;
934 vcc->dev = &lecatm_dev;
935 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
Chas Williamsd44f7742006-09-29 17:11:14 -0700937 vcc->proto_data = dev_lec[i];
938 set_bit(ATM_VF_META, &vcc->flags);
939 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
Chas Williamsd44f7742006-09-29 17:11:14 -0700941 /* Set default values to these variables */
942 priv->maximum_unknown_frame_count = 1;
943 priv->max_unknown_frame_time = (1 * HZ);
944 priv->vcc_timeout_period = (1200 * HZ);
945 priv->max_retry_count = 1;
946 priv->aging_time = (300 * HZ);
947 priv->forward_delay_time = (15 * HZ);
948 priv->topology_change = 0;
949 priv->arp_response_time = (1 * HZ);
950 priv->flush_timeout = (4 * HZ);
951 priv->path_switching_delay = (6 * HZ);
952
953 if (dev_lec[i]->flags & IFF_UP) {
954 netif_start_queue(dev_lec[i]);
955 }
956 __module_get(THIS_MODULE);
957 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958}
959
960#ifdef CONFIG_PROC_FS
Chas Williamsd44f7742006-09-29 17:11:14 -0700961static char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962{
963 static char *lec_arp_status_string[] = {
964 "ESI_UNKNOWN ",
965 "ESI_ARP_PENDING ",
966 "ESI_VC_PENDING ",
967 "<Undefined> ",
968 "ESI_FLUSH_PENDING ",
969 "ESI_FORWARD_DIRECT"
970 };
971
972 if (status > ESI_FORWARD_DIRECT)
973 status = 3; /* ESI_UNDEFINED */
974 return lec_arp_status_string[status];
975}
976
977static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
978{
979 int i;
980
981 for (i = 0; i < ETH_ALEN; i++)
982 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
983 seq_printf(seq, " ");
984 for (i = 0; i < ATM_ESA_LEN; i++)
985 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
986 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
987 entry->flags & 0xffff);
988 if (entry->vcc)
989 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
990 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700991 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 if (entry->recv_vcc) {
993 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
994 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -0700995 }
996 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997}
998
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999struct lec_state {
1000 unsigned long flags;
1001 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -07001002 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 struct net_device *dev;
1004 int itf;
1005 int arp_table;
1006 int misc_table;
1007};
1008
Chas Williamsd0732f62006-09-29 17:14:27 -07001009static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 loff_t *l)
1011{
Chas Williamsd0732f62006-09-29 17:14:27 -07001012 struct hlist_node *e = state->node;
1013 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
1015 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -07001016 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 if (e == (void *)1) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001018 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 --*l;
1020 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001021
1022 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 if (--*l < 0)
1024 break;
1025 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001026 state->node = e;
1027
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 return (*l < 0) ? state : NULL;
1029}
1030
1031static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -07001032 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033{
1034 void *v = NULL;
1035 int p;
1036
1037 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001038 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 if (v)
1040 break;
1041 }
1042 state->arp_table = p;
1043 return v;
1044}
1045
1046static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1047 struct lec_priv *priv)
1048{
Chas Williamsd0732f62006-09-29 17:14:27 -07001049 struct hlist_head *lec_misc_tables[] = {
1050 &priv->lec_arp_empty_ones,
1051 &priv->lec_no_forward,
1052 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 };
1054 void *v = NULL;
1055 int q;
1056
1057 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1058 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1059 if (v)
1060 break;
1061 }
1062 state->misc_table = q;
1063 return v;
1064}
1065
1066static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1067 struct lec_priv *priv)
1068{
1069 if (!state->locked) {
1070 state->locked = priv;
1071 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1072 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001073 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1075 state->locked = NULL;
1076 /* Partial state reset for the next time we get called */
1077 state->arp_table = state->misc_table = 0;
1078 }
1079 return state->locked;
1080}
1081
1082static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1083{
1084 struct net_device *dev;
1085 void *v;
1086
1087 dev = state->dev ? state->dev : dev_lec[state->itf];
1088 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
1089 if (!v && dev) {
1090 dev_put(dev);
1091 /* Partial state reset for the next time we get called */
1092 dev = NULL;
1093 }
1094 state->dev = dev;
1095 return v;
1096}
1097
1098static void *lec_get_idx(struct lec_state *state, loff_t l)
1099{
1100 void *v = NULL;
1101
1102 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1103 v = lec_itf_walk(state, &l);
1104 if (v)
1105 break;
1106 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001107 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108}
1109
1110static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1111{
1112 struct lec_state *state = seq->private;
1113
1114 state->itf = 0;
1115 state->dev = NULL;
1116 state->locked = NULL;
1117 state->arp_table = 0;
1118 state->misc_table = 0;
Chas Williamsd0732f62006-09-29 17:14:27 -07001119 state->node = (void *)1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
Chas Williamsd44f7742006-09-29 17:11:14 -07001121 return *pos ? lec_get_idx(state, *pos) : (void *)1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122}
1123
1124static void lec_seq_stop(struct seq_file *seq, void *v)
1125{
1126 struct lec_state *state = seq->private;
1127
1128 if (state->dev) {
1129 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1130 state->flags);
1131 dev_put(state->dev);
1132 }
1133}
1134
1135static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1136{
1137 struct lec_state *state = seq->private;
1138
1139 v = lec_get_idx(state, 1);
1140 *pos += !!PTR_ERR(v);
1141 return v;
1142}
1143
1144static int lec_seq_show(struct seq_file *seq, void *v)
1145{
Chas Williamsd44f7742006-09-29 17:11:14 -07001146 static char lec_banner[] = "Itf MAC ATM destination"
1147 " Status Flags "
1148 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
1150 if (v == (void *)1)
1151 seq_puts(seq, lec_banner);
1152 else {
1153 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001154 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001155 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001158 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 }
1160 return 0;
1161}
1162
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001163static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001164 .start = lec_seq_start,
1165 .next = lec_seq_next,
1166 .stop = lec_seq_stop,
1167 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168};
1169
1170static int lec_seq_open(struct inode *inode, struct file *file)
1171{
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001172 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173}
1174
Arjan van de Ven9a321442007-02-12 00:55:35 -08001175static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001176 .owner = THIS_MODULE,
1177 .open = lec_seq_open,
1178 .read = seq_read,
1179 .llseek = seq_lseek,
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001180 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181};
1182#endif
1183
1184static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1185{
1186 struct atm_vcc *vcc = ATM_SD(sock);
1187 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001188
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001190 case ATMLEC_CTRL:
1191 case ATMLEC_MCAST:
1192 case ATMLEC_DATA:
1193 if (!capable(CAP_NET_ADMIN))
1194 return -EPERM;
1195 break;
1196 default:
1197 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 }
1199
1200 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001201 case ATMLEC_CTRL:
1202 err = lecd_attach(vcc, (int)arg);
1203 if (err >= 0)
1204 sock->state = SS_CONNECTED;
1205 break;
1206 case ATMLEC_MCAST:
1207 err = lec_mcast_attach(vcc, (int)arg);
1208 break;
1209 case ATMLEC_DATA:
1210 err = lec_vcc_attach(vcc, (void __user *)arg);
1211 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 }
1213
1214 return err;
1215}
1216
1217static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001218 .owner = THIS_MODULE,
1219 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220};
1221
1222static int __init lane_module_init(void)
1223{
1224#ifdef CONFIG_PROC_FS
1225 struct proc_dir_entry *p;
1226
Wang Chen16e297b2008-02-28 13:55:45 -08001227 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228#endif
1229
1230 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001231 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1232 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233}
1234
1235static void __exit lane_module_cleanup(void)
1236{
Chas Williamsd44f7742006-09-29 17:11:14 -07001237 int i;
1238 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
1240 remove_proc_entry("lec", atm_proc_root);
1241
1242 deregister_atm_ioctl(&lane_ioctl_ops);
1243
Chas Williamsd44f7742006-09-29 17:11:14 -07001244 for (i = 0; i < MAX_LEC_ITF; i++) {
1245 if (dev_lec[i] != NULL) {
1246 priv = (struct lec_priv *)dev_lec[i]->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001248 free_netdev(dev_lec[i]);
1249 dev_lec[i] = NULL;
1250 }
1251 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
Chas Williamsd44f7742006-09-29 17:11:14 -07001253 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254}
1255
1256module_init(lane_module_init);
1257module_exit(lane_module_cleanup);
1258
1259/*
1260 * LANE2: 3.1.3, LE_RESOLVE.request
1261 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1262 * If sizeoftlvs == NULL the default TLVs associated with with this
1263 * lec will be used.
1264 * If dst_mac == NULL, targetless LE_ARP will be sent
1265 */
1266static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001267 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268{
1269 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -07001270 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1271 struct lec_arp_table *table;
1272 struct sk_buff *skb;
1273 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
Chas Williamsd44f7742006-09-29 17:11:14 -07001275 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001277 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001279 if (table == NULL)
1280 return -1;
1281
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001282 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001283 if (*tlvs == NULL)
1284 return -1;
1285
Chas Williamsd44f7742006-09-29 17:11:14 -07001286 *sizeoftlvs = table->sizeoftlvs;
1287
1288 return 0;
1289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
1291 if (sizeoftlvs == NULL)
1292 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001293
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 else {
1295 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1296 if (skb == NULL)
1297 return -1;
1298 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001299 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1301 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001302 return retval;
1303}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
1305/*
1306 * LANE2: 3.1.4, LE_ASSOCIATE.request
1307 * Associate the *tlvs with the *lan_dst address.
1308 * Will overwrite any previous association
1309 * Returns 1 for success, 0 for failure (out of memory)
1310 *
1311 */
Chas Williamsd44f7742006-09-29 17:11:14 -07001312static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
1313 u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314{
Chas Williamsd44f7742006-09-29 17:11:14 -07001315 int retval;
1316 struct sk_buff *skb;
1317 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Chas Williamsd44f7742006-09-29 17:11:14 -07001319 if (compare_ether_addr(lan_dst, dev->dev_addr))
1320 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
Chas Williamsd44f7742006-09-29 17:11:14 -07001322 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001324 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001325 if (priv->tlvs == NULL)
1326 return (0);
1327 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
Chas Williamsd44f7742006-09-29 17:11:14 -07001329 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1330 if (skb == NULL)
1331 return 0;
1332 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001333 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001334 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1335 if (retval != 0)
1336 printk("lec.c: lane2_associate_req() failed\n");
1337 /*
1338 * If the previous association has changed we must
1339 * somehow notify other LANE entities about the change
1340 */
1341 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342}
1343
1344/*
1345 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1346 *
1347 */
Chas Williamsd44f7742006-09-29 17:11:14 -07001348static void lane2_associate_ind(struct net_device *dev, u8 *mac_addr,
1349 u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350{
1351#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001352 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353#endif
1354 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Chas Williamsd44f7742006-09-29 17:11:14 -07001355#if 0 /*
1356 * Why have the TLVs in LE_ARP entries
1357 * since we do not use them? When you
1358 * uncomment this code, make sure the
1359 * TLVs get freed when entry is killed
1360 */
1361 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Chas Williamsd44f7742006-09-29 17:11:14 -07001363 if (entry == NULL)
1364 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Chas Williamsd44f7742006-09-29 17:11:14 -07001366 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001368 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001369 if (entry->tlvs == NULL)
1370 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001371 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372#endif
1373#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001374 printk("lec.c: lane2_associate_ind()\n");
1375 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1376 while (i < sizeoftlvs)
1377 printk("%02x ", tlvs[i++]);
1378
1379 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380#endif
1381
Chas Williamsd44f7742006-09-29 17:11:14 -07001382 /* tell MPOA about the TLVs we saw */
1383 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1384 priv->lane2_ops->associate_indicator(dev, mac_addr,
1385 tlvs, sizeoftlvs);
1386 }
1387 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388}
1389
1390/*
1391 * Here starts what used to lec_arpc.c
1392 *
1393 * lec_arpc.c was added here when making
1394 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 */
1396
1397#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398#include <linux/timer.h>
1399#include <asm/param.h>
1400#include <asm/atomic.h>
1401#include <linux/inetdevice.h>
1402#include <net/route.h>
1403
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404#if 0
Stephen Hemminger52240062007-08-28 15:22:09 -07001405#define pr_debug(format,args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406/*
Stephen Hemminger52240062007-08-28 15:22:09 -07001407#define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408*/
1409#endif
1410#define DEBUG_ARP_TABLE 0
1411
1412#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1413
David Howellsc4028952006-11-22 14:57:56 +00001414static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415static void lec_arp_expire_arp(unsigned long data);
1416
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001417/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 * Arp table funcs
1419 */
1420
1421#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1422
1423/*
1424 * Initialization of arp-cache
1425 */
Chas Williams1fa99612006-09-29 17:11:47 -07001426static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427{
Chas Williams1fa99612006-09-29 17:11:47 -07001428 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Chas Williams1fa99612006-09-29 17:11:47 -07001430 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001431 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001432 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001433 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1434 INIT_HLIST_HEAD(&priv->lec_no_forward);
1435 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001437 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001438 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439}
1440
Chas Williams1fa99612006-09-29 17:11:47 -07001441static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442{
Chas Williams1fa99612006-09-29 17:11:47 -07001443 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 struct atm_vcc *vcc = entry->vcc;
1445 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001446 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
Chas Williams1fa99612006-09-29 17:11:47 -07001448 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 if (vpriv->xoff)
1450 netif_wake_queue(dev);
1451 kfree(vpriv);
1452 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001453 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001455 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001456 }
1457 if (entry->recv_vcc) {
1458 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001460 entry->recv_vcc = NULL;
1461 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462}
1463
1464/*
1465 * Insert entry to lec_arp_table
1466 * LANE2: Add to the end of the list to satisfy 8.1.13
1467 */
Chas Williams1fa99612006-09-29 17:11:47 -07001468static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001469lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470{
Chas Williamsd0732f62006-09-29 17:14:27 -07001471 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Chas Williamsd0732f62006-09-29 17:14:27 -07001473 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1474 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001475
Stephen Hemminger52240062007-08-28 15:22:09 -07001476 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 -07001477 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1478 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1479 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480}
1481
1482/*
1483 * Remove entry from lec_arp_table
1484 */
Chas Williams1fa99612006-09-29 17:11:47 -07001485static int
1486lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487{
Chas Williamsd0732f62006-09-29 17:14:27 -07001488 struct hlist_node *node;
1489 struct lec_arp_table *entry;
1490 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Chas Williams1fa99612006-09-29 17:11:47 -07001492 if (!to_remove) {
1493 return -1;
1494 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001495
1496 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001497 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
Chas Williamsd0732f62006-09-29 17:14:27 -07001499 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001500 if (to_remove->status >= ESI_FLUSH_PENDING) {
1501 /*
1502 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1503 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001504 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1505 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1506 if (memcmp(to_remove->atm_addr,
1507 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001508 remove_vcc = 0;
1509 break;
1510 }
1511 }
1512 }
1513 if (remove_vcc)
1514 lec_arp_clear_vccs(to_remove);
1515 }
1516 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1517
Stephen Hemminger52240062007-08-28 15:22:09 -07001518 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 -07001519 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1520 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1521 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1522 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523}
1524
1525#if DEBUG_ARP_TABLE
Chas Williams1fa99612006-09-29 17:11:47 -07001526static char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527{
Chas Williams1fa99612006-09-29 17:11:47 -07001528 switch (st) {
1529 case ESI_UNKNOWN:
1530 return "ESI_UNKNOWN";
1531 case ESI_ARP_PENDING:
1532 return "ESI_ARP_PENDING";
1533 case ESI_VC_PENDING:
1534 return "ESI_VC_PENDING";
1535 case ESI_FLUSH_PENDING:
1536 return "ESI_FLUSH_PENDING";
1537 case ESI_FORWARD_DIRECT:
1538 return "ESI_FORWARD_DIRECT";
1539 default:
1540 return "<UNKNOWN>";
1541 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
Chas Williams1fa99612006-09-29 17:11:47 -07001544static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545{
Chas Williamsd0732f62006-09-29 17:14:27 -07001546 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001547 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001548 char buf[256];
1549 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Chas Williams1fa99612006-09-29 17:11:47 -07001551 printk("Dump %p:\n", priv);
1552 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001553 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1554 offset = 0;
1555 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001556 offset += sprintf(buf + offset, "Mac:");
1557 for (j = 0; j < ETH_ALEN; j++) {
1558 offset += sprintf(buf + offset,
1559 "%2.2x ",
1560 rulla->mac_addr[j] & 0xff);
1561 }
1562 offset += sprintf(buf + offset, "Atm:");
1563 for (j = 0; j < ATM_ESA_LEN; j++) {
1564 offset += sprintf(buf + offset,
1565 "%2.2x ",
1566 rulla->atm_addr[j] & 0xff);
1567 }
1568 offset += sprintf(buf + offset,
1569 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1570 rulla->vcc ? rulla->vcc->vpi : 0,
1571 rulla->vcc ? rulla->vcc->vci : 0,
1572 rulla->recv_vcc ? rulla->recv_vcc->
1573 vpi : 0,
1574 rulla->recv_vcc ? rulla->recv_vcc->
1575 vci : 0, rulla->last_used,
1576 rulla->timestamp, rulla->no_tries);
1577 offset +=
1578 sprintf(buf + offset,
1579 "Flags:%x, Packets_flooded:%x, Status: %s ",
1580 rulla->flags, rulla->packets_flooded,
1581 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001582 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001583 }
Chas Williams1fa99612006-09-29 17:11:47 -07001584 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001585
1586 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001587 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001588 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001589 offset = 0;
1590 offset += sprintf(buf + offset, "Mac:");
1591 for (j = 0; j < ETH_ALEN; j++) {
1592 offset += sprintf(buf + offset, "%2.2x ",
1593 rulla->mac_addr[j] & 0xff);
1594 }
1595 offset += sprintf(buf + offset, "Atm:");
1596 for (j = 0; j < ATM_ESA_LEN; j++) {
1597 offset += sprintf(buf + offset, "%2.2x ",
1598 rulla->atm_addr[j] & 0xff);
1599 }
1600 offset += sprintf(buf + offset,
1601 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1602 rulla->vcc ? rulla->vcc->vpi : 0,
1603 rulla->vcc ? rulla->vcc->vci : 0,
1604 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1605 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1606 rulla->last_used,
1607 rulla->timestamp, rulla->no_tries);
1608 offset += sprintf(buf + offset,
1609 "Flags:%x, Packets_flooded:%x, Status: %s ",
1610 rulla->flags, rulla->packets_flooded,
1611 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001612 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001613 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001614
1615 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001616 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001617 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001618 offset = 0;
1619 offset += sprintf(buf + offset, "Mac:");
1620 for (j = 0; j < ETH_ALEN; j++) {
1621 offset += sprintf(buf + offset, "%2.2x ",
1622 rulla->mac_addr[j] & 0xff);
1623 }
1624 offset += sprintf(buf + offset, "Atm:");
1625 for (j = 0; j < ATM_ESA_LEN; j++) {
1626 offset += sprintf(buf + offset, "%2.2x ",
1627 rulla->atm_addr[j] & 0xff);
1628 }
1629 offset += sprintf(buf + offset,
1630 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1631 rulla->vcc ? rulla->vcc->vpi : 0,
1632 rulla->vcc ? rulla->vcc->vci : 0,
1633 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1634 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1635 rulla->last_used,
1636 rulla->timestamp, rulla->no_tries);
1637 offset += sprintf(buf + offset,
1638 "Flags:%x, Packets_flooded:%x, Status: %s ",
1639 rulla->flags, rulla->packets_flooded,
1640 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001641 printk("%s", buf);
1642 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
Chas Williamsd0732f62006-09-29 17:14:27 -07001644 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001645 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001646 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001647 offset = 0;
1648 offset += sprintf(buf + offset, "Mac:");
1649 for (j = 0; j < ETH_ALEN; j++) {
1650 offset += sprintf(buf + offset, "%2.2x ",
1651 rulla->mac_addr[j] & 0xff);
1652 }
1653 offset += sprintf(buf + offset, "Atm:");
1654 for (j = 0; j < ATM_ESA_LEN; j++) {
1655 offset += sprintf(buf + offset, "%2.2x ",
1656 rulla->atm_addr[j] & 0xff);
1657 }
1658 offset += sprintf(buf + offset,
1659 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1660 rulla->vcc ? rulla->vcc->vpi : 0,
1661 rulla->vcc ? rulla->vcc->vci : 0,
1662 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1663 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1664 rulla->last_used,
1665 rulla->timestamp, rulla->no_tries);
1666 offset += sprintf(buf + offset,
1667 "Flags:%x, Packets_flooded:%x, Status: %s ",
1668 rulla->flags, rulla->packets_flooded,
1669 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001670 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673}
Chas Williamsd0732f62006-09-29 17:14:27 -07001674#else
1675#define dump_arp_table(priv) do { } while (0)
1676#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
1678/*
1679 * Destruction of arp-cache
1680 */
Chas Williams1fa99612006-09-29 17:11:47 -07001681static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682{
1683 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001684 struct hlist_node *node, *next;
1685 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001686 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
Chas Williams987e46b2006-09-29 17:15:59 -07001688 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001689
1690 /*
1691 * Remove all entries
1692 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
1694 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001695 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001696 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001697 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001698 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001699 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001700 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001701 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001702
1703 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001704 del_timer_sync(&entry->timer);
1705 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001706 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001707 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001708 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001709 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1710
1711 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001712 del_timer_sync(&entry->timer);
1713 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001714 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001715 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001716 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001717 INIT_HLIST_HEAD(&priv->lec_no_forward);
1718
1719 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001720 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1721 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001722 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001723 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001724 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001725 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001726 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1728}
1729
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001730/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 * Find entry by mac_address
1732 */
Chas Williams1fa99612006-09-29 17:11:47 -07001733static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
1734 unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735{
Chas Williamsd0732f62006-09-29 17:14:27 -07001736 struct hlist_node *node;
1737 struct hlist_head *head;
1738 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
Stephen Hemminger52240062007-08-28 15:22:09 -07001740 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 -07001741 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1742 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
Chas Williams1fa99612006-09-29 17:11:47 -07001743
Chas Williamsd0732f62006-09-29 17:14:27 -07001744 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1745 hlist_for_each_entry(entry, node, head, next) {
1746 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1747 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001748 }
Chas Williams1fa99612006-09-29 17:11:47 -07001749 }
1750 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751}
1752
Chas Williams1fa99612006-09-29 17:11:47 -07001753static struct lec_arp_table *make_entry(struct lec_priv *priv,
1754 unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755{
Chas Williams1fa99612006-09-29 17:11:47 -07001756 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
Chas Williams1fa99612006-09-29 17:11:47 -07001758 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1759 if (!to_return) {
1760 printk("LEC: Arp entry kmalloc failed\n");
1761 return NULL;
1762 }
1763 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001764 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001765 setup_timer(&to_return->timer, lec_arp_expire_arp,
1766 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001767 to_return->last_used = jiffies;
1768 to_return->priv = priv;
1769 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001770 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001771 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772}
1773
Chas Williams1fa99612006-09-29 17:11:47 -07001774/* Arp sent timer expired */
1775static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776{
Chas Williams1fa99612006-09-29 17:11:47 -07001777 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
Chas Williams1fa99612006-09-29 17:11:47 -07001779 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780
Stephen Hemminger52240062007-08-28 15:22:09 -07001781 pr_debug("lec_arp_expire_arp\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001782 if (entry->status == ESI_ARP_PENDING) {
1783 if (entry->no_tries <= entry->priv->max_retry_count) {
1784 if (entry->is_rdesc)
1785 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1786 entry->mac_addr, NULL, NULL);
1787 else
1788 send_to_lecd(entry->priv, l_arp_xmt,
1789 entry->mac_addr, NULL, NULL);
1790 entry->no_tries++;
1791 }
1792 mod_timer(&entry->timer, jiffies + (1 * HZ));
1793 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794}
1795
Chas Williams1fa99612006-09-29 17:11:47 -07001796/* Unknown/unused vcc expire, remove associated entry */
1797static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798{
1799 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001800 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1801 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802
Chas Williams1fa99612006-09-29 17:11:47 -07001803 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
Stephen Hemminger52240062007-08-28 15:22:09 -07001805 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001806 to_remove, priv,
1807 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1808 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809
1810 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001811 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1813
Chas Williams1fa99612006-09-29 17:11:47 -07001814 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001815 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816}
1817
1818/*
1819 * Expire entries.
1820 * 1. Re-set timer
1821 * 2. For each entry, delete entries that have aged past the age limit.
1822 * 3. For each entry, depending on the status of the entry, perform
1823 * the following maintenance.
1824 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1825 * tick_count is above the max_unknown_frame_time, clear
1826 * the tick_count to zero and clear the packets_flooded counter
1827 * to zero. This supports the packet rate limit per address
1828 * while flooding unknowns.
1829 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1830 * than or equal to the path_switching_delay, change the status
1831 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1832 * regardless of the progress of the flush protocol.
1833 */
David Howellsc4028952006-11-22 14:57:56 +00001834static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835{
1836 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001837 struct lec_priv *priv =
1838 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001839 struct hlist_node *node, *next;
1840 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001841 unsigned long now;
1842 unsigned long time_to_check;
1843 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
Stephen Hemminger52240062007-08-28 15:22:09 -07001845 pr_debug("lec_arp_check_expire %p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001847restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001849 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001850 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001851 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 priv->topology_change)
1853 time_to_check = priv->forward_delay_time;
1854 else
1855 time_to_check = priv->aging_time;
1856
Stephen Hemminger52240062007-08-28 15:22:09 -07001857 pr_debug("About to expire: %lx - %lx > %lx\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001858 now, entry->last_used, time_to_check);
1859 if (time_after(now, entry->last_used + time_to_check)
1860 && !(entry->flags & LEC_PERMANENT_FLAG)
1861 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 /* Remove entry */
Stephen Hemminger52240062007-08-28 15:22:09 -07001863 pr_debug("LEC:Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001865 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 } else {
1867 /* Something else */
1868 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001869 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001871 entry->timestamp +
1872 priv->
1873 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 entry->timestamp = jiffies;
1875 entry->packets_flooded = 0;
1876 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001877 send_to_lecd(priv, l_svc_setup,
1878 entry->mac_addr,
1879 entry->atm_addr,
1880 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 }
Chas Williams1fa99612006-09-29 17:11:47 -07001882 if (entry->status == ESI_FLUSH_PENDING
1883 &&
1884 time_after_eq(now, entry->timestamp +
1885 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001887 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Chas Williams6656e3c2006-09-29 17:17:17 -07001889 lec_arp_hold(entry);
1890 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1891 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1892 lec_send(vcc, skb, entry->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001894 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001895 lec_arp_put(entry);
1896 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 }
1899 }
1900 }
1901 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1902
Chas Williams987e46b2006-09-29 17:15:59 -07001903 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904}
Chas Williams1fa99612006-09-29 17:11:47 -07001905
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906/*
1907 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001908 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 */
Chas Williams1fa99612006-09-29 17:11:47 -07001910static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1911 unsigned char *mac_to_find, int is_rdesc,
1912 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913{
1914 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001915 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 struct atm_vcc *found;
1917
Chas Williams1fa99612006-09-29 17:11:47 -07001918 if (mac_to_find[0] & 0x01) {
1919 switch (priv->lane_version) {
1920 case 1:
1921 return priv->mcast_vcc;
1922 break;
1923 case 2: /* LANE2 wants arp for multicast addresses */
1924 if (!compare_ether_addr(mac_to_find, bus_mac))
1925 return priv->mcast_vcc;
1926 break;
1927 default:
1928 break;
1929 }
1930 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931
1932 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001933 entry = lec_arp_find(priv, mac_to_find);
1934
1935 if (entry) {
1936 if (entry->status == ESI_FORWARD_DIRECT) {
1937 /* Connection Ok */
1938 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001939 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001940 *ret_entry = entry;
1941 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001943 }
1944 /*
1945 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001946 * so another LE_ARP request can be made for this frame.
1947 */
1948 if (entry->status == ESI_ARP_PENDING) {
1949 entry->no_tries = 0;
1950 }
Chas Williams1fa99612006-09-29 17:11:47 -07001951 /*
1952 * Data direct VC not yet set up, check to see if the unknown
1953 * frame count is greater than the limit. If the limit has
1954 * not been reached, allow the caller to send packet to
1955 * BUS.
1956 */
1957 if (entry->status != ESI_FLUSH_PENDING &&
1958 entry->packets_flooded <
1959 priv->maximum_unknown_frame_count) {
1960 entry->packets_flooded++;
Stephen Hemminger52240062007-08-28 15:22:09 -07001961 pr_debug("LEC_ARP: Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001962 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001964 }
1965 /*
1966 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 * or BUS flood limit was reached for an entry which is
1968 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1969 */
Chas Williams6656e3c2006-09-29 17:17:17 -07001970 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001971 *ret_entry = entry;
Stephen Hemminger52240062007-08-28 15:22:09 -07001972 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
Chas Williams1fa99612006-09-29 17:11:47 -07001973 entry->vcc);
1974 found = NULL;
1975 } else {
1976 /* No matching entry was found */
1977 entry = make_entry(priv, mac_to_find);
Stephen Hemminger52240062007-08-28 15:22:09 -07001978 pr_debug("LEC_ARP: Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001979 if (!entry) {
1980 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001982 }
1983 lec_arp_add(priv, entry);
1984 /* We want arp-request(s) to be sent */
1985 entry->packets_flooded = 1;
1986 entry->status = ESI_ARP_PENDING;
1987 entry->no_tries = 1;
1988 entry->last_used = entry->timestamp = jiffies;
1989 entry->is_rdesc = is_rdesc;
1990 if (entry->is_rdesc)
1991 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1992 NULL);
1993 else
1994 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1995 entry->timer.expires = jiffies + (1 * HZ);
1996 entry->timer.function = lec_arp_expire_arp;
1997 add_timer(&entry->timer);
1998 found = priv->mcast_vcc;
1999 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
2001out:
2002 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2003 return found;
2004}
2005
2006static int
Chas Williams1fa99612006-09-29 17:11:47 -07002007lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
2008 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009{
2010 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002011 struct hlist_node *node, *next;
2012 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002013 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014
Stephen Hemminger52240062007-08-28 15:22:09 -07002015 pr_debug("lec_addr_delete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002017 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002018 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002019 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2020 && (permanent ||
2021 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002023 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002024 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002026 return 0;
2027 }
2028 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002030 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031}
2032
2033/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002034 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 */
2036static void
2037lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07002038 unsigned char *atm_addr, unsigned long remoteflag,
2039 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040{
2041 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002042 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07002043 struct lec_arp_table *entry, *tmp;
2044 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
Stephen Hemminger52240062007-08-28 15:22:09 -07002046 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2047 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 -07002048 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2049 mac_addr[4], mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
2051 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002052 entry = lec_arp_find(priv, mac_addr);
2053 if (entry == NULL && targetless_le_arp)
2054 goto out; /*
2055 * LANE2: ignore targetless LE_ARPs for which
2056 * we have no entry in the cache. 7.1.30
2057 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002058 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2059 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2060 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2061 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002062 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002063 tmp = lec_arp_find(priv, mac_addr);
2064 if (tmp) {
2065 del_timer(&tmp->timer);
2066 tmp->status = ESI_FORWARD_DIRECT;
2067 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2068 tmp->vcc = entry->vcc;
2069 tmp->old_push = entry->old_push;
2070 tmp->last_used = jiffies;
2071 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002072 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002073 entry = tmp;
2074 } else {
2075 entry->status = ESI_FORWARD_DIRECT;
2076 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2077 entry->last_used = jiffies;
2078 lec_arp_add(priv, entry);
2079 }
2080 if (remoteflag)
2081 entry->flags |= LEC_REMOTE_FLAG;
2082 else
2083 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002084 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002085 dump_arp_table(priv);
2086 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002087 }
Chas Williams1fa99612006-09-29 17:11:47 -07002088 }
2089 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002090
Chas Williams1fa99612006-09-29 17:11:47 -07002091 entry = lec_arp_find(priv, mac_addr);
2092 if (!entry) {
2093 entry = make_entry(priv, mac_addr);
2094 if (!entry)
2095 goto out;
2096 entry->status = ESI_UNKNOWN;
2097 lec_arp_add(priv, entry);
2098 /* Temporary, changes before end of function */
2099 }
2100 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2101 del_timer(&entry->timer);
2102 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002103 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002104 if (entry != tmp &&
2105 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2106 /* Vcc to this host exists */
2107 if (tmp->status > ESI_VC_PENDING) {
2108 /*
2109 * ESI_FLUSH_PENDING,
2110 * ESI_FORWARD_DIRECT
2111 */
2112 entry->vcc = tmp->vcc;
2113 entry->old_push = tmp->old_push;
2114 }
2115 entry->status = tmp->status;
2116 break;
2117 }
2118 }
2119 }
2120 if (remoteflag)
2121 entry->flags |= LEC_REMOTE_FLAG;
2122 else
2123 entry->flags &= ~LEC_REMOTE_FLAG;
2124 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2125 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002126 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002127 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002128 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002129 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130out:
2131 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2132}
2133
2134/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002135 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 */
2137static void
2138lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002139 struct atm_vcc *vcc,
2140 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141{
2142 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002143 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002144 struct lec_arp_table *entry;
2145 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146
2147 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002148 if (ioc_data->receive == 2) {
2149 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
Stephen Hemminger52240062007-08-28 15:22:09 -07002151 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002153 entry = lec_arp_find(priv, bus_mac);
2154 if (!entry) {
2155 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002157 }
2158 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2159 entry->recv_vcc = vcc;
2160 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002162 entry = make_entry(priv, bus_mac);
2163 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002165 del_timer(&entry->timer);
2166 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2167 entry->recv_vcc = vcc;
2168 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002169 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002170 goto out;
2171 } else if (ioc_data->receive == 1) {
2172 /*
2173 * Vcc which we don't want to make default vcc,
2174 * attach it anyway.
2175 */
Stephen Hemminger52240062007-08-28 15:22:09 -07002176 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002177 ("LEC_ARP:Attaching data direct, not default: "
2178 "%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",
2179 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2180 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2181 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2182 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2183 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2184 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2185 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2186 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2187 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2188 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2189 entry = make_entry(priv, bus_mac);
2190 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002192 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2193 memset(entry->mac_addr, 0, ETH_ALEN);
2194 entry->recv_vcc = vcc;
2195 entry->old_recv_push = old_push;
2196 entry->status = ESI_UNKNOWN;
2197 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2198 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002199 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002200 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 dump_arp_table(priv);
2202 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002203 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002204 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002205 ("LEC_ARP:Attaching data direct, default: "
2206 "%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",
2207 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2208 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2209 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2210 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2211 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2212 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2213 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2214 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2215 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2216 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2217 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002218 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002219 if (memcmp
2220 (ioc_data->atm_addr, entry->atm_addr,
2221 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002222 pr_debug("LEC_ARP: Attaching data direct\n");
2223 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07002224 entry->vcc ? entry->vcc->vci : 0,
2225 entry->recv_vcc ? entry->recv_vcc->
2226 vci : 0);
2227 found_entry = 1;
2228 del_timer(&entry->timer);
2229 entry->vcc = vcc;
2230 entry->old_push = old_push;
2231 if (entry->status == ESI_VC_PENDING) {
2232 if (priv->maximum_unknown_frame_count
2233 == 0)
2234 entry->status =
2235 ESI_FORWARD_DIRECT;
2236 else {
2237 entry->timestamp = jiffies;
2238 entry->status =
2239 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002241 send_to_lecd(priv, l_flush_xmt,
2242 NULL,
2243 entry->atm_addr,
2244 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002246 }
2247 } else {
2248 /*
2249 * They were forming a connection
2250 * to us, and we to them. Our
2251 * ATM address is numerically lower
2252 * than theirs, so we make connection
2253 * we formed into default VCC (8.1.11).
2254 * Connection they made gets torn
2255 * down. This might confuse some
2256 * clients. Can be changed if
2257 * someone reports trouble...
2258 */
2259 ;
2260 }
2261 }
2262 }
2263 }
2264 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002265 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002266 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002268 }
2269 /*
2270 * Not found, snatch address from first data packet that arrives
2271 * from this vcc
2272 */
2273 entry = make_entry(priv, bus_mac);
2274 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002276 entry->vcc = vcc;
2277 entry->old_push = old_push;
2278 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2279 memset(entry->mac_addr, 0, ETH_ALEN);
2280 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002281 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002282 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2283 entry->timer.function = lec_arp_expire_vcc;
2284 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002285 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 dump_arp_table(priv);
2287out:
2288 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2289}
2290
Chas Williams1fa99612006-09-29 17:11:47 -07002291static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292{
2293 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002294 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002295 struct lec_arp_table *entry;
2296 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297
Stephen Hemminger52240062007-08-28 15:22:09 -07002298 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002299restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002300 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2301 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002302 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002303 if (entry->flush_tran_id == tran_id
2304 && entry->status == ESI_FLUSH_PENDING) {
2305 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002306 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002307
Chas Williams6656e3c2006-09-29 17:17:17 -07002308 lec_arp_hold(entry);
2309 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2310 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2311 lec_send(vcc, skb, entry->priv);
2312 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002313 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002314 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002315 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002316 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002317 }
2318 }
2319 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002321 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322}
2323
2324static void
2325lec_set_flush_tran_id(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002326 unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327{
2328 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002329 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002330 struct lec_arp_table *entry;
2331 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
2333 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002334 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002335 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002336 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2337 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002338 pr_debug("Set flush transaction id to %lx for %p\n",
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002339 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002340 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2343}
2344
Chas Williams1fa99612006-09-29 17:11:47 -07002345static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346{
2347 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002348 unsigned char mac_addr[] = {
2349 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2350 };
2351 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 struct lec_vcc_priv *vpriv;
2353 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002354
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2356 return -ENOMEM;
2357 vpriv->xoff = 0;
2358 vpriv->old_pop = vcc->pop;
2359 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002360 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002362 to_add = make_entry(priv, mac_addr);
2363 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 vcc->pop = vpriv->old_pop;
2365 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002366 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002368 }
2369 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2370 to_add->status = ESI_FORWARD_DIRECT;
2371 to_add->flags |= LEC_PERMANENT_FLAG;
2372 to_add->vcc = vcc;
2373 to_add->old_push = vcc->push;
2374 vcc->push = lec_push;
2375 priv->mcast_vcc = vcc;
2376 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377out:
2378 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002379 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380}
2381
Chas Williams1fa99612006-09-29 17:11:47 -07002382static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383{
2384 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002385 struct hlist_node *node, *next;
2386 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002387 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388
Stephen Hemminger52240062007-08-28 15:22:09 -07002389 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002390 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002391
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002393
Chas Williams1fa99612006-09-29 17:11:47 -07002394 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002395 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002396 if (vcc == entry->vcc) {
2397 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002398 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002399 if (priv->mcast_vcc == vcc) {
2400 priv->mcast_vcc = NULL;
2401 }
2402 }
2403 }
2404 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405
Chas Williamsd0732f62006-09-29 17:14:27 -07002406 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2407 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002408 lec_arp_clear_vccs(entry);
2409 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002410 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002411 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002412 }
Chas Williams1fa99612006-09-29 17:11:47 -07002413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414
Chas Williamsd0732f62006-09-29 17:14:27 -07002415 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002416 if (entry->recv_vcc == vcc) {
2417 lec_arp_clear_vccs(entry);
2418 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002419 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002420 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002421 }
Chas Williams1fa99612006-09-29 17:11:47 -07002422 }
2423
Chas Williamsd0732f62006-09-29 17:14:27 -07002424 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002425 if (entry->recv_vcc == vcc) {
2426 lec_arp_clear_vccs(entry);
2427 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002428 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002429 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002430 }
Chas Williams1fa99612006-09-29 17:11:47 -07002431 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432
2433 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2434 dump_arp_table(priv);
2435}
2436
2437static void
2438lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002439 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440{
Chas Williams1fa99612006-09-29 17:11:47 -07002441 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002442 struct hlist_node *node, *next;
2443 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002444 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2445 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002447 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
Chas Williams1fa99612006-09-29 17:11:47 -07002449 if (priv->is_trdev)
2450 src = tr_hdr->h_source;
2451 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002453 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454
2455 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002456 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2457 if (vcc == entry->vcc) {
2458 del_timer(&entry->timer);
2459 memcpy(entry->mac_addr, src, ETH_ALEN);
2460 entry->status = ESI_FORWARD_DIRECT;
2461 entry->last_used = jiffies;
2462 /* We might have got an entry */
2463 if ((tmp = lec_arp_find(priv, src))) {
2464 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002465 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002466 }
2467 hlist_del(&entry->next);
2468 lec_arp_add(priv, entry);
2469 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002470 }
Chas Williams1fa99612006-09-29 17:11:47 -07002471 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002472 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473out:
2474 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2475}
Chas Williams1fa99612006-09-29 17:11:47 -07002476
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477MODULE_LICENSE("GPL");