blob: b2d644560323c945da9019cdba493212d9dd20e9 [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)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include "../bridge/br_private.h"
38
Chas Williamsd44f7742006-09-29 17:11:14 -070039static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#endif
41
42/* Modular too */
43#include <linux/module.h>
44#include <linux/init.h>
45
46#include "lec.h"
47#include "lec_arpc.h"
48#include "resources.h"
49
Chas Williamsd44f7742006-09-29 17:11:14 -070050#define DUMP_PACKETS 0 /*
51 * 0 = None,
52 * 1 = 30 first bytes
53 * 2 = Whole packet
54 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Chas Williamsd44f7742006-09-29 17:11:14 -070056#define LEC_UNRES_QUE_LEN 8 /*
57 * number of tx packets to queue for a
58 * single destination while waiting for SVC
59 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61static int lec_open(struct net_device *dev);
Stephen Hemminger3c805a22009-08-31 19:50:42 +000062static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
63 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static int lec_close(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065static void lec_init(struct net_device *dev);
Chas Williamsd44f7742006-09-29 17:11:14 -070066static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070067 const unsigned char *mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068static int lec_arp_remove(struct lec_priv *priv,
Chas Williamsd44f7742006-09-29 17:11:14 -070069 struct lec_arp_table *to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070/* LANE2 functions */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070071static void lane2_associate_ind(struct net_device *dev, const u8 *mac_address,
72 const u8 *tlvs, u32 sizeoftlvs);
73static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -070074 u8 **tlvs, u32 *sizeoftlvs);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070075static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
76 const u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070078static int lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 unsigned long permanent);
80static void lec_arp_check_empties(struct lec_priv *priv,
81 struct atm_vcc *vcc, struct sk_buff *skb);
82static void lec_arp_destroy(struct lec_priv *priv);
83static void lec_arp_init(struct lec_priv *priv);
Chas Williamsd44f7742006-09-29 17:11:14 -070084static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070085 const unsigned char *mac_to_find,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 int is_rdesc,
87 struct lec_arp_table **ret_entry);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070088static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
89 const unsigned char *atm_addr, unsigned long remoteflag,
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 unsigned int targetless_le_arp);
91static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
92static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
93static void lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070094 const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 unsigned long tran_id);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070096static void lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 struct atm_vcc *vcc,
Chas Williamsd44f7742006-09-29 17:11:14 -070098 void (*old_push) (struct atm_vcc *vcc,
99 struct sk_buff *skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
101
Chas Williams33a9c2d2006-09-29 17:16:48 -0700102/* must be done under lec_arp_lock */
103static inline void lec_arp_hold(struct lec_arp_table *entry)
104{
105 atomic_inc(&entry->usage);
106}
107
108static inline void lec_arp_put(struct lec_arp_table *entry)
109{
110 if (atomic_dec_and_test(&entry->usage))
111 kfree(entry);
112}
113
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115static struct lane2_ops lane2_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700116 lane2_resolve, /* resolve, spec 3.1.3 */
117 lane2_associate_req, /* associate_req, spec 3.1.4 */
118 NULL /* associate indicator, spec 3.1.5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119};
120
Chas Williamsd44f7742006-09-29 17:11:14 -0700121static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123/* Device structures */
124static struct net_device *dev_lec[MAX_LEC_ITF];
125
126#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
127static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
128{
Chas Williamsd44f7742006-09-29 17:11:14 -0700129 struct ethhdr *eth;
130 char *buff;
131 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Chas Williamsd44f7742006-09-29 17:11:14 -0700133 /*
134 * Check if this is a BPDU. If so, ask zeppelin to send
135 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
136 * as the Config BPDU has
137 */
138 eth = (struct ethhdr *)skb->data;
139 buff = skb->data + skb->dev->hard_header_len;
140 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 struct sock *sk;
Chas Williamsd44f7742006-09-29 17:11:14 -0700142 struct sk_buff *skb2;
143 struct atmlec_msg *mesg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Chas Williamsd44f7742006-09-29 17:11:14 -0700145 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
146 if (skb2 == NULL)
147 return;
148 skb2->len = sizeof(struct atmlec_msg);
149 mesg = (struct atmlec_msg *)skb2->data;
150 mesg->type = l_topology_change;
151 buff += 4;
152 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Wang Chen524ad0a2008-11-12 23:39:10 -0800154 priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700155 atm_force_charge(priv->lecd, skb2->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 sk = sk_atm(priv->lecd);
Chas Williamsd44f7742006-09-29 17:11:14 -0700157 skb_queue_tail(&sk->sk_receive_queue, skb2);
158 sk->sk_data_ready(sk, skb2->len);
159 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Chas Williamsd44f7742006-09-29 17:11:14 -0700161 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
164
165/*
166 * Modelled after tr_type_trans
167 * All multicast and ARE or STE frames go to BUS.
168 * Non source routed frames go by destination address.
169 * Last hop source routed frames go by destination address.
170 * Not last hop source routed frames go by _next_ route descriptor.
171 * Returns pointer to destination MAC address or fills in rdesc
172 * and returns NULL.
173 */
174#ifdef CONFIG_TR
175static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
176{
Chas Williamsd44f7742006-09-29 17:11:14 -0700177 struct trh_hdr *trh;
Eric Dumazet5c17d5f2008-01-15 03:29:50 -0800178 unsigned int riflen, num_rdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Chas Williamsd44f7742006-09-29 17:11:14 -0700180 trh = (struct trh_hdr *)packet;
181 if (trh->daddr[0] & (uint8_t) 0x80)
182 return bus_mac; /* multicast */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Chas Williamsd44f7742006-09-29 17:11:14 -0700184 if (trh->saddr[0] & TR_RII) {
185 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
186 if ((ntohs(trh->rcf) >> 13) != 0)
187 return bus_mac; /* ARE or STE */
188 } else
189 return trh->daddr; /* not source routed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Chas Williamsd44f7742006-09-29 17:11:14 -0700191 if (riflen < 6)
192 return trh->daddr; /* last hop, source routed */
193
194 /* riflen is 6 or more, packet has more than one route descriptor */
195 num_rdsc = (riflen / 2) - 1;
196 memset(rdesc, 0, ETH_ALEN);
197 /* offset 4 comes from LAN destination field in LE control frames */
198 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
Al Viro30d492d2006-11-14 21:11:29 -0800199 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700200 else {
Al Viro30d492d2006-11-14 21:11:29 -0800201 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700202 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
203 }
204
205 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206}
207#endif /* CONFIG_TR */
208
209/*
210 * Open/initialize the netdevice. This is called (in the current kernel)
211 * sometime after booting when the 'ifconfig' program is run.
212 *
213 * This routine should set everything up anew at each open, even
214 * registers that "should" only need to be set once at boot, so that
215 * there is non-reboot way to recover if something goes wrong.
216 */
217
Chas Williamsd44f7742006-09-29 17:11:14 -0700218static int lec_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 netif_start_queue(dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000221 memset(&dev->stats, 0, sizeof(struct net_device_stats));
Chas Williamsd44f7742006-09-29 17:11:14 -0700222
223 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224}
225
Stephen Hemminger162619e2009-01-09 13:01:01 +0000226static void
227lec_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
Stephen Hemminger162619e2009-01-09 13:01:01 +0000229 struct net_device *dev = skb->dev;
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 ATM_SKB(skb)->vcc = vcc;
232 ATM_SKB(skb)->atm_options = vcc->atm_options;
233
234 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
235 if (vcc->send(vcc, skb) < 0) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000236 dev->stats.tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 return;
238 }
239
Stephen Hemminger162619e2009-01-09 13:01:01 +0000240 dev->stats.tx_packets++;
241 dev->stats.tx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242}
243
Chas Williamsd44f7742006-09-29 17:11:14 -0700244static void lec_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
246 printk(KERN_INFO "%s: tx timeout\n", dev->name);
247 dev->trans_start = jiffies;
248 netif_wake_queue(dev);
249}
250
Stephen Hemminger3c805a22009-08-31 19:50:42 +0000251static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
252 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
Chas Williamsd44f7742006-09-29 17:11:14 -0700254 struct sk_buff *skb2;
Wang Chen524ad0a2008-11-12 23:39:10 -0800255 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700256 struct lecdatahdr_8023 *lec_h;
257 struct atm_vcc *vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700259 unsigned char *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 int min_frame_size;
261#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700262 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700264 int is_rdesc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700266 char buf[300];
267 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268#endif /* DUMP_PACKETS >0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Stephen Hemminger52240062007-08-28 15:22:09 -0700270 pr_debug("lec_start_xmit called\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700271 if (!priv->lecd) {
272 printk("%s:No lecd attached\n", dev->name);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000273 dev->stats.tx_errors++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700274 netif_stop_queue(dev);
Patrick McHardy81fbbf62009-06-12 05:34:37 +0000275 kfree_skb(skb);
276 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700277 }
278
Stephen Hemminger52240062007-08-28 15:22:09 -0700279 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700280 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700281 (long)skb_end_pointer(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700283 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
284 lec_handle_bridge(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285#endif
286
Chas Williamsd44f7742006-09-29 17:11:14 -0700287 /* Make sure we have room for lec_id */
288 if (skb_headroom(skb) < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Stephen Hemminger52240062007-08-28 15:22:09 -0700290 pr_debug("lec_start_xmit: reallocating skb\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700291 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
292 kfree_skb(skb);
293 if (skb2 == NULL)
Patrick McHardy6ed10652009-06-23 06:03:08 +0000294 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700295 skb = skb2;
296 }
297 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Chas Williamsd44f7742006-09-29 17:11:14 -0700299 /* Put le header to place, works for TokenRing too */
300 lec_h = (struct lecdatahdr_8023 *)skb->data;
301 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700304 /*
305 * Ugly. Use this to realign Token Ring packets for
306 * e.g. PCA-200E driver.
307 */
308 if (priv->is_trdev) {
309 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
310 kfree_skb(skb);
311 if (skb2 == NULL)
Patrick McHardy6ed10652009-06-23 06:03:08 +0000312 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700313 skb = skb2;
314 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#endif
316
317#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700318 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
319 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700321 for (i = 0; i < skb->len && i < 99; i++) {
322 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700325 for (i = 0; i < skb->len && i < 30; i++) {
326 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700329 if (i == skb->len)
330 printk("%s\n", buf);
331 else
332 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333#endif /* DUMP_PACKETS > 0 */
334
Chas Williamsd44f7742006-09-29 17:11:14 -0700335 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700337 if (priv->is_trdev)
338 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 else
340#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700341 min_frame_size = LEC_MINIMUM_8023_SIZE;
342 if (skb->len < min_frame_size) {
343 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
344 skb2 = skb_copy_expand(skb, 0,
345 min_frame_size - skb->truesize,
346 GFP_ATOMIC);
347 dev_kfree_skb(skb);
348 if (skb2 == NULL) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000349 dev->stats.tx_dropped++;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000350 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700351 }
352 skb = skb2;
353 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700355 }
356
357 /* Send to right vcc */
358 is_rdesc = 0;
359 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700361 if (priv->is_trdev) {
362 dst = get_tr_dst(skb->data + 2, rdesc);
363 if (dst == NULL) {
364 dst = rdesc;
365 is_rdesc = 1;
366 }
367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700369 entry = NULL;
370 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
Andrew Morton58c14a82007-09-26 22:31:19 -0700371 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700372 vcc, vcc ? vcc->flags : 0, entry);
373 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
374 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700375 pr_debug("%s:lec_start_xmit: queuing packet, ",
Chas Williamsd44f7742006-09-29 17:11:14 -0700376 dev->name);
Johannes Berge1749612008-10-27 15:59:26 -0700377 pr_debug("MAC address %pM\n", lec_h->h_dest);
Chas Williamsd44f7742006-09-29 17:11:14 -0700378 skb_queue_tail(&entry->tx_wait, skb);
379 } else {
Stephen Hemminger52240062007-08-28 15:22:09 -0700380 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700381 ("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ",
382 dev->name);
Johannes Berge1749612008-10-27 15:59:26 -0700383 pr_debug("MAC address %pM\n", lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000384 dev->stats.tx_dropped++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700385 dev_kfree_skb(skb);
386 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700387 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700388 }
389#if DUMP_PACKETS > 0
390 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700392
393 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700394 pr_debug("lec.c: emptying tx queue, ");
Johannes Berge1749612008-10-27 15:59:26 -0700395 pr_debug("MAC address %pM\n", lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000396 lec_send(vcc, skb2);
Chas Williamsd44f7742006-09-29 17:11:14 -0700397 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Stephen Hemminger162619e2009-01-09 13:01:01 +0000399 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
401 if (!atm_may_send(vcc, 0)) {
402 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
403
404 vpriv->xoff = 1;
405 netif_stop_queue(dev);
406
407 /*
408 * vcc->pop() might have occurred in between, making
409 * the vcc usuable again. Since xmit is serialized,
410 * this is the only situation we have to re-test.
411 */
412
413 if (atm_may_send(vcc, 0))
414 netif_wake_queue(dev);
415 }
416
Chas Williams6656e3c2006-09-29 17:17:17 -0700417out:
418 if (entry)
419 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 dev->trans_start = jiffies;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000421 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
423
424/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700425static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426{
Chas Williamsd44f7742006-09-29 17:11:14 -0700427 netif_stop_queue(dev);
428 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429}
430
Chas Williamsd44f7742006-09-29 17:11:14 -0700431static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
433 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700434 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800435 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700436 struct atmlec_msg *mesg;
437 struct lec_arp_table *entry;
438 int i;
439 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700442 mesg = (struct atmlec_msg *)skb->data;
443 tmp = skb->data;
444 tmp += sizeof(struct atmlec_msg);
Stephen Hemminger52240062007-08-28 15:22:09 -0700445 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700446 switch (mesg->type) {
447 case l_set_mac_addr:
448 for (i = 0; i < 6; i++) {
449 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
450 }
451 break;
452 case l_del_mac_addr:
453 for (i = 0; i < 6; i++) {
454 dev->dev_addr[i] = 0;
455 }
456 break;
457 case l_addr_delete:
458 lec_addr_delete(priv, mesg->content.normal.atm_addr,
459 mesg->content.normal.flag);
460 break;
461 case l_topology_change:
462 priv->topology_change = mesg->content.normal.flag;
463 break;
464 case l_flush_complete:
465 lec_flush_complete(priv, mesg->content.normal.flag);
466 break;
467 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700469 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
470 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
472
Chas Williamsd44f7742006-09-29 17:11:14 -0700473 if (mesg->content.normal.no_source_le_narp)
474 break;
475 /* FALL THROUGH */
476 case l_arp_update:
477 lec_arp_update(priv, mesg->content.normal.mac_addr,
478 mesg->content.normal.atm_addr,
479 mesg->content.normal.flag,
480 mesg->content.normal.targetless_le_arp);
Stephen Hemminger52240062007-08-28 15:22:09 -0700481 pr_debug("lec: in l_arp_update\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700482 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700483 pr_debug("lec: LANE2 3.1.5, got tlvs, size %d\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700484 mesg->sizeoftlvs);
485 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
486 tmp, mesg->sizeoftlvs);
487 }
488 break;
489 case l_config:
490 priv->maximum_unknown_frame_count =
491 mesg->content.config.maximum_unknown_frame_count;
492 priv->max_unknown_frame_time =
493 (mesg->content.config.max_unknown_frame_time * HZ);
494 priv->max_retry_count = mesg->content.config.max_retry_count;
495 priv->aging_time = (mesg->content.config.aging_time * HZ);
496 priv->forward_delay_time =
497 (mesg->content.config.forward_delay_time * HZ);
498 priv->arp_response_time =
499 (mesg->content.config.arp_response_time * HZ);
500 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
501 priv->path_switching_delay =
502 (mesg->content.config.path_switching_delay * HZ);
503 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 priv->lane2_ops = NULL;
505 if (priv->lane_version > 1)
506 priv->lane2_ops = &lane2_ops;
Stephen Hemminger1f1900f2009-03-21 13:37:28 -0700507 if (dev_set_mtu(dev, mesg->content.config.mtu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 printk("%s: change_mtu to %d failed\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700509 mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700511 break;
512 case l_flush_tran_id:
513 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
514 mesg->content.normal.flag);
515 break;
516 case l_set_lecid:
517 priv->lecid =
518 (unsigned short)(0xffff & mesg->content.normal.flag);
519 break;
520 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700522 {
Johannes Berge1749612008-10-27 15:59:26 -0700523 pr_debug("%s: bridge zeppelin asks about %pM\n",
524 dev->name, mesg->content.proxy.mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Michał Mirosławda678292009-06-05 05:35:28 +0000526 if (br_fdb_test_addr_hook == NULL)
Chas Williamsd44f7742006-09-29 17:11:14 -0700527 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Michał Mirosławda678292009-06-05 05:35:28 +0000529 if (br_fdb_test_addr_hook(dev,
530 mesg->content.proxy.mac_addr)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700531 /* hit from bridge table, send LE_ARP_RESPONSE */
532 struct sk_buff *skb2;
533 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Stephen Hemminger52240062007-08-28 15:22:09 -0700535 pr_debug
Chas Williamsd44f7742006-09-29 17:11:14 -0700536 ("%s: entry found, responding to zeppelin\n",
537 dev->name);
538 skb2 =
539 alloc_skb(sizeof(struct atmlec_msg),
540 GFP_ATOMIC);
Michał Mirosławda678292009-06-05 05:35:28 +0000541 if (skb2 == NULL)
Chas Williamsd44f7742006-09-29 17:11:14 -0700542 break;
Chas Williamsd44f7742006-09-29 17:11:14 -0700543 skb2->len = sizeof(struct atmlec_msg);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300544 skb_copy_to_linear_data(skb2, mesg,
545 sizeof(*mesg));
Chas Williamsd44f7742006-09-29 17:11:14 -0700546 atm_force_charge(priv->lecd, skb2->truesize);
547 sk = sk_atm(priv->lecd);
548 skb_queue_tail(&sk->sk_receive_queue, skb2);
549 sk->sk_data_ready(sk, skb2->len);
550 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700551 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700553 break;
554 default:
555 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
556 dev_kfree_skb(skb);
557 return -EINVAL;
558 }
559 dev_kfree_skb(skb);
560 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561}
562
Chas Williamsd44f7742006-09-29 17:11:14 -0700563static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Chas Williamsd44f7742006-09-29 17:11:14 -0700565 struct sk_buff *skb;
566 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800567 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Chas Williamsd44f7742006-09-29 17:11:14 -0700569 priv->lecd = NULL;
570 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
Chas Williamsd44f7742006-09-29 17:11:14 -0700572 netif_stop_queue(dev);
573 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Chas Williamsd44f7742006-09-29 17:11:14 -0700575 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700577 dev->name);
578 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
579 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700581 }
582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700584 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585}
586
587static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700588 .close = lec_atm_close,
589 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590};
591
592static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700593 .ops = &lecdev_ops,
594 .type = "lec",
595 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700596 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597};
598
599/*
600 * LANE2: new argument struct sk_buff *data contains
601 * the LE_ARP based TLVs introduced in the LANE2 spec
602 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700603static int
604send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700605 const unsigned char *mac_addr, const unsigned char *atm_addr,
Chas Williamsd44f7742006-09-29 17:11:14 -0700606 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
608 struct sock *sk;
609 struct sk_buff *skb;
610 struct atmlec_msg *mesg;
611
612 if (!priv || !priv->lecd) {
613 return -1;
614 }
615 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
616 if (!skb)
617 return -1;
618 skb->len = sizeof(struct atmlec_msg);
619 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700620 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700622 if (data != NULL)
623 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 if (mac_addr)
625 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700626 else
627 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 if (atm_addr)
629 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
630
Chas Williamsd44f7742006-09-29 17:11:14 -0700631 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 sk = sk_atm(priv->lecd);
633 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700634 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Chas Williamsd44f7742006-09-29 17:11:14 -0700636 if (data != NULL) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700637 pr_debug("lec: about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700638 atm_force_charge(priv->lecd, data->truesize);
639 skb_queue_tail(&sk->sk_receive_queue, data);
640 sk->sk_data_ready(sk, skb->len);
641 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Chas Williamsd44f7742006-09-29 17:11:14 -0700643 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644}
645
646/* shamelessly stolen from drivers/net/net_init.c */
647static int lec_change_mtu(struct net_device *dev, int new_mtu)
648{
Chas Williamsd44f7742006-09-29 17:11:14 -0700649 if ((new_mtu < 68) || (new_mtu > 18190))
650 return -EINVAL;
651 dev->mtu = new_mtu;
652 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653}
654
655static void lec_set_multicast_list(struct net_device *dev)
656{
Chas Williamsd44f7742006-09-29 17:11:14 -0700657 /*
658 * by default, all multicast frames arrive over the bus.
659 * eventually support selective multicast service
660 */
661 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662}
663
Stephen Hemminger004b3222009-01-09 13:01:02 +0000664static const struct net_device_ops lec_netdev_ops = {
665 .ndo_open = lec_open,
666 .ndo_stop = lec_close,
667 .ndo_start_xmit = lec_start_xmit,
668 .ndo_change_mtu = lec_change_mtu,
669 .ndo_tx_timeout = lec_tx_timeout,
670 .ndo_set_multicast_list = lec_set_multicast_list,
671};
672
673
Chas Williamsd44f7742006-09-29 17:11:14 -0700674static void lec_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675{
Stephen Hemminger004b3222009-01-09 13:01:02 +0000676 dev->netdev_ops = &lec_netdev_ops;
Chas Williamsd44f7742006-09-29 17:11:14 -0700677 printk("%s: Initialized!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700680static const unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700681 0xff,
682 0x00,
683 0x01,
684 0x01
685};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Scott Talbert4a7097f2005-09-29 17:30:54 -0700687#define LEC_DATA_DIRECT_8023 2
688#define LEC_DATA_DIRECT_8025 3
689
690static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700691{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700692 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
693 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700694}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700695
Chas Williamsd44f7742006-09-29 17:11:14 -0700696static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700698 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700699 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800700 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
702#if DUMP_PACKETS >0
Chas Williamsd44f7742006-09-29 17:11:14 -0700703 int i = 0;
704 char buf[300];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Chas Williamsd44f7742006-09-29 17:11:14 -0700706 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
707 vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700709 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700710 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700711 lec_vcc_close(priv, vcc);
712 return;
713 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700715 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
716 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700718 for (i = 0; i < skb->len && i < 99; i++) {
719 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
720 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700722 for (i = 0; i < skb->len && i < 30; i++) {
723 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
724 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700726 if (i == skb->len)
727 printk("%s\n", buf);
728 else
729 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700731 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 struct sock *sk = sk_atm(vcc);
733
Stephen Hemminger52240062007-08-28 15:22:09 -0700734 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700735 skb_queue_tail(&sk->sk_receive_queue, skb);
736 sk->sk_data_ready(sk, skb->len);
737 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700738 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700739 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Chas Williamsd44f7742006-09-29 17:11:14 -0700741 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800742 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700743 !priv->lecd || !(dev->flags & IFF_UP)) {
744 /*
745 * Probably looping back, or if lecd is missing,
746 * lecd has gone down
747 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700748 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700749 dev_kfree_skb(skb);
750 return;
751 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700753 if (priv->is_trdev)
754 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
755 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700757 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700758
Chas Williamsd44f7742006-09-29 17:11:14 -0700759 /*
760 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700761 * the LE_ARP cache entry, delete the LE_ARP cache entry.
762 */
763 spin_lock_irqsave(&priv->lec_arp_lock, flags);
764 if (lec_is_data_direct(vcc)) {
765#ifdef CONFIG_TR
766 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700767 src =
768 ((struct lecdatahdr_8025 *)skb->data)->
769 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700770 else
771#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700772 src =
773 ((struct lecdatahdr_8023 *)skb->data)->
774 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700775 entry = lec_arp_find(priv, src);
776 if (entry && entry->vcc != vcc) {
777 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700778 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700779 }
780 }
781 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Chas Williamsd44f7742006-09-29 17:11:14 -0700783 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
784 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700786 dev_kfree_skb(skb);
787 return;
788 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700789 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700790 lec_arp_check_empties(priv, vcc, skb);
791 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700792 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700794 if (priv->is_trdev)
795 skb->protocol = tr_type_trans(skb, dev);
796 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700798 skb->protocol = eth_type_trans(skb, dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000799 dev->stats.rx_packets++;
800 dev->stats.rx_bytes += skb->len;
Chas Williamsd44f7742006-09-29 17:11:14 -0700801 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
802 netif_rx(skb);
803 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804}
805
Chas Williamsd44f7742006-09-29 17:11:14 -0700806static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807{
808 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
809 struct net_device *dev = skb->dev;
810
811 if (vpriv == NULL) {
812 printk("lec_pop(): vpriv = NULL!?!?!?\n");
813 return;
814 }
815
816 vpriv->old_pop(vcc, skb);
817
818 if (vpriv->xoff && atm_may_send(vcc, 0)) {
819 vpriv->xoff = 0;
820 if (netif_running(dev) && netif_queue_stopped(dev))
821 netif_wake_queue(dev);
822 }
823}
824
Chas Williamsd44f7742006-09-29 17:11:14 -0700825static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826{
827 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700828 int bytes_left;
829 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Chas Williamsd44f7742006-09-29 17:11:14 -0700831 /* Lecd must be up in this case */
832 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
833 if (bytes_left != 0) {
834 printk
835 ("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
836 bytes_left);
837 }
838 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
839 !dev_lec[ioc_data.dev_num])
840 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
842 return -ENOMEM;
843 vpriv->xoff = 0;
844 vpriv->old_pop = vcc->pop;
845 vcc->user_back = vpriv;
846 vcc->pop = lec_pop;
Wang Chen524ad0a2008-11-12 23:39:10 -0800847 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
Chas Williamsd44f7742006-09-29 17:11:14 -0700848 &ioc_data, vcc, vcc->push);
849 vcc->proto_data = dev_lec[ioc_data.dev_num];
850 vcc->push = lec_push;
851 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852}
853
Chas Williamsd44f7742006-09-29 17:11:14 -0700854static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
Chas Williamsd44f7742006-09-29 17:11:14 -0700856 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
857 return -EINVAL;
858 vcc->proto_data = dev_lec[arg];
Wang Chen524ad0a2008-11-12 23:39:10 -0800859 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
860 vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861}
862
863/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700864static int lecd_attach(struct atm_vcc *vcc, int arg)
865{
866 int i;
867 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
Chas Williamsd44f7742006-09-29 17:11:14 -0700869 if (arg < 0)
870 i = 0;
871 else
872 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700874 if (arg >= MAX_LEC_ITF)
875 return -EINVAL;
876#else /* Reserve the top NUM_TR_DEVS for TR */
877 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
878 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700880 if (!dev_lec[i]) {
881 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
Chas Williamsd44f7742006-09-29 17:11:14 -0700883 is_trdev = 0;
884 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
885 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Chas Williamsd44f7742006-09-29 17:11:14 -0700887 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700889 if (is_trdev)
890 dev_lec[i] = alloc_trdev(size);
891 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700893 dev_lec[i] = alloc_etherdev(size);
894 if (!dev_lec[i])
895 return -ENOMEM;
896 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
897 if (register_netdev(dev_lec[i])) {
898 free_netdev(dev_lec[i]);
899 return -EINVAL;
900 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
Wang Chen524ad0a2008-11-12 23:39:10 -0800902 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700903 priv->is_trdev = is_trdev;
904 lec_init(dev_lec[i]);
905 } else {
Wang Chen524ad0a2008-11-12 23:39:10 -0800906 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700907 if (priv->lecd)
908 return -EADDRINUSE;
909 }
910 lec_arp_init(priv);
911 priv->itfnum = i; /* LANE2 addition */
912 priv->lecd = vcc;
913 vcc->dev = &lecatm_dev;
914 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Chas Williamsd44f7742006-09-29 17:11:14 -0700916 vcc->proto_data = dev_lec[i];
917 set_bit(ATM_VF_META, &vcc->flags);
918 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
Chas Williamsd44f7742006-09-29 17:11:14 -0700920 /* Set default values to these variables */
921 priv->maximum_unknown_frame_count = 1;
922 priv->max_unknown_frame_time = (1 * HZ);
923 priv->vcc_timeout_period = (1200 * HZ);
924 priv->max_retry_count = 1;
925 priv->aging_time = (300 * HZ);
926 priv->forward_delay_time = (15 * HZ);
927 priv->topology_change = 0;
928 priv->arp_response_time = (1 * HZ);
929 priv->flush_timeout = (4 * HZ);
930 priv->path_switching_delay = (6 * HZ);
931
932 if (dev_lec[i]->flags & IFF_UP) {
933 netif_start_queue(dev_lec[i]);
934 }
935 __module_get(THIS_MODULE);
936 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937}
938
939#ifdef CONFIG_PROC_FS
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700940static const char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700942 static const char *const lec_arp_status_string[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 "ESI_UNKNOWN ",
944 "ESI_ARP_PENDING ",
945 "ESI_VC_PENDING ",
946 "<Undefined> ",
947 "ESI_FLUSH_PENDING ",
948 "ESI_FORWARD_DIRECT"
949 };
950
951 if (status > ESI_FORWARD_DIRECT)
952 status = 3; /* ESI_UNDEFINED */
953 return lec_arp_status_string[status];
954}
955
956static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
957{
958 int i;
959
960 for (i = 0; i < ETH_ALEN; i++)
961 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
962 seq_printf(seq, " ");
963 for (i = 0; i < ATM_ESA_LEN; i++)
964 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
965 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
966 entry->flags & 0xffff);
967 if (entry->vcc)
968 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
969 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700970 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 if (entry->recv_vcc) {
972 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
973 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -0700974 }
975 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976}
977
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978struct lec_state {
979 unsigned long flags;
980 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -0700981 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 struct net_device *dev;
983 int itf;
984 int arp_table;
985 int misc_table;
986};
987
Chas Williamsd0732f62006-09-29 17:14:27 -0700988static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 loff_t *l)
990{
Chas Williamsd0732f62006-09-29 17:14:27 -0700991 struct hlist_node *e = state->node;
992 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
994 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -0700995 e = tbl->first;
Joe Perches2e1e9842008-04-10 03:33:03 -0700996 if (e == SEQ_START_TOKEN) {
Chas Williamsd0732f62006-09-29 17:14:27 -0700997 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 --*l;
999 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001000
1001 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 if (--*l < 0)
1003 break;
1004 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001005 state->node = e;
1006
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 return (*l < 0) ? state : NULL;
1008}
1009
1010static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -07001011 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012{
1013 void *v = NULL;
1014 int p;
1015
1016 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001017 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 if (v)
1019 break;
1020 }
1021 state->arp_table = p;
1022 return v;
1023}
1024
1025static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1026 struct lec_priv *priv)
1027{
Chas Williamsd0732f62006-09-29 17:14:27 -07001028 struct hlist_head *lec_misc_tables[] = {
1029 &priv->lec_arp_empty_ones,
1030 &priv->lec_no_forward,
1031 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 };
1033 void *v = NULL;
1034 int q;
1035
1036 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1037 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1038 if (v)
1039 break;
1040 }
1041 state->misc_table = q;
1042 return v;
1043}
1044
1045static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1046 struct lec_priv *priv)
1047{
1048 if (!state->locked) {
1049 state->locked = priv;
1050 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1051 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001052 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1054 state->locked = NULL;
1055 /* Partial state reset for the next time we get called */
1056 state->arp_table = state->misc_table = 0;
1057 }
1058 return state->locked;
1059}
1060
1061static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1062{
1063 struct net_device *dev;
1064 void *v;
1065
1066 dev = state->dev ? state->dev : dev_lec[state->itf];
Wang Chen524ad0a2008-11-12 23:39:10 -08001067 v = (dev && netdev_priv(dev)) ?
1068 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 if (!v && dev) {
1070 dev_put(dev);
1071 /* Partial state reset for the next time we get called */
1072 dev = NULL;
1073 }
1074 state->dev = dev;
1075 return v;
1076}
1077
1078static void *lec_get_idx(struct lec_state *state, loff_t l)
1079{
1080 void *v = NULL;
1081
1082 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1083 v = lec_itf_walk(state, &l);
1084 if (v)
1085 break;
1086 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001087 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
1090static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1091{
1092 struct lec_state *state = seq->private;
1093
1094 state->itf = 0;
1095 state->dev = NULL;
1096 state->locked = NULL;
1097 state->arp_table = 0;
1098 state->misc_table = 0;
Joe Perches2e1e9842008-04-10 03:33:03 -07001099 state->node = SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Joe Perches2e1e9842008-04-10 03:33:03 -07001101 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102}
1103
1104static void lec_seq_stop(struct seq_file *seq, void *v)
1105{
1106 struct lec_state *state = seq->private;
1107
1108 if (state->dev) {
1109 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1110 state->flags);
1111 dev_put(state->dev);
1112 }
1113}
1114
1115static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1116{
1117 struct lec_state *state = seq->private;
1118
1119 v = lec_get_idx(state, 1);
1120 *pos += !!PTR_ERR(v);
1121 return v;
1122}
1123
1124static int lec_seq_show(struct seq_file *seq, void *v)
1125{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001126 static const char lec_banner[] =
1127 "Itf MAC ATM destination"
Chas Williamsd44f7742006-09-29 17:11:14 -07001128 " Status Flags "
1129 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
Joe Perches2e1e9842008-04-10 03:33:03 -07001131 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 seq_puts(seq, lec_banner);
1133 else {
1134 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001135 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001136 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
1138 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001139 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 }
1141 return 0;
1142}
1143
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001144static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001145 .start = lec_seq_start,
1146 .next = lec_seq_next,
1147 .stop = lec_seq_stop,
1148 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149};
1150
1151static int lec_seq_open(struct inode *inode, struct file *file)
1152{
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001153 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154}
1155
Arjan van de Ven9a321442007-02-12 00:55:35 -08001156static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001157 .owner = THIS_MODULE,
1158 .open = lec_seq_open,
1159 .read = seq_read,
1160 .llseek = seq_lseek,
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001161 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162};
1163#endif
1164
1165static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1166{
1167 struct atm_vcc *vcc = ATM_SD(sock);
1168 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001169
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001171 case ATMLEC_CTRL:
1172 case ATMLEC_MCAST:
1173 case ATMLEC_DATA:
1174 if (!capable(CAP_NET_ADMIN))
1175 return -EPERM;
1176 break;
1177 default:
1178 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 }
1180
1181 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001182 case ATMLEC_CTRL:
1183 err = lecd_attach(vcc, (int)arg);
1184 if (err >= 0)
1185 sock->state = SS_CONNECTED;
1186 break;
1187 case ATMLEC_MCAST:
1188 err = lec_mcast_attach(vcc, (int)arg);
1189 break;
1190 case ATMLEC_DATA:
1191 err = lec_vcc_attach(vcc, (void __user *)arg);
1192 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 }
1194
1195 return err;
1196}
1197
1198static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001199 .owner = THIS_MODULE,
1200 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201};
1202
1203static int __init lane_module_init(void)
1204{
1205#ifdef CONFIG_PROC_FS
1206 struct proc_dir_entry *p;
1207
Wang Chen16e297b2008-02-28 13:55:45 -08001208 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Wang Chendbee0d32008-03-23 21:45:36 -07001209 if (!p) {
1210 printk(KERN_ERR "Unable to initialize /proc/net/atm/lec\n");
1211 return -ENOMEM;
1212 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213#endif
1214
1215 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001216 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1217 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218}
1219
1220static void __exit lane_module_cleanup(void)
1221{
Chas Williamsd44f7742006-09-29 17:11:14 -07001222 int i;
1223 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
1225 remove_proc_entry("lec", atm_proc_root);
1226
1227 deregister_atm_ioctl(&lane_ioctl_ops);
1228
Chas Williamsd44f7742006-09-29 17:11:14 -07001229 for (i = 0; i < MAX_LEC_ITF; i++) {
1230 if (dev_lec[i] != NULL) {
Wang Chen524ad0a2008-11-12 23:39:10 -08001231 priv = netdev_priv(dev_lec[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001233 free_netdev(dev_lec[i]);
1234 dev_lec[i] = NULL;
1235 }
1236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Chas Williamsd44f7742006-09-29 17:11:14 -07001238 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239}
1240
1241module_init(lane_module_init);
1242module_exit(lane_module_cleanup);
1243
1244/*
1245 * LANE2: 3.1.3, LE_RESOLVE.request
1246 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1247 * If sizeoftlvs == NULL the default TLVs associated with with this
1248 * lec will be used.
1249 * If dst_mac == NULL, targetless LE_ARP will be sent
1250 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001251static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001252 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253{
1254 unsigned long flags;
Wang Chen524ad0a2008-11-12 23:39:10 -08001255 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001256 struct lec_arp_table *table;
1257 struct sk_buff *skb;
1258 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Chas Williamsd44f7742006-09-29 17:11:14 -07001260 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001262 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001264 if (table == NULL)
1265 return -1;
1266
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001267 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001268 if (*tlvs == NULL)
1269 return -1;
1270
Chas Williamsd44f7742006-09-29 17:11:14 -07001271 *sizeoftlvs = table->sizeoftlvs;
1272
1273 return 0;
1274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276 if (sizeoftlvs == NULL)
1277 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001278
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 else {
1280 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1281 if (skb == NULL)
1282 return -1;
1283 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001284 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1286 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001287 return retval;
1288}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
1290/*
1291 * LANE2: 3.1.4, LE_ASSOCIATE.request
1292 * Associate the *tlvs with the *lan_dst address.
1293 * Will overwrite any previous association
1294 * Returns 1 for success, 0 for failure (out of memory)
1295 *
1296 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001297static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1298 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299{
Chas Williamsd44f7742006-09-29 17:11:14 -07001300 int retval;
1301 struct sk_buff *skb;
Wang Chen524ad0a2008-11-12 23:39:10 -08001302 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
Chas Williamsd44f7742006-09-29 17:11:14 -07001304 if (compare_ether_addr(lan_dst, dev->dev_addr))
1305 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Chas Williamsd44f7742006-09-29 17:11:14 -07001307 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001309 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001310 if (priv->tlvs == NULL)
1311 return (0);
1312 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Chas Williamsd44f7742006-09-29 17:11:14 -07001314 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1315 if (skb == NULL)
1316 return 0;
1317 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001318 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001319 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1320 if (retval != 0)
1321 printk("lec.c: lane2_associate_req() failed\n");
1322 /*
1323 * If the previous association has changed we must
1324 * somehow notify other LANE entities about the change
1325 */
1326 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327}
1328
1329/*
1330 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1331 *
1332 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001333static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1334 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335{
1336#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001337 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338#endif
Wang Chen524ad0a2008-11-12 23:39:10 -08001339 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001340#if 0 /*
1341 * Why have the TLVs in LE_ARP entries
1342 * since we do not use them? When you
1343 * uncomment this code, make sure the
1344 * TLVs get freed when entry is killed
1345 */
1346 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Chas Williamsd44f7742006-09-29 17:11:14 -07001348 if (entry == NULL)
1349 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Chas Williamsd44f7742006-09-29 17:11:14 -07001351 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001353 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001354 if (entry->tlvs == NULL)
1355 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001356 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357#endif
1358#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001359 printk("lec.c: lane2_associate_ind()\n");
1360 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1361 while (i < sizeoftlvs)
1362 printk("%02x ", tlvs[i++]);
1363
1364 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365#endif
1366
Chas Williamsd44f7742006-09-29 17:11:14 -07001367 /* tell MPOA about the TLVs we saw */
1368 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1369 priv->lane2_ops->associate_indicator(dev, mac_addr,
1370 tlvs, sizeoftlvs);
1371 }
1372 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373}
1374
1375/*
1376 * Here starts what used to lec_arpc.c
1377 *
1378 * lec_arpc.c was added here when making
1379 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 */
1381
1382#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383#include <linux/timer.h>
1384#include <asm/param.h>
1385#include <asm/atomic.h>
1386#include <linux/inetdevice.h>
1387#include <net/route.h>
1388
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389#if 0
Stephen Hemminger52240062007-08-28 15:22:09 -07001390#define pr_debug(format,args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391/*
Stephen Hemminger52240062007-08-28 15:22:09 -07001392#define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393*/
1394#endif
1395#define DEBUG_ARP_TABLE 0
1396
1397#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1398
David Howellsc4028952006-11-22 14:57:56 +00001399static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400static void lec_arp_expire_arp(unsigned long data);
1401
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001402/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 * Arp table funcs
1404 */
1405
1406#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1407
1408/*
1409 * Initialization of arp-cache
1410 */
Chas Williams1fa99612006-09-29 17:11:47 -07001411static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412{
Chas Williams1fa99612006-09-29 17:11:47 -07001413 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Chas Williams1fa99612006-09-29 17:11:47 -07001415 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001416 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001417 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001418 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1419 INIT_HLIST_HEAD(&priv->lec_no_forward);
1420 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001422 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001423 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424}
1425
Chas Williams1fa99612006-09-29 17:11:47 -07001426static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427{
Chas Williams1fa99612006-09-29 17:11:47 -07001428 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 struct atm_vcc *vcc = entry->vcc;
1430 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001431 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
Chas Williams1fa99612006-09-29 17:11:47 -07001433 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 if (vpriv->xoff)
1435 netif_wake_queue(dev);
1436 kfree(vpriv);
1437 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001438 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001440 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001441 }
1442 if (entry->recv_vcc) {
1443 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001445 entry->recv_vcc = NULL;
1446 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447}
1448
1449/*
1450 * Insert entry to lec_arp_table
1451 * LANE2: Add to the end of the list to satisfy 8.1.13
1452 */
Chas Williams1fa99612006-09-29 17:11:47 -07001453static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001454lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455{
Chas Williamsd0732f62006-09-29 17:14:27 -07001456 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
Chas Williamsd0732f62006-09-29 17:14:27 -07001458 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1459 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001460
Stephen Hemminger52240062007-08-28 15:22:09 -07001461 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 -07001462 0xff & entry->mac_addr[0], 0xff & entry->mac_addr[1],
1463 0xff & entry->mac_addr[2], 0xff & entry->mac_addr[3],
1464 0xff & entry->mac_addr[4], 0xff & entry->mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465}
1466
1467/*
1468 * Remove entry from lec_arp_table
1469 */
Chas Williams1fa99612006-09-29 17:11:47 -07001470static int
1471lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472{
Chas Williamsd0732f62006-09-29 17:14:27 -07001473 struct hlist_node *node;
1474 struct lec_arp_table *entry;
1475 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Chas Williams1fa99612006-09-29 17:11:47 -07001477 if (!to_remove) {
1478 return -1;
1479 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001480
1481 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001482 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Chas Williamsd0732f62006-09-29 17:14:27 -07001484 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001485 if (to_remove->status >= ESI_FLUSH_PENDING) {
1486 /*
1487 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1488 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001489 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1490 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1491 if (memcmp(to_remove->atm_addr,
1492 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001493 remove_vcc = 0;
1494 break;
1495 }
1496 }
1497 }
1498 if (remove_vcc)
1499 lec_arp_clear_vccs(to_remove);
1500 }
1501 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1502
Stephen Hemminger52240062007-08-28 15:22:09 -07001503 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 -07001504 0xff & to_remove->mac_addr[0], 0xff & to_remove->mac_addr[1],
1505 0xff & to_remove->mac_addr[2], 0xff & to_remove->mac_addr[3],
1506 0xff & to_remove->mac_addr[4], 0xff & to_remove->mac_addr[5]);
1507 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508}
1509
1510#if DEBUG_ARP_TABLE
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001511static const char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512{
Chas Williams1fa99612006-09-29 17:11:47 -07001513 switch (st) {
1514 case ESI_UNKNOWN:
1515 return "ESI_UNKNOWN";
1516 case ESI_ARP_PENDING:
1517 return "ESI_ARP_PENDING";
1518 case ESI_VC_PENDING:
1519 return "ESI_VC_PENDING";
1520 case ESI_FLUSH_PENDING:
1521 return "ESI_FLUSH_PENDING";
1522 case ESI_FORWARD_DIRECT:
1523 return "ESI_FORWARD_DIRECT";
1524 default:
1525 return "<UNKNOWN>";
1526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Chas Williams1fa99612006-09-29 17:11:47 -07001529static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530{
Chas Williamsd0732f62006-09-29 17:14:27 -07001531 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001532 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001533 char buf[256];
1534 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Chas Williams1fa99612006-09-29 17:11:47 -07001536 printk("Dump %p:\n", priv);
1537 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001538 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1539 offset = 0;
1540 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001541 offset += sprintf(buf + offset, "Mac:");
1542 for (j = 0; j < ETH_ALEN; j++) {
1543 offset += sprintf(buf + offset,
1544 "%2.2x ",
1545 rulla->mac_addr[j] & 0xff);
1546 }
1547 offset += sprintf(buf + offset, "Atm:");
1548 for (j = 0; j < ATM_ESA_LEN; j++) {
1549 offset += sprintf(buf + offset,
1550 "%2.2x ",
1551 rulla->atm_addr[j] & 0xff);
1552 }
1553 offset += sprintf(buf + offset,
1554 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1555 rulla->vcc ? rulla->vcc->vpi : 0,
1556 rulla->vcc ? rulla->vcc->vci : 0,
1557 rulla->recv_vcc ? rulla->recv_vcc->
1558 vpi : 0,
1559 rulla->recv_vcc ? rulla->recv_vcc->
1560 vci : 0, rulla->last_used,
1561 rulla->timestamp, rulla->no_tries);
1562 offset +=
1563 sprintf(buf + offset,
1564 "Flags:%x, Packets_flooded:%x, Status: %s ",
1565 rulla->flags, rulla->packets_flooded,
1566 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001567 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001568 }
Chas Williams1fa99612006-09-29 17:11:47 -07001569 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001570
1571 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001572 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001573 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001574 offset = 0;
1575 offset += sprintf(buf + offset, "Mac:");
1576 for (j = 0; j < ETH_ALEN; j++) {
1577 offset += sprintf(buf + offset, "%2.2x ",
1578 rulla->mac_addr[j] & 0xff);
1579 }
1580 offset += sprintf(buf + offset, "Atm:");
1581 for (j = 0; j < ATM_ESA_LEN; j++) {
1582 offset += sprintf(buf + offset, "%2.2x ",
1583 rulla->atm_addr[j] & 0xff);
1584 }
1585 offset += sprintf(buf + offset,
1586 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1587 rulla->vcc ? rulla->vcc->vpi : 0,
1588 rulla->vcc ? rulla->vcc->vci : 0,
1589 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1590 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1591 rulla->last_used,
1592 rulla->timestamp, rulla->no_tries);
1593 offset += sprintf(buf + offset,
1594 "Flags:%x, Packets_flooded:%x, Status: %s ",
1595 rulla->flags, rulla->packets_flooded,
1596 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001597 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001598 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001599
1600 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001601 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001602 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001603 offset = 0;
1604 offset += sprintf(buf + offset, "Mac:");
1605 for (j = 0; j < ETH_ALEN; j++) {
1606 offset += sprintf(buf + offset, "%2.2x ",
1607 rulla->mac_addr[j] & 0xff);
1608 }
1609 offset += sprintf(buf + offset, "Atm:");
1610 for (j = 0; j < ATM_ESA_LEN; j++) {
1611 offset += sprintf(buf + offset, "%2.2x ",
1612 rulla->atm_addr[j] & 0xff);
1613 }
1614 offset += sprintf(buf + offset,
1615 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1616 rulla->vcc ? rulla->vcc->vpi : 0,
1617 rulla->vcc ? rulla->vcc->vci : 0,
1618 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1619 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1620 rulla->last_used,
1621 rulla->timestamp, rulla->no_tries);
1622 offset += sprintf(buf + offset,
1623 "Flags:%x, Packets_flooded:%x, Status: %s ",
1624 rulla->flags, rulla->packets_flooded,
1625 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001626 printk("%s", buf);
1627 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
Chas Williamsd0732f62006-09-29 17:14:27 -07001629 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001630 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001631 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001632 offset = 0;
1633 offset += sprintf(buf + offset, "Mac:");
1634 for (j = 0; j < ETH_ALEN; j++) {
1635 offset += sprintf(buf + offset, "%2.2x ",
1636 rulla->mac_addr[j] & 0xff);
1637 }
1638 offset += sprintf(buf + offset, "Atm:");
1639 for (j = 0; j < ATM_ESA_LEN; j++) {
1640 offset += sprintf(buf + offset, "%2.2x ",
1641 rulla->atm_addr[j] & 0xff);
1642 }
1643 offset += sprintf(buf + offset,
1644 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1645 rulla->vcc ? rulla->vcc->vpi : 0,
1646 rulla->vcc ? rulla->vcc->vci : 0,
1647 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1648 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1649 rulla->last_used,
1650 rulla->timestamp, rulla->no_tries);
1651 offset += sprintf(buf + offset,
1652 "Flags:%x, Packets_flooded:%x, Status: %s ",
1653 rulla->flags, rulla->packets_flooded,
1654 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001655 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658}
Chas Williamsd0732f62006-09-29 17:14:27 -07001659#else
1660#define dump_arp_table(priv) do { } while (0)
1661#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
1663/*
1664 * Destruction of arp-cache
1665 */
Chas Williams1fa99612006-09-29 17:11:47 -07001666static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667{
1668 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001669 struct hlist_node *node, *next;
1670 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001671 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
Chas Williams987e46b2006-09-29 17:15:59 -07001673 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001674
1675 /*
1676 * Remove all entries
1677 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
1679 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001680 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001681 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001682 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001683 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001684 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001685 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001686 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001687
1688 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001689 del_timer_sync(&entry->timer);
1690 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001691 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001692 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001693 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001694 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1695
1696 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001697 del_timer_sync(&entry->timer);
1698 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001699 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001700 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001701 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001702 INIT_HLIST_HEAD(&priv->lec_no_forward);
1703
1704 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001705 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1706 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001707 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001708 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001709 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001710 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001711 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1713}
1714
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001715/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 * Find entry by mac_address
1717 */
Chas Williams1fa99612006-09-29 17:11:47 -07001718static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001719 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720{
Chas Williamsd0732f62006-09-29 17:14:27 -07001721 struct hlist_node *node;
1722 struct hlist_head *head;
1723 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
Stephen Hemminger52240062007-08-28 15:22:09 -07001725 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 -07001726 mac_addr[0] & 0xff, mac_addr[1] & 0xff, mac_addr[2] & 0xff,
1727 mac_addr[3] & 0xff, mac_addr[4] & 0xff, mac_addr[5] & 0xff);
Chas Williams1fa99612006-09-29 17:11:47 -07001728
Chas Williamsd0732f62006-09-29 17:14:27 -07001729 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1730 hlist_for_each_entry(entry, node, head, next) {
1731 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1732 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001733 }
Chas Williams1fa99612006-09-29 17:11:47 -07001734 }
1735 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736}
1737
Chas Williams1fa99612006-09-29 17:11:47 -07001738static struct lec_arp_table *make_entry(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001739 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740{
Chas Williams1fa99612006-09-29 17:11:47 -07001741 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
Chas Williams1fa99612006-09-29 17:11:47 -07001743 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1744 if (!to_return) {
1745 printk("LEC: Arp entry kmalloc failed\n");
1746 return NULL;
1747 }
1748 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001749 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001750 setup_timer(&to_return->timer, lec_arp_expire_arp,
1751 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001752 to_return->last_used = jiffies;
1753 to_return->priv = priv;
1754 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001755 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001756 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757}
1758
Chas Williams1fa99612006-09-29 17:11:47 -07001759/* Arp sent timer expired */
1760static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761{
Chas Williams1fa99612006-09-29 17:11:47 -07001762 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
Chas Williams1fa99612006-09-29 17:11:47 -07001764 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
Stephen Hemminger52240062007-08-28 15:22:09 -07001766 pr_debug("lec_arp_expire_arp\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001767 if (entry->status == ESI_ARP_PENDING) {
1768 if (entry->no_tries <= entry->priv->max_retry_count) {
1769 if (entry->is_rdesc)
1770 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1771 entry->mac_addr, NULL, NULL);
1772 else
1773 send_to_lecd(entry->priv, l_arp_xmt,
1774 entry->mac_addr, NULL, NULL);
1775 entry->no_tries++;
1776 }
1777 mod_timer(&entry->timer, jiffies + (1 * HZ));
1778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779}
1780
Chas Williams1fa99612006-09-29 17:11:47 -07001781/* Unknown/unused vcc expire, remove associated entry */
1782static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783{
1784 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001785 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1786 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
Chas Williams1fa99612006-09-29 17:11:47 -07001788 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
Stephen Hemminger52240062007-08-28 15:22:09 -07001790 pr_debug("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001791 to_remove, priv,
1792 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1793 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
1795 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001796 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1798
Chas Williams1fa99612006-09-29 17:11:47 -07001799 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001800 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801}
1802
1803/*
1804 * Expire entries.
1805 * 1. Re-set timer
1806 * 2. For each entry, delete entries that have aged past the age limit.
1807 * 3. For each entry, depending on the status of the entry, perform
1808 * the following maintenance.
1809 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1810 * tick_count is above the max_unknown_frame_time, clear
1811 * the tick_count to zero and clear the packets_flooded counter
1812 * to zero. This supports the packet rate limit per address
1813 * while flooding unknowns.
1814 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1815 * than or equal to the path_switching_delay, change the status
1816 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1817 * regardless of the progress of the flush protocol.
1818 */
David Howellsc4028952006-11-22 14:57:56 +00001819static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820{
1821 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001822 struct lec_priv *priv =
1823 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001824 struct hlist_node *node, *next;
1825 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001826 unsigned long now;
1827 unsigned long time_to_check;
1828 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829
Stephen Hemminger52240062007-08-28 15:22:09 -07001830 pr_debug("lec_arp_check_expire %p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001832restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001834 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001835 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001836 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 priv->topology_change)
1838 time_to_check = priv->forward_delay_time;
1839 else
1840 time_to_check = priv->aging_time;
1841
Stephen Hemminger52240062007-08-28 15:22:09 -07001842 pr_debug("About to expire: %lx - %lx > %lx\n",
Chas Williams1fa99612006-09-29 17:11:47 -07001843 now, entry->last_used, time_to_check);
1844 if (time_after(now, entry->last_used + time_to_check)
1845 && !(entry->flags & LEC_PERMANENT_FLAG)
1846 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 /* Remove entry */
Stephen Hemminger52240062007-08-28 15:22:09 -07001848 pr_debug("LEC:Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001850 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 } else {
1852 /* Something else */
1853 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001854 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001856 entry->timestamp +
1857 priv->
1858 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 entry->timestamp = jiffies;
1860 entry->packets_flooded = 0;
1861 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001862 send_to_lecd(priv, l_svc_setup,
1863 entry->mac_addr,
1864 entry->atm_addr,
1865 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 }
Chas Williams1fa99612006-09-29 17:11:47 -07001867 if (entry->status == ESI_FLUSH_PENDING
1868 &&
1869 time_after_eq(now, entry->timestamp +
1870 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001872 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873
Chas Williams6656e3c2006-09-29 17:17:17 -07001874 lec_arp_hold(entry);
1875 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1876 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
Stephen Hemminger162619e2009-01-09 13:01:01 +00001877 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001879 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001880 lec_arp_put(entry);
1881 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 }
1884 }
1885 }
1886 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1887
Chas Williams987e46b2006-09-29 17:15:59 -07001888 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889}
Chas Williams1fa99612006-09-29 17:11:47 -07001890
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891/*
1892 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001893 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 */
Chas Williams1fa99612006-09-29 17:11:47 -07001895static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001896 const unsigned char *mac_to_find, int is_rdesc,
Chas Williams1fa99612006-09-29 17:11:47 -07001897 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898{
1899 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001900 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 struct atm_vcc *found;
1902
Chas Williams1fa99612006-09-29 17:11:47 -07001903 if (mac_to_find[0] & 0x01) {
1904 switch (priv->lane_version) {
1905 case 1:
1906 return priv->mcast_vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07001907 case 2: /* LANE2 wants arp for multicast addresses */
1908 if (!compare_ether_addr(mac_to_find, bus_mac))
1909 return priv->mcast_vcc;
1910 break;
1911 default:
1912 break;
1913 }
1914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915
1916 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001917 entry = lec_arp_find(priv, mac_to_find);
1918
1919 if (entry) {
1920 if (entry->status == ESI_FORWARD_DIRECT) {
1921 /* Connection Ok */
1922 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001923 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001924 *ret_entry = entry;
1925 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001927 }
1928 /*
1929 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001930 * so another LE_ARP request can be made for this frame.
1931 */
1932 if (entry->status == ESI_ARP_PENDING) {
1933 entry->no_tries = 0;
1934 }
Chas Williams1fa99612006-09-29 17:11:47 -07001935 /*
1936 * Data direct VC not yet set up, check to see if the unknown
1937 * frame count is greater than the limit. If the limit has
1938 * not been reached, allow the caller to send packet to
1939 * BUS.
1940 */
1941 if (entry->status != ESI_FLUSH_PENDING &&
1942 entry->packets_flooded <
1943 priv->maximum_unknown_frame_count) {
1944 entry->packets_flooded++;
Stephen Hemminger52240062007-08-28 15:22:09 -07001945 pr_debug("LEC_ARP: Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001946 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001948 }
1949 /*
1950 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 * or BUS flood limit was reached for an entry which is
1952 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1953 */
Chas Williams6656e3c2006-09-29 17:17:17 -07001954 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001955 *ret_entry = entry;
Stephen Hemminger52240062007-08-28 15:22:09 -07001956 pr_debug("lec: entry->status %d entry->vcc %p\n", entry->status,
Chas Williams1fa99612006-09-29 17:11:47 -07001957 entry->vcc);
1958 found = NULL;
1959 } else {
1960 /* No matching entry was found */
1961 entry = make_entry(priv, mac_to_find);
Stephen Hemminger52240062007-08-28 15:22:09 -07001962 pr_debug("LEC_ARP: Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001963 if (!entry) {
1964 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001966 }
1967 lec_arp_add(priv, entry);
1968 /* We want arp-request(s) to be sent */
1969 entry->packets_flooded = 1;
1970 entry->status = ESI_ARP_PENDING;
1971 entry->no_tries = 1;
1972 entry->last_used = entry->timestamp = jiffies;
1973 entry->is_rdesc = is_rdesc;
1974 if (entry->is_rdesc)
1975 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1976 NULL);
1977 else
1978 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1979 entry->timer.expires = jiffies + (1 * HZ);
1980 entry->timer.function = lec_arp_expire_arp;
1981 add_timer(&entry->timer);
1982 found = priv->mcast_vcc;
1983 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984
1985out:
1986 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1987 return found;
1988}
1989
1990static int
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001991lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07001992 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993{
1994 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001995 struct hlist_node *node, *next;
1996 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001997 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
Stephen Hemminger52240062007-08-28 15:22:09 -07001999 pr_debug("lec_addr_delete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002001 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002002 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002003 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2004 && (permanent ||
2005 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002007 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002010 return 0;
2011 }
2012 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002014 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015}
2016
2017/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002018 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 */
2020static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002021lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
2022 const unsigned char *atm_addr, unsigned long remoteflag,
Chas Williams1fa99612006-09-29 17:11:47 -07002023 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024{
2025 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002026 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07002027 struct lec_arp_table *entry, *tmp;
2028 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
Stephen Hemminger52240062007-08-28 15:22:09 -07002030 pr_debug("lec:%s", (targetless_le_arp) ? "targetless " : " ");
2031 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 -07002032 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2033 mac_addr[4], mac_addr[5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
2035 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002036 entry = lec_arp_find(priv, mac_addr);
2037 if (entry == NULL && targetless_le_arp)
2038 goto out; /*
2039 * LANE2: ignore targetless LE_ARPs for which
2040 * we have no entry in the cache. 7.1.30
2041 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002042 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2043 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2044 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2045 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002046 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002047 tmp = lec_arp_find(priv, mac_addr);
2048 if (tmp) {
2049 del_timer(&tmp->timer);
2050 tmp->status = ESI_FORWARD_DIRECT;
2051 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2052 tmp->vcc = entry->vcc;
2053 tmp->old_push = entry->old_push;
2054 tmp->last_used = jiffies;
2055 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002056 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002057 entry = tmp;
2058 } else {
2059 entry->status = ESI_FORWARD_DIRECT;
2060 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2061 entry->last_used = jiffies;
2062 lec_arp_add(priv, entry);
2063 }
2064 if (remoteflag)
2065 entry->flags |= LEC_REMOTE_FLAG;
2066 else
2067 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002068 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002069 dump_arp_table(priv);
2070 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002071 }
Chas Williams1fa99612006-09-29 17:11:47 -07002072 }
2073 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002074
Chas Williams1fa99612006-09-29 17:11:47 -07002075 entry = lec_arp_find(priv, mac_addr);
2076 if (!entry) {
2077 entry = make_entry(priv, mac_addr);
2078 if (!entry)
2079 goto out;
2080 entry->status = ESI_UNKNOWN;
2081 lec_arp_add(priv, entry);
2082 /* Temporary, changes before end of function */
2083 }
2084 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2085 del_timer(&entry->timer);
2086 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002087 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002088 if (entry != tmp &&
2089 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2090 /* Vcc to this host exists */
2091 if (tmp->status > ESI_VC_PENDING) {
2092 /*
2093 * ESI_FLUSH_PENDING,
2094 * ESI_FORWARD_DIRECT
2095 */
2096 entry->vcc = tmp->vcc;
2097 entry->old_push = tmp->old_push;
2098 }
2099 entry->status = tmp->status;
2100 break;
2101 }
2102 }
2103 }
2104 if (remoteflag)
2105 entry->flags |= LEC_REMOTE_FLAG;
2106 else
2107 entry->flags &= ~LEC_REMOTE_FLAG;
2108 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2109 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002110 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002111 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002112 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002113 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114out:
2115 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2116}
2117
2118/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002119 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 */
2121static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002122lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002123 struct atm_vcc *vcc,
2124 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125{
2126 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002127 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002128 struct lec_arp_table *entry;
2129 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
2131 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002132 if (ioc_data->receive == 2) {
2133 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Stephen Hemminger52240062007-08-28 15:22:09 -07002135 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002137 entry = lec_arp_find(priv, bus_mac);
2138 if (!entry) {
2139 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002141 }
2142 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2143 entry->recv_vcc = vcc;
2144 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002146 entry = make_entry(priv, bus_mac);
2147 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002149 del_timer(&entry->timer);
2150 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2151 entry->recv_vcc = vcc;
2152 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002153 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002154 goto out;
2155 } else if (ioc_data->receive == 1) {
2156 /*
2157 * Vcc which we don't want to make default vcc,
2158 * attach it anyway.
2159 */
Stephen Hemminger52240062007-08-28 15:22:09 -07002160 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002161 ("LEC_ARP:Attaching data direct, not default: "
2162 "%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",
2163 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2164 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2165 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2166 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2167 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2168 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2169 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2170 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2171 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2172 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2173 entry = make_entry(priv, bus_mac);
2174 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002176 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2177 memset(entry->mac_addr, 0, ETH_ALEN);
2178 entry->recv_vcc = vcc;
2179 entry->old_recv_push = old_push;
2180 entry->status = ESI_UNKNOWN;
2181 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2182 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002183 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002184 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 dump_arp_table(priv);
2186 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002187 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002188 pr_debug
Chas Williams1fa99612006-09-29 17:11:47 -07002189 ("LEC_ARP:Attaching data direct, default: "
2190 "%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",
2191 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2192 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2193 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2194 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2195 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2196 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2197 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2198 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2199 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2200 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2201 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002202 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002203 if (memcmp
2204 (ioc_data->atm_addr, entry->atm_addr,
2205 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002206 pr_debug("LEC_ARP: Attaching data direct\n");
2207 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Chas Williams1fa99612006-09-29 17:11:47 -07002208 entry->vcc ? entry->vcc->vci : 0,
2209 entry->recv_vcc ? entry->recv_vcc->
2210 vci : 0);
2211 found_entry = 1;
2212 del_timer(&entry->timer);
2213 entry->vcc = vcc;
2214 entry->old_push = old_push;
2215 if (entry->status == ESI_VC_PENDING) {
2216 if (priv->maximum_unknown_frame_count
2217 == 0)
2218 entry->status =
2219 ESI_FORWARD_DIRECT;
2220 else {
2221 entry->timestamp = jiffies;
2222 entry->status =
2223 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002225 send_to_lecd(priv, l_flush_xmt,
2226 NULL,
2227 entry->atm_addr,
2228 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002230 }
2231 } else {
2232 /*
2233 * They were forming a connection
2234 * to us, and we to them. Our
2235 * ATM address is numerically lower
2236 * than theirs, so we make connection
2237 * we formed into default VCC (8.1.11).
2238 * Connection they made gets torn
2239 * down. This might confuse some
2240 * clients. Can be changed if
2241 * someone reports trouble...
2242 */
2243 ;
2244 }
2245 }
2246 }
2247 }
2248 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002249 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002250 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002252 }
2253 /*
2254 * Not found, snatch address from first data packet that arrives
2255 * from this vcc
2256 */
2257 entry = make_entry(priv, bus_mac);
2258 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002260 entry->vcc = vcc;
2261 entry->old_push = old_push;
2262 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2263 memset(entry->mac_addr, 0, ETH_ALEN);
2264 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002265 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002266 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2267 entry->timer.function = lec_arp_expire_vcc;
2268 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002269 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 dump_arp_table(priv);
2271out:
2272 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2273}
2274
Chas Williams1fa99612006-09-29 17:11:47 -07002275static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276{
2277 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002278 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002279 struct lec_arp_table *entry;
2280 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
Stephen Hemminger52240062007-08-28 15:22:09 -07002282 pr_debug("LEC:lec_flush_complete %lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002283restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002284 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2285 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002286 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002287 if (entry->flush_tran_id == tran_id
2288 && entry->status == ESI_FLUSH_PENDING) {
2289 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002290 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002291
Chas Williams6656e3c2006-09-29 17:17:17 -07002292 lec_arp_hold(entry);
2293 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2294 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
Stephen Hemminger162619e2009-01-09 13:01:01 +00002295 lec_send(vcc, skb);
Chas Williams6656e3c2006-09-29 17:17:17 -07002296 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002297 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002298 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002299 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002300 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002301 }
2302 }
2303 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002305 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306}
2307
2308static void
2309lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002310 const unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311{
2312 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002313 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002314 struct lec_arp_table *entry;
2315 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316
2317 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002318 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002319 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002320 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2321 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002322 pr_debug("Set flush transaction id to %lx for %p\n",
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002323 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002324 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2327}
2328
Chas Williams1fa99612006-09-29 17:11:47 -07002329static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330{
2331 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002332 unsigned char mac_addr[] = {
2333 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2334 };
2335 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 struct lec_vcc_priv *vpriv;
2337 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002338
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2340 return -ENOMEM;
2341 vpriv->xoff = 0;
2342 vpriv->old_pop = vcc->pop;
2343 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002344 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002346 to_add = make_entry(priv, mac_addr);
2347 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 vcc->pop = vpriv->old_pop;
2349 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002350 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002352 }
2353 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2354 to_add->status = ESI_FORWARD_DIRECT;
2355 to_add->flags |= LEC_PERMANENT_FLAG;
2356 to_add->vcc = vcc;
2357 to_add->old_push = vcc->push;
2358 vcc->push = lec_push;
2359 priv->mcast_vcc = vcc;
2360 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361out:
2362 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002363 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364}
2365
Chas Williams1fa99612006-09-29 17:11:47 -07002366static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367{
2368 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002369 struct hlist_node *node, *next;
2370 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002371 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372
Stephen Hemminger52240062007-08-28 15:22:09 -07002373 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002374 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002375
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002377
Chas Williams1fa99612006-09-29 17:11:47 -07002378 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002379 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002380 if (vcc == entry->vcc) {
2381 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002382 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002383 if (priv->mcast_vcc == vcc) {
2384 priv->mcast_vcc = NULL;
2385 }
2386 }
2387 }
2388 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389
Chas Williamsd0732f62006-09-29 17:14:27 -07002390 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2391 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002392 lec_arp_clear_vccs(entry);
2393 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002394 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002395 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002396 }
Chas Williams1fa99612006-09-29 17:11:47 -07002397 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398
Chas Williamsd0732f62006-09-29 17:14:27 -07002399 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002400 if (entry->recv_vcc == vcc) {
2401 lec_arp_clear_vccs(entry);
2402 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002403 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002404 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002405 }
Chas Williams1fa99612006-09-29 17:11:47 -07002406 }
2407
Chas Williamsd0732f62006-09-29 17:14:27 -07002408 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002409 if (entry->recv_vcc == vcc) {
2410 lec_arp_clear_vccs(entry);
2411 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002412 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002413 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002414 }
Chas Williams1fa99612006-09-29 17:11:47 -07002415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416
2417 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2418 dump_arp_table(priv);
2419}
2420
2421static void
2422lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002423 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424{
Chas Williams1fa99612006-09-29 17:11:47 -07002425 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002426 struct hlist_node *node, *next;
2427 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002428 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2429 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002431 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432
Chas Williams1fa99612006-09-29 17:11:47 -07002433 if (priv->is_trdev)
2434 src = tr_hdr->h_source;
2435 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002437 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438
2439 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002440 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2441 if (vcc == entry->vcc) {
2442 del_timer(&entry->timer);
2443 memcpy(entry->mac_addr, src, ETH_ALEN);
2444 entry->status = ESI_FORWARD_DIRECT;
2445 entry->last_used = jiffies;
2446 /* We might have got an entry */
2447 if ((tmp = lec_arp_find(priv, src))) {
2448 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002449 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002450 }
2451 hlist_del(&entry->next);
2452 lec_arp_add(priv, entry);
2453 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002454 }
Chas Williams1fa99612006-09-29 17:11:47 -07002455 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002456 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457out:
2458 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2459}
Chas Williams1fa99612006-09-29 17:11:47 -07002460
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461MODULE_LICENSE("GPL");