blob: 3235c57615e4fb7cda6b9278b3d6ca34b1a2bb52 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002 * lec.c: Lan Emulation driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Chas Williamsd44f7742006-09-29 17:11:14 -07004 * Marko Kiiskila <mkiiskila@yahoo.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/kernel.h>
8#include <linux/bitops.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -08009#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11/* We are ethernet device */
12#include <linux/if_ether.h>
13#include <linux/netdevice.h>
14#include <linux/etherdevice.h>
15#include <net/sock.h>
16#include <linux/skbuff.h>
17#include <linux/ip.h>
18#include <asm/byteorder.h>
19#include <asm/uaccess.h>
20#include <net/arp.h>
21#include <net/dst.h>
22#include <linux/proc_fs.h>
23#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/seq_file.h>
25
26/* TokenRing if needed */
27#ifdef CONFIG_TR
28#include <linux/trdevice.h>
29#endif
30
31/* And atm device */
32#include <linux/atmdev.h>
33#include <linux/atmlec.h>
34
35/* Proxy LEC knows about bridging */
36#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
37#include <linux/if_bridge.h>
38#include "../bridge/br_private.h"
39
Chas Williamsd44f7742006-09-29 17:11:14 -070040static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#endif
42
43/* Modular too */
44#include <linux/module.h>
45#include <linux/init.h>
46
47#include "lec.h"
48#include "lec_arpc.h"
49#include "resources.h"
50
Chas Williamsd44f7742006-09-29 17:11:14 -070051#define DUMP_PACKETS 0 /*
52 * 0 = None,
53 * 1 = 30 first bytes
54 * 2 = Whole packet
55 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Chas Williamsd44f7742006-09-29 17:11:14 -070057#define LEC_UNRES_QUE_LEN 8 /*
58 * number of tx packets to queue for a
59 * single destination while waiting for SVC
60 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62static int lec_open(struct net_device *dev);
63static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev);
64static int lec_close(struct net_device *dev);
65static struct net_device_stats *lec_get_stats(struct net_device *dev);
66static void lec_init(struct net_device *dev);
Chas Williamsd44f7742006-09-29 17:11:14 -070067static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
68 unsigned char *mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static int lec_arp_remove(struct lec_priv *priv,
Chas Williamsd44f7742006-09-29 17:11:14 -070070 struct lec_arp_table *to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* LANE2 functions */
Chas Williamsd44f7742006-09-29 17:11:14 -070072static void lane2_associate_ind(struct net_device *dev, u8 *mac_address,
73 u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -070075 u8 **tlvs, u32 *sizeoftlvs);
76static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
77 u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Chas Williamsd44f7742006-09-29 17:11:14 -070079static int lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 unsigned long permanent);
81static void lec_arp_check_empties(struct lec_priv *priv,
82 struct atm_vcc *vcc, struct sk_buff *skb);
83static void lec_arp_destroy(struct lec_priv *priv);
84static void lec_arp_init(struct lec_priv *priv);
Chas Williamsd44f7742006-09-29 17:11:14 -070085static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 unsigned char *mac_to_find,
87 int is_rdesc,
88 struct lec_arp_table **ret_entry);
89static void lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
90 unsigned char *atm_addr, unsigned long remoteflag,
91 unsigned int targetless_le_arp);
92static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
93static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
94static void lec_set_flush_tran_id(struct lec_priv *priv,
95 unsigned char *atm_addr,
96 unsigned long tran_id);
97static void lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
98 struct atm_vcc *vcc,
Chas Williamsd44f7742006-09-29 17:11:14 -070099 void (*old_push) (struct atm_vcc *vcc,
100 struct sk_buff *skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
102
Chas Williams33a9c2d2006-09-29 17:16:48 -0700103/* must be done under lec_arp_lock */
104static inline void lec_arp_hold(struct lec_arp_table *entry)
105{
106 atomic_inc(&entry->usage);
107}
108
109static inline void lec_arp_put(struct lec_arp_table *entry)
110{
111 if (atomic_dec_and_test(&entry->usage))
112 kfree(entry);
113}
114
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116static struct lane2_ops lane2_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700117 lane2_resolve, /* resolve, spec 3.1.3 */
118 lane2_associate_req, /* associate_req, spec 3.1.4 */
119 NULL /* associate indicator, spec 3.1.5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120};
121
Chas Williamsd44f7742006-09-29 17:11:14 -0700122static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124/* Device structures */
125static struct net_device *dev_lec[MAX_LEC_ITF];
126
127#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
128static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
129{
Chas Williamsd44f7742006-09-29 17:11:14 -0700130 struct ethhdr *eth;
131 char *buff;
132 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Chas Williamsd44f7742006-09-29 17:11:14 -0700134 /*
135 * Check if this is a BPDU. If so, ask zeppelin to send
136 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
137 * as the Config BPDU has
138 */
139 eth = (struct ethhdr *)skb->data;
140 buff = skb->data + skb->dev->hard_header_len;
141 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 struct sock *sk;
Chas Williamsd44f7742006-09-29 17:11:14 -0700143 struct sk_buff *skb2;
144 struct atmlec_msg *mesg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Chas Williamsd44f7742006-09-29 17:11:14 -0700146 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
147 if (skb2 == NULL)
148 return;
149 skb2->len = sizeof(struct atmlec_msg);
150 mesg = (struct atmlec_msg *)skb2->data;
151 mesg->type = l_topology_change;
152 buff += 4;
153 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Chas Williamsd44f7742006-09-29 17:11:14 -0700155 priv = (struct lec_priv *)dev->priv;
156 atm_force_charge(priv->lecd, skb2->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 sk = sk_atm(priv->lecd);
Chas Williamsd44f7742006-09-29 17:11:14 -0700158 skb_queue_tail(&sk->sk_receive_queue, skb2);
159 sk->sk_data_ready(sk, skb2->len);
160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Chas Williamsd44f7742006-09-29 17:11:14 -0700162 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
165
166/*
167 * Modelled after tr_type_trans
168 * All multicast and ARE or STE frames go to BUS.
169 * Non source routed frames go by destination address.
170 * Last hop source routed frames go by destination address.
171 * Not last hop source routed frames go by _next_ route descriptor.
172 * Returns pointer to destination MAC address or fills in rdesc
173 * and returns NULL.
174 */
175#ifdef CONFIG_TR
176static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
177{
Chas Williamsd44f7742006-09-29 17:11:14 -0700178 struct trh_hdr *trh;
Eric Dumazet5c17d5f2008-01-15 03:29:50 -0800179 unsigned int riflen, num_rdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Chas Williamsd44f7742006-09-29 17:11:14 -0700181 trh = (struct trh_hdr *)packet;
182 if (trh->daddr[0] & (uint8_t) 0x80)
183 return bus_mac; /* multicast */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Chas Williamsd44f7742006-09-29 17:11:14 -0700185 if (trh->saddr[0] & TR_RII) {
186 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
187 if ((ntohs(trh->rcf) >> 13) != 0)
188 return bus_mac; /* ARE or STE */
189 } else
190 return trh->daddr; /* not source routed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Chas Williamsd44f7742006-09-29 17:11:14 -0700192 if (riflen < 6)
193 return trh->daddr; /* last hop, source routed */
194
195 /* riflen is 6 or more, packet has more than one route descriptor */
196 num_rdsc = (riflen / 2) - 1;
197 memset(rdesc, 0, ETH_ALEN);
198 /* offset 4 comes from LAN destination field in LE control frames */
199 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
Al Viro30d492d2006-11-14 21:11:29 -0800200 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700201 else {
Al Viro30d492d2006-11-14 21:11:29 -0800202 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700203 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
204 }
205
206 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
208#endif /* CONFIG_TR */
209
210/*
211 * Open/initialize the netdevice. This is called (in the current kernel)
212 * sometime after booting when the 'ifconfig' program is run.
213 *
214 * This routine should set everything up anew at each open, even
215 * registers that "should" only need to be set once at boot, so that
216 * there is non-reboot way to recover if something goes wrong.
217 */
218
Chas Williamsd44f7742006-09-29 17:11:14 -0700219static int lec_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Chas Williamsd44f7742006-09-29 17:11:14 -0700221 struct lec_priv *priv = (struct lec_priv *)dev->priv;
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 netif_start_queue(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700224 memset(&priv->stats, 0, sizeof(struct net_device_stats));
225
226 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
229static __inline__ void
230lec_send(struct atm_vcc *vcc, struct sk_buff *skb, struct lec_priv *priv)
231{
232 ATM_SKB(skb)->vcc = vcc;
233 ATM_SKB(skb)->atm_options = vcc->atm_options;
234
235 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
236 if (vcc->send(vcc, skb) < 0) {
237 priv->stats.tx_dropped++;
238 return;
239 }
240
241 priv->stats.tx_packets++;
242 priv->stats.tx_bytes += skb->len;
243}
244
Chas Williamsd44f7742006-09-29 17:11:14 -0700245static void lec_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
247 printk(KERN_INFO "%s: tx timeout\n", dev->name);
248 dev->trans_start = jiffies;
249 netif_wake_queue(dev);
250}
251
Chas Williamsd44f7742006-09-29 17:11:14 -0700252static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
Chas Williamsd44f7742006-09-29 17:11:14 -0700254 struct sk_buff *skb2;
255 struct lec_priv *priv = (struct lec_priv *)dev->priv;
256 struct lecdatahdr_8023 *lec_h;
257 struct atm_vcc *vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700259 unsigned char *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 int min_frame_size;
261#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700262 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700264 int is_rdesc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700266 char buf[300];
267 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268#endif /* DUMP_PACKETS >0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Stephen Hemminger52240062007-08-28 15:22:09 -0700270 pr_debug("lec_start_xmit called\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700271 if (!priv->lecd) {
272 printk("%s:No lecd attached\n", dev->name);
273 priv->stats.tx_errors++;
274 netif_stop_queue(dev);
275 return -EUNATCH;
276 }
277
Stephen Hemminger52240062007-08-28 15:22:09 -0700278 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700279 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700280 (long)skb_end_pointer(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700282 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
283 lec_handle_bridge(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#endif
285
Chas Williamsd44f7742006-09-29 17:11:14 -0700286 /* Make sure we have room for lec_id */
287 if (skb_headroom(skb) < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Stephen Hemminger52240062007-08-28 15:22:09 -0700289 pr_debug("lec_start_xmit: reallocating skb\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700290 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
291 kfree_skb(skb);
292 if (skb2 == NULL)
293 return 0;
294 skb = skb2;
295 }
296 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Chas Williamsd44f7742006-09-29 17:11:14 -0700298 /* Put le header to place, works for TokenRing too */
299 lec_h = (struct lecdatahdr_8023 *)skb->data;
300 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700303 /*
304 * Ugly. Use this to realign Token Ring packets for
305 * e.g. PCA-200E driver.
306 */
307 if (priv->is_trdev) {
308 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
309 kfree_skb(skb);
310 if (skb2 == NULL)
311 return 0;
312 skb = skb2;
313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314#endif
315
316#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700317 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
318 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700320 for (i = 0; i < skb->len && i < 99; i++) {
321 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700324 for (i = 0; i < skb->len && i < 30; i++) {
325 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700328 if (i == skb->len)
329 printk("%s\n", buf);
330 else
331 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#endif /* DUMP_PACKETS > 0 */
333
Chas Williamsd44f7742006-09-29 17:11:14 -0700334 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700336 if (priv->is_trdev)
337 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 else
339#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700340 min_frame_size = LEC_MINIMUM_8023_SIZE;
341 if (skb->len < min_frame_size) {
342 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
343 skb2 = skb_copy_expand(skb, 0,
344 min_frame_size - skb->truesize,
345 GFP_ATOMIC);
346 dev_kfree_skb(skb);
347 if (skb2 == NULL) {
348 priv->stats.tx_dropped++;
349 return 0;
350 }
351 skb = skb2;
352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700354 }
355
356 /* Send to right vcc */
357 is_rdesc = 0;
358 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700360 if (priv->is_trdev) {
361 dst = get_tr_dst(skb->data + 2, rdesc);
362 if (dst == NULL) {
363 dst = rdesc;
364 is_rdesc = 1;
365 }
366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700368 entry = NULL;
369 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
Andrew Morton58c14a82007-09-26 22:31:19 -0700370 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700371 vcc, vcc ? vcc->flags : 0, entry);
372 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
373 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700374 pr_debug("%s:lec_start_xmit: queuing packet, ",
Chas Williamsd44f7742006-09-29 17:11:14 -0700375 dev->name);
David S. Miller21f644f2008-04-08 16:50:44 -0700376 pr_debug("MAC address " MAC_FMT "\n",
377 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]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700380 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);
David S. Miller21f644f2008-04-08 16:50:44 -0700385 pr_debug("MAC address " MAC_FMT "\n",
386 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]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700389 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, ");
David S. Miller21f644f2008-04-08 16:50:44 -0700400 pr_debug("MAC address " MAC_FMT "\n",
401 lec_h->h_dest[0], lec_h->h_dest[1],
402 lec_h->h_dest[2], lec_h->h_dest[3],
403 lec_h->h_dest[4], lec_h->h_dest[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 lec_send(vcc, skb2, priv);
Chas Williamsd44f7742006-09-29 17:11:14 -0700405 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407 lec_send(vcc, skb, priv);
408
409 if (!atm_may_send(vcc, 0)) {
410 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
411
412 vpriv->xoff = 1;
413 netif_stop_queue(dev);
414
415 /*
416 * vcc->pop() might have occurred in between, making
417 * the vcc usuable again. Since xmit is serialized,
418 * this is the only situation we have to re-test.
419 */
420
421 if (atm_may_send(vcc, 0))
422 netif_wake_queue(dev);
423 }
424
Chas Williams6656e3c2006-09-29 17:17:17 -0700425out:
426 if (entry)
427 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 dev->trans_start = jiffies;
Chas Williamsd44f7742006-09-29 17:11:14 -0700429 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
432/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700433static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
Chas Williamsd44f7742006-09-29 17:11:14 -0700435 netif_stop_queue(dev);
436 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438
439/*
440 * Get the current statistics.
441 * This may be called with the card open or closed.
442 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700443static struct net_device_stats *lec_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Chas Williamsd44f7742006-09-29 17:11:14 -0700445 return &((struct lec_priv *)dev->priv)->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
447
Chas Williamsd44f7742006-09-29 17:11:14 -0700448static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
450 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700451 struct net_device *dev = (struct net_device *)vcc->proto_data;
452 struct lec_priv *priv = (struct lec_priv *)dev->priv;
453 struct atmlec_msg *mesg;
454 struct lec_arp_table *entry;
455 int i;
456 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700459 mesg = (struct atmlec_msg *)skb->data;
460 tmp = skb->data;
461 tmp += sizeof(struct atmlec_msg);
Stephen Hemminger52240062007-08-28 15:22:09 -0700462 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700463 switch (mesg->type) {
464 case l_set_mac_addr:
465 for (i = 0; i < 6; i++) {
466 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
467 }
468 break;
469 case l_del_mac_addr:
470 for (i = 0; i < 6; i++) {
471 dev->dev_addr[i] = 0;
472 }
473 break;
474 case l_addr_delete:
475 lec_addr_delete(priv, mesg->content.normal.atm_addr,
476 mesg->content.normal.flag);
477 break;
478 case l_topology_change:
479 priv->topology_change = mesg->content.normal.flag;
480 break;
481 case l_flush_complete:
482 lec_flush_complete(priv, mesg->content.normal.flag);
483 break;
484 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700486 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
487 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
489
Chas Williamsd44f7742006-09-29 17:11:14 -0700490 if (mesg->content.normal.no_source_le_narp)
491 break;
492 /* FALL THROUGH */
493 case l_arp_update:
494 lec_arp_update(priv, mesg->content.normal.mac_addr,
495 mesg->content.normal.atm_addr,
496 mesg->content.normal.flag,
497 mesg->content.normal.targetless_le_arp);
Stephen Hemminger52240062007-08-28 15:22:09 -0700498 pr_debug("lec: in l_arp_update\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700499 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700500 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700501 mesg->sizeoftlvs);
502 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
503 tmp, mesg->sizeoftlvs);
504 }
505 break;
506 case l_config:
507 priv->maximum_unknown_frame_count =
508 mesg->content.config.maximum_unknown_frame_count;
509 priv->max_unknown_frame_time =
510 (mesg->content.config.max_unknown_frame_time * HZ);
511 priv->max_retry_count = mesg->content.config.max_retry_count;
512 priv->aging_time = (mesg->content.config.aging_time * HZ);
513 priv->forward_delay_time =
514 (mesg->content.config.forward_delay_time * HZ);
515 priv->arp_response_time =
516 (mesg->content.config.arp_response_time * HZ);
517 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
518 priv->path_switching_delay =
519 (mesg->content.config.path_switching_delay * HZ);
520 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 priv->lane2_ops = NULL;
522 if (priv->lane_version > 1)
523 priv->lane2_ops = &lane2_ops;
524 if (dev->change_mtu(dev, mesg->content.config.mtu))
525 printk("%s: change_mtu to %d failed\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700526 mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700528 break;
529 case l_flush_tran_id:
530 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
531 mesg->content.normal.flag);
532 break;
533 case l_set_lecid:
534 priv->lecid =
535 (unsigned short)(0xffff & mesg->content.normal.flag);
536 break;
537 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700539 {
540 struct net_bridge_fdb_entry *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Stephen Hemminger52240062007-08-28 15:22:09 -0700542 pr_debug
David S. Miller21f644f2008-04-08 16:50:44 -0700543 ("%s: bridge zeppelin asks about " MAC_FMT "\n",
Joe Perches0795af52007-10-03 17:59:30 -0700544 dev->name,
David S. Miller21f644f2008-04-08 16:50:44 -0700545 mesg->content.proxy.mac_addr[0],
546 mesg->content.proxy.mac_addr[1],
547 mesg->content.proxy.mac_addr[2],
548 mesg->content.proxy.mac_addr[3],
549 mesg->content.proxy.mac_addr[4],
550 mesg->content.proxy.mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Chas Williamsd44f7742006-09-29 17:11:14 -0700552 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
553 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Chas Williamsd44f7742006-09-29 17:11:14 -0700555 f = br_fdb_get_hook(dev->br_port->br,
556 mesg->content.proxy.mac_addr);
557 if (f != NULL && f->dst->dev != dev
558 && f->dst->state == BR_STATE_FORWARDING) {
559 /* hit from bridge table, send LE_ARP_RESPONSE */
560 struct sk_buff *skb2;
561 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Stephen Hemminger52240062007-08-28 15:22:09 -0700563 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700564 ("%s: entry found, responding to zeppelin\n",
565 dev->name);
566 skb2 =
567 alloc_skb(sizeof(struct atmlec_msg),
568 GFP_ATOMIC);
569 if (skb2 == NULL) {
570 br_fdb_put_hook(f);
571 break;
572 }
573 skb2->len = sizeof(struct atmlec_msg);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300574 skb_copy_to_linear_data(skb2, mesg,
575 sizeof(*mesg));
Chas Williamsd44f7742006-09-29 17:11:14 -0700576 atm_force_charge(priv->lecd, skb2->truesize);
577 sk = sk_atm(priv->lecd);
578 skb_queue_tail(&sk->sk_receive_queue, skb2);
579 sk->sk_data_ready(sk, skb2->len);
580 }
581 if (f != NULL)
582 br_fdb_put_hook(f);
583 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700585 break;
586 default:
587 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
588 dev_kfree_skb(skb);
589 return -EINVAL;
590 }
591 dev_kfree_skb(skb);
592 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593}
594
Chas Williamsd44f7742006-09-29 17:11:14 -0700595static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596{
Chas Williamsd44f7742006-09-29 17:11:14 -0700597 struct sk_buff *skb;
598 struct net_device *dev = (struct net_device *)vcc->proto_data;
599 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Chas Williamsd44f7742006-09-29 17:11:14 -0700601 priv->lecd = NULL;
602 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Chas Williamsd44f7742006-09-29 17:11:14 -0700604 netif_stop_queue(dev);
605 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Chas Williamsd44f7742006-09-29 17:11:14 -0700607 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700609 dev->name);
610 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
611 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700613 }
614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700616 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617}
618
619static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700620 .close = lec_atm_close,
621 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622};
623
624static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700625 .ops = &lecdev_ops,
626 .type = "lec",
627 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700628 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629};
630
631/*
632 * LANE2: new argument struct sk_buff *data contains
633 * the LE_ARP based TLVs introduced in the LANE2 spec
634 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700635static int
636send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
637 unsigned char *mac_addr, unsigned char *atm_addr,
638 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639{
640 struct sock *sk;
641 struct sk_buff *skb;
642 struct atmlec_msg *mesg;
643
644 if (!priv || !priv->lecd) {
645 return -1;
646 }
647 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
648 if (!skb)
649 return -1;
650 skb->len = sizeof(struct atmlec_msg);
651 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700652 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700654 if (data != NULL)
655 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 if (mac_addr)
657 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700658 else
659 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 if (atm_addr)
661 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
662
Chas Williamsd44f7742006-09-29 17:11:14 -0700663 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 sk = sk_atm(priv->lecd);
665 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700666 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Chas Williamsd44f7742006-09-29 17:11:14 -0700668 if (data != NULL) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700669 pr_debug("lec: about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700670 atm_force_charge(priv->lecd, data->truesize);
671 skb_queue_tail(&sk->sk_receive_queue, data);
672 sk->sk_data_ready(sk, skb->len);
673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Chas Williamsd44f7742006-09-29 17:11:14 -0700675 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676}
677
678/* shamelessly stolen from drivers/net/net_init.c */
679static int lec_change_mtu(struct net_device *dev, int new_mtu)
680{
Chas Williamsd44f7742006-09-29 17:11:14 -0700681 if ((new_mtu < 68) || (new_mtu > 18190))
682 return -EINVAL;
683 dev->mtu = new_mtu;
684 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685}
686
687static void lec_set_multicast_list(struct net_device *dev)
688{
Chas Williamsd44f7742006-09-29 17:11:14 -0700689 /*
690 * by default, all multicast frames arrive over the bus.
691 * eventually support selective multicast service
692 */
693 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694}
695
Chas Williamsd44f7742006-09-29 17:11:14 -0700696static void lec_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697{
Chas Williamsd44f7742006-09-29 17:11:14 -0700698 dev->change_mtu = lec_change_mtu;
699 dev->open = lec_open;
700 dev->stop = lec_close;
701 dev->hard_start_xmit = lec_start_xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 dev->tx_timeout = lec_tx_timeout;
703
Chas Williamsd44f7742006-09-29 17:11:14 -0700704 dev->get_stats = lec_get_stats;
705 dev->set_multicast_list = lec_set_multicast_list;
706 dev->do_ioctl = NULL;
707 printk("%s: Initialized!\n", dev->name);
708 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709}
710
711static unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700712 0xff,
713 0x00,
714 0x01,
715 0x01
716};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Scott Talbert4a7097f2005-09-29 17:30:54 -0700718#define LEC_DATA_DIRECT_8023 2
719#define LEC_DATA_DIRECT_8025 3
720
721static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700722{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700723 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
724 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700725}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700726
Chas Williamsd44f7742006-09-29 17:11:14 -0700727static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700729 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700730 struct net_device *dev = (struct net_device *)vcc->proto_data;
731 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733#if DUMP_PACKETS >0
Chas Williamsd44f7742006-09-29 17:11:14 -0700734 int i = 0;
735 char buf[300];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Chas Williamsd44f7742006-09-29 17:11:14 -0700737 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
738 vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700740 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700741 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700742 lec_vcc_close(priv, vcc);
743 return;
744 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700746 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
747 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700749 for (i = 0; i < skb->len && i < 99; i++) {
750 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
751 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700753 for (i = 0; i < skb->len && i < 30; i++) {
754 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
755 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700757 if (i == skb->len)
758 printk("%s\n", buf);
759 else
760 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700762 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 struct sock *sk = sk_atm(vcc);
764
Stephen Hemminger52240062007-08-28 15:22:09 -0700765 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700766 skb_queue_tail(&sk->sk_receive_queue, skb);
767 sk->sk_data_ready(sk, skb->len);
768 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700769 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700770 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Chas Williamsd44f7742006-09-29 17:11:14 -0700772 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800773 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700774 !priv->lecd || !(dev->flags & IFF_UP)) {
775 /*
776 * Probably looping back, or if lecd is missing,
777 * lecd has gone down
778 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700779 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700780 dev_kfree_skb(skb);
781 return;
782 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700784 if (priv->is_trdev)
785 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
786 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700788 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700789
Chas Williamsd44f7742006-09-29 17:11:14 -0700790 /*
791 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700792 * the LE_ARP cache entry, delete the LE_ARP cache entry.
793 */
794 spin_lock_irqsave(&priv->lec_arp_lock, flags);
795 if (lec_is_data_direct(vcc)) {
796#ifdef CONFIG_TR
797 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700798 src =
799 ((struct lecdatahdr_8025 *)skb->data)->
800 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700801 else
802#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700803 src =
804 ((struct lecdatahdr_8023 *)skb->data)->
805 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700806 entry = lec_arp_find(priv, src);
807 if (entry && entry->vcc != vcc) {
808 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700809 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700810 }
811 }
812 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Chas Williamsd44f7742006-09-29 17:11:14 -0700814 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
815 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700817 dev_kfree_skb(skb);
818 return;
819 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700820 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700821 lec_arp_check_empties(priv, vcc, skb);
822 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700823 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700825 if (priv->is_trdev)
826 skb->protocol = tr_type_trans(skb, dev);
827 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700829 skb->protocol = eth_type_trans(skb, dev);
830 priv->stats.rx_packets++;
831 priv->stats.rx_bytes += skb->len;
832 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
833 netif_rx(skb);
834 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835}
836
Chas Williamsd44f7742006-09-29 17:11:14 -0700837static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838{
839 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
840 struct net_device *dev = skb->dev;
841
842 if (vpriv == NULL) {
843 printk("lec_pop(): vpriv = NULL!?!?!?\n");
844 return;
845 }
846
847 vpriv->old_pop(vcc, skb);
848
849 if (vpriv->xoff && atm_may_send(vcc, 0)) {
850 vpriv->xoff = 0;
851 if (netif_running(dev) && netif_queue_stopped(dev))
852 netif_wake_queue(dev);
853 }
854}
855
Chas Williamsd44f7742006-09-29 17:11:14 -0700856static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
858 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700859 int bytes_left;
860 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Chas Williamsd44f7742006-09-29 17:11:14 -0700862 /* Lecd must be up in this case */
863 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
864 if (bytes_left != 0) {
865 printk
866 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
867 bytes_left);
868 }
869 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
870 !dev_lec[ioc_data.dev_num])
871 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
873 return -ENOMEM;
874 vpriv->xoff = 0;
875 vpriv->old_pop = vcc->pop;
876 vcc->user_back = vpriv;
877 vcc->pop = lec_pop;
Chas Williamsd44f7742006-09-29 17:11:14 -0700878 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
879 &ioc_data, vcc, vcc->push);
880 vcc->proto_data = dev_lec[ioc_data.dev_num];
881 vcc->push = lec_push;
882 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883}
884
Chas Williamsd44f7742006-09-29 17:11:14 -0700885static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886{
Chas Williamsd44f7742006-09-29 17:11:14 -0700887 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
888 return -EINVAL;
889 vcc->proto_data = dev_lec[arg];
890 return (lec_mcast_make((struct lec_priv *)dev_lec[arg]->priv, vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891}
892
893/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700894static int lecd_attach(struct atm_vcc *vcc, int arg)
895{
896 int i;
897 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Chas Williamsd44f7742006-09-29 17:11:14 -0700899 if (arg < 0)
900 i = 0;
901 else
902 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700904 if (arg >= MAX_LEC_ITF)
905 return -EINVAL;
906#else /* Reserve the top NUM_TR_DEVS for TR */
907 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
908 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700910 if (!dev_lec[i]) {
911 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Chas Williamsd44f7742006-09-29 17:11:14 -0700913 is_trdev = 0;
914 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
915 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Chas Williamsd44f7742006-09-29 17:11:14 -0700917 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700919 if (is_trdev)
920 dev_lec[i] = alloc_trdev(size);
921 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700923 dev_lec[i] = alloc_etherdev(size);
924 if (!dev_lec[i])
925 return -ENOMEM;
926 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
927 if (register_netdev(dev_lec[i])) {
928 free_netdev(dev_lec[i]);
929 return -EINVAL;
930 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
Chas Williamsd44f7742006-09-29 17:11:14 -0700932 priv = dev_lec[i]->priv;
933 priv->is_trdev = is_trdev;
934 lec_init(dev_lec[i]);
935 } else {
936 priv = dev_lec[i]->priv;
937 if (priv->lecd)
938 return -EADDRINUSE;
939 }
940 lec_arp_init(priv);
941 priv->itfnum = i; /* LANE2 addition */
942 priv->lecd = vcc;
943 vcc->dev = &lecatm_dev;
944 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Chas Williamsd44f7742006-09-29 17:11:14 -0700946 vcc->proto_data = dev_lec[i];
947 set_bit(ATM_VF_META, &vcc->flags);
948 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Chas Williamsd44f7742006-09-29 17:11:14 -0700950 /* Set default values to these variables */
951 priv->maximum_unknown_frame_count = 1;
952 priv->max_unknown_frame_time = (1 * HZ);
953 priv->vcc_timeout_period = (1200 * HZ);
954 priv->max_retry_count = 1;
955 priv->aging_time = (300 * HZ);
956 priv->forward_delay_time = (15 * HZ);
957 priv->topology_change = 0;
958 priv->arp_response_time = (1 * HZ);
959 priv->flush_timeout = (4 * HZ);
960 priv->path_switching_delay = (6 * HZ);
961
962 if (dev_lec[i]->flags & IFF_UP) {
963 netif_start_queue(dev_lec[i]);
964 }
965 __module_get(THIS_MODULE);
966 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967}
968
969#ifdef CONFIG_PROC_FS
Chas Williamsd44f7742006-09-29 17:11:14 -0700970static char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971{
972 static char *lec_arp_status_string[] = {
973 "ESI_UNKNOWN ",
974 "ESI_ARP_PENDING ",
975 "ESI_VC_PENDING ",
976 "<Undefined> ",
977 "ESI_FLUSH_PENDING ",
978 "ESI_FORWARD_DIRECT"
979 };
980
981 if (status > ESI_FORWARD_DIRECT)
982 status = 3; /* ESI_UNDEFINED */
983 return lec_arp_status_string[status];
984}
985
986static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
987{
988 int i;
989
990 for (i = 0; i < ETH_ALEN; i++)
991 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
992 seq_printf(seq, " ");
993 for (i = 0; i < ATM_ESA_LEN; i++)
994 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
995 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
996 entry->flags & 0xffff);
997 if (entry->vcc)
998 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
999 else
Chas Williamsd44f7742006-09-29 17:11:14 -07001000 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 if (entry->recv_vcc) {
1002 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
1003 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -07001004 }
1005 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006}
1007
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008struct lec_state {
1009 unsigned long flags;
1010 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -07001011 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 struct net_device *dev;
1013 int itf;
1014 int arp_table;
1015 int misc_table;
1016};
1017
Chas Williamsd0732f62006-09-29 17:14:27 -07001018static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 loff_t *l)
1020{
Chas Williamsd0732f62006-09-29 17:14:27 -07001021 struct hlist_node *e = state->node;
1022 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
1024 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -07001025 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 if (e == (void *)1) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001027 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 --*l;
1029 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001030
1031 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 if (--*l < 0)
1033 break;
1034 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001035 state->node = e;
1036
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 return (*l < 0) ? state : NULL;
1038}
1039
1040static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -07001041 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042{
1043 void *v = NULL;
1044 int p;
1045
1046 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001047 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 if (v)
1049 break;
1050 }
1051 state->arp_table = p;
1052 return v;
1053}
1054
1055static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1056 struct lec_priv *priv)
1057{
Chas Williamsd0732f62006-09-29 17:14:27 -07001058 struct hlist_head *lec_misc_tables[] = {
1059 &priv->lec_arp_empty_ones,
1060 &priv->lec_no_forward,
1061 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 };
1063 void *v = NULL;
1064 int q;
1065
1066 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1067 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1068 if (v)
1069 break;
1070 }
1071 state->misc_table = q;
1072 return v;
1073}
1074
1075static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1076 struct lec_priv *priv)
1077{
1078 if (!state->locked) {
1079 state->locked = priv;
1080 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1081 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001082 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1084 state->locked = NULL;
1085 /* Partial state reset for the next time we get called */
1086 state->arp_table = state->misc_table = 0;
1087 }
1088 return state->locked;
1089}
1090
1091static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1092{
1093 struct net_device *dev;
1094 void *v;
1095
1096 dev = state->dev ? state->dev : dev_lec[state->itf];
1097 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
1098 if (!v && dev) {
1099 dev_put(dev);
1100 /* Partial state reset for the next time we get called */
1101 dev = NULL;
1102 }
1103 state->dev = dev;
1104 return v;
1105}
1106
1107static void *lec_get_idx(struct lec_state *state, loff_t l)
1108{
1109 void *v = NULL;
1110
1111 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1112 v = lec_itf_walk(state, &l);
1113 if (v)
1114 break;
1115 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001116 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117}
1118
1119static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1120{
1121 struct lec_state *state = seq->private;
1122
1123 state->itf = 0;
1124 state->dev = NULL;
1125 state->locked = NULL;
1126 state->arp_table = 0;
1127 state->misc_table = 0;
Chas Williamsd0732f62006-09-29 17:14:27 -07001128 state->node = (void *)1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Chas Williamsd44f7742006-09-29 17:11:14 -07001130 return *pos ? lec_get_idx(state, *pos) : (void *)1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131}
1132
1133static void lec_seq_stop(struct seq_file *seq, void *v)
1134{
1135 struct lec_state *state = seq->private;
1136
1137 if (state->dev) {
1138 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1139 state->flags);
1140 dev_put(state->dev);
1141 }
1142}
1143
1144static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1145{
1146 struct lec_state *state = seq->private;
1147
1148 v = lec_get_idx(state, 1);
1149 *pos += !!PTR_ERR(v);
1150 return v;
1151}
1152
1153static int lec_seq_show(struct seq_file *seq, void *v)
1154{
Chas Williamsd44f7742006-09-29 17:11:14 -07001155 static char lec_banner[] = "Itf MAC ATM destination"
1156 " Status Flags "
1157 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
1159 if (v == (void *)1)
1160 seq_puts(seq, lec_banner);
1161 else {
1162 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001163 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001164 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
1166 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001167 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 }
1169 return 0;
1170}
1171
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001172static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001173 .start = lec_seq_start,
1174 .next = lec_seq_next,
1175 .stop = lec_seq_stop,
1176 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177};
1178
1179static int lec_seq_open(struct inode *inode, struct file *file)
1180{
1181 struct lec_state *state;
1182 struct seq_file *seq;
1183 int rc = -EAGAIN;
1184
1185 state = kmalloc(sizeof(*state), GFP_KERNEL);
1186 if (!state) {
1187 rc = -ENOMEM;
1188 goto out;
1189 }
1190
1191 rc = seq_open(file, &lec_seq_ops);
1192 if (rc)
1193 goto out_kfree;
1194 seq = file->private_data;
1195 seq->private = state;
1196out:
1197 return rc;
1198
1199out_kfree:
1200 kfree(state);
1201 goto out;
1202}
1203
1204static int lec_seq_release(struct inode *inode, struct file *file)
1205{
1206 return seq_release_private(inode, file);
1207}
1208
Arjan van de Ven9a321442007-02-12 00:55:35 -08001209static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001210 .owner = THIS_MODULE,
1211 .open = lec_seq_open,
1212 .read = seq_read,
1213 .llseek = seq_lseek,
1214 .release = lec_seq_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215};
1216#endif
1217
1218static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1219{
1220 struct atm_vcc *vcc = ATM_SD(sock);
1221 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001222
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001224 case ATMLEC_CTRL:
1225 case ATMLEC_MCAST:
1226 case ATMLEC_DATA:
1227 if (!capable(CAP_NET_ADMIN))
1228 return -EPERM;
1229 break;
1230 default:
1231 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 }
1233
1234 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001235 case ATMLEC_CTRL:
1236 err = lecd_attach(vcc, (int)arg);
1237 if (err >= 0)
1238 sock->state = SS_CONNECTED;
1239 break;
1240 case ATMLEC_MCAST:
1241 err = lec_mcast_attach(vcc, (int)arg);
1242 break;
1243 case ATMLEC_DATA:
1244 err = lec_vcc_attach(vcc, (void __user *)arg);
1245 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 }
1247
1248 return err;
1249}
1250
1251static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001252 .owner = THIS_MODULE,
1253 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254};
1255
1256static int __init lane_module_init(void)
1257{
1258#ifdef CONFIG_PROC_FS
1259 struct proc_dir_entry *p;
1260
Wang Chen16e297b2008-02-28 13:55:45 -08001261 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Wang Chendbee0d32008-03-23 21:45:36 -07001262 if (!p) {
1263 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n");
1264 return -ENOMEM;
1265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266#endif
1267
1268 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001269 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1270 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271}
1272
1273static void __exit lane_module_cleanup(void)
1274{
Chas Williamsd44f7742006-09-29 17:11:14 -07001275 int i;
1276 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
1278 remove_proc_entry("lec", atm_proc_root);
1279
1280 deregister_atm_ioctl(&lane_ioctl_ops);
1281
Chas Williamsd44f7742006-09-29 17:11:14 -07001282 for (i = 0; i < MAX_LEC_ITF; i++) {
1283 if (dev_lec[i] != NULL) {
1284 priv = (struct lec_priv *)dev_lec[i]->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001286 free_netdev(dev_lec[i]);
1287 dev_lec[i] = NULL;
1288 }
1289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Chas Williamsd44f7742006-09-29 17:11:14 -07001291 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292}
1293
1294module_init(lane_module_init);
1295module_exit(lane_module_cleanup);
1296
1297/*
1298 * LANE2: 3.1.3, LE_RESOLVE.request
1299 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1300 * If sizeoftlvs == NULL the default TLVs associated with with this
1301 * lec will be used.
1302 * If dst_mac == NULL, targetless LE_ARP will be sent
1303 */
1304static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001305 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306{
1307 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -07001308 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1309 struct lec_arp_table *table;
1310 struct sk_buff *skb;
1311 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
Chas Williamsd44f7742006-09-29 17:11:14 -07001313 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001315 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001317 if (table == NULL)
1318 return -1;
1319
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001320 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001321 if (*tlvs == NULL)
1322 return -1;
1323
Chas Williamsd44f7742006-09-29 17:11:14 -07001324 *sizeoftlvs = table->sizeoftlvs;
1325
1326 return 0;
1327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
1329 if (sizeoftlvs == NULL)
1330 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001331
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 else {
1333 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1334 if (skb == NULL)
1335 return -1;
1336 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001337 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1339 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001340 return retval;
1341}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
1343/*
1344 * LANE2: 3.1.4, LE_ASSOCIATE.request
1345 * Associate the *tlvs with the *lan_dst address.
1346 * Will overwrite any previous association
1347 * Returns 1 for success, 0 for failure (out of memory)
1348 *
1349 */
Chas Williamsd44f7742006-09-29 17:11:14 -07001350static int lane2_associate_req(struct net_device *dev, u8 *lan_dst,
1351 u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352{
Chas Williamsd44f7742006-09-29 17:11:14 -07001353 int retval;
1354 struct sk_buff *skb;
1355 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
Chas Williamsd44f7742006-09-29 17:11:14 -07001357 if (compare_ether_addr(lan_dst, dev->dev_addr))
1358 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
Chas Williamsd44f7742006-09-29 17:11:14 -07001360 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001362 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001363 if (priv->tlvs == NULL)
1364 return (0);
1365 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
Chas Williamsd44f7742006-09-29 17:11:14 -07001367 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1368 if (skb == NULL)
1369 return 0;
1370 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001371 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001372 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1373 if (retval != 0)
1374 printk("lec.c: lane2_associate_req() failed\n");
1375 /*
1376 * If the previous association has changed we must
1377 * somehow notify other LANE entities about the change
1378 */
1379 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380}
1381
1382/*
1383 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1384 *
1385 */
Chas Williamsd44f7742006-09-29 17:11:14 -07001386static void lane2_associate_ind(struct net_device *dev, u8 *mac_addr,
1387 u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388{
1389#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001390 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391#endif
1392 struct lec_priv *priv = (struct lec_priv *)dev->priv;
Chas Williamsd44f7742006-09-29 17:11:14 -07001393#if 0 /*
1394 * Why have the TLVs in LE_ARP entries
1395 * since we do not use them? When you
1396 * uncomment this code, make sure the
1397 * TLVs get freed when entry is killed
1398 */
1399 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Chas Williamsd44f7742006-09-29 17:11:14 -07001401 if (entry == NULL)
1402 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Chas Williamsd44f7742006-09-29 17:11:14 -07001404 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001406 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001407 if (entry->tlvs == NULL)
1408 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001409 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410#endif
1411#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001412 printk("lec.c: lane2_associate_ind()\n");
1413 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1414 while (i < sizeoftlvs)
1415 printk("%02x ", tlvs[i++]);
1416
1417 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418#endif
1419
Chas Williamsd44f7742006-09-29 17:11:14 -07001420 /* tell MPOA about the TLVs we saw */
1421 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1422 priv->lane2_ops->associate_indicator(dev, mac_addr,
1423 tlvs, sizeoftlvs);
1424 }
1425 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426}
1427
1428/*
1429 * Here starts what used to lec_arpc.c
1430 *
1431 * lec_arpc.c was added here when making
1432 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 */
1434
1435#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436#include <linux/timer.h>
1437#include <asm/param.h>
1438#include <asm/atomic.h>
1439#include <linux/inetdevice.h>
1440#include <net/route.h>
1441
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442#if 0
Stephen Hemminger52240062007-08-28 15:22:09 -07001443#define pr_debug(format,args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444/*
Stephen Hemminger52240062007-08-28 15:22:09 -07001445#define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446*/
1447#endif
1448#define DEBUG_ARP_TABLE 0
1449
1450#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1451
David Howellsc4028952006-11-22 14:57:56 +00001452static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453static void lec_arp_expire_arp(unsigned long data);
1454
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001455/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 * Arp table funcs
1457 */
1458
1459#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1460
1461/*
1462 * Initialization of arp-cache
1463 */
Chas Williams1fa99612006-09-29 17:11:47 -07001464static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465{
Chas Williams1fa99612006-09-29 17:11:47 -07001466 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Chas Williams1fa99612006-09-29 17:11:47 -07001468 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001469 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001470 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001471 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1472 INIT_HLIST_HEAD(&priv->lec_no_forward);
1473 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001475 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001476 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477}
1478
Chas Williams1fa99612006-09-29 17:11:47 -07001479static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480{
Chas Williams1fa99612006-09-29 17:11:47 -07001481 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 struct atm_vcc *vcc = entry->vcc;
1483 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001484 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
Chas Williams1fa99612006-09-29 17:11:47 -07001486 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 if (vpriv->xoff)
1488 netif_wake_queue(dev);
1489 kfree(vpriv);
1490 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001491 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001493 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001494 }
1495 if (entry->recv_vcc) {
1496 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001498 entry->recv_vcc = NULL;
1499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500}
1501
1502/*
1503 * Insert entry to lec_arp_table
1504 * LANE2: Add to the end of the list to satisfy 8.1.13
1505 */
Chas Williams1fa99612006-09-29 17:11:47 -07001506static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001507lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Chas Williamsd0732f62006-09-29 17:14:27 -07001509 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Chas Williamsd0732f62006-09-29 17:14:27 -07001511 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1512 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001513
Stephen Hemminger52240062007-08-28 15:22:09 -07001514 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 -07001515 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1516 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1517 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518}
1519
1520/*
1521 * Remove entry from lec_arp_table
1522 */
Chas Williams1fa99612006-09-29 17:11:47 -07001523static int
1524lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525{
Chas Williamsd0732f62006-09-29 17:14:27 -07001526 struct hlist_node *node;
1527 struct lec_arp_table *entry;
1528 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
Chas Williams1fa99612006-09-29 17:11:47 -07001530 if (!to_remove) {
1531 return -1;
1532 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001533
1534 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001535 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Chas Williamsd0732f62006-09-29 17:14:27 -07001537 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001538 if (to_remove->status >= ESI_FLUSH_PENDING) {
1539 /*
1540 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1541 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001542 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1543 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1544 if (memcmp(to_remove->atm_addr,
1545 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001546 remove_vcc = 0;
1547 break;
1548 }
1549 }
1550 }
1551 if (remove_vcc)
1552 lec_arp_clear_vccs(to_remove);
1553 }
1554 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1555
Stephen Hemminger52240062007-08-28 15:22:09 -07001556 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 -07001557 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1558 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1559 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1560 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561}
1562
1563#if DEBUG_ARP_TABLE
Chas Williams1fa99612006-09-29 17:11:47 -07001564static char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565{
Chas Williams1fa99612006-09-29 17:11:47 -07001566 switch (st) {
1567 case ESI_UNKNOWN:
1568 return "ESI_UNKNOWN";
1569 case ESI_ARP_PENDING:
1570 return "ESI_ARP_PENDING";
1571 case ESI_VC_PENDING:
1572 return "ESI_VC_PENDING";
1573 case ESI_FLUSH_PENDING:
1574 return "ESI_FLUSH_PENDING";
1575 case ESI_FORWARD_DIRECT:
1576 return "ESI_FORWARD_DIRECT";
1577 default:
1578 return "<UNKNOWN>";
1579 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Chas Williams1fa99612006-09-29 17:11:47 -07001582static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583{
Chas Williamsd0732f62006-09-29 17:14:27 -07001584 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001585 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001586 char buf[256];
1587 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
Chas Williams1fa99612006-09-29 17:11:47 -07001589 printk("Dump %p:\n", priv);
1590 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001591 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1592 offset = 0;
1593 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001594 offset += sprintf(buf + offset, "Mac:");
1595 for (j = 0; j < ETH_ALEN; j++) {
1596 offset += sprintf(buf + offset,
1597 "%2.2x ",
1598 rulla->mac_addr[j] & 0xff);
1599 }
1600 offset += sprintf(buf + offset, "Atm:");
1601 for (j = 0; j < ATM_ESA_LEN; j++) {
1602 offset += sprintf(buf + offset,
1603 "%2.2x ",
1604 rulla->atm_addr[j] & 0xff);
1605 }
1606 offset += sprintf(buf + offset,
1607 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1608 rulla->vcc ? rulla->vcc->vpi : 0,
1609 rulla->vcc ? rulla->vcc->vci : 0,
1610 rulla->recv_vcc ? rulla->recv_vcc->
1611 vpi : 0,
1612 rulla->recv_vcc ? rulla->recv_vcc->
1613 vci : 0, rulla->last_used,
1614 rulla->timestamp, rulla->no_tries);
1615 offset +=
1616 sprintf(buf + offset,
1617 "Flags:%x, Packets_flooded:%x, Status: %s ",
1618 rulla->flags, rulla->packets_flooded,
1619 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001620 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001621 }
Chas Williams1fa99612006-09-29 17:11:47 -07001622 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001623
1624 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001625 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001626 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001627 offset = 0;
1628 offset += sprintf(buf + offset, "Mac:");
1629 for (j = 0; j < ETH_ALEN; j++) {
1630 offset += sprintf(buf + offset, "%2.2x ",
1631 rulla->mac_addr[j] & 0xff);
1632 }
1633 offset += sprintf(buf + offset, "Atm:");
1634 for (j = 0; j < ATM_ESA_LEN; j++) {
1635 offset += sprintf(buf + offset, "%2.2x ",
1636 rulla->atm_addr[j] & 0xff);
1637 }
1638 offset += sprintf(buf + offset,
1639 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1640 rulla->vcc ? rulla->vcc->vpi : 0,
1641 rulla->vcc ? rulla->vcc->vci : 0,
1642 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1643 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1644 rulla->last_used,
1645 rulla->timestamp, rulla->no_tries);
1646 offset += sprintf(buf + offset,
1647 "Flags:%x, Packets_flooded:%x, Status: %s ",
1648 rulla->flags, rulla->packets_flooded,
1649 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001650 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001651 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001652
1653 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001654 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001655 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001656 offset = 0;
1657 offset += sprintf(buf + offset, "Mac:");
1658 for (j = 0; j < ETH_ALEN; j++) {
1659 offset += sprintf(buf + offset, "%2.2x ",
1660 rulla->mac_addr[j] & 0xff);
1661 }
1662 offset += sprintf(buf + offset, "Atm:");
1663 for (j = 0; j < ATM_ESA_LEN; j++) {
1664 offset += sprintf(buf + offset, "%2.2x ",
1665 rulla->atm_addr[j] & 0xff);
1666 }
1667 offset += sprintf(buf + offset,
1668 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1669 rulla->vcc ? rulla->vcc->vpi : 0,
1670 rulla->vcc ? rulla->vcc->vci : 0,
1671 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1672 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1673 rulla->last_used,
1674 rulla->timestamp, rulla->no_tries);
1675 offset += sprintf(buf + offset,
1676 "Flags:%x, Packets_flooded:%x, Status: %s ",
1677 rulla->flags, rulla->packets_flooded,
1678 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001679 printk("%s", buf);
1680 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
Chas Williamsd0732f62006-09-29 17:14:27 -07001682 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001683 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001684 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001685 offset = 0;
1686 offset += sprintf(buf + offset, "Mac:");
1687 for (j = 0; j < ETH_ALEN; j++) {
1688 offset += sprintf(buf + offset, "%2.2x ",
1689 rulla->mac_addr[j] & 0xff);
1690 }
1691 offset += sprintf(buf + offset, "Atm:");
1692 for (j = 0; j < ATM_ESA_LEN; j++) {
1693 offset += sprintf(buf + offset, "%2.2x ",
1694 rulla->atm_addr[j] & 0xff);
1695 }
1696 offset += sprintf(buf + offset,
1697 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1698 rulla->vcc ? rulla->vcc->vpi : 0,
1699 rulla->vcc ? rulla->vcc->vci : 0,
1700 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1701 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1702 rulla->last_used,
1703 rulla->timestamp, rulla->no_tries);
1704 offset += sprintf(buf + offset,
1705 "Flags:%x, Packets_flooded:%x, Status: %s ",
1706 rulla->flags, rulla->packets_flooded,
1707 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001708 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711}
Chas Williamsd0732f62006-09-29 17:14:27 -07001712#else
1713#define dump_arp_table(priv) do { } while (0)
1714#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
1716/*
1717 * Destruction of arp-cache
1718 */
Chas Williams1fa99612006-09-29 17:11:47 -07001719static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720{
1721 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001722 struct hlist_node *node, *next;
1723 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001724 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
Chas Williams987e46b2006-09-29 17:15:59 -07001726 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001727
1728 /*
1729 * Remove all entries
1730 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
1732 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001733 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001734 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001735 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001736 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001737 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001738 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001739 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001740
1741 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001742 del_timer_sync(&entry->timer);
1743 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001744 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001745 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001746 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001747 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1748
1749 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001750 del_timer_sync(&entry->timer);
1751 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001752 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001753 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001754 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001755 INIT_HLIST_HEAD(&priv->lec_no_forward);
1756
1757 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001758 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1759 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001760 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001761 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001762 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001763 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001764 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1766}
1767
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001768/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 * Find entry by mac_address
1770 */
Chas Williams1fa99612006-09-29 17:11:47 -07001771static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
1772 unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773{
Chas Williamsd0732f62006-09-29 17:14:27 -07001774 struct hlist_node *node;
1775 struct hlist_head *head;
1776 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
Stephen Hemminger52240062007-08-28 15:22:09 -07001778 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 -07001779 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1780 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
Chas Williams1fa99612006-09-29 17:11:47 -07001781
Chas Williamsd0732f62006-09-29 17:14:27 -07001782 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1783 hlist_for_each_entry(entry, node, head, next) {
1784 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1785 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001786 }
Chas Williams1fa99612006-09-29 17:11:47 -07001787 }
1788 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789}
1790
Chas Williams1fa99612006-09-29 17:11:47 -07001791static struct lec_arp_table *make_entry(struct lec_priv *priv,
1792 unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793{
Chas Williams1fa99612006-09-29 17:11:47 -07001794 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
Chas Williams1fa99612006-09-29 17:11:47 -07001796 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1797 if (!to_return) {
1798 printk("LEC: Arp entry kmalloc failed\n");
1799 return NULL;
1800 }
1801 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001802 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001803 setup_timer(&to_return->timer, lec_arp_expire_arp,
1804 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001805 to_return->last_used = jiffies;
1806 to_return->priv = priv;
1807 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001808 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001809 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810}
1811
Chas Williams1fa99612006-09-29 17:11:47 -07001812/* Arp sent timer expired */
1813static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814{
Chas Williams1fa99612006-09-29 17:11:47 -07001815 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
Chas Williams1fa99612006-09-29 17:11:47 -07001817 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
Stephen Hemminger52240062007-08-28 15:22:09 -07001819 pr_debug("lec_arp_expire_arp\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001820 if (entry->status == ESI_ARP_PENDING) {
1821 if (entry->no_tries <= entry->priv->max_retry_count) {
1822 if (entry->is_rdesc)
1823 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1824 entry->mac_addr, NULL, NULL);
1825 else
1826 send_to_lecd(entry->priv, l_arp_xmt,
1827 entry->mac_addr, NULL, NULL);
1828 entry->no_tries++;
1829 }
1830 mod_timer(&entry->timer, jiffies + (1 * HZ));
1831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832}
1833
Chas Williams1fa99612006-09-29 17:11:47 -07001834/* Unknown/unused vcc expire, remove associated entry */
1835static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836{
1837 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001838 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1839 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
Chas Williams1fa99612006-09-29 17:11:47 -07001841 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
Stephen Hemminger52240062007-08-28 15:22:09 -07001843 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001844 to_remove, priv,
1845 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1846 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
1848 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001849 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1851
Chas Williams1fa99612006-09-29 17:11:47 -07001852 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001853 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854}
1855
1856/*
1857 * Expire entries.
1858 * 1. Re-set timer
1859 * 2. For each entry, delete entries that have aged past the age limit.
1860 * 3. For each entry, depending on the status of the entry, perform
1861 * the following maintenance.
1862 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1863 * tick_count is above the max_unknown_frame_time, clear
1864 * the tick_count to zero and clear the packets_flooded counter
1865 * to zero. This supports the packet rate limit per address
1866 * while flooding unknowns.
1867 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1868 * than or equal to the path_switching_delay, change the status
1869 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1870 * regardless of the progress of the flush protocol.
1871 */
David Howellsc4028952006-11-22 14:57:56 +00001872static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873{
1874 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001875 struct lec_priv *priv =
1876 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001877 struct hlist_node *node, *next;
1878 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001879 unsigned long now;
1880 unsigned long time_to_check;
1881 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
Stephen Hemminger52240062007-08-28 15:22:09 -07001883 pr_debug("lec_arp_check_expire %p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001885restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001887 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001888 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001889 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 priv->topology_change)
1891 time_to_check = priv->forward_delay_time;
1892 else
1893 time_to_check = priv->aging_time;
1894
Stephen Hemminger52240062007-08-28 15:22:09 -07001895 pr_debug("About to expire: %lx - %lx > %lx\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001896 now, entry->last_used, time_to_check);
1897 if (time_after(now, entry->last_used + time_to_check)
1898 && !(entry->flags & LEC_PERMANENT_FLAG)
1899 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 /* Remove entry */
Stephen Hemminger52240062007-08-28 15:22:09 -07001901 pr_debug("LEC:Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001903 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 } else {
1905 /* Something else */
1906 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001907 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001909 entry->timestamp +
1910 priv->
1911 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 entry->timestamp = jiffies;
1913 entry->packets_flooded = 0;
1914 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001915 send_to_lecd(priv, l_svc_setup,
1916 entry->mac_addr,
1917 entry->atm_addr,
1918 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 }
Chas Williams1fa99612006-09-29 17:11:47 -07001920 if (entry->status == ESI_FLUSH_PENDING
1921 &&
1922 time_after_eq(now, entry->timestamp +
1923 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001925 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926
Chas Williams6656e3c2006-09-29 17:17:17 -07001927 lec_arp_hold(entry);
1928 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1929 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1930 lec_send(vcc, skb, entry->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001932 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001933 lec_arp_put(entry);
1934 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 }
1937 }
1938 }
1939 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1940
Chas Williams987e46b2006-09-29 17:15:59 -07001941 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942}
Chas Williams1fa99612006-09-29 17:11:47 -07001943
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944/*
1945 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001946 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 */
Chas Williams1fa99612006-09-29 17:11:47 -07001948static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1949 unsigned char *mac_to_find, int is_rdesc,
1950 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951{
1952 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001953 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 struct atm_vcc *found;
1955
Chas Williams1fa99612006-09-29 17:11:47 -07001956 if (mac_to_find[0] & 0x01) {
1957 switch (priv->lane_version) {
1958 case 1:
1959 return priv->mcast_vcc;
1960 break;
1961 case 2: /* LANE2 wants arp for multicast addresses */
1962 if (!compare_ether_addr(mac_to_find, bus_mac))
1963 return priv->mcast_vcc;
1964 break;
1965 default:
1966 break;
1967 }
1968 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969
1970 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001971 entry = lec_arp_find(priv, mac_to_find);
1972
1973 if (entry) {
1974 if (entry->status == ESI_FORWARD_DIRECT) {
1975 /* Connection Ok */
1976 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001977 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001978 *ret_entry = entry;
1979 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001981 }
1982 /*
1983 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001984 * so another LE_ARP request can be made for this frame.
1985 */
1986 if (entry->status == ESI_ARP_PENDING) {
1987 entry->no_tries = 0;
1988 }
Chas Williams1fa99612006-09-29 17:11:47 -07001989 /*
1990 * Data direct VC not yet set up, check to see if the unknown
1991 * frame count is greater than the limit. If the limit has
1992 * not been reached, allow the caller to send packet to
1993 * BUS.
1994 */
1995 if (entry->status != ESI_FLUSH_PENDING &&
1996 entry->packets_flooded <
1997 priv->maximum_unknown_frame_count) {
1998 entry->packets_flooded++;
Stephen Hemminger52240062007-08-28 15:22:09 -07001999 pr_debug("LEC_ARP: Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002000 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002002 }
2003 /*
2004 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 * or BUS flood limit was reached for an entry which is
2006 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
2007 */
Chas Williams6656e3c2006-09-29 17:17:17 -07002008 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002009 *ret_entry = entry;
Stephen Hemminger52240062007-08-28 15:22:09 -07002010 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
Chas Williams1fa99612006-09-29 17:11:47 -07002011 entry->vcc);
2012 found = NULL;
2013 } else {
2014 /* No matching entry was found */
2015 entry = make_entry(priv, mac_to_find);
Stephen Hemminger52240062007-08-28 15:22:09 -07002016 pr_debug("LEC_ARP: Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002017 if (!entry) {
2018 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002020 }
2021 lec_arp_add(priv, entry);
2022 /* We want arp-request(s) to be sent */
2023 entry->packets_flooded = 1;
2024 entry->status = ESI_ARP_PENDING;
2025 entry->no_tries = 1;
2026 entry->last_used = entry->timestamp = jiffies;
2027 entry->is_rdesc = is_rdesc;
2028 if (entry->is_rdesc)
2029 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
2030 NULL);
2031 else
2032 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
2033 entry->timer.expires = jiffies + (1 * HZ);
2034 entry->timer.function = lec_arp_expire_arp;
2035 add_timer(&entry->timer);
2036 found = priv->mcast_vcc;
2037 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038
2039out:
2040 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2041 return found;
2042}
2043
2044static int
Chas Williams1fa99612006-09-29 17:11:47 -07002045lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
2046 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047{
2048 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002049 struct hlist_node *node, *next;
2050 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002051 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052
Stephen Hemminger52240062007-08-28 15:22:09 -07002053 pr_debug("lec_addr_delete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002055 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002056 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002057 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2058 && (permanent ||
2059 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002061 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002062 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002064 return 0;
2065 }
2066 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002068 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069}
2070
2071/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002072 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 */
2074static void
2075lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07002076 unsigned char *atm_addr, unsigned long remoteflag,
2077 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078{
2079 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002080 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07002081 struct lec_arp_table *entry, *tmp;
2082 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
Stephen Hemminger52240062007-08-28 15:22:09 -07002084 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2085 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 -07002086 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2087 mac_addr[4], mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088
2089 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002090 entry = lec_arp_find(priv, mac_addr);
2091 if (entry == NULL && targetless_le_arp)
2092 goto out; /*
2093 * LANE2: ignore targetless LE_ARPs for which
2094 * we have no entry in the cache. 7.1.30
2095 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002096 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2097 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2098 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2099 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002100 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002101 tmp = lec_arp_find(priv, mac_addr);
2102 if (tmp) {
2103 del_timer(&tmp->timer);
2104 tmp->status = ESI_FORWARD_DIRECT;
2105 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2106 tmp->vcc = entry->vcc;
2107 tmp->old_push = entry->old_push;
2108 tmp->last_used = jiffies;
2109 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002110 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002111 entry = tmp;
2112 } else {
2113 entry->status = ESI_FORWARD_DIRECT;
2114 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2115 entry->last_used = jiffies;
2116 lec_arp_add(priv, entry);
2117 }
2118 if (remoteflag)
2119 entry->flags |= LEC_REMOTE_FLAG;
2120 else
2121 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002122 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002123 dump_arp_table(priv);
2124 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002125 }
Chas Williams1fa99612006-09-29 17:11:47 -07002126 }
2127 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002128
Chas Williams1fa99612006-09-29 17:11:47 -07002129 entry = lec_arp_find(priv, mac_addr);
2130 if (!entry) {
2131 entry = make_entry(priv, mac_addr);
2132 if (!entry)
2133 goto out;
2134 entry->status = ESI_UNKNOWN;
2135 lec_arp_add(priv, entry);
2136 /* Temporary, changes before end of function */
2137 }
2138 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2139 del_timer(&entry->timer);
2140 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002141 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002142 if (entry != tmp &&
2143 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2144 /* Vcc to this host exists */
2145 if (tmp->status > ESI_VC_PENDING) {
2146 /*
2147 * ESI_FLUSH_PENDING,
2148 * ESI_FORWARD_DIRECT
2149 */
2150 entry->vcc = tmp->vcc;
2151 entry->old_push = tmp->old_push;
2152 }
2153 entry->status = tmp->status;
2154 break;
2155 }
2156 }
2157 }
2158 if (remoteflag)
2159 entry->flags |= LEC_REMOTE_FLAG;
2160 else
2161 entry->flags &= ~LEC_REMOTE_FLAG;
2162 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2163 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002164 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002165 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002166 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002167 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168out:
2169 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2170}
2171
2172/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002173 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 */
2175static void
2176lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002177 struct atm_vcc *vcc,
2178 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179{
2180 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002181 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002182 struct lec_arp_table *entry;
2183 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
2185 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002186 if (ioc_data->receive == 2) {
2187 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
Stephen Hemminger52240062007-08-28 15:22:09 -07002189 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002191 entry = lec_arp_find(priv, bus_mac);
2192 if (!entry) {
2193 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002195 }
2196 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2197 entry->recv_vcc = vcc;
2198 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002200 entry = make_entry(priv, bus_mac);
2201 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002203 del_timer(&entry->timer);
2204 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2205 entry->recv_vcc = vcc;
2206 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002207 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002208 goto out;
2209 } else if (ioc_data->receive == 1) {
2210 /*
2211 * Vcc which we don't want to make default vcc,
2212 * attach it anyway.
2213 */
Stephen Hemminger52240062007-08-28 15:22:09 -07002214 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002215 ("LEC_ARP:Attaching data direct, not default: "
2216 "%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",
2217 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2218 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2219 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2220 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2221 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2222 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2223 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2224 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2225 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2226 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2227 entry = make_entry(priv, bus_mac);
2228 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002230 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2231 memset(entry->mac_addr, 0, ETH_ALEN);
2232 entry->recv_vcc = vcc;
2233 entry->old_recv_push = old_push;
2234 entry->status = ESI_UNKNOWN;
2235 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2236 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002237 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002238 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 dump_arp_table(priv);
2240 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002241 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002242 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002243 ("LEC_ARP:Attaching data direct, default: "
2244 "%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",
2245 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2246 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2247 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2248 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2249 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2250 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2251 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2252 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2253 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2254 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2255 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002256 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002257 if (memcmp
2258 (ioc_data->atm_addr, entry->atm_addr,
2259 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002260 pr_debug("LEC_ARP: Attaching data direct\n");
2261 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07002262 entry->vcc ? entry->vcc->vci : 0,
2263 entry->recv_vcc ? entry->recv_vcc->
2264 vci : 0);
2265 found_entry = 1;
2266 del_timer(&entry->timer);
2267 entry->vcc = vcc;
2268 entry->old_push = old_push;
2269 if (entry->status == ESI_VC_PENDING) {
2270 if (priv->maximum_unknown_frame_count
2271 == 0)
2272 entry->status =
2273 ESI_FORWARD_DIRECT;
2274 else {
2275 entry->timestamp = jiffies;
2276 entry->status =
2277 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002279 send_to_lecd(priv, l_flush_xmt,
2280 NULL,
2281 entry->atm_addr,
2282 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002284 }
2285 } else {
2286 /*
2287 * They were forming a connection
2288 * to us, and we to them. Our
2289 * ATM address is numerically lower
2290 * than theirs, so we make connection
2291 * we formed into default VCC (8.1.11).
2292 * Connection they made gets torn
2293 * down. This might confuse some
2294 * clients. Can be changed if
2295 * someone reports trouble...
2296 */
2297 ;
2298 }
2299 }
2300 }
2301 }
2302 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002303 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002304 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002306 }
2307 /*
2308 * Not found, snatch address from first data packet that arrives
2309 * from this vcc
2310 */
2311 entry = make_entry(priv, bus_mac);
2312 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002314 entry->vcc = vcc;
2315 entry->old_push = old_push;
2316 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2317 memset(entry->mac_addr, 0, ETH_ALEN);
2318 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002319 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002320 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2321 entry->timer.function = lec_arp_expire_vcc;
2322 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002323 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 dump_arp_table(priv);
2325out:
2326 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2327}
2328
Chas Williams1fa99612006-09-29 17:11:47 -07002329static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330{
2331 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002332 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002333 struct lec_arp_table *entry;
2334 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
Stephen Hemminger52240062007-08-28 15:22:09 -07002336 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002337restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002338 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2339 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002340 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002341 if (entry->flush_tran_id == tran_id
2342 && entry->status == ESI_FLUSH_PENDING) {
2343 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002344 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002345
Chas Williams6656e3c2006-09-29 17:17:17 -07002346 lec_arp_hold(entry);
2347 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2348 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2349 lec_send(vcc, skb, entry->priv);
2350 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002351 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002352 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002353 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002354 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002355 }
2356 }
2357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002359 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360}
2361
2362static void
2363lec_set_flush_tran_id(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002364 unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365{
2366 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002367 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002368 struct lec_arp_table *entry;
2369 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370
2371 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002372 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002373 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002374 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2375 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002376 pr_debug("Set flush transaction id to %lx for %p\n",
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002377 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002378 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002379 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2381}
2382
Chas Williams1fa99612006-09-29 17:11:47 -07002383static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384{
2385 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002386 unsigned char mac_addr[] = {
2387 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2388 };
2389 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 struct lec_vcc_priv *vpriv;
2391 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002392
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2394 return -ENOMEM;
2395 vpriv->xoff = 0;
2396 vpriv->old_pop = vcc->pop;
2397 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002398 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002400 to_add = make_entry(priv, mac_addr);
2401 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 vcc->pop = vpriv->old_pop;
2403 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002404 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002406 }
2407 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2408 to_add->status = ESI_FORWARD_DIRECT;
2409 to_add->flags |= LEC_PERMANENT_FLAG;
2410 to_add->vcc = vcc;
2411 to_add->old_push = vcc->push;
2412 vcc->push = lec_push;
2413 priv->mcast_vcc = vcc;
2414 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415out:
2416 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002417 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418}
2419
Chas Williams1fa99612006-09-29 17:11:47 -07002420static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421{
2422 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002423 struct hlist_node *node, *next;
2424 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002425 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426
Stephen Hemminger52240062007-08-28 15:22:09 -07002427 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002428 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002429
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002431
Chas Williams1fa99612006-09-29 17:11:47 -07002432 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002433 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002434 if (vcc == entry->vcc) {
2435 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002436 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002437 if (priv->mcast_vcc == vcc) {
2438 priv->mcast_vcc = NULL;
2439 }
2440 }
2441 }
2442 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443
Chas Williamsd0732f62006-09-29 17:14:27 -07002444 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2445 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002446 lec_arp_clear_vccs(entry);
2447 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002448 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002449 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002450 }
Chas Williams1fa99612006-09-29 17:11:47 -07002451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452
Chas Williamsd0732f62006-09-29 17:14:27 -07002453 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002454 if (entry->recv_vcc == vcc) {
2455 lec_arp_clear_vccs(entry);
2456 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002457 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002458 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002459 }
Chas Williams1fa99612006-09-29 17:11:47 -07002460 }
2461
Chas Williamsd0732f62006-09-29 17:14:27 -07002462 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002463 if (entry->recv_vcc == vcc) {
2464 lec_arp_clear_vccs(entry);
2465 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002466 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002467 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002468 }
Chas Williams1fa99612006-09-29 17:11:47 -07002469 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470
2471 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2472 dump_arp_table(priv);
2473}
2474
2475static void
2476lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002477 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478{
Chas Williams1fa99612006-09-29 17:11:47 -07002479 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002480 struct hlist_node *node, *next;
2481 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002482 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2483 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002485 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
Chas Williams1fa99612006-09-29 17:11:47 -07002487 if (priv->is_trdev)
2488 src = tr_hdr->h_source;
2489 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002491 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
2493 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002494 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2495 if (vcc == entry->vcc) {
2496 del_timer(&entry->timer);
2497 memcpy(entry->mac_addr, src, ETH_ALEN);
2498 entry->status = ESI_FORWARD_DIRECT;
2499 entry->last_used = jiffies;
2500 /* We might have got an entry */
2501 if ((tmp = lec_arp_find(priv, src))) {
2502 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002503 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002504 }
2505 hlist_del(&entry->next);
2506 lec_arp_add(priv, entry);
2507 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002508 }
Chas Williams1fa99612006-09-29 17:11:47 -07002509 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002510 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511out:
2512 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2513}
Chas Williams1fa99612006-09-29 17:11:47 -07002514
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515MODULE_LICENSE("GPL");