blob: 813a090dcaf4663abc0294e4eaf8aa79d6b99ad6 [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;
179 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Stephen Hemminger52240062007-08-28 15:22:09 -0700270 pr_debug("lec_start_xmit called\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700271 if (!priv->lecd) {
272 printk("%s:No lecd attached\n", dev->name);
273 priv->stats.tx_errors++;
274 netif_stop_queue(dev);
275 return -EUNATCH;
276 }
277
Stephen Hemminger52240062007-08-28 15:22:09 -0700278 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700279 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700280 (long)skb_end_pointer(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700282 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
283 lec_handle_bridge(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#endif
285
Chas Williamsd44f7742006-09-29 17:11:14 -0700286 /* Make sure we have room for lec_id */
287 if (skb_headroom(skb) < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Stephen Hemminger52240062007-08-28 15:22:09 -0700289 pr_debug("lec_start_xmit: reallocating skb\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700290 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
291 kfree_skb(skb);
292 if (skb2 == NULL)
293 return 0;
294 skb = skb2;
295 }
296 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Chas Williamsd44f7742006-09-29 17:11:14 -0700298 /* Put le header to place, works for TokenRing too */
299 lec_h = (struct lecdatahdr_8023 *)skb->data;
300 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700303 /*
304 * Ugly. Use this to realign Token Ring packets for
305 * e.g. PCA-200E driver.
306 */
307 if (priv->is_trdev) {
308 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
309 kfree_skb(skb);
310 if (skb2 == NULL)
311 return 0;
312 skb = skb2;
313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314#endif
315
316#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700317 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
318 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700320 for (i = 0; i < skb->len && i < 99; i++) {
321 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700324 for (i = 0; i < skb->len && i < 30; i++) {
325 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700328 if (i == skb->len)
329 printk("%s\n", buf);
330 else
331 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#endif /* DUMP_PACKETS > 0 */
333
Chas Williamsd44f7742006-09-29 17:11:14 -0700334 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700336 if (priv->is_trdev)
337 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 else
339#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700340 min_frame_size = LEC_MINIMUM_8023_SIZE;
341 if (skb->len < min_frame_size) {
342 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
343 skb2 = skb_copy_expand(skb, 0,
344 min_frame_size - skb->truesize,
345 GFP_ATOMIC);
346 dev_kfree_skb(skb);
347 if (skb2 == NULL) {
348 priv->stats.tx_dropped++;
349 return 0;
350 }
351 skb = skb2;
352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700354 }
355
356 /* Send to right vcc */
357 is_rdesc = 0;
358 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700360 if (priv->is_trdev) {
361 dst = get_tr_dst(skb->data + 2, rdesc);
362 if (dst == NULL) {
363 dst = rdesc;
364 is_rdesc = 1;
365 }
366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700368 entry = NULL;
369 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
Stephen Hemminger52240062007-08-28 15:22:09 -0700370 pr_debug("%s:vcc:%p vcc_flags:%x, entry:%p\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700371 vcc, vcc ? vcc->flags : 0, entry);
372 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
373 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700374 pr_debug("%s:lec_start_xmit: queuing packet, ",
Chas Williamsd44f7742006-09-29 17:11:14 -0700375 dev->name);
Stephen Hemminger52240062007-08-28 15:22:09 -0700376 pr_debug("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700377 lec_h->h_dest[0], lec_h->h_dest[1],
378 lec_h->h_dest[2], lec_h->h_dest[3],
379 lec_h->h_dest[4], lec_h->h_dest[5]);
380 skb_queue_tail(&entry->tx_wait, skb);
381 } else {
Stephen Hemminger52240062007-08-28 15:22:09 -0700382 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700383 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
384 dev->name);
Stephen Hemminger52240062007-08-28 15:22:09 -0700385 pr_debug("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700386 lec_h->h_dest[0], lec_h->h_dest[1],
387 lec_h->h_dest[2], lec_h->h_dest[3],
388 lec_h->h_dest[4], lec_h->h_dest[5]);
389 priv->stats.tx_dropped++;
390 dev_kfree_skb(skb);
391 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700392 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700393 }
394#if DUMP_PACKETS > 0
395 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700397
398 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700399 pr_debug("lec.c: emptying tx queue, ");
400 pr_debug("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700401 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
402 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 lec_send(vcc, skb2, priv);
Chas Williamsd44f7742006-09-29 17:11:14 -0700404 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 lec_send(vcc, skb, priv);
407
408 if (!atm_may_send(vcc, 0)) {
409 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
410
411 vpriv->xoff = 1;
412 netif_stop_queue(dev);
413
414 /*
415 * vcc->pop() might have occurred in between, making
416 * the vcc usuable again. Since xmit is serialized,
417 * this is the only situation we have to re-test.
418 */
419
420 if (atm_may_send(vcc, 0))
421 netif_wake_queue(dev);
422 }
423
Chas Williams6656e3c2006-09-29 17:17:17 -0700424out:
425 if (entry)
426 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 dev->trans_start = jiffies;
Chas Williamsd44f7742006-09-29 17:11:14 -0700428 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429}
430
431/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700432static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
Chas Williamsd44f7742006-09-29 17:11:14 -0700434 netif_stop_queue(dev);
435 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436}
437
438/*
439 * Get the current statistics.
440 * This may be called with the card open or closed.
441 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700442static struct net_device_stats *lec_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443{
Chas Williamsd44f7742006-09-29 17:11:14 -0700444 return &((struct lec_priv *)dev->priv)->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445}
446
Chas Williamsd44f7742006-09-29 17:11:14 -0700447static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448{
449 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700450 struct net_device *dev = (struct net_device *)vcc->proto_data;
451 struct lec_priv *priv = (struct lec_priv *)dev->priv;
452 struct atmlec_msg *mesg;
453 struct lec_arp_table *entry;
454 int i;
455 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700458 mesg = (struct atmlec_msg *)skb->data;
459 tmp = skb->data;
460 tmp += sizeof(struct atmlec_msg);
Stephen Hemminger52240062007-08-28 15:22:09 -0700461 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700462 switch (mesg->type) {
463 case l_set_mac_addr:
464 for (i = 0; i < 6; i++) {
465 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
466 }
467 break;
468 case l_del_mac_addr:
469 for (i = 0; i < 6; i++) {
470 dev->dev_addr[i] = 0;
471 }
472 break;
473 case l_addr_delete:
474 lec_addr_delete(priv, mesg->content.normal.atm_addr,
475 mesg->content.normal.flag);
476 break;
477 case l_topology_change:
478 priv->topology_change = mesg->content.normal.flag;
479 break;
480 case l_flush_complete:
481 lec_flush_complete(priv, mesg->content.normal.flag);
482 break;
483 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700485 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
486 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
488
Chas Williamsd44f7742006-09-29 17:11:14 -0700489 if (mesg->content.normal.no_source_le_narp)
490 break;
491 /* FALL THROUGH */
492 case l_arp_update:
493 lec_arp_update(priv, mesg->content.normal.mac_addr,
494 mesg->content.normal.atm_addr,
495 mesg->content.normal.flag,
496 mesg->content.normal.targetless_le_arp);
Stephen Hemminger52240062007-08-28 15:22:09 -0700497 pr_debug("lec: in l_arp_update\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700498 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700499 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700500 mesg->sizeoftlvs);
501 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
502 tmp, mesg->sizeoftlvs);
503 }
504 break;
505 case l_config:
506 priv->maximum_unknown_frame_count =
507 mesg->content.config.maximum_unknown_frame_count;
508 priv->max_unknown_frame_time =
509 (mesg->content.config.max_unknown_frame_time * HZ);
510 priv->max_retry_count = mesg->content.config.max_retry_count;
511 priv->aging_time = (mesg->content.config.aging_time * HZ);
512 priv->forward_delay_time =
513 (mesg->content.config.forward_delay_time * HZ);
514 priv->arp_response_time =
515 (mesg->content.config.arp_response_time * HZ);
516 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
517 priv->path_switching_delay =
518 (mesg->content.config.path_switching_delay * HZ);
519 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 priv->lane2_ops = NULL;
521 if (priv->lane_version > 1)
522 priv->lane2_ops = &lane2_ops;
523 if (dev->change_mtu(dev, mesg->content.config.mtu))
524 printk("%s: change_mtu to %d failed\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700525 mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700527 break;
528 case l_flush_tran_id:
529 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
530 mesg->content.normal.flag);
531 break;
532 case l_set_lecid:
533 priv->lecid =
534 (unsigned short)(0xffff & mesg->content.normal.flag);
535 break;
536 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700538 {
539 struct net_bridge_fdb_entry *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Stephen Hemminger52240062007-08-28 15:22:09 -0700541 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700542 ("%s: bridge zeppelin asks about 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
543 dev->name, mesg->content.proxy.mac_addr[0],
544 mesg->content.proxy.mac_addr[1],
545 mesg->content.proxy.mac_addr[2],
546 mesg->content.proxy.mac_addr[3],
547 mesg->content.proxy.mac_addr[4],
548 mesg->content.proxy.mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Chas Williamsd44f7742006-09-29 17:11:14 -0700550 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
551 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
Chas Williamsd44f7742006-09-29 17:11:14 -0700553 f = br_fdb_get_hook(dev->br_port->br,
554 mesg->content.proxy.mac_addr);
555 if (f != NULL && f->dst->dev != dev
556 && f->dst->state == BR_STATE_FORWARDING) {
557 /* hit from bridge table, send LE_ARP_RESPONSE */
558 struct sk_buff *skb2;
559 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Stephen Hemminger52240062007-08-28 15:22:09 -0700561 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700562 ("%s: entry found, responding to zeppelin\n",
563 dev->name);
564 skb2 =
565 alloc_skb(sizeof(struct atmlec_msg),
566 GFP_ATOMIC);
567 if (skb2 == NULL) {
568 br_fdb_put_hook(f);
569 break;
570 }
571 skb2->len = sizeof(struct atmlec_msg);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300572 skb_copy_to_linear_data(skb2, mesg,
573 sizeof(*mesg));
Chas Williamsd44f7742006-09-29 17:11:14 -0700574 atm_force_charge(priv->lecd, skb2->truesize);
575 sk = sk_atm(priv->lecd);
576 skb_queue_tail(&sk->sk_receive_queue, skb2);
577 sk->sk_data_ready(sk, skb2->len);
578 }
579 if (f != NULL)
580 br_fdb_put_hook(f);
581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700583 break;
584 default:
585 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
586 dev_kfree_skb(skb);
587 return -EINVAL;
588 }
589 dev_kfree_skb(skb);
590 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591}
592
Chas Williamsd44f7742006-09-29 17:11:14 -0700593static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
Chas Williamsd44f7742006-09-29 17:11:14 -0700595 struct sk_buff *skb;
596 struct net_device *dev = (struct net_device *)vcc->proto_data;
597 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Chas Williamsd44f7742006-09-29 17:11:14 -0700599 priv->lecd = NULL;
600 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Chas Williamsd44f7742006-09-29 17:11:14 -0700602 netif_stop_queue(dev);
603 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Chas Williamsd44f7742006-09-29 17:11:14 -0700605 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700607 dev->name);
608 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
609 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700611 }
612
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700614 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615}
616
617static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700618 .close = lec_atm_close,
619 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620};
621
622static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700623 .ops = &lecdev_ops,
624 .type = "lec",
625 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700626 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627};
628
629/*
630 * LANE2: new argument struct sk_buff *data contains
631 * the LE_ARP based TLVs introduced in the LANE2 spec
632 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700633static int
634send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
635 unsigned char *mac_addr, unsigned char *atm_addr,
636 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
638 struct sock *sk;
639 struct sk_buff *skb;
640 struct atmlec_msg *mesg;
641
642 if (!priv || !priv->lecd) {
643 return -1;
644 }
645 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
646 if (!skb)
647 return -1;
648 skb->len = sizeof(struct atmlec_msg);
649 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700650 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700652 if (data != NULL)
653 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 if (mac_addr)
655 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700656 else
657 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 if (atm_addr)
659 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
660
Chas Williamsd44f7742006-09-29 17:11:14 -0700661 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 sk = sk_atm(priv->lecd);
663 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700664 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Chas Williamsd44f7742006-09-29 17:11:14 -0700666 if (data != NULL) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700667 pr_debug("lec: about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700668 atm_force_charge(priv->lecd, data->truesize);
669 skb_queue_tail(&sk->sk_receive_queue, data);
670 sk->sk_data_ready(sk, skb->len);
671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Chas Williamsd44f7742006-09-29 17:11:14 -0700673 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674}
675
676/* shamelessly stolen from drivers/net/net_init.c */
677static int lec_change_mtu(struct net_device *dev, int new_mtu)
678{
Chas Williamsd44f7742006-09-29 17:11:14 -0700679 if ((new_mtu < 68) || (new_mtu > 18190))
680 return -EINVAL;
681 dev->mtu = new_mtu;
682 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
685static void lec_set_multicast_list(struct net_device *dev)
686{
Chas Williamsd44f7742006-09-29 17:11:14 -0700687 /*
688 * by default, all multicast frames arrive over the bus.
689 * eventually support selective multicast service
690 */
691 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692}
693
Chas Williamsd44f7742006-09-29 17:11:14 -0700694static void lec_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
Chas Williamsd44f7742006-09-29 17:11:14 -0700696 dev->change_mtu = lec_change_mtu;
697 dev->open = lec_open;
698 dev->stop = lec_close;
699 dev->hard_start_xmit = lec_start_xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 dev->tx_timeout = lec_tx_timeout;
701
Chas Williamsd44f7742006-09-29 17:11:14 -0700702 dev->get_stats = lec_get_stats;
703 dev->set_multicast_list = lec_set_multicast_list;
704 dev->do_ioctl = NULL;
705 printk("%s: Initialized!\n", dev->name);
706 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707}
708
709static unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700710 0xff,
711 0x00,
712 0x01,
713 0x01
714};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Scott Talbert4a7097f2005-09-29 17:30:54 -0700716#define LEC_DATA_DIRECT_8023 2
717#define LEC_DATA_DIRECT_8025 3
718
719static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700720{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700721 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
722 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700723}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700724
Chas Williamsd44f7742006-09-29 17:11:14 -0700725static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700727 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700728 struct net_device *dev = (struct net_device *)vcc->proto_data;
729 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731#if DUMP_PACKETS >0
Chas Williamsd44f7742006-09-29 17:11:14 -0700732 int i = 0;
733 char buf[300];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
Chas Williamsd44f7742006-09-29 17:11:14 -0700735 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
736 vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700738 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700739 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700740 lec_vcc_close(priv, vcc);
741 return;
742 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700744 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
745 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700747 for (i = 0; i < skb->len && i < 99; i++) {
748 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700751 for (i = 0; i < skb->len && i < 30; i++) {
752 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
753 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700755 if (i == skb->len)
756 printk("%s\n", buf);
757 else
758 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700760 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 struct sock *sk = sk_atm(vcc);
762
Stephen Hemminger52240062007-08-28 15:22:09 -0700763 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700764 skb_queue_tail(&sk->sk_receive_queue, skb);
765 sk->sk_data_ready(sk, skb->len);
766 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700767 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700768 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Chas Williamsd44f7742006-09-29 17:11:14 -0700770 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800771 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700772 !priv->lecd || !(dev->flags & IFF_UP)) {
773 /*
774 * Probably looping back, or if lecd is missing,
775 * lecd has gone down
776 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700777 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700778 dev_kfree_skb(skb);
779 return;
780 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700782 if (priv->is_trdev)
783 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
784 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700786 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700787
Chas Williamsd44f7742006-09-29 17:11:14 -0700788 /*
789 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700790 * the LE_ARP cache entry, delete the LE_ARP cache entry.
791 */
792 spin_lock_irqsave(&priv->lec_arp_lock, flags);
793 if (lec_is_data_direct(vcc)) {
794#ifdef CONFIG_TR
795 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700796 src =
797 ((struct lecdatahdr_8025 *)skb->data)->
798 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700799 else
800#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700801 src =
802 ((struct lecdatahdr_8023 *)skb->data)->
803 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700804 entry = lec_arp_find(priv, src);
805 if (entry && entry->vcc != vcc) {
806 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700807 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700808 }
809 }
810 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Chas Williamsd44f7742006-09-29 17:11:14 -0700812 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
813 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700815 dev_kfree_skb(skb);
816 return;
817 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700818 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700819 lec_arp_check_empties(priv, vcc, skb);
820 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700821 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700823 if (priv->is_trdev)
824 skb->protocol = tr_type_trans(skb, dev);
825 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700827 skb->protocol = eth_type_trans(skb, dev);
828 priv->stats.rx_packets++;
829 priv->stats.rx_bytes += skb->len;
830 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
831 netif_rx(skb);
832 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833}
834
Chas Williamsd44f7742006-09-29 17:11:14 -0700835static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836{
837 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
838 struct net_device *dev = skb->dev;
839
840 if (vpriv == NULL) {
841 printk("lec_pop(): vpriv = NULL!?!?!?\n");
842 return;
843 }
844
845 vpriv->old_pop(vcc, skb);
846
847 if (vpriv->xoff && atm_may_send(vcc, 0)) {
848 vpriv->xoff = 0;
849 if (netif_running(dev) && netif_queue_stopped(dev))
850 netif_wake_queue(dev);
851 }
852}
853
Chas Williamsd44f7742006-09-29 17:11:14 -0700854static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
856 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700857 int bytes_left;
858 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Chas Williamsd44f7742006-09-29 17:11:14 -0700860 /* Lecd must be up in this case */
861 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
862 if (bytes_left != 0) {
863 printk
864 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
865 bytes_left);
866 }
867 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
868 !dev_lec[ioc_data.dev_num])
869 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
871 return -ENOMEM;
872 vpriv->xoff = 0;
873 vpriv->old_pop = vcc->pop;
874 vcc->user_back = vpriv;
875 vcc->pop = lec_pop;
Chas Williamsd44f7742006-09-29 17:11:14 -0700876 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
877 &ioc_data, vcc, vcc->push);
878 vcc->proto_data = dev_lec[ioc_data.dev_num];
879 vcc->push = lec_push;
880 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881}
882
Chas Williamsd44f7742006-09-29 17:11:14 -0700883static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884{
Chas Williamsd44f7742006-09-29 17:11:14 -0700885 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
886 return -EINVAL;
887 vcc->proto_data = dev_lec[arg];
888 return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889}
890
891/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700892static int lecd_attach(struct atm_vcc *vcc, int arg)
893{
894 int i;
895 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Chas Williamsd44f7742006-09-29 17:11:14 -0700897 if (arg < 0)
898 i = 0;
899 else
900 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700902 if (arg >= MAX_LEC_ITF)
903 return -EINVAL;
904#else /* Reserve the top NUM_TR_DEVS for TR */
905 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
906 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700908 if (!dev_lec[i]) {
909 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Chas Williamsd44f7742006-09-29 17:11:14 -0700911 is_trdev = 0;
912 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
913 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Chas Williamsd44f7742006-09-29 17:11:14 -0700915 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700917 if (is_trdev)
918 dev_lec[i] = alloc_trdev(size);
919 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700921 dev_lec[i] = alloc_etherdev(size);
922 if (!dev_lec[i])
923 return -ENOMEM;
924 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
925 if (register_netdev(dev_lec[i])) {
926 free_netdev(dev_lec[i]);
927 return -EINVAL;
928 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Chas Williamsd44f7742006-09-29 17:11:14 -0700930 priv = dev_lec[i]->priv;
931 priv->is_trdev = is_trdev;
932 lec_init(dev_lec[i]);
933 } else {
934 priv = dev_lec[i]->priv;
935 if (priv->lecd)
936 return -EADDRINUSE;
937 }
938 lec_arp_init(priv);
939 priv->itfnum = i; /* LANE2 addition */
940 priv->lecd = vcc;
941 vcc->dev = &lecatm_dev;
942 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Chas Williamsd44f7742006-09-29 17:11:14 -0700944 vcc->proto_data = dev_lec[i];
945 set_bit(ATM_VF_META, &vcc->flags);
946 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
Chas Williamsd44f7742006-09-29 17:11:14 -0700948 /* Set default values to these variables */
949 priv->maximum_unknown_frame_count = 1;
950 priv->max_unknown_frame_time = (1 * HZ);
951 priv->vcc_timeout_period = (1200 * HZ);
952 priv->max_retry_count = 1;
953 priv->aging_time = (300 * HZ);
954 priv->forward_delay_time = (15 * HZ);
955 priv->topology_change = 0;
956 priv->arp_response_time = (1 * HZ);
957 priv->flush_timeout = (4 * HZ);
958 priv->path_switching_delay = (6 * HZ);
959
960 if (dev_lec[i]->flags & IFF_UP) {
961 netif_start_queue(dev_lec[i]);
962 }
963 __module_get(THIS_MODULE);
964 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965}
966
967#ifdef CONFIG_PROC_FS
Chas Williamsd44f7742006-09-29 17:11:14 -0700968static char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
970 static char *lec_arp_status_string[] = {
971 "ESI_UNKNOWN ",
972 "ESI_ARP_PENDING ",
973 "ESI_VC_PENDING ",
974 "<Undefined> ",
975 "ESI_FLUSH_PENDING ",
976 "ESI_FORWARD_DIRECT"
977 };
978
979 if (status > ESI_FORWARD_DIRECT)
980 status = 3; /* ESI_UNDEFINED */
981 return lec_arp_status_string[status];
982}
983
984static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
985{
986 int i;
987
988 for (i = 0; i < ETH_ALEN; i++)
989 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
990 seq_printf(seq, " ");
991 for (i = 0; i < ATM_ESA_LEN; i++)
992 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
993 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
994 entry->flags & 0xffff);
995 if (entry->vcc)
996 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
997 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700998 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 if (entry->recv_vcc) {
1000 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
1001 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -07001002 }
1003 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004}
1005
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006struct lec_state {
1007 unsigned long flags;
1008 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -07001009 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 struct net_device *dev;
1011 int itf;
1012 int arp_table;
1013 int misc_table;
1014};
1015
Chas Williamsd0732f62006-09-29 17:14:27 -07001016static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 loff_t *l)
1018{
Chas Williamsd0732f62006-09-29 17:14:27 -07001019 struct hlist_node *e = state->node;
1020 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
1022 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -07001023 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 if (e == (void *)1) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001025 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 --*l;
1027 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001028
1029 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 if (--*l < 0)
1031 break;
1032 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001033 state->node = e;
1034
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 return (*l < 0) ? state : NULL;
1036}
1037
1038static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -07001039 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040{
1041 void *v = NULL;
1042 int p;
1043
1044 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001045 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 if (v)
1047 break;
1048 }
1049 state->arp_table = p;
1050 return v;
1051}
1052
1053static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1054 struct lec_priv *priv)
1055{
Chas Williamsd0732f62006-09-29 17:14:27 -07001056 struct hlist_head *lec_misc_tables[] = {
1057 &priv->lec_arp_empty_ones,
1058 &priv->lec_no_forward,
1059 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 };
1061 void *v = NULL;
1062 int q;
1063
1064 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1065 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1066 if (v)
1067 break;
1068 }
1069 state->misc_table = q;
1070 return v;
1071}
1072
1073static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1074 struct lec_priv *priv)
1075{
1076 if (!state->locked) {
1077 state->locked = priv;
1078 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1079 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001080 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1082 state->locked = NULL;
1083 /* Partial state reset for the next time we get called */
1084 state->arp_table = state->misc_table = 0;
1085 }
1086 return state->locked;
1087}
1088
1089static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1090{
1091 struct net_device *dev;
1092 void *v;
1093
1094 dev = state->dev ? state->dev : dev_lec[state->itf];
1095 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
1096 if (!v && dev) {
1097 dev_put(dev);
1098 /* Partial state reset for the next time we get called */
1099 dev = NULL;
1100 }
1101 state->dev = dev;
1102 return v;
1103}
1104
1105static void *lec_get_idx(struct lec_state *state, loff_t l)
1106{
1107 void *v = NULL;
1108
1109 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1110 v = lec_itf_walk(state, &l);
1111 if (v)
1112 break;
1113 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001114 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115}
1116
1117static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1118{
1119 struct lec_state *state = seq->private;
1120
1121 state->itf = 0;
1122 state->dev = NULL;
1123 state->locked = NULL;
1124 state->arp_table = 0;
1125 state->misc_table = 0;
Chas Williamsd0732f62006-09-29 17:14:27 -07001126 state->node = (void *)1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
Chas Williamsd44f7742006-09-29 17:11:14 -07001128 return *pos ? lec_get_idx(state, *pos) : (void *)1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129}
1130
1131static void lec_seq_stop(struct seq_file *seq, void *v)
1132{
1133 struct lec_state *state = seq->private;
1134
1135 if (state->dev) {
1136 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1137 state->flags);
1138 dev_put(state->dev);
1139 }
1140}
1141
1142static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1143{
1144 struct lec_state *state = seq->private;
1145
1146 v = lec_get_idx(state, 1);
1147 *pos += !!PTR_ERR(v);
1148 return v;
1149}
1150
1151static int lec_seq_show(struct seq_file *seq, void *v)
1152{
Chas Williamsd44f7742006-09-29 17:11:14 -07001153 static char lec_banner[] = "Itf MAC ATM destination"
1154 " Status Flags "
1155 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157 if (v == (void *)1)
1158 seq_puts(seq, lec_banner);
1159 else {
1160 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001161 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001162 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
1164 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001165 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 }
1167 return 0;
1168}
1169
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001170static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001171 .start = lec_seq_start,
1172 .next = lec_seq_next,
1173 .stop = lec_seq_stop,
1174 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175};
1176
1177static int lec_seq_open(struct inode *inode, struct file *file)
1178{
1179 struct lec_state *state;
1180 struct seq_file *seq;
1181 int rc = -EAGAIN;
1182
1183 state = kmalloc(sizeof(*state), GFP_KERNEL);
1184 if (!state) {
1185 rc = -ENOMEM;
1186 goto out;
1187 }
1188
1189 rc = seq_open(file, &lec_seq_ops);
1190 if (rc)
1191 goto out_kfree;
1192 seq = file->private_data;
1193 seq->private = state;
1194out:
1195 return rc;
1196
1197out_kfree:
1198 kfree(state);
1199 goto out;
1200}
1201
1202static int lec_seq_release(struct inode *inode, struct file *file)
1203{
1204 return seq_release_private(inode, file);
1205}
1206
Arjan van de Ven9a321442007-02-12 00:55:35 -08001207static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001208 .owner = THIS_MODULE,
1209 .open = lec_seq_open,
1210 .read = seq_read,
1211 .llseek = seq_lseek,
1212 .release = lec_seq_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213};
1214#endif
1215
1216static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1217{
1218 struct atm_vcc *vcc = ATM_SD(sock);
1219 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001220
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001222 case ATMLEC_CTRL:
1223 case ATMLEC_MCAST:
1224 case ATMLEC_DATA:
1225 if (!capable(CAP_NET_ADMIN))
1226 return -EPERM;
1227 break;
1228 default:
1229 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 }
1231
1232 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001233 case ATMLEC_CTRL:
1234 err = lecd_attach(vcc, (int)arg);
1235 if (err >= 0)
1236 sock->state = SS_CONNECTED;
1237 break;
1238 case ATMLEC_MCAST:
1239 err = lec_mcast_attach(vcc, (int)arg);
1240 break;
1241 case ATMLEC_DATA:
1242 err = lec_vcc_attach(vcc, (void __user *)arg);
1243 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 }
1245
1246 return err;
1247}
1248
1249static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001250 .owner = THIS_MODULE,
1251 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252};
1253
1254static int __init lane_module_init(void)
1255{
1256#ifdef CONFIG_PROC_FS
1257 struct proc_dir_entry *p;
1258
1259 p = create_proc_entry("lec", S_IRUGO, atm_proc_root);
1260 if (p)
1261 p->proc_fops = &lec_seq_fops;
1262#endif
1263
1264 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001265 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1266 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267}
1268
1269static void __exit lane_module_cleanup(void)
1270{
Chas Williamsd44f7742006-09-29 17:11:14 -07001271 int i;
1272 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
1274 remove_proc_entry("lec", atm_proc_root);
1275
1276 deregister_atm_ioctl(&lane_ioctl_ops);
1277
Chas Williamsd44f7742006-09-29 17:11:14 -07001278 for (i = 0; i < MAX_LEC_ITF; i++) {
1279 if (dev_lec[i] != NULL) {
1280 priv = (struct lec_priv *)dev_lec[i]->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001282 free_netdev(dev_lec[i]);
1283 dev_lec[i] = NULL;
1284 }
1285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Chas Williamsd44f7742006-09-29 17:11:14 -07001287 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288}
1289
1290module_init(lane_module_init);
1291module_exit(lane_module_cleanup);
1292
1293/*
1294 * LANE2: 3.1.3, LE_RESOLVE.request
1295 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1296 * If sizeoftlvs == NULL the default TLVs associated with with this
1297 * lec will be used.
1298 * If dst_mac == NULL, targetless LE_ARP will be sent
1299 */
1300static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001301 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302{
1303 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -07001304 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1305 struct lec_arp_table *table;
1306 struct sk_buff *skb;
1307 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Chas Williamsd44f7742006-09-29 17:11:14 -07001309 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001311 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001313 if (table == NULL)
1314 return -1;
1315
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001316 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001317 if (*tlvs == NULL)
1318 return -1;
1319
Chas Williamsd44f7742006-09-29 17:11:14 -07001320 *sizeoftlvs = table->sizeoftlvs;
1321
1322 return 0;
1323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
1325 if (sizeoftlvs == NULL)
1326 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001327
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 else {
1329 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1330 if (skb == NULL)
1331 return -1;
1332 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001333 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1335 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001336 return retval;
1337}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
1339/*
1340 * LANE2: 3.1.4, LE_ASSOCIATE.request
1341 * Associate the *tlvs with the *lan_dst address.
1342 * Will overwrite any previous association
1343 * Returns 1 for success, 0 for failure (out of memory)
1344 *
1345 */
Chas Williamsd44f7742006-09-29 17:11:14 -07001346static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
1347 u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348{
Chas Williamsd44f7742006-09-29 17:11:14 -07001349 int retval;
1350 struct sk_buff *skb;
1351 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Chas Williamsd44f7742006-09-29 17:11:14 -07001353 if (compare_ether_addr(lan_dst, dev->dev_addr))
1354 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
Chas Williamsd44f7742006-09-29 17:11:14 -07001356 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001358 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001359 if (priv->tlvs == NULL)
1360 return (0);
1361 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Chas Williamsd44f7742006-09-29 17:11:14 -07001363 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1364 if (skb == NULL)
1365 return 0;
1366 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001367 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001368 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1369 if (retval != 0)
1370 printk("lec.c: lane2_associate_req() failed\n");
1371 /*
1372 * If the previous association has changed we must
1373 * somehow notify other LANE entities about the change
1374 */
1375 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376}
1377
1378/*
1379 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1380 *
1381 */
Chas Williamsd44f7742006-09-29 17:11:14 -07001382static void lane2_associate_ind(struct net_device *dev, u8 *mac_addr,
1383 u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384{
1385#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001386 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387#endif
1388 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Chas Williamsd44f7742006-09-29 17:11:14 -07001389#if 0 /*
1390 * Why have the TLVs in LE_ARP entries
1391 * since we do not use them? When you
1392 * uncomment this code, make sure the
1393 * TLVs get freed when entry is killed
1394 */
1395 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
Chas Williamsd44f7742006-09-29 17:11:14 -07001397 if (entry == NULL)
1398 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Chas Williamsd44f7742006-09-29 17:11:14 -07001400 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001402 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001403 if (entry->tlvs == NULL)
1404 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001405 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406#endif
1407#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001408 printk("lec.c: lane2_associate_ind()\n");
1409 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1410 while (i < sizeoftlvs)
1411 printk("%02x ", tlvs[i++]);
1412
1413 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414#endif
1415
Chas Williamsd44f7742006-09-29 17:11:14 -07001416 /* tell MPOA about the TLVs we saw */
1417 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1418 priv->lane2_ops->associate_indicator(dev, mac_addr,
1419 tlvs, sizeoftlvs);
1420 }
1421 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422}
1423
1424/*
1425 * Here starts what used to lec_arpc.c
1426 *
1427 * lec_arpc.c was added here when making
1428 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 */
1430
1431#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432#include <linux/timer.h>
1433#include <asm/param.h>
1434#include <asm/atomic.h>
1435#include <linux/inetdevice.h>
1436#include <net/route.h>
1437
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438#if 0
Stephen Hemminger52240062007-08-28 15:22:09 -07001439#define pr_debug(format,args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440/*
Stephen Hemminger52240062007-08-28 15:22:09 -07001441#define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442*/
1443#endif
1444#define DEBUG_ARP_TABLE 0
1445
1446#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1447
David Howellsc4028952006-11-22 14:57:56 +00001448static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449static void lec_arp_expire_arp(unsigned long data);
1450
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001451/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 * Arp table funcs
1453 */
1454
1455#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1456
1457/*
1458 * Initialization of arp-cache
1459 */
Chas Williams1fa99612006-09-29 17:11:47 -07001460static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461{
Chas Williams1fa99612006-09-29 17:11:47 -07001462 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Chas Williams1fa99612006-09-29 17:11:47 -07001464 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001465 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001466 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001467 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1468 INIT_HLIST_HEAD(&priv->lec_no_forward);
1469 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001471 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001472 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473}
1474
Chas Williams1fa99612006-09-29 17:11:47 -07001475static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
Chas Williams1fa99612006-09-29 17:11:47 -07001477 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 struct atm_vcc *vcc = entry->vcc;
1479 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001480 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Chas Williams1fa99612006-09-29 17:11:47 -07001482 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 if (vpriv->xoff)
1484 netif_wake_queue(dev);
1485 kfree(vpriv);
1486 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001487 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001489 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001490 }
1491 if (entry->recv_vcc) {
1492 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001494 entry->recv_vcc = NULL;
1495 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496}
1497
1498/*
1499 * Insert entry to lec_arp_table
1500 * LANE2: Add to the end of the list to satisfy 8.1.13
1501 */
Chas Williams1fa99612006-09-29 17:11:47 -07001502static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001503lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504{
Chas Williamsd0732f62006-09-29 17:14:27 -07001505 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
Chas Williamsd0732f62006-09-29 17:14:27 -07001507 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1508 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001509
Stephen Hemminger52240062007-08-28 15:22:09 -07001510 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 -07001511 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1512 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1513 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514}
1515
1516/*
1517 * Remove entry from lec_arp_table
1518 */
Chas Williams1fa99612006-09-29 17:11:47 -07001519static int
1520lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521{
Chas Williamsd0732f62006-09-29 17:14:27 -07001522 struct hlist_node *node;
1523 struct lec_arp_table *entry;
1524 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
Chas Williams1fa99612006-09-29 17:11:47 -07001526 if (!to_remove) {
1527 return -1;
1528 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001529
1530 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001531 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Chas Williamsd0732f62006-09-29 17:14:27 -07001533 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001534 if (to_remove->status >= ESI_FLUSH_PENDING) {
1535 /*
1536 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1537 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001538 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1539 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1540 if (memcmp(to_remove->atm_addr,
1541 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001542 remove_vcc = 0;
1543 break;
1544 }
1545 }
1546 }
1547 if (remove_vcc)
1548 lec_arp_clear_vccs(to_remove);
1549 }
1550 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1551
Stephen Hemminger52240062007-08-28 15:22:09 -07001552 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 -07001553 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1554 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1555 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1556 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557}
1558
1559#if DEBUG_ARP_TABLE
Chas Williams1fa99612006-09-29 17:11:47 -07001560static char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
Chas Williams1fa99612006-09-29 17:11:47 -07001562 switch (st) {
1563 case ESI_UNKNOWN:
1564 return "ESI_UNKNOWN";
1565 case ESI_ARP_PENDING:
1566 return "ESI_ARP_PENDING";
1567 case ESI_VC_PENDING:
1568 return "ESI_VC_PENDING";
1569 case ESI_FLUSH_PENDING:
1570 return "ESI_FLUSH_PENDING";
1571 case ESI_FORWARD_DIRECT:
1572 return "ESI_FORWARD_DIRECT";
1573 default:
1574 return "<UNKNOWN>";
1575 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Chas Williams1fa99612006-09-29 17:11:47 -07001578static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579{
Chas Williamsd0732f62006-09-29 17:14:27 -07001580 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001581 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001582 char buf[256];
1583 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Chas Williams1fa99612006-09-29 17:11:47 -07001585 printk("Dump %p:\n", priv);
1586 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001587 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1588 offset = 0;
1589 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001590 offset += sprintf(buf + offset, "Mac:");
1591 for (j = 0; j < ETH_ALEN; j++) {
1592 offset += sprintf(buf + offset,
1593 "%2.2x ",
1594 rulla->mac_addr[j] & 0xff);
1595 }
1596 offset += sprintf(buf + offset, "Atm:");
1597 for (j = 0; j < ATM_ESA_LEN; j++) {
1598 offset += sprintf(buf + offset,
1599 "%2.2x ",
1600 rulla->atm_addr[j] & 0xff);
1601 }
1602 offset += sprintf(buf + offset,
1603 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1604 rulla->vcc ? rulla->vcc->vpi : 0,
1605 rulla->vcc ? rulla->vcc->vci : 0,
1606 rulla->recv_vcc ? rulla->recv_vcc->
1607 vpi : 0,
1608 rulla->recv_vcc ? rulla->recv_vcc->
1609 vci : 0, rulla->last_used,
1610 rulla->timestamp, rulla->no_tries);
1611 offset +=
1612 sprintf(buf + offset,
1613 "Flags:%x, Packets_flooded:%x, Status: %s ",
1614 rulla->flags, rulla->packets_flooded,
1615 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001616 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001617 }
Chas Williams1fa99612006-09-29 17:11:47 -07001618 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001619
1620 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001621 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001622 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001623 offset = 0;
1624 offset += sprintf(buf + offset, "Mac:");
1625 for (j = 0; j < ETH_ALEN; j++) {
1626 offset += sprintf(buf + offset, "%2.2x ",
1627 rulla->mac_addr[j] & 0xff);
1628 }
1629 offset += sprintf(buf + offset, "Atm:");
1630 for (j = 0; j < ATM_ESA_LEN; j++) {
1631 offset += sprintf(buf + offset, "%2.2x ",
1632 rulla->atm_addr[j] & 0xff);
1633 }
1634 offset += sprintf(buf + offset,
1635 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1636 rulla->vcc ? rulla->vcc->vpi : 0,
1637 rulla->vcc ? rulla->vcc->vci : 0,
1638 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1639 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1640 rulla->last_used,
1641 rulla->timestamp, rulla->no_tries);
1642 offset += sprintf(buf + offset,
1643 "Flags:%x, Packets_flooded:%x, Status: %s ",
1644 rulla->flags, rulla->packets_flooded,
1645 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001646 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001647 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001648
1649 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001650 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001651 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001652 offset = 0;
1653 offset += sprintf(buf + offset, "Mac:");
1654 for (j = 0; j < ETH_ALEN; j++) {
1655 offset += sprintf(buf + offset, "%2.2x ",
1656 rulla->mac_addr[j] & 0xff);
1657 }
1658 offset += sprintf(buf + offset, "Atm:");
1659 for (j = 0; j < ATM_ESA_LEN; j++) {
1660 offset += sprintf(buf + offset, "%2.2x ",
1661 rulla->atm_addr[j] & 0xff);
1662 }
1663 offset += sprintf(buf + offset,
1664 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1665 rulla->vcc ? rulla->vcc->vpi : 0,
1666 rulla->vcc ? rulla->vcc->vci : 0,
1667 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1668 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1669 rulla->last_used,
1670 rulla->timestamp, rulla->no_tries);
1671 offset += sprintf(buf + offset,
1672 "Flags:%x, Packets_flooded:%x, Status: %s ",
1673 rulla->flags, rulla->packets_flooded,
1674 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001675 printk("%s", buf);
1676 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
Chas Williamsd0732f62006-09-29 17:14:27 -07001678 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001679 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001680 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001681 offset = 0;
1682 offset += sprintf(buf + offset, "Mac:");
1683 for (j = 0; j < ETH_ALEN; j++) {
1684 offset += sprintf(buf + offset, "%2.2x ",
1685 rulla->mac_addr[j] & 0xff);
1686 }
1687 offset += sprintf(buf + offset, "Atm:");
1688 for (j = 0; j < ATM_ESA_LEN; j++) {
1689 offset += sprintf(buf + offset, "%2.2x ",
1690 rulla->atm_addr[j] & 0xff);
1691 }
1692 offset += sprintf(buf + offset,
1693 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1694 rulla->vcc ? rulla->vcc->vpi : 0,
1695 rulla->vcc ? rulla->vcc->vci : 0,
1696 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1697 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1698 rulla->last_used,
1699 rulla->timestamp, rulla->no_tries);
1700 offset += sprintf(buf + offset,
1701 "Flags:%x, Packets_flooded:%x, Status: %s ",
1702 rulla->flags, rulla->packets_flooded,
1703 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001704 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001705 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707}
Chas Williamsd0732f62006-09-29 17:14:27 -07001708#else
1709#define dump_arp_table(priv) do { } while (0)
1710#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
1712/*
1713 * Destruction of arp-cache
1714 */
Chas Williams1fa99612006-09-29 17:11:47 -07001715static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716{
1717 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001718 struct hlist_node *node, *next;
1719 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001720 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
Chas Williams987e46b2006-09-29 17:15:59 -07001722 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001723
1724 /*
1725 * Remove all entries
1726 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
1728 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001729 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001730 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001731 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001732 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001733 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001734 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001735 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001736
1737 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001738 del_timer_sync(&entry->timer);
1739 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001740 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001741 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001742 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001743 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1744
1745 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001746 del_timer_sync(&entry->timer);
1747 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001748 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001749 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001750 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001751 INIT_HLIST_HEAD(&priv->lec_no_forward);
1752
1753 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001754 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1755 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001756 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001757 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001758 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001759 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001760 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1762}
1763
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001764/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 * Find entry by mac_address
1766 */
Chas Williams1fa99612006-09-29 17:11:47 -07001767static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
1768 unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769{
Chas Williamsd0732f62006-09-29 17:14:27 -07001770 struct hlist_node *node;
1771 struct hlist_head *head;
1772 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773
Stephen Hemminger52240062007-08-28 15:22:09 -07001774 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 -07001775 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1776 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
Chas Williams1fa99612006-09-29 17:11:47 -07001777
Chas Williamsd0732f62006-09-29 17:14:27 -07001778 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1779 hlist_for_each_entry(entry, node, head, next) {
1780 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1781 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001782 }
Chas Williams1fa99612006-09-29 17:11:47 -07001783 }
1784 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785}
1786
Chas Williams1fa99612006-09-29 17:11:47 -07001787static struct lec_arp_table *make_entry(struct lec_priv *priv,
1788 unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789{
Chas Williams1fa99612006-09-29 17:11:47 -07001790 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
Chas Williams1fa99612006-09-29 17:11:47 -07001792 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1793 if (!to_return) {
1794 printk("LEC: Arp entry kmalloc failed\n");
1795 return NULL;
1796 }
1797 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001798 INIT_HLIST_NODE(&to_return->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001799 init_timer(&to_return->timer);
1800 to_return->timer.function = lec_arp_expire_arp;
1801 to_return->timer.data = (unsigned long)to_return;
1802 to_return->last_used = jiffies;
1803 to_return->priv = priv;
1804 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001805 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001806 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807}
1808
Chas Williams1fa99612006-09-29 17:11:47 -07001809/* Arp sent timer expired */
1810static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811{
Chas Williams1fa99612006-09-29 17:11:47 -07001812 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813
Chas Williams1fa99612006-09-29 17:11:47 -07001814 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815
Stephen Hemminger52240062007-08-28 15:22:09 -07001816 pr_debug("lec_arp_expire_arp\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001817 if (entry->status == ESI_ARP_PENDING) {
1818 if (entry->no_tries <= entry->priv->max_retry_count) {
1819 if (entry->is_rdesc)
1820 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1821 entry->mac_addr, NULL, NULL);
1822 else
1823 send_to_lecd(entry->priv, l_arp_xmt,
1824 entry->mac_addr, NULL, NULL);
1825 entry->no_tries++;
1826 }
1827 mod_timer(&entry->timer, jiffies + (1 * HZ));
1828 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829}
1830
Chas Williams1fa99612006-09-29 17:11:47 -07001831/* Unknown/unused vcc expire, remove associated entry */
1832static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833{
1834 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001835 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1836 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
Chas Williams1fa99612006-09-29 17:11:47 -07001838 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
Stephen Hemminger52240062007-08-28 15:22:09 -07001840 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001841 to_remove, priv,
1842 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1843 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
1845 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001846 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1848
Chas Williams1fa99612006-09-29 17:11:47 -07001849 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001850 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851}
1852
1853/*
1854 * Expire entries.
1855 * 1. Re-set timer
1856 * 2. For each entry, delete entries that have aged past the age limit.
1857 * 3. For each entry, depending on the status of the entry, perform
1858 * the following maintenance.
1859 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1860 * tick_count is above the max_unknown_frame_time, clear
1861 * the tick_count to zero and clear the packets_flooded counter
1862 * to zero. This supports the packet rate limit per address
1863 * while flooding unknowns.
1864 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1865 * than or equal to the path_switching_delay, change the status
1866 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1867 * regardless of the progress of the flush protocol.
1868 */
David Howellsc4028952006-11-22 14:57:56 +00001869static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870{
1871 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001872 struct lec_priv *priv =
1873 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001874 struct hlist_node *node, *next;
1875 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001876 unsigned long now;
1877 unsigned long time_to_check;
1878 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
Stephen Hemminger52240062007-08-28 15:22:09 -07001880 pr_debug("lec_arp_check_expire %p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001882restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001884 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001885 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001886 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 priv->topology_change)
1888 time_to_check = priv->forward_delay_time;
1889 else
1890 time_to_check = priv->aging_time;
1891
Stephen Hemminger52240062007-08-28 15:22:09 -07001892 pr_debug("About to expire: %lx - %lx > %lx\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001893 now, entry->last_used, time_to_check);
1894 if (time_after(now, entry->last_used + time_to_check)
1895 && !(entry->flags & LEC_PERMANENT_FLAG)
1896 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 /* Remove entry */
Stephen Hemminger52240062007-08-28 15:22:09 -07001898 pr_debug("LEC:Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001900 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 } else {
1902 /* Something else */
1903 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001904 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001906 entry->timestamp +
1907 priv->
1908 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 entry->timestamp = jiffies;
1910 entry->packets_flooded = 0;
1911 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001912 send_to_lecd(priv, l_svc_setup,
1913 entry->mac_addr,
1914 entry->atm_addr,
1915 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 }
Chas Williams1fa99612006-09-29 17:11:47 -07001917 if (entry->status == ESI_FLUSH_PENDING
1918 &&
1919 time_after_eq(now, entry->timestamp +
1920 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001922 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923
Chas Williams6656e3c2006-09-29 17:17:17 -07001924 lec_arp_hold(entry);
1925 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1926 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1927 lec_send(vcc, skb, entry->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001929 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001930 lec_arp_put(entry);
1931 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 }
1934 }
1935 }
1936 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1937
Chas Williams987e46b2006-09-29 17:15:59 -07001938 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939}
Chas Williams1fa99612006-09-29 17:11:47 -07001940
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941/*
1942 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001943 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 */
Chas Williams1fa99612006-09-29 17:11:47 -07001945static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1946 unsigned char *mac_to_find, int is_rdesc,
1947 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948{
1949 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001950 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 struct atm_vcc *found;
1952
Chas Williams1fa99612006-09-29 17:11:47 -07001953 if (mac_to_find[0] & 0x01) {
1954 switch (priv->lane_version) {
1955 case 1:
1956 return priv->mcast_vcc;
1957 break;
1958 case 2: /* LANE2 wants arp for multicast addresses */
1959 if (!compare_ether_addr(mac_to_find, bus_mac))
1960 return priv->mcast_vcc;
1961 break;
1962 default:
1963 break;
1964 }
1965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
1967 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001968 entry = lec_arp_find(priv, mac_to_find);
1969
1970 if (entry) {
1971 if (entry->status == ESI_FORWARD_DIRECT) {
1972 /* Connection Ok */
1973 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001974 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001975 *ret_entry = entry;
1976 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001978 }
1979 /*
1980 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001981 * so another LE_ARP request can be made for this frame.
1982 */
1983 if (entry->status == ESI_ARP_PENDING) {
1984 entry->no_tries = 0;
1985 }
Chas Williams1fa99612006-09-29 17:11:47 -07001986 /*
1987 * Data direct VC not yet set up, check to see if the unknown
1988 * frame count is greater than the limit. If the limit has
1989 * not been reached, allow the caller to send packet to
1990 * BUS.
1991 */
1992 if (entry->status != ESI_FLUSH_PENDING &&
1993 entry->packets_flooded <
1994 priv->maximum_unknown_frame_count) {
1995 entry->packets_flooded++;
Stephen Hemminger52240062007-08-28 15:22:09 -07001996 pr_debug("LEC_ARP: Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001997 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001999 }
2000 /*
2001 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 * or BUS flood limit was reached for an entry which is
2003 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
2004 */
Chas Williams6656e3c2006-09-29 17:17:17 -07002005 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002006 *ret_entry = entry;
Stephen Hemminger52240062007-08-28 15:22:09 -07002007 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
Chas Williams1fa99612006-09-29 17:11:47 -07002008 entry->vcc);
2009 found = NULL;
2010 } else {
2011 /* No matching entry was found */
2012 entry = make_entry(priv, mac_to_find);
Stephen Hemminger52240062007-08-28 15:22:09 -07002013 pr_debug("LEC_ARP: Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002014 if (!entry) {
2015 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002017 }
2018 lec_arp_add(priv, entry);
2019 /* We want arp-request(s) to be sent */
2020 entry->packets_flooded = 1;
2021 entry->status = ESI_ARP_PENDING;
2022 entry->no_tries = 1;
2023 entry->last_used = entry->timestamp = jiffies;
2024 entry->is_rdesc = is_rdesc;
2025 if (entry->is_rdesc)
2026 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
2027 NULL);
2028 else
2029 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
2030 entry->timer.expires = jiffies + (1 * HZ);
2031 entry->timer.function = lec_arp_expire_arp;
2032 add_timer(&entry->timer);
2033 found = priv->mcast_vcc;
2034 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
2036out:
2037 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2038 return found;
2039}
2040
2041static int
Chas Williams1fa99612006-09-29 17:11:47 -07002042lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
2043 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044{
2045 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002046 struct hlist_node *node, *next;
2047 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002048 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
Stephen Hemminger52240062007-08-28 15:22:09 -07002050 pr_debug("lec_addr_delete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002052 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002053 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002054 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2055 && (permanent ||
2056 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002058 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002059 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002061 return 0;
2062 }
2063 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002065 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066}
2067
2068/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002069 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 */
2071static void
2072lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07002073 unsigned char *atm_addr, unsigned long remoteflag,
2074 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075{
2076 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002077 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07002078 struct lec_arp_table *entry, *tmp;
2079 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
Stephen Hemminger52240062007-08-28 15:22:09 -07002081 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2082 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 -07002083 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2084 mac_addr[4], mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
2086 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002087 entry = lec_arp_find(priv, mac_addr);
2088 if (entry == NULL && targetless_le_arp)
2089 goto out; /*
2090 * LANE2: ignore targetless LE_ARPs for which
2091 * we have no entry in the cache. 7.1.30
2092 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002093 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2094 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2095 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2096 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002097 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002098 tmp = lec_arp_find(priv, mac_addr);
2099 if (tmp) {
2100 del_timer(&tmp->timer);
2101 tmp->status = ESI_FORWARD_DIRECT;
2102 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2103 tmp->vcc = entry->vcc;
2104 tmp->old_push = entry->old_push;
2105 tmp->last_used = jiffies;
2106 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002107 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002108 entry = tmp;
2109 } else {
2110 entry->status = ESI_FORWARD_DIRECT;
2111 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2112 entry->last_used = jiffies;
2113 lec_arp_add(priv, entry);
2114 }
2115 if (remoteflag)
2116 entry->flags |= LEC_REMOTE_FLAG;
2117 else
2118 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002119 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002120 dump_arp_table(priv);
2121 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002122 }
Chas Williams1fa99612006-09-29 17:11:47 -07002123 }
2124 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002125
Chas Williams1fa99612006-09-29 17:11:47 -07002126 entry = lec_arp_find(priv, mac_addr);
2127 if (!entry) {
2128 entry = make_entry(priv, mac_addr);
2129 if (!entry)
2130 goto out;
2131 entry->status = ESI_UNKNOWN;
2132 lec_arp_add(priv, entry);
2133 /* Temporary, changes before end of function */
2134 }
2135 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2136 del_timer(&entry->timer);
2137 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002138 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002139 if (entry != tmp &&
2140 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2141 /* Vcc to this host exists */
2142 if (tmp->status > ESI_VC_PENDING) {
2143 /*
2144 * ESI_FLUSH_PENDING,
2145 * ESI_FORWARD_DIRECT
2146 */
2147 entry->vcc = tmp->vcc;
2148 entry->old_push = tmp->old_push;
2149 }
2150 entry->status = tmp->status;
2151 break;
2152 }
2153 }
2154 }
2155 if (remoteflag)
2156 entry->flags |= LEC_REMOTE_FLAG;
2157 else
2158 entry->flags &= ~LEC_REMOTE_FLAG;
2159 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2160 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002161 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002162 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002163 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002164 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165out:
2166 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2167}
2168
2169/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002170 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 */
2172static void
2173lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002174 struct atm_vcc *vcc,
2175 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176{
2177 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002178 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002179 struct lec_arp_table *entry;
2180 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
2182 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002183 if (ioc_data->receive == 2) {
2184 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185
Stephen Hemminger52240062007-08-28 15:22:09 -07002186 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002188 entry = lec_arp_find(priv, bus_mac);
2189 if (!entry) {
2190 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002192 }
2193 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2194 entry->recv_vcc = vcc;
2195 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002197 entry = make_entry(priv, bus_mac);
2198 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002200 del_timer(&entry->timer);
2201 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2202 entry->recv_vcc = vcc;
2203 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002204 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002205 goto out;
2206 } else if (ioc_data->receive == 1) {
2207 /*
2208 * Vcc which we don't want to make default vcc,
2209 * attach it anyway.
2210 */
Stephen Hemminger52240062007-08-28 15:22:09 -07002211 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002212 ("LEC_ARP:Attaching data direct, not default: "
2213 "%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",
2214 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2215 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2216 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2217 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2218 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2219 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2220 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2221 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2222 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2223 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2224 entry = make_entry(priv, bus_mac);
2225 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002227 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2228 memset(entry->mac_addr, 0, ETH_ALEN);
2229 entry->recv_vcc = vcc;
2230 entry->old_recv_push = old_push;
2231 entry->status = ESI_UNKNOWN;
2232 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2233 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002234 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002235 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 dump_arp_table(priv);
2237 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002238 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002239 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002240 ("LEC_ARP:Attaching data direct, default: "
2241 "%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",
2242 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2243 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2244 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2245 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2246 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2247 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2248 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2249 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2250 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2251 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2252 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002253 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002254 if (memcmp
2255 (ioc_data->atm_addr, entry->atm_addr,
2256 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002257 pr_debug("LEC_ARP: Attaching data direct\n");
2258 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07002259 entry->vcc ? entry->vcc->vci : 0,
2260 entry->recv_vcc ? entry->recv_vcc->
2261 vci : 0);
2262 found_entry = 1;
2263 del_timer(&entry->timer);
2264 entry->vcc = vcc;
2265 entry->old_push = old_push;
2266 if (entry->status == ESI_VC_PENDING) {
2267 if (priv->maximum_unknown_frame_count
2268 == 0)
2269 entry->status =
2270 ESI_FORWARD_DIRECT;
2271 else {
2272 entry->timestamp = jiffies;
2273 entry->status =
2274 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002276 send_to_lecd(priv, l_flush_xmt,
2277 NULL,
2278 entry->atm_addr,
2279 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002281 }
2282 } else {
2283 /*
2284 * They were forming a connection
2285 * to us, and we to them. Our
2286 * ATM address is numerically lower
2287 * than theirs, so we make connection
2288 * we formed into default VCC (8.1.11).
2289 * Connection they made gets torn
2290 * down. This might confuse some
2291 * clients. Can be changed if
2292 * someone reports trouble...
2293 */
2294 ;
2295 }
2296 }
2297 }
2298 }
2299 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002300 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002301 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002303 }
2304 /*
2305 * Not found, snatch address from first data packet that arrives
2306 * from this vcc
2307 */
2308 entry = make_entry(priv, bus_mac);
2309 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002311 entry->vcc = vcc;
2312 entry->old_push = old_push;
2313 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2314 memset(entry->mac_addr, 0, ETH_ALEN);
2315 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002316 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002317 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2318 entry->timer.function = lec_arp_expire_vcc;
2319 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002320 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 dump_arp_table(priv);
2322out:
2323 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2324}
2325
Chas Williams1fa99612006-09-29 17:11:47 -07002326static void lec_flush_complete(struct lec_priv *priv, 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
Stephen Hemminger52240062007-08-28 15:22:09 -07002333 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002334restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002335 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2336 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002337 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002338 if (entry->flush_tran_id == tran_id
2339 && entry->status == ESI_FLUSH_PENDING) {
2340 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002341 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002342
Chas Williams6656e3c2006-09-29 17:17:17 -07002343 lec_arp_hold(entry);
2344 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2345 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2346 lec_send(vcc, skb, entry->priv);
2347 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002348 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002349 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002350 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002351 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002352 }
2353 }
2354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002356 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357}
2358
2359static void
2360lec_set_flush_tran_id(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002361 unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362{
2363 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002364 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002365 struct lec_arp_table *entry;
2366 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367
2368 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002369 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002370 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002371 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2372 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002373 pr_debug("Set flush transaction id to %lx for %p\n",
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002374 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002375 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002376 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2378}
2379
Chas Williams1fa99612006-09-29 17:11:47 -07002380static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381{
2382 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002383 unsigned char mac_addr[] = {
2384 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2385 };
2386 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 struct lec_vcc_priv *vpriv;
2388 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002389
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2391 return -ENOMEM;
2392 vpriv->xoff = 0;
2393 vpriv->old_pop = vcc->pop;
2394 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002395 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002397 to_add = make_entry(priv, mac_addr);
2398 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 vcc->pop = vpriv->old_pop;
2400 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002401 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002403 }
2404 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2405 to_add->status = ESI_FORWARD_DIRECT;
2406 to_add->flags |= LEC_PERMANENT_FLAG;
2407 to_add->vcc = vcc;
2408 to_add->old_push = vcc->push;
2409 vcc->push = lec_push;
2410 priv->mcast_vcc = vcc;
2411 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412out:
2413 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002414 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415}
2416
Chas Williams1fa99612006-09-29 17:11:47 -07002417static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418{
2419 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002420 struct hlist_node *node, *next;
2421 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002422 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423
Stephen Hemminger52240062007-08-28 15:22:09 -07002424 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002425 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002426
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002428
Chas Williams1fa99612006-09-29 17:11:47 -07002429 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002430 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002431 if (vcc == entry->vcc) {
2432 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002433 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002434 if (priv->mcast_vcc == vcc) {
2435 priv->mcast_vcc = NULL;
2436 }
2437 }
2438 }
2439 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440
Chas Williamsd0732f62006-09-29 17:14:27 -07002441 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2442 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002443 lec_arp_clear_vccs(entry);
2444 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002445 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002446 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002447 }
Chas Williams1fa99612006-09-29 17:11:47 -07002448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449
Chas Williamsd0732f62006-09-29 17:14:27 -07002450 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002451 if (entry->recv_vcc == vcc) {
2452 lec_arp_clear_vccs(entry);
2453 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002454 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002455 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002456 }
Chas Williams1fa99612006-09-29 17:11:47 -07002457 }
2458
Chas Williamsd0732f62006-09-29 17:14:27 -07002459 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002460 if (entry->recv_vcc == vcc) {
2461 lec_arp_clear_vccs(entry);
2462 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002463 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002464 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002465 }
Chas Williams1fa99612006-09-29 17:11:47 -07002466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467
2468 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2469 dump_arp_table(priv);
2470}
2471
2472static void
2473lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002474 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475{
Chas Williams1fa99612006-09-29 17:11:47 -07002476 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002477 struct hlist_node *node, *next;
2478 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002479 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2480 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002482 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483
Chas Williams1fa99612006-09-29 17:11:47 -07002484 if (priv->is_trdev)
2485 src = tr_hdr->h_source;
2486 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002488 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
2490 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002491 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2492 if (vcc == entry->vcc) {
2493 del_timer(&entry->timer);
2494 memcpy(entry->mac_addr, src, ETH_ALEN);
2495 entry->status = ESI_FORWARD_DIRECT;
2496 entry->last_used = jiffies;
2497 /* We might have got an entry */
2498 if ((tmp = lec_arp_find(priv, src))) {
2499 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002500 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002501 }
2502 hlist_del(&entry->next);
2503 lec_arp_add(priv, entry);
2504 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002505 }
Chas Williams1fa99612006-09-29 17:11:47 -07002506 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002507 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508out:
2509 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2510}
Chas Williams1fa99612006-09-29 17:11:47 -07002511
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512MODULE_LICENSE("GPL");