blob: 6873813c3c99e48bd1ba4b604335fbc336afa86b [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
Joe Perches99824462010-01-26 11:40:00 +00007#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/kernel.h>
10#include <linux/bitops.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -080011#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13/* We are ethernet device */
14#include <linux/if_ether.h>
15#include <linux/netdevice.h>
16#include <linux/etherdevice.h>
17#include <net/sock.h>
18#include <linux/skbuff.h>
19#include <linux/ip.h>
20#include <asm/byteorder.h>
21#include <asm/uaccess.h>
22#include <net/arp.h>
23#include <net/dst.h>
24#include <linux/proc_fs.h>
25#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/seq_file.h>
27
28/* TokenRing if needed */
29#ifdef CONFIG_TR
30#include <linux/trdevice.h>
31#endif
32
33/* And atm device */
34#include <linux/atmdev.h>
35#include <linux/atmlec.h>
36
37/* Proxy LEC knows about bridging */
38#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include "../bridge/br_private.h"
40
Chas Williamsd44f7742006-09-29 17:11:14 -070041static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#endif
43
44/* Modular too */
45#include <linux/module.h>
46#include <linux/init.h>
47
48#include "lec.h"
49#include "lec_arpc.h"
50#include "resources.h"
51
Chas Williamsd44f7742006-09-29 17:11:14 -070052#define DUMP_PACKETS 0 /*
53 * 0 = None,
54 * 1 = 30 first bytes
55 * 2 = Whole packet
56 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Chas Williamsd44f7742006-09-29 17:11:14 -070058#define LEC_UNRES_QUE_LEN 8 /*
59 * number of tx packets to queue for a
60 * single destination while waiting for SVC
61 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63static int lec_open(struct net_device *dev);
Stephen Hemminger3c805a22009-08-31 19:50:42 +000064static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
65 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static int lec_close(struct net_device *dev);
Chas Williamsd44f7742006-09-29 17:11:14 -070067static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070068 const unsigned char *mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static int lec_arp_remove(struct lec_priv *priv,
Chas Williamsd44f7742006-09-29 17:11:14 -070070 struct lec_arp_table *to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* LANE2 functions */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070072static void lane2_associate_ind(struct net_device *dev, const u8 *mac_address,
73 const u8 *tlvs, u32 sizeoftlvs);
74static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -070075 u8 **tlvs, u32 *sizeoftlvs);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070076static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
77 const u8 *tlvs, u32 sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070079static int lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 unsigned long permanent);
81static void lec_arp_check_empties(struct lec_priv *priv,
82 struct atm_vcc *vcc, struct sk_buff *skb);
83static void lec_arp_destroy(struct lec_priv *priv);
84static void lec_arp_init(struct lec_priv *priv);
Chas Williamsd44f7742006-09-29 17:11:14 -070085static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070086 const unsigned char *mac_to_find,
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 int is_rdesc,
88 struct lec_arp_table **ret_entry);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070089static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
90 const unsigned char *atm_addr, unsigned long remoteflag,
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 unsigned int targetless_le_arp);
92static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
93static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
94static void lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070095 const unsigned char *atm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 unsigned long tran_id);
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -070097static void lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 struct atm_vcc *vcc,
Chas Williamsd44f7742006-09-29 17:11:14 -070099 void (*old_push) (struct atm_vcc *vcc,
100 struct sk_buff *skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
102
Chas Williams33a9c2d2006-09-29 17:16:48 -0700103/* must be done under lec_arp_lock */
104static inline void lec_arp_hold(struct lec_arp_table *entry)
105{
106 atomic_inc(&entry->usage);
107}
108
109static inline void lec_arp_put(struct lec_arp_table *entry)
110{
111 if (atomic_dec_and_test(&entry->usage))
112 kfree(entry);
113}
114
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116static struct lane2_ops lane2_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700117 lane2_resolve, /* resolve, spec 3.1.3 */
118 lane2_associate_req, /* associate_req, spec 3.1.4 */
119 NULL /* associate indicator, spec 3.1.5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120};
121
Chas Williamsd44f7742006-09-29 17:11:14 -0700122static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124/* Device structures */
125static struct net_device *dev_lec[MAX_LEC_ITF];
126
127#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
128static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
129{
Chas Williamsd44f7742006-09-29 17:11:14 -0700130 struct ethhdr *eth;
131 char *buff;
132 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Chas Williamsd44f7742006-09-29 17:11:14 -0700134 /*
135 * Check if this is a BPDU. If so, ask zeppelin to send
136 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
137 * as the Config BPDU has
138 */
139 eth = (struct ethhdr *)skb->data;
140 buff = skb->data + skb->dev->hard_header_len;
141 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 struct sock *sk;
Chas Williamsd44f7742006-09-29 17:11:14 -0700143 struct sk_buff *skb2;
144 struct atmlec_msg *mesg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Chas Williamsd44f7742006-09-29 17:11:14 -0700146 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
147 if (skb2 == NULL)
148 return;
149 skb2->len = sizeof(struct atmlec_msg);
150 mesg = (struct atmlec_msg *)skb2->data;
151 mesg->type = l_topology_change;
152 buff += 4;
153 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Wang Chen524ad0a2008-11-12 23:39:10 -0800155 priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700156 atm_force_charge(priv->lecd, skb2->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 sk = sk_atm(priv->lecd);
Chas Williamsd44f7742006-09-29 17:11:14 -0700158 skb_queue_tail(&sk->sk_receive_queue, skb2);
159 sk->sk_data_ready(sk, skb2->len);
160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Chas Williamsd44f7742006-09-29 17:11:14 -0700162 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
165
166/*
167 * Modelled after tr_type_trans
168 * All multicast and ARE or STE frames go to BUS.
169 * Non source routed frames go by destination address.
170 * Last hop source routed frames go by destination address.
171 * Not last hop source routed frames go by _next_ route descriptor.
172 * Returns pointer to destination MAC address or fills in rdesc
173 * and returns NULL.
174 */
175#ifdef CONFIG_TR
176static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
177{
Chas Williamsd44f7742006-09-29 17:11:14 -0700178 struct trh_hdr *trh;
Eric Dumazet5c17d5f2008-01-15 03:29:50 -0800179 unsigned int riflen, num_rdsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Chas Williamsd44f7742006-09-29 17:11:14 -0700181 trh = (struct trh_hdr *)packet;
182 if (trh->daddr[0] & (uint8_t) 0x80)
183 return bus_mac; /* multicast */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Chas Williamsd44f7742006-09-29 17:11:14 -0700185 if (trh->saddr[0] & TR_RII) {
186 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
187 if ((ntohs(trh->rcf) >> 13) != 0)
188 return bus_mac; /* ARE or STE */
189 } else
190 return trh->daddr; /* not source routed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Chas Williamsd44f7742006-09-29 17:11:14 -0700192 if (riflen < 6)
193 return trh->daddr; /* last hop, source routed */
194
195 /* riflen is 6 or more, packet has more than one route descriptor */
196 num_rdsc = (riflen / 2) - 1;
197 memset(rdesc, 0, ETH_ALEN);
198 /* offset 4 comes from LAN destination field in LE control frames */
199 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
Al Viro30d492d2006-11-14 21:11:29 -0800200 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700201 else {
Al Viro30d492d2006-11-14 21:11:29 -0800202 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
Chas Williamsd44f7742006-09-29 17:11:14 -0700203 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
204 }
205
206 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
208#endif /* CONFIG_TR */
209
210/*
211 * Open/initialize the netdevice. This is called (in the current kernel)
212 * sometime after booting when the 'ifconfig' program is run.
213 *
214 * This routine should set everything up anew at each open, even
215 * registers that "should" only need to be set once at boot, so that
216 * there is non-reboot way to recover if something goes wrong.
217 */
218
Chas Williamsd44f7742006-09-29 17:11:14 -0700219static int lec_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 netif_start_queue(dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000222 memset(&dev->stats, 0, sizeof(struct net_device_stats));
Chas Williamsd44f7742006-09-29 17:11:14 -0700223
224 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
226
Stephen Hemminger162619e2009-01-09 13:01:01 +0000227static void
228lec_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
Stephen Hemminger162619e2009-01-09 13:01:01 +0000230 struct net_device *dev = skb->dev;
231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 ATM_SKB(skb)->vcc = vcc;
233 ATM_SKB(skb)->atm_options = vcc->atm_options;
234
235 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
236 if (vcc->send(vcc, skb) < 0) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000237 dev->stats.tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 return;
239 }
240
Stephen Hemminger162619e2009-01-09 13:01:01 +0000241 dev->stats.tx_packets++;
242 dev->stats.tx_bytes += skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243}
244
Chas Williamsd44f7742006-09-29 17:11:14 -0700245static void lec_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
Joe Perches99824462010-01-26 11:40:00 +0000247 pr_info("%s\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 dev->trans_start = jiffies;
249 netif_wake_queue(dev);
250}
251
Stephen Hemminger3c805a22009-08-31 19:50:42 +0000252static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
253 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
Chas Williamsd44f7742006-09-29 17:11:14 -0700255 struct sk_buff *skb2;
Wang Chen524ad0a2008-11-12 23:39:10 -0800256 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700257 struct lecdatahdr_8023 *lec_h;
258 struct atm_vcc *vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700260 unsigned char *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 int min_frame_size;
262#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700263 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700265 int is_rdesc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700267 char buf[300];
268 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269#endif /* DUMP_PACKETS >0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Joe Perches99824462010-01-26 11:40:00 +0000271 pr_debug("called\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700272 if (!priv->lecd) {
273 printk("%s:No lecd attached\n", dev->name);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000274 dev->stats.tx_errors++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700275 netif_stop_queue(dev);
Patrick McHardy81fbbf62009-06-12 05:34:37 +0000276 kfree_skb(skb);
277 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700278 }
279
Stephen Hemminger52240062007-08-28 15:22:09 -0700280 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
Joe Perches99824462010-01-26 11:40:00 +0000281 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
282 (long)skb_end_pointer(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700284 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
285 lec_handle_bridge(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286#endif
287
Chas Williamsd44f7742006-09-29 17:11:14 -0700288 /* Make sure we have room for lec_id */
289 if (skb_headroom(skb) < 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Joe Perches99824462010-01-26 11:40:00 +0000291 pr_debug("reallocating skb\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700292 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
293 kfree_skb(skb);
294 if (skb2 == NULL)
Patrick McHardy6ed10652009-06-23 06:03:08 +0000295 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700296 skb = skb2;
297 }
298 skb_push(skb, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Chas Williamsd44f7742006-09-29 17:11:14 -0700300 /* Put le header to place, works for TokenRing too */
301 lec_h = (struct lecdatahdr_8023 *)skb->data;
302 lec_h->le_header = htons(priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700305 /*
306 * Ugly. Use this to realign Token Ring packets for
307 * e.g. PCA-200E driver.
308 */
309 if (priv->is_trdev) {
310 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
311 kfree_skb(skb);
312 if (skb2 == NULL)
Patrick McHardy6ed10652009-06-23 06:03:08 +0000313 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700314 skb = skb2;
315 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316#endif
317
318#if DUMP_PACKETS > 0
Chas Williamsd44f7742006-09-29 17:11:14 -0700319 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
320 skb->len, priv->lecid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321#if DUMP_PACKETS >= 2
Chas Williamsd44f7742006-09-29 17:11:14 -0700322 for (i = 0; i < skb->len && i < 99; i++) {
323 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325#elif DUMP_PACKETS >= 1
Chas Williamsd44f7742006-09-29 17:11:14 -0700326 for (i = 0; i < skb->len && i < 30; i++) {
327 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329#endif /* DUMP_PACKETS >= 1 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700330 if (i == skb->len)
331 printk("%s\n", buf);
332 else
333 printk("%s...\n", buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334#endif /* DUMP_PACKETS > 0 */
335
Chas Williamsd44f7742006-09-29 17:11:14 -0700336 /* Minimum ethernet-frame size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700338 if (priv->is_trdev)
339 min_frame_size = LEC_MINIMUM_8025_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 else
341#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700342 min_frame_size = LEC_MINIMUM_8023_SIZE;
343 if (skb->len < min_frame_size) {
344 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
345 skb2 = skb_copy_expand(skb, 0,
346 min_frame_size - skb->truesize,
347 GFP_ATOMIC);
348 dev_kfree_skb(skb);
349 if (skb2 == NULL) {
Stephen Hemminger162619e2009-01-09 13:01:01 +0000350 dev->stats.tx_dropped++;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000351 return NETDEV_TX_OK;
Chas Williamsd44f7742006-09-29 17:11:14 -0700352 }
353 skb = skb2;
354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 skb_put(skb, min_frame_size - skb->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700356 }
357
358 /* Send to right vcc */
359 is_rdesc = 0;
360 dst = lec_h->h_dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700362 if (priv->is_trdev) {
363 dst = get_tr_dst(skb->data + 2, rdesc);
364 if (dst == NULL) {
365 dst = rdesc;
366 is_rdesc = 1;
367 }
368 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700370 entry = NULL;
371 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
Joe Perches99824462010-01-26 11:40:00 +0000372 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n",
373 dev->name, vcc, vcc ? vcc->flags : 0, entry);
Chas Williamsd44f7742006-09-29 17:11:14 -0700374 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
375 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
Joe Perches99824462010-01-26 11:40:00 +0000376 pr_debug("%s:queuing packet, MAC address %pM\n",
377 dev->name, lec_h->h_dest);
Chas Williamsd44f7742006-09-29 17:11:14 -0700378 skb_queue_tail(&entry->tx_wait, skb);
379 } else {
Joe Perches99824462010-01-26 11:40:00 +0000380 pr_debug("%s:tx queue full or no arp entry, dropping, MAC address: %pM\n",
381 dev->name, lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000382 dev->stats.tx_dropped++;
Chas Williamsd44f7742006-09-29 17:11:14 -0700383 dev_kfree_skb(skb);
384 }
Chas Williams6656e3c2006-09-29 17:17:17 -0700385 goto out;
Chas Williamsd44f7742006-09-29 17:11:14 -0700386 }
387#if DUMP_PACKETS > 0
388 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389#endif /* DUMP_PACKETS > 0 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700390
391 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
Joe Perches99824462010-01-26 11:40:00 +0000392 pr_debug("emptying tx queue, MAC address %pM\n", lec_h->h_dest);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000393 lec_send(vcc, skb2);
Chas Williamsd44f7742006-09-29 17:11:14 -0700394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Stephen Hemminger162619e2009-01-09 13:01:01 +0000396 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 if (!atm_may_send(vcc, 0)) {
399 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
400
401 vpriv->xoff = 1;
402 netif_stop_queue(dev);
403
404 /*
405 * vcc->pop() might have occurred in between, making
406 * the vcc usuable again. Since xmit is serialized,
407 * this is the only situation we have to re-test.
408 */
409
410 if (atm_may_send(vcc, 0))
411 netif_wake_queue(dev);
412 }
413
Chas Williams6656e3c2006-09-29 17:17:17 -0700414out:
415 if (entry)
416 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 dev->trans_start = jiffies;
Patrick McHardy6ed10652009-06-23 06:03:08 +0000418 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419}
420
421/* The inverse routine to net_open(). */
Chas Williamsd44f7742006-09-29 17:11:14 -0700422static int lec_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
Chas Williamsd44f7742006-09-29 17:11:14 -0700424 netif_stop_queue(dev);
425 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426}
427
Chas Williamsd44f7742006-09-29 17:11:14 -0700428static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
430 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700431 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800432 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -0700433 struct atmlec_msg *mesg;
434 struct lec_arp_table *entry;
435 int i;
436 char *tmp; /* FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
Chas Williamsd44f7742006-09-29 17:11:14 -0700439 mesg = (struct atmlec_msg *)skb->data;
440 tmp = skb->data;
441 tmp += sizeof(struct atmlec_msg);
Stephen Hemminger52240062007-08-28 15:22:09 -0700442 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
Chas Williamsd44f7742006-09-29 17:11:14 -0700443 switch (mesg->type) {
444 case l_set_mac_addr:
445 for (i = 0; i < 6; i++) {
446 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
447 }
448 break;
449 case l_del_mac_addr:
450 for (i = 0; i < 6; i++) {
451 dev->dev_addr[i] = 0;
452 }
453 break;
454 case l_addr_delete:
455 lec_addr_delete(priv, mesg->content.normal.atm_addr,
456 mesg->content.normal.flag);
457 break;
458 case l_topology_change:
459 priv->topology_change = mesg->content.normal.flag;
460 break;
461 case l_flush_complete:
462 lec_flush_complete(priv, mesg->content.normal.flag);
463 break;
464 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -0700466 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
467 lec_arp_remove(priv, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
469
Chas Williamsd44f7742006-09-29 17:11:14 -0700470 if (mesg->content.normal.no_source_le_narp)
471 break;
472 /* FALL THROUGH */
473 case l_arp_update:
474 lec_arp_update(priv, mesg->content.normal.mac_addr,
475 mesg->content.normal.atm_addr,
476 mesg->content.normal.flag,
477 mesg->content.normal.targetless_le_arp);
Joe Perches99824462010-01-26 11:40:00 +0000478 pr_debug("in l_arp_update\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700479 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
Joe Perches99824462010-01-26 11:40:00 +0000480 pr_debug("LANE2 3.1.5, got tlvs, size %d\n",
481 mesg->sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -0700482 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
483 tmp, mesg->sizeoftlvs);
484 }
485 break;
486 case l_config:
487 priv->maximum_unknown_frame_count =
488 mesg->content.config.maximum_unknown_frame_count;
489 priv->max_unknown_frame_time =
490 (mesg->content.config.max_unknown_frame_time * HZ);
491 priv->max_retry_count = mesg->content.config.max_retry_count;
492 priv->aging_time = (mesg->content.config.aging_time * HZ);
493 priv->forward_delay_time =
494 (mesg->content.config.forward_delay_time * HZ);
495 priv->arp_response_time =
496 (mesg->content.config.arp_response_time * HZ);
497 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
498 priv->path_switching_delay =
499 (mesg->content.config.path_switching_delay * HZ);
500 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 priv->lane2_ops = NULL;
502 if (priv->lane_version > 1)
503 priv->lane2_ops = &lane2_ops;
Stephen Hemminger1f1900f2009-03-21 13:37:28 -0700504 if (dev_set_mtu(dev, mesg->content.config.mtu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 printk("%s: change_mtu to %d failed\n", dev->name,
Chas Williamsd44f7742006-09-29 17:11:14 -0700506 mesg->content.config.mtu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 priv->is_proxy = mesg->content.config.is_proxy;
Chas Williamsd44f7742006-09-29 17:11:14 -0700508 break;
509 case l_flush_tran_id:
510 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
511 mesg->content.normal.flag);
512 break;
513 case l_set_lecid:
514 priv->lecid =
515 (unsigned short)(0xffff & mesg->content.normal.flag);
516 break;
517 case l_should_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
Chas Williamsd44f7742006-09-29 17:11:14 -0700519 {
Johannes Berge1749612008-10-27 15:59:26 -0700520 pr_debug("%s: bridge zeppelin asks about %pM\n",
521 dev->name, mesg->content.proxy.mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Michał Mirosławda678292009-06-05 05:35:28 +0000523 if (br_fdb_test_addr_hook == NULL)
Chas Williamsd44f7742006-09-29 17:11:14 -0700524 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Michał Mirosławda678292009-06-05 05:35:28 +0000526 if (br_fdb_test_addr_hook(dev,
527 mesg->content.proxy.mac_addr)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700528 /* hit from bridge table, send LE_ARP_RESPONSE */
529 struct sk_buff *skb2;
530 struct sock *sk;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Joe Perches99824462010-01-26 11:40:00 +0000532 pr_debug("%s: entry found, responding to zeppelin\n",
533 dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700534 skb2 =
535 alloc_skb(sizeof(struct atmlec_msg),
536 GFP_ATOMIC);
Michał Mirosławda678292009-06-05 05:35:28 +0000537 if (skb2 == NULL)
Chas Williamsd44f7742006-09-29 17:11:14 -0700538 break;
Chas Williamsd44f7742006-09-29 17:11:14 -0700539 skb2->len = sizeof(struct atmlec_msg);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300540 skb_copy_to_linear_data(skb2, mesg,
541 sizeof(*mesg));
Chas Williamsd44f7742006-09-29 17:11:14 -0700542 atm_force_charge(priv->lecd, skb2->truesize);
543 sk = sk_atm(priv->lecd);
544 skb_queue_tail(&sk->sk_receive_queue, skb2);
545 sk->sk_data_ready(sk, skb2->len);
546 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548#endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
Chas Williamsd44f7742006-09-29 17:11:14 -0700549 break;
550 default:
551 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
552 dev_kfree_skb(skb);
553 return -EINVAL;
554 }
555 dev_kfree_skb(skb);
556 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557}
558
Chas Williamsd44f7742006-09-29 17:11:14 -0700559static void lec_atm_close(struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560{
Chas Williamsd44f7742006-09-29 17:11:14 -0700561 struct sk_buff *skb;
562 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800563 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
Chas Williamsd44f7742006-09-29 17:11:14 -0700565 priv->lecd = NULL;
566 /* Do something needful? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Chas Williamsd44f7742006-09-29 17:11:14 -0700568 netif_stop_queue(dev);
569 lec_arp_destroy(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Chas Williamsd44f7742006-09-29 17:11:14 -0700571 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 printk("%s lec_atm_close: closing with messages pending\n",
Chas Williamsd44f7742006-09-29 17:11:14 -0700573 dev->name);
574 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
575 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 dev_kfree_skb(skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700577 }
578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 printk("%s: Shut down!\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700580 module_put(THIS_MODULE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581}
582
583static struct atmdev_ops lecdev_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700584 .close = lec_atm_close,
585 .send = lec_atm_send
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586};
587
588static struct atm_dev lecatm_dev = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700589 .ops = &lecdev_ops,
590 .type = "lec",
591 .number = 999, /* dummy device number */
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700592 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593};
594
595/*
596 * LANE2: new argument struct sk_buff *data contains
597 * the LE_ARP based TLVs introduced in the LANE2 spec
598 */
Chas Williamsd44f7742006-09-29 17:11:14 -0700599static int
600send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700601 const unsigned char *mac_addr, const unsigned char *atm_addr,
Chas Williamsd44f7742006-09-29 17:11:14 -0700602 struct sk_buff *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
604 struct sock *sk;
605 struct sk_buff *skb;
606 struct atmlec_msg *mesg;
607
608 if (!priv || !priv->lecd) {
609 return -1;
610 }
611 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
612 if (!skb)
613 return -1;
614 skb->len = sizeof(struct atmlec_msg);
615 mesg = (struct atmlec_msg *)skb->data;
Chas Williamsd44f7742006-09-29 17:11:14 -0700616 memset(mesg, 0, sizeof(struct atmlec_msg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 mesg->type = type;
Chas Williamsd44f7742006-09-29 17:11:14 -0700618 if (data != NULL)
619 mesg->sizeoftlvs = data->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 if (mac_addr)
621 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd44f7742006-09-29 17:11:14 -0700622 else
623 mesg->content.normal.targetless_le_arp = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 if (atm_addr)
625 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
626
Chas Williamsd44f7742006-09-29 17:11:14 -0700627 atm_force_charge(priv->lecd, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 sk = sk_atm(priv->lecd);
629 skb_queue_tail(&sk->sk_receive_queue, skb);
Chas Williamsd44f7742006-09-29 17:11:14 -0700630 sk->sk_data_ready(sk, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
Chas Williamsd44f7742006-09-29 17:11:14 -0700632 if (data != NULL) {
Joe Perches99824462010-01-26 11:40:00 +0000633 pr_debug("about to send %d bytes of data\n", data->len);
Chas Williamsd44f7742006-09-29 17:11:14 -0700634 atm_force_charge(priv->lecd, data->truesize);
635 skb_queue_tail(&sk->sk_receive_queue, data);
636 sk->sk_data_ready(sk, skb->len);
637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Chas Williamsd44f7742006-09-29 17:11:14 -0700639 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640}
641
642/* shamelessly stolen from drivers/net/net_init.c */
643static int lec_change_mtu(struct net_device *dev, int new_mtu)
644{
Chas Williamsd44f7742006-09-29 17:11:14 -0700645 if ((new_mtu < 68) || (new_mtu > 18190))
646 return -EINVAL;
647 dev->mtu = new_mtu;
648 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649}
650
651static void lec_set_multicast_list(struct net_device *dev)
652{
Chas Williamsd44f7742006-09-29 17:11:14 -0700653 /*
654 * by default, all multicast frames arrive over the bus.
655 * eventually support selective multicast service
656 */
657 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658}
659
Stephen Hemminger004b3222009-01-09 13:01:02 +0000660static const struct net_device_ops lec_netdev_ops = {
661 .ndo_open = lec_open,
662 .ndo_stop = lec_close,
663 .ndo_start_xmit = lec_start_xmit,
664 .ndo_change_mtu = lec_change_mtu,
665 .ndo_tx_timeout = lec_tx_timeout,
666 .ndo_set_multicast_list = lec_set_multicast_list,
667};
668
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700669static const unsigned char lec_ctrl_magic[] = {
Chas Williamsd44f7742006-09-29 17:11:14 -0700670 0xff,
671 0x00,
672 0x01,
673 0x01
674};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Scott Talbert4a7097f2005-09-29 17:30:54 -0700676#define LEC_DATA_DIRECT_8023 2
677#define LEC_DATA_DIRECT_8025 3
678
679static int lec_is_data_direct(struct atm_vcc *vcc)
Chas Williamsd44f7742006-09-29 17:11:14 -0700680{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700681 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
682 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
Chas Williamsd44f7742006-09-29 17:11:14 -0700683}
Scott Talbert4a7097f2005-09-29 17:30:54 -0700684
Chas Williamsd44f7742006-09-29 17:11:14 -0700685static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
Scott Talbert4a7097f2005-09-29 17:30:54 -0700687 unsigned long flags;
Chas Williamsd44f7742006-09-29 17:11:14 -0700688 struct net_device *dev = (struct net_device *)vcc->proto_data;
Wang Chen524ad0a2008-11-12 23:39:10 -0800689 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691#if DUMP_PACKETS >0
Joe Perches99824462010-01-26 11:40:00 +0000692 printk(KERN_DEBUG "%s: vcc vpi:%d vci:%d\n",
693 dev->name, vcc->vpi, vcc->vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700695 if (!skb) {
Stephen Hemminger52240062007-08-28 15:22:09 -0700696 pr_debug("%s: null skb\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700697 lec_vcc_close(priv, vcc);
698 return;
699 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700#if DUMP_PACKETS >= 2
Joe Perches99824462010-01-26 11:40:00 +0000701#define MAX_SKB_DUMP 99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702#elif DUMP_PACKETS >= 1
Joe Perches99824462010-01-26 11:40:00 +0000703#define MAX_SKB_DUMP 30
704#endif
705#if DUMP_PACKETS > 0
706 printk(KERN_DEBUG "%s: rcv datalen:%ld lecid:%4.4x\n",
707 dev->name, skb->len, priv->lecid);
708 print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1,
709 skb->data, min(MAX_SKB_DUMP, skb->len), true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710#endif /* DUMP_PACKETS > 0 */
Joe Perches99824462010-01-26 11:40:00 +0000711 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) {
712 /* Control frame, to daemon */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 struct sock *sk = sk_atm(vcc);
714
Stephen Hemminger52240062007-08-28 15:22:09 -0700715 pr_debug("%s: To daemon\n", dev->name);
Chas Williamsd44f7742006-09-29 17:11:14 -0700716 skb_queue_tail(&sk->sk_receive_queue, skb);
717 sk->sk_data_ready(sk, skb->len);
718 } else { /* Data frame, queue to protocol handlers */
Scott Talbert4a7097f2005-09-29 17:30:54 -0700719 struct lec_arp_table *entry;
Chas Williamsd44f7742006-09-29 17:11:14 -0700720 unsigned char *src, *dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Chas Williamsd44f7742006-09-29 17:11:14 -0700722 atm_return(vcc, skb->truesize);
Al Viro30d492d2006-11-14 21:11:29 -0800723 if (*(__be16 *) skb->data == htons(priv->lecid) ||
Chas Williamsd44f7742006-09-29 17:11:14 -0700724 !priv->lecd || !(dev->flags & IFF_UP)) {
725 /*
726 * Probably looping back, or if lecd is missing,
727 * lecd has gone down
728 */
Stephen Hemminger52240062007-08-28 15:22:09 -0700729 pr_debug("Ignoring frame...\n");
Chas Williamsd44f7742006-09-29 17:11:14 -0700730 dev_kfree_skb(skb);
731 return;
732 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700734 if (priv->is_trdev)
735 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
736 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700738 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700739
Chas Williamsd44f7742006-09-29 17:11:14 -0700740 /*
741 * If this is a Data Direct VCC, and the VCC does not match
Scott Talbert4a7097f2005-09-29 17:30:54 -0700742 * the LE_ARP cache entry, delete the LE_ARP cache entry.
743 */
744 spin_lock_irqsave(&priv->lec_arp_lock, flags);
745 if (lec_is_data_direct(vcc)) {
746#ifdef CONFIG_TR
747 if (priv->is_trdev)
Chas Williamsd44f7742006-09-29 17:11:14 -0700748 src =
749 ((struct lecdatahdr_8025 *)skb->data)->
750 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700751 else
752#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700753 src =
754 ((struct lecdatahdr_8023 *)skb->data)->
755 h_source;
Scott Talbert4a7097f2005-09-29 17:30:54 -0700756 entry = lec_arp_find(priv, src);
757 if (entry && entry->vcc != vcc) {
758 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -0700759 lec_arp_put(entry);
Scott Talbert4a7097f2005-09-29 17:30:54 -0700760 }
761 }
762 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Chas Williamsd44f7742006-09-29 17:11:14 -0700764 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
765 !priv->is_proxy && /* Proxy wants all the packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 memcmp(dst, dev->dev_addr, dev->addr_len)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700767 dev_kfree_skb(skb);
768 return;
769 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700770 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
Chas Williamsd44f7742006-09-29 17:11:14 -0700771 lec_arp_check_empties(priv, vcc, skb);
772 }
Chas Williamsd44f7742006-09-29 17:11:14 -0700773 skb_pull(skb, 2); /* skip lec_id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700775 if (priv->is_trdev)
776 skb->protocol = tr_type_trans(skb, dev);
777 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700779 skb->protocol = eth_type_trans(skb, dev);
Stephen Hemminger162619e2009-01-09 13:01:01 +0000780 dev->stats.rx_packets++;
781 dev->stats.rx_bytes += skb->len;
Chas Williamsd44f7742006-09-29 17:11:14 -0700782 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
783 netif_rx(skb);
784 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785}
786
Chas Williamsd44f7742006-09-29 17:11:14 -0700787static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788{
789 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
790 struct net_device *dev = skb->dev;
791
792 if (vpriv == NULL) {
Joe Perches99824462010-01-26 11:40:00 +0000793 pr_info("vpriv = NULL!?!?!?\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 return;
795 }
796
797 vpriv->old_pop(vcc, skb);
798
799 if (vpriv->xoff && atm_may_send(vcc, 0)) {
800 vpriv->xoff = 0;
801 if (netif_running(dev) && netif_queue_stopped(dev))
802 netif_wake_queue(dev);
803 }
804}
805
Chas Williamsd44f7742006-09-29 17:11:14 -0700806static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807{
808 struct lec_vcc_priv *vpriv;
Chas Williamsd44f7742006-09-29 17:11:14 -0700809 int bytes_left;
810 struct atmlec_ioc ioc_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Chas Williamsd44f7742006-09-29 17:11:14 -0700812 /* Lecd must be up in this case */
813 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
Joe Perches99824462010-01-26 11:40:00 +0000814 if (bytes_left != 0)
815 pr_info("copy from user failed for %d bytes\n", bytes_left);
Chas Williamsd44f7742006-09-29 17:11:14 -0700816 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
817 !dev_lec[ioc_data.dev_num])
818 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
820 return -ENOMEM;
821 vpriv->xoff = 0;
822 vpriv->old_pop = vcc->pop;
823 vcc->user_back = vpriv;
824 vcc->pop = lec_pop;
Wang Chen524ad0a2008-11-12 23:39:10 -0800825 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
Chas Williamsd44f7742006-09-29 17:11:14 -0700826 &ioc_data, vcc, vcc->push);
827 vcc->proto_data = dev_lec[ioc_data.dev_num];
828 vcc->push = lec_push;
829 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830}
831
Chas Williamsd44f7742006-09-29 17:11:14 -0700832static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833{
Chas Williamsd44f7742006-09-29 17:11:14 -0700834 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
835 return -EINVAL;
836 vcc->proto_data = dev_lec[arg];
Wang Chen524ad0a2008-11-12 23:39:10 -0800837 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
838 vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839}
840
841/* Initialize device. */
Chas Williamsd44f7742006-09-29 17:11:14 -0700842static int lecd_attach(struct atm_vcc *vcc, int arg)
843{
844 int i;
845 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
Chas Williamsd44f7742006-09-29 17:11:14 -0700847 if (arg < 0)
848 i = 0;
849 else
850 i = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700852 if (arg >= MAX_LEC_ITF)
853 return -EINVAL;
854#else /* Reserve the top NUM_TR_DEVS for TR */
855 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
856 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700858 if (!dev_lec[i]) {
859 int is_trdev, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Chas Williamsd44f7742006-09-29 17:11:14 -0700861 is_trdev = 0;
862 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
863 is_trdev = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Chas Williamsd44f7742006-09-29 17:11:14 -0700865 size = sizeof(struct lec_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866#ifdef CONFIG_TR
Chas Williamsd44f7742006-09-29 17:11:14 -0700867 if (is_trdev)
868 dev_lec[i] = alloc_trdev(size);
869 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870#endif
Chas Williamsd44f7742006-09-29 17:11:14 -0700871 dev_lec[i] = alloc_etherdev(size);
872 if (!dev_lec[i])
873 return -ENOMEM;
chas williams - CONTRACTOReb044582009-12-04 05:19:30 +0000874 dev_lec[i]->netdev_ops = &lec_netdev_ops;
Chas Williamsd44f7742006-09-29 17:11:14 -0700875 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
876 if (register_netdev(dev_lec[i])) {
877 free_netdev(dev_lec[i]);
878 return -EINVAL;
879 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
Wang Chen524ad0a2008-11-12 23:39:10 -0800881 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700882 priv->is_trdev = is_trdev;
Chas Williamsd44f7742006-09-29 17:11:14 -0700883 } else {
Wang Chen524ad0a2008-11-12 23:39:10 -0800884 priv = netdev_priv(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -0700885 if (priv->lecd)
886 return -EADDRINUSE;
887 }
888 lec_arp_init(priv);
889 priv->itfnum = i; /* LANE2 addition */
890 priv->lecd = vcc;
891 vcc->dev = &lecatm_dev;
892 vcc_insert_socket(sk_atm(vcc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Chas Williamsd44f7742006-09-29 17:11:14 -0700894 vcc->proto_data = dev_lec[i];
895 set_bit(ATM_VF_META, &vcc->flags);
896 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
Chas Williamsd44f7742006-09-29 17:11:14 -0700898 /* Set default values to these variables */
899 priv->maximum_unknown_frame_count = 1;
900 priv->max_unknown_frame_time = (1 * HZ);
901 priv->vcc_timeout_period = (1200 * HZ);
902 priv->max_retry_count = 1;
903 priv->aging_time = (300 * HZ);
904 priv->forward_delay_time = (15 * HZ);
905 priv->topology_change = 0;
906 priv->arp_response_time = (1 * HZ);
907 priv->flush_timeout = (4 * HZ);
908 priv->path_switching_delay = (6 * HZ);
909
910 if (dev_lec[i]->flags & IFF_UP) {
911 netif_start_queue(dev_lec[i]);
912 }
913 __module_get(THIS_MODULE);
914 return i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915}
916
917#ifdef CONFIG_PROC_FS
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700918static const char *lec_arp_get_status_string(unsigned char status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700920 static const char *const lec_arp_status_string[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 "ESI_UNKNOWN ",
922 "ESI_ARP_PENDING ",
923 "ESI_VC_PENDING ",
924 "<Undefined> ",
925 "ESI_FLUSH_PENDING ",
926 "ESI_FORWARD_DIRECT"
927 };
928
929 if (status > ESI_FORWARD_DIRECT)
930 status = 3; /* ESI_UNDEFINED */
931 return lec_arp_status_string[status];
932}
933
934static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
935{
936 int i;
937
938 for (i = 0; i < ETH_ALEN; i++)
939 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
940 seq_printf(seq, " ");
941 for (i = 0; i < ATM_ESA_LEN; i++)
942 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
943 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
944 entry->flags & 0xffff);
945 if (entry->vcc)
946 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
947 else
Chas Williamsd44f7742006-09-29 17:11:14 -0700948 seq_printf(seq, " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 if (entry->recv_vcc) {
950 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
951 entry->recv_vcc->vci);
Chas Williamsd44f7742006-09-29 17:11:14 -0700952 }
953 seq_putc(seq, '\n');
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954}
955
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956struct lec_state {
957 unsigned long flags;
958 struct lec_priv *locked;
Chas Williamsd0732f62006-09-29 17:14:27 -0700959 struct hlist_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 struct net_device *dev;
961 int itf;
962 int arp_table;
963 int misc_table;
964};
965
Chas Williamsd0732f62006-09-29 17:14:27 -0700966static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 loff_t *l)
968{
Chas Williamsd0732f62006-09-29 17:14:27 -0700969 struct hlist_node *e = state->node;
970 struct lec_arp_table *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
972 if (!e)
Chas Williamsd0732f62006-09-29 17:14:27 -0700973 e = tbl->first;
Joe Perches2e1e9842008-04-10 03:33:03 -0700974 if (e == SEQ_START_TOKEN) {
Chas Williamsd0732f62006-09-29 17:14:27 -0700975 e = tbl->first;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 --*l;
977 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700978
979 hlist_for_each_entry_from(tmp, e, next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 if (--*l < 0)
981 break;
982 }
Chas Williamsd0732f62006-09-29 17:14:27 -0700983 state->node = e;
984
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 return (*l < 0) ? state : NULL;
986}
987
988static void *lec_arp_walk(struct lec_state *state, loff_t *l,
Chas Williamsd44f7742006-09-29 17:11:14 -0700989 struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990{
991 void *v = NULL;
992 int p;
993
994 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
Chas Williamsd0732f62006-09-29 17:14:27 -0700995 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 if (v)
997 break;
998 }
999 state->arp_table = p;
1000 return v;
1001}
1002
1003static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1004 struct lec_priv *priv)
1005{
Chas Williamsd0732f62006-09-29 17:14:27 -07001006 struct hlist_head *lec_misc_tables[] = {
1007 &priv->lec_arp_empty_ones,
1008 &priv->lec_no_forward,
1009 &priv->mcast_fwds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 };
1011 void *v = NULL;
1012 int q;
1013
1014 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1015 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1016 if (v)
1017 break;
1018 }
1019 state->misc_table = q;
1020 return v;
1021}
1022
1023static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1024 struct lec_priv *priv)
1025{
1026 if (!state->locked) {
1027 state->locked = priv;
1028 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1029 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001030 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1032 state->locked = NULL;
1033 /* Partial state reset for the next time we get called */
1034 state->arp_table = state->misc_table = 0;
1035 }
1036 return state->locked;
1037}
1038
1039static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1040{
1041 struct net_device *dev;
1042 void *v;
1043
1044 dev = state->dev ? state->dev : dev_lec[state->itf];
Wang Chen524ad0a2008-11-12 23:39:10 -08001045 v = (dev && netdev_priv(dev)) ?
1046 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 if (!v && dev) {
1048 dev_put(dev);
1049 /* Partial state reset for the next time we get called */
1050 dev = NULL;
1051 }
1052 state->dev = dev;
1053 return v;
1054}
1055
1056static void *lec_get_idx(struct lec_state *state, loff_t l)
1057{
1058 void *v = NULL;
1059
1060 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1061 v = lec_itf_walk(state, &l);
1062 if (v)
1063 break;
1064 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001065 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066}
1067
1068static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1069{
1070 struct lec_state *state = seq->private;
1071
1072 state->itf = 0;
1073 state->dev = NULL;
1074 state->locked = NULL;
1075 state->arp_table = 0;
1076 state->misc_table = 0;
Joe Perches2e1e9842008-04-10 03:33:03 -07001077 state->node = SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
Joe Perches2e1e9842008-04-10 03:33:03 -07001079 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080}
1081
1082static void lec_seq_stop(struct seq_file *seq, void *v)
1083{
1084 struct lec_state *state = seq->private;
1085
1086 if (state->dev) {
1087 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1088 state->flags);
1089 dev_put(state->dev);
1090 }
1091}
1092
1093static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1094{
1095 struct lec_state *state = seq->private;
1096
1097 v = lec_get_idx(state, 1);
1098 *pos += !!PTR_ERR(v);
1099 return v;
1100}
1101
1102static int lec_seq_show(struct seq_file *seq, void *v)
1103{
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001104 static const char lec_banner[] =
1105 "Itf MAC ATM destination"
Chas Williamsd44f7742006-09-29 17:11:14 -07001106 " Status Flags "
1107 "VPI/VCI Recv VPI/VCI\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
Joe Perches2e1e9842008-04-10 03:33:03 -07001109 if (v == SEQ_START_TOKEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 seq_puts(seq, lec_banner);
1111 else {
1112 struct lec_state *state = seq->private;
Chas Williamsd44f7742006-09-29 17:11:14 -07001113 struct net_device *dev = state->dev;
Chas Williamsd0732f62006-09-29 17:14:27 -07001114 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
1116 seq_printf(seq, "%s ", dev->name);
Chas Williamsd0732f62006-09-29 17:14:27 -07001117 lec_info(seq, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 }
1119 return 0;
1120}
1121
Philippe De Muyter56b3d972007-07-10 23:07:31 -07001122static const struct seq_operations lec_seq_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001123 .start = lec_seq_start,
1124 .next = lec_seq_next,
1125 .stop = lec_seq_stop,
1126 .show = lec_seq_show,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127};
1128
1129static int lec_seq_open(struct inode *inode, struct file *file)
1130{
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001131 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
Arjan van de Ven9a321442007-02-12 00:55:35 -08001134static const struct file_operations lec_seq_fops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001135 .owner = THIS_MODULE,
1136 .open = lec_seq_open,
1137 .read = seq_read,
1138 .llseek = seq_lseek,
Pavel Emelyanov9a8c09e2008-02-29 11:37:02 -08001139 .release = seq_release_private,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140};
1141#endif
1142
1143static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1144{
1145 struct atm_vcc *vcc = ATM_SD(sock);
1146 int err = 0;
Chas Williamsd44f7742006-09-29 17:11:14 -07001147
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001149 case ATMLEC_CTRL:
1150 case ATMLEC_MCAST:
1151 case ATMLEC_DATA:
1152 if (!capable(CAP_NET_ADMIN))
1153 return -EPERM;
1154 break;
1155 default:
1156 return -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 }
1158
1159 switch (cmd) {
Chas Williamsd44f7742006-09-29 17:11:14 -07001160 case ATMLEC_CTRL:
1161 err = lecd_attach(vcc, (int)arg);
1162 if (err >= 0)
1163 sock->state = SS_CONNECTED;
1164 break;
1165 case ATMLEC_MCAST:
1166 err = lec_mcast_attach(vcc, (int)arg);
1167 break;
1168 case ATMLEC_DATA:
1169 err = lec_vcc_attach(vcc, (void __user *)arg);
1170 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 }
1172
1173 return err;
1174}
1175
1176static struct atm_ioctl lane_ioctl_ops = {
Chas Williamsd44f7742006-09-29 17:11:14 -07001177 .owner = THIS_MODULE,
1178 .ioctl = lane_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179};
1180
1181static int __init lane_module_init(void)
1182{
1183#ifdef CONFIG_PROC_FS
1184 struct proc_dir_entry *p;
1185
Wang Chen16e297b2008-02-28 13:55:45 -08001186 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
Wang Chendbee0d32008-03-23 21:45:36 -07001187 if (!p) {
Joe Perches99824462010-01-26 11:40:00 +00001188 pr_err("Unable to initialize /proc/net/atm/lec\n");
Wang Chendbee0d32008-03-23 21:45:36 -07001189 return -ENOMEM;
1190 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191#endif
1192
1193 register_atm_ioctl(&lane_ioctl_ops);
Chas Williamsd44f7742006-09-29 17:11:14 -07001194 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1195 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196}
1197
1198static void __exit lane_module_cleanup(void)
1199{
Chas Williamsd44f7742006-09-29 17:11:14 -07001200 int i;
1201 struct lec_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
1203 remove_proc_entry("lec", atm_proc_root);
1204
1205 deregister_atm_ioctl(&lane_ioctl_ops);
1206
Chas Williamsd44f7742006-09-29 17:11:14 -07001207 for (i = 0; i < MAX_LEC_ITF; i++) {
1208 if (dev_lec[i] != NULL) {
Wang Chen524ad0a2008-11-12 23:39:10 -08001209 priv = netdev_priv(dev_lec[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 unregister_netdev(dev_lec[i]);
Chas Williamsd44f7742006-09-29 17:11:14 -07001211 free_netdev(dev_lec[i]);
1212 dev_lec[i] = NULL;
1213 }
1214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
Chas Williamsd44f7742006-09-29 17:11:14 -07001216 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217}
1218
1219module_init(lane_module_init);
1220module_exit(lane_module_cleanup);
1221
1222/*
1223 * LANE2: 3.1.3, LE_RESOLVE.request
1224 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1225 * If sizeoftlvs == NULL the default TLVs associated with with this
1226 * lec will be used.
1227 * If dst_mac == NULL, targetless LE_ARP will be sent
1228 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001229static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
Chas Williamsd44f7742006-09-29 17:11:14 -07001230 u8 **tlvs, u32 *sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231{
1232 unsigned long flags;
Wang Chen524ad0a2008-11-12 23:39:10 -08001233 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001234 struct lec_arp_table *table;
1235 struct sk_buff *skb;
1236 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Chas Williamsd44f7742006-09-29 17:11:14 -07001238 if (force == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001240 table = lec_arp_find(priv, dst_mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williamsd44f7742006-09-29 17:11:14 -07001242 if (table == NULL)
1243 return -1;
1244
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001245 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
Chas Williamsd44f7742006-09-29 17:11:14 -07001246 if (*tlvs == NULL)
1247 return -1;
1248
Chas Williamsd44f7742006-09-29 17:11:14 -07001249 *sizeoftlvs = table->sizeoftlvs;
1250
1251 return 0;
1252 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
1254 if (sizeoftlvs == NULL)
1255 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001256
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 else {
1258 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1259 if (skb == NULL)
1260 return -1;
1261 skb->len = *sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001262 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1264 }
Chas Williamsd44f7742006-09-29 17:11:14 -07001265 return retval;
1266}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268/*
1269 * LANE2: 3.1.4, LE_ASSOCIATE.request
1270 * Associate the *tlvs with the *lan_dst address.
1271 * Will overwrite any previous association
1272 * Returns 1 for success, 0 for failure (out of memory)
1273 *
1274 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001275static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1276 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277{
Chas Williamsd44f7742006-09-29 17:11:14 -07001278 int retval;
1279 struct sk_buff *skb;
Wang Chen524ad0a2008-11-12 23:39:10 -08001280 struct lec_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Chas Williamsd44f7742006-09-29 17:11:14 -07001282 if (compare_ether_addr(lan_dst, dev->dev_addr))
1283 return (0); /* not our mac address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
Chas Williamsd44f7742006-09-29 17:11:14 -07001285 kfree(priv->tlvs); /* NULL if there was no previous association */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001287 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001288 if (priv->tlvs == NULL)
1289 return (0);
1290 priv->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Chas Williamsd44f7742006-09-29 17:11:14 -07001292 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1293 if (skb == NULL)
1294 return 0;
1295 skb->len = sizeoftlvs;
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03001296 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
Chas Williamsd44f7742006-09-29 17:11:14 -07001297 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1298 if (retval != 0)
1299 printk("lec.c: lane2_associate_req() failed\n");
1300 /*
1301 * If the previous association has changed we must
1302 * somehow notify other LANE entities about the change
1303 */
1304 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305}
1306
1307/*
1308 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1309 *
1310 */
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001311static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1312 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313{
1314#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001315 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316#endif
Wang Chen524ad0a2008-11-12 23:39:10 -08001317 struct lec_priv *priv = netdev_priv(dev);
Chas Williamsd44f7742006-09-29 17:11:14 -07001318#if 0 /*
1319 * Why have the TLVs in LE_ARP entries
1320 * since we do not use them? When you
1321 * uncomment this code, make sure the
1322 * TLVs get freed when entry is killed
1323 */
1324 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
Chas Williamsd44f7742006-09-29 17:11:14 -07001326 if (entry == NULL)
1327 return; /* should not happen */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
Chas Williamsd44f7742006-09-29 17:11:14 -07001329 kfree(entry->tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001331 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
Chas Williamsd44f7742006-09-29 17:11:14 -07001332 if (entry->tlvs == NULL)
1333 return;
Chas Williamsd44f7742006-09-29 17:11:14 -07001334 entry->sizeoftlvs = sizeoftlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335#endif
1336#if 0
Chas Williamsd44f7742006-09-29 17:11:14 -07001337 printk("lec.c: lane2_associate_ind()\n");
1338 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1339 while (i < sizeoftlvs)
1340 printk("%02x ", tlvs[i++]);
1341
1342 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343#endif
1344
Chas Williamsd44f7742006-09-29 17:11:14 -07001345 /* tell MPOA about the TLVs we saw */
1346 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1347 priv->lane2_ops->associate_indicator(dev, mac_addr,
1348 tlvs, sizeoftlvs);
1349 }
1350 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351}
1352
1353/*
1354 * Here starts what used to lec_arpc.c
1355 *
1356 * lec_arpc.c was added here when making
1357 * lane client modular. October 1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 */
1359
1360#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361#include <linux/timer.h>
1362#include <asm/param.h>
1363#include <asm/atomic.h>
1364#include <linux/inetdevice.h>
1365#include <net/route.h>
1366
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367#if 0
Stephen Hemminger52240062007-08-28 15:22:09 -07001368#define pr_debug(format,args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369/*
Joe Perches99824462010-01-26 11:40:00 +00001370 #define pr_debug printk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371*/
1372#endif
1373#define DEBUG_ARP_TABLE 0
1374
1375#define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1376
David Howellsc4028952006-11-22 14:57:56 +00001377static void lec_arp_check_expire(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378static void lec_arp_expire_arp(unsigned long data);
1379
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001380/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 * Arp table funcs
1382 */
1383
1384#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1385
1386/*
1387 * Initialization of arp-cache
1388 */
Chas Williams1fa99612006-09-29 17:11:47 -07001389static void lec_arp_init(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390{
Chas Williams1fa99612006-09-29 17:11:47 -07001391 unsigned short i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Chas Williams1fa99612006-09-29 17:11:47 -07001393 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001394 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001395 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001396 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1397 INIT_HLIST_HEAD(&priv->lec_no_forward);
1398 INIT_HLIST_HEAD(&priv->mcast_fwds);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 spin_lock_init(&priv->lec_arp_lock);
David Howellsc4028952006-11-22 14:57:56 +00001400 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
Chas Williams987e46b2006-09-29 17:15:59 -07001401 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402}
1403
Chas Williams1fa99612006-09-29 17:11:47 -07001404static void lec_arp_clear_vccs(struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405{
Chas Williams1fa99612006-09-29 17:11:47 -07001406 if (entry->vcc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 struct atm_vcc *vcc = entry->vcc;
1408 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001409 struct net_device *dev = (struct net_device *)vcc->proto_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Chas Williams1fa99612006-09-29 17:11:47 -07001411 vcc->pop = vpriv->old_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 if (vpriv->xoff)
1413 netif_wake_queue(dev);
1414 kfree(vpriv);
1415 vcc->user_back = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001416 vcc->push = entry->old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 vcc_release_async(vcc, -EPIPE);
Chas Williamsd0732f62006-09-29 17:14:27 -07001418 entry->vcc = NULL;
Chas Williams1fa99612006-09-29 17:11:47 -07001419 }
1420 if (entry->recv_vcc) {
1421 entry->recv_vcc->push = entry->old_recv_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 vcc_release_async(entry->recv_vcc, -EPIPE);
Chas Williams1fa99612006-09-29 17:11:47 -07001423 entry->recv_vcc = NULL;
1424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425}
1426
1427/*
1428 * Insert entry to lec_arp_table
1429 * LANE2: Add to the end of the list to satisfy 8.1.13
1430 */
Chas Williams1fa99612006-09-29 17:11:47 -07001431static inline void
Chas Williamsd0732f62006-09-29 17:14:27 -07001432lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433{
Chas Williamsd0732f62006-09-29 17:14:27 -07001434 struct hlist_head *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Chas Williamsd0732f62006-09-29 17:14:27 -07001436 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1437 hlist_add_head(&entry->next, tmp);
Chas Williams1fa99612006-09-29 17:11:47 -07001438
Joe Perches99824462010-01-26 11:40:00 +00001439 pr_debug("Added entry:%pM\n", entry->mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440}
1441
1442/*
1443 * Remove entry from lec_arp_table
1444 */
Chas Williams1fa99612006-09-29 17:11:47 -07001445static int
1446lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447{
Chas Williamsd0732f62006-09-29 17:14:27 -07001448 struct hlist_node *node;
1449 struct lec_arp_table *entry;
1450 int i, remove_vcc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
Chas Williams1fa99612006-09-29 17:11:47 -07001452 if (!to_remove) {
1453 return -1;
1454 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001455
1456 hlist_del(&to_remove->next);
Chas Williams1fa99612006-09-29 17:11:47 -07001457 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Chas Williamsd0732f62006-09-29 17:14:27 -07001459 /* If this is the only MAC connected to this VCC, also tear down the VCC */
Chas Williams1fa99612006-09-29 17:11:47 -07001460 if (to_remove->status >= ESI_FLUSH_PENDING) {
1461 /*
1462 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1463 */
Chas Williamsd0732f62006-09-29 17:14:27 -07001464 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1465 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1466 if (memcmp(to_remove->atm_addr,
1467 entry->atm_addr, ATM_ESA_LEN) == 0) {
Chas Williams1fa99612006-09-29 17:11:47 -07001468 remove_vcc = 0;
1469 break;
1470 }
1471 }
1472 }
1473 if (remove_vcc)
1474 lec_arp_clear_vccs(to_remove);
1475 }
1476 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1477
Joe Perches99824462010-01-26 11:40:00 +00001478 pr_debug("Removed entry:%pM\n", to_remove->mac_addr);
Chas Williams1fa99612006-09-29 17:11:47 -07001479 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480}
1481
1482#if DEBUG_ARP_TABLE
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -07001483static const char *get_status_string(unsigned char st)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484{
Chas Williams1fa99612006-09-29 17:11:47 -07001485 switch (st) {
1486 case ESI_UNKNOWN:
1487 return "ESI_UNKNOWN";
1488 case ESI_ARP_PENDING:
1489 return "ESI_ARP_PENDING";
1490 case ESI_VC_PENDING:
1491 return "ESI_VC_PENDING";
1492 case ESI_FLUSH_PENDING:
1493 return "ESI_FLUSH_PENDING";
1494 case ESI_FORWARD_DIRECT:
1495 return "ESI_FORWARD_DIRECT";
1496 default:
1497 return "<UNKNOWN>";
1498 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
Chas Williams1fa99612006-09-29 17:11:47 -07001501static void dump_arp_table(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502{
Chas Williamsd0732f62006-09-29 17:14:27 -07001503 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07001504 struct lec_arp_table *rulla;
Chas Williamsd0732f62006-09-29 17:14:27 -07001505 char buf[256];
1506 int i, j, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
Chas Williams1fa99612006-09-29 17:11:47 -07001508 printk("Dump %p:\n", priv);
1509 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001510 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1511 offset = 0;
1512 offset += sprintf(buf, "%d: %p\n", i, rulla);
Chas Williams1fa99612006-09-29 17:11:47 -07001513 offset += sprintf(buf + offset, "Mac:");
1514 for (j = 0; j < ETH_ALEN; j++) {
1515 offset += sprintf(buf + offset,
1516 "%2.2x ",
1517 rulla->mac_addr[j] & 0xff);
1518 }
1519 offset += sprintf(buf + offset, "Atm:");
1520 for (j = 0; j < ATM_ESA_LEN; j++) {
1521 offset += sprintf(buf + offset,
1522 "%2.2x ",
1523 rulla->atm_addr[j] & 0xff);
1524 }
1525 offset += sprintf(buf + offset,
1526 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1527 rulla->vcc ? rulla->vcc->vpi : 0,
1528 rulla->vcc ? rulla->vcc->vci : 0,
1529 rulla->recv_vcc ? rulla->recv_vcc->
1530 vpi : 0,
1531 rulla->recv_vcc ? rulla->recv_vcc->
1532 vci : 0, rulla->last_used,
1533 rulla->timestamp, rulla->no_tries);
1534 offset +=
1535 sprintf(buf + offset,
1536 "Flags:%x, Packets_flooded:%x, Status: %s ",
1537 rulla->flags, rulla->packets_flooded,
1538 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001539 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001540 }
Chas Williams1fa99612006-09-29 17:11:47 -07001541 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001542
1543 if (!hlist_empty(&priv->lec_no_forward))
Chas Williams1fa99612006-09-29 17:11:47 -07001544 printk("No forward\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001545 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001546 offset = 0;
1547 offset += sprintf(buf + offset, "Mac:");
1548 for (j = 0; j < ETH_ALEN; j++) {
1549 offset += sprintf(buf + offset, "%2.2x ",
1550 rulla->mac_addr[j] & 0xff);
1551 }
1552 offset += sprintf(buf + offset, "Atm:");
1553 for (j = 0; j < ATM_ESA_LEN; j++) {
1554 offset += sprintf(buf + offset, "%2.2x ",
1555 rulla->atm_addr[j] & 0xff);
1556 }
1557 offset += sprintf(buf + offset,
1558 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1559 rulla->vcc ? rulla->vcc->vpi : 0,
1560 rulla->vcc ? rulla->vcc->vci : 0,
1561 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1562 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1563 rulla->last_used,
1564 rulla->timestamp, rulla->no_tries);
1565 offset += sprintf(buf + offset,
1566 "Flags:%x, Packets_flooded:%x, Status: %s ",
1567 rulla->flags, rulla->packets_flooded,
1568 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001569 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001570 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001571
1572 if (!hlist_empty(&priv->lec_arp_empty_ones))
Chas Williams1fa99612006-09-29 17:11:47 -07001573 printk("Empty ones\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001574 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001575 offset = 0;
1576 offset += sprintf(buf + offset, "Mac:");
1577 for (j = 0; j < ETH_ALEN; j++) {
1578 offset += sprintf(buf + offset, "%2.2x ",
1579 rulla->mac_addr[j] & 0xff);
1580 }
1581 offset += sprintf(buf + offset, "Atm:");
1582 for (j = 0; j < ATM_ESA_LEN; j++) {
1583 offset += sprintf(buf + offset, "%2.2x ",
1584 rulla->atm_addr[j] & 0xff);
1585 }
1586 offset += sprintf(buf + offset,
1587 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1588 rulla->vcc ? rulla->vcc->vpi : 0,
1589 rulla->vcc ? rulla->vcc->vci : 0,
1590 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1591 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1592 rulla->last_used,
1593 rulla->timestamp, rulla->no_tries);
1594 offset += sprintf(buf + offset,
1595 "Flags:%x, Packets_flooded:%x, Status: %s ",
1596 rulla->flags, rulla->packets_flooded,
1597 get_status_string(rulla->status));
Chas Williams1fa99612006-09-29 17:11:47 -07001598 printk("%s", buf);
1599 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
Chas Williamsd0732f62006-09-29 17:14:27 -07001601 if (!hlist_empty(&priv->mcast_fwds))
Chas Williams1fa99612006-09-29 17:11:47 -07001602 printk("Multicast Forward VCCs\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07001603 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001604 offset = 0;
1605 offset += sprintf(buf + offset, "Mac:");
1606 for (j = 0; j < ETH_ALEN; j++) {
1607 offset += sprintf(buf + offset, "%2.2x ",
1608 rulla->mac_addr[j] & 0xff);
1609 }
1610 offset += sprintf(buf + offset, "Atm:");
1611 for (j = 0; j < ATM_ESA_LEN; j++) {
1612 offset += sprintf(buf + offset, "%2.2x ",
1613 rulla->atm_addr[j] & 0xff);
1614 }
1615 offset += sprintf(buf + offset,
1616 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1617 rulla->vcc ? rulla->vcc->vpi : 0,
1618 rulla->vcc ? rulla->vcc->vci : 0,
1619 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1620 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1621 rulla->last_used,
1622 rulla->timestamp, rulla->no_tries);
1623 offset += sprintf(buf + offset,
1624 "Flags:%x, Packets_flooded:%x, Status: %s ",
1625 rulla->flags, rulla->packets_flooded,
1626 get_status_string(rulla->status));
Chas Williamsd0732f62006-09-29 17:14:27 -07001627 printk("%s\n", buf);
Chas Williams1fa99612006-09-29 17:11:47 -07001628 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630}
Chas Williamsd0732f62006-09-29 17:14:27 -07001631#else
1632#define dump_arp_table(priv) do { } while (0)
1633#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
1635/*
1636 * Destruction of arp-cache
1637 */
Chas Williams1fa99612006-09-29 17:11:47 -07001638static void lec_arp_destroy(struct lec_priv *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639{
1640 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001641 struct hlist_node *node, *next;
1642 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001643 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
Chas Williams987e46b2006-09-29 17:15:59 -07001645 cancel_rearming_delayed_work(&priv->lec_arp_work);
Chas Williams1fa99612006-09-29 17:11:47 -07001646
1647 /*
1648 * Remove all entries
1649 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
1651 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001652 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001653 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001654 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001655 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001656 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001657 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
Chas Williams1fa99612006-09-29 17:11:47 -07001658 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001659
1660 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001661 del_timer_sync(&entry->timer);
1662 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001663 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001664 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001665 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001666 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1667
1668 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001669 del_timer_sync(&entry->timer);
1670 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001671 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001672 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001673 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001674 INIT_HLIST_HEAD(&priv->lec_no_forward);
1675
1676 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001677 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1678 lec_arp_clear_vccs(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07001679 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001680 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001681 }
Chas Williamsd0732f62006-09-29 17:14:27 -07001682 INIT_HLIST_HEAD(&priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07001683 priv->mcast_vcc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1685}
1686
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001687/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 * Find entry by mac_address
1689 */
Chas Williams1fa99612006-09-29 17:11:47 -07001690static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001691 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692{
Chas Williamsd0732f62006-09-29 17:14:27 -07001693 struct hlist_node *node;
1694 struct hlist_head *head;
1695 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
Joe Perches99824462010-01-26 11:40:00 +00001697 pr_debug("%pM\n", mac_addr);
Chas Williams1fa99612006-09-29 17:11:47 -07001698
Chas Williamsd0732f62006-09-29 17:14:27 -07001699 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1700 hlist_for_each_entry(entry, node, head, next) {
1701 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1702 return entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001703 }
Chas Williams1fa99612006-09-29 17:11:47 -07001704 }
1705 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706}
1707
Chas Williams1fa99612006-09-29 17:11:47 -07001708static struct lec_arp_table *make_entry(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001709 const unsigned char *mac_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710{
Chas Williams1fa99612006-09-29 17:11:47 -07001711 struct lec_arp_table *to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712
Chas Williams1fa99612006-09-29 17:11:47 -07001713 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1714 if (!to_return) {
1715 printk("LEC: Arp entry kmalloc failed\n");
1716 return NULL;
1717 }
1718 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
Chas Williamsd0732f62006-09-29 17:14:27 -07001719 INIT_HLIST_NODE(&to_return->next);
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -08001720 setup_timer(&to_return->timer, lec_arp_expire_arp,
1721 (unsigned long)to_return);
Chas Williams1fa99612006-09-29 17:11:47 -07001722 to_return->last_used = jiffies;
1723 to_return->priv = priv;
1724 skb_queue_head_init(&to_return->tx_wait);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001725 atomic_set(&to_return->usage, 1);
Chas Williams1fa99612006-09-29 17:11:47 -07001726 return to_return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727}
1728
Chas Williams1fa99612006-09-29 17:11:47 -07001729/* Arp sent timer expired */
1730static void lec_arp_expire_arp(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731{
Chas Williams1fa99612006-09-29 17:11:47 -07001732 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
Chas Williams1fa99612006-09-29 17:11:47 -07001734 entry = (struct lec_arp_table *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
Joe Perches99824462010-01-26 11:40:00 +00001736 pr_debug("\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001737 if (entry->status == ESI_ARP_PENDING) {
1738 if (entry->no_tries <= entry->priv->max_retry_count) {
1739 if (entry->is_rdesc)
1740 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1741 entry->mac_addr, NULL, NULL);
1742 else
1743 send_to_lecd(entry->priv, l_arp_xmt,
1744 entry->mac_addr, NULL, NULL);
1745 entry->no_tries++;
1746 }
1747 mod_timer(&entry->timer, jiffies + (1 * HZ));
1748 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749}
1750
Chas Williams1fa99612006-09-29 17:11:47 -07001751/* Unknown/unused vcc expire, remove associated entry */
1752static void lec_arp_expire_vcc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753{
1754 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001755 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1756 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
Chas Williams1fa99612006-09-29 17:11:47 -07001758 del_timer(&to_remove->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759
Joe Perches99824462010-01-26 11:40:00 +00001760 pr_debug("%p %p: vpi:%d vci:%d\n",
1761 to_remove, priv,
1762 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1763 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
1765 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07001766 hlist_del(&to_remove->next);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1768
Chas Williams1fa99612006-09-29 17:11:47 -07001769 lec_arp_clear_vccs(to_remove);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001770 lec_arp_put(to_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771}
1772
1773/*
1774 * Expire entries.
1775 * 1. Re-set timer
1776 * 2. For each entry, delete entries that have aged past the age limit.
1777 * 3. For each entry, depending on the status of the entry, perform
1778 * the following maintenance.
1779 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1780 * tick_count is above the max_unknown_frame_time, clear
1781 * the tick_count to zero and clear the packets_flooded counter
1782 * to zero. This supports the packet rate limit per address
1783 * while flooding unknowns.
1784 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1785 * than or equal to the path_switching_delay, change the status
1786 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1787 * regardless of the progress of the flush protocol.
1788 */
David Howellsc4028952006-11-22 14:57:56 +00001789static void lec_arp_check_expire(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790{
1791 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +00001792 struct lec_priv *priv =
1793 container_of(work, struct lec_priv, lec_arp_work.work);
Chas Williamsd0732f62006-09-29 17:14:27 -07001794 struct hlist_node *node, *next;
1795 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001796 unsigned long now;
1797 unsigned long time_to_check;
1798 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799
Joe Perches99824462010-01-26 11:40:00 +00001800 pr_debug("%p\n", priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 now = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001802restart:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001804 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001805 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001806 if ((entry->flags) & LEC_REMOTE_FLAG &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 priv->topology_change)
1808 time_to_check = priv->forward_delay_time;
1809 else
1810 time_to_check = priv->aging_time;
1811
Stephen Hemminger52240062007-08-28 15:22:09 -07001812 pr_debug("About to expire: %lx - %lx > %lx\n",
Joe Perches99824462010-01-26 11:40:00 +00001813 now, entry->last_used, time_to_check);
Chas Williams1fa99612006-09-29 17:11:47 -07001814 if (time_after(now, entry->last_used + time_to_check)
1815 && !(entry->flags & LEC_PERMANENT_FLAG)
1816 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 /* Remove entry */
Joe Perches99824462010-01-26 11:40:00 +00001818 pr_debug("Entry timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001820 lec_arp_put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 } else {
1822 /* Something else */
1823 if ((entry->status == ESI_VC_PENDING ||
Chas Williams1fa99612006-09-29 17:11:47 -07001824 entry->status == ESI_ARP_PENDING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 && time_after_eq(now,
Chas Williams1fa99612006-09-29 17:11:47 -07001826 entry->timestamp +
1827 priv->
1828 max_unknown_frame_time)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 entry->timestamp = jiffies;
1830 entry->packets_flooded = 0;
1831 if (entry->status == ESI_VC_PENDING)
Chas Williams1fa99612006-09-29 17:11:47 -07001832 send_to_lecd(priv, l_svc_setup,
1833 entry->mac_addr,
1834 entry->atm_addr,
1835 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 }
Chas Williams1fa99612006-09-29 17:11:47 -07001837 if (entry->status == ESI_FLUSH_PENDING
1838 &&
1839 time_after_eq(now, entry->timestamp +
1840 priv->path_switching_delay)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07001842 struct atm_vcc *vcc = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
Chas Williams6656e3c2006-09-29 17:17:17 -07001844 lec_arp_hold(entry);
1845 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1846 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
Stephen Hemminger162619e2009-01-09 13:01:01 +00001847 lec_send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07001849 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07001850 lec_arp_put(entry);
1851 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 }
1854 }
1855 }
1856 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1857
Chas Williams987e46b2006-09-29 17:15:59 -07001858 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859}
Chas Williams1fa99612006-09-29 17:11:47 -07001860
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861/*
1862 * Try to find vcc where mac_address is attached.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001863 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 */
Chas Williams1fa99612006-09-29 17:11:47 -07001865static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001866 const unsigned char *mac_to_find, int is_rdesc,
Chas Williams1fa99612006-09-29 17:11:47 -07001867 struct lec_arp_table **ret_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868{
1869 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07001870 struct lec_arp_table *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 struct atm_vcc *found;
1872
Chas Williams1fa99612006-09-29 17:11:47 -07001873 if (mac_to_find[0] & 0x01) {
1874 switch (priv->lane_version) {
1875 case 1:
1876 return priv->mcast_vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07001877 case 2: /* LANE2 wants arp for multicast addresses */
1878 if (!compare_ether_addr(mac_to_find, bus_mac))
1879 return priv->mcast_vcc;
1880 break;
1881 default:
1882 break;
1883 }
1884 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
1886 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001887 entry = lec_arp_find(priv, mac_to_find);
1888
1889 if (entry) {
1890 if (entry->status == ESI_FORWARD_DIRECT) {
1891 /* Connection Ok */
1892 entry->last_used = jiffies;
Chas Williams6656e3c2006-09-29 17:17:17 -07001893 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001894 *ret_entry = entry;
1895 found = entry->vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001897 }
1898 /*
1899 * If the LE_ARP cache entry is still pending, reset count to 0
Scott Talbert75b895c2005-09-29 17:31:30 -07001900 * so another LE_ARP request can be made for this frame.
1901 */
1902 if (entry->status == ESI_ARP_PENDING) {
1903 entry->no_tries = 0;
1904 }
Chas Williams1fa99612006-09-29 17:11:47 -07001905 /*
1906 * Data direct VC not yet set up, check to see if the unknown
1907 * frame count is greater than the limit. If the limit has
1908 * not been reached, allow the caller to send packet to
1909 * BUS.
1910 */
1911 if (entry->status != ESI_FLUSH_PENDING &&
1912 entry->packets_flooded <
1913 priv->maximum_unknown_frame_count) {
1914 entry->packets_flooded++;
Joe Perches99824462010-01-26 11:40:00 +00001915 pr_debug("Flooding..\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001916 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001918 }
1919 /*
1920 * We got here because entry->status == ESI_FLUSH_PENDING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 * or BUS flood limit was reached for an entry which is
1922 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1923 */
Chas Williams6656e3c2006-09-29 17:17:17 -07001924 lec_arp_hold(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001925 *ret_entry = entry;
Joe Perches99824462010-01-26 11:40:00 +00001926 pr_debug("entry->status %d entry->vcc %p\n", entry->status,
1927 entry->vcc);
Chas Williams1fa99612006-09-29 17:11:47 -07001928 found = NULL;
1929 } else {
1930 /* No matching entry was found */
1931 entry = make_entry(priv, mac_to_find);
Joe Perches99824462010-01-26 11:40:00 +00001932 pr_debug("Making entry\n");
Chas Williams1fa99612006-09-29 17:11:47 -07001933 if (!entry) {
1934 found = priv->mcast_vcc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07001936 }
1937 lec_arp_add(priv, entry);
1938 /* We want arp-request(s) to be sent */
1939 entry->packets_flooded = 1;
1940 entry->status = ESI_ARP_PENDING;
1941 entry->no_tries = 1;
1942 entry->last_used = entry->timestamp = jiffies;
1943 entry->is_rdesc = is_rdesc;
1944 if (entry->is_rdesc)
1945 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1946 NULL);
1947 else
1948 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1949 entry->timer.expires = jiffies + (1 * HZ);
1950 entry->timer.function = lec_arp_expire_arp;
1951 add_timer(&entry->timer);
1952 found = priv->mcast_vcc;
1953 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954
1955out:
1956 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1957 return found;
1958}
1959
1960static int
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001961lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
Chas Williams1fa99612006-09-29 17:11:47 -07001962 unsigned long permanent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963{
1964 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001965 struct hlist_node *node, *next;
1966 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07001967 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968
Joe Perches99824462010-01-26 11:40:00 +00001969 pr_debug("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001971 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07001972 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07001973 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
1974 && (permanent ||
1975 !(entry->flags & LEC_PERMANENT_FLAG))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07001977 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07001978 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001980 return 0;
1981 }
1982 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07001984 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985}
1986
1987/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001988 * Notifies: Response to arp_request (atm_addr != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 */
1990static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07001991lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
1992 const unsigned char *atm_addr, unsigned long remoteflag,
Chas Williams1fa99612006-09-29 17:11:47 -07001993 unsigned int targetless_le_arp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994{
1995 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07001996 struct hlist_node *node, *next;
Chas Williams1fa99612006-09-29 17:11:47 -07001997 struct lec_arp_table *entry, *tmp;
1998 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
Joe Perches99824462010-01-26 11:40:00 +00002000 pr_debug("%smac:%pM\n",
2001 (targetless_le_arp) ? "targetless " : "", mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002
2003 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002004 entry = lec_arp_find(priv, mac_addr);
2005 if (entry == NULL && targetless_le_arp)
2006 goto out; /*
2007 * LANE2: ignore targetless LE_ARPs for which
2008 * we have no entry in the cache. 7.1.30
2009 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002010 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2011 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2012 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2013 hlist_del(&entry->next);
Chas Williams1fa99612006-09-29 17:11:47 -07002014 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002015 tmp = lec_arp_find(priv, mac_addr);
2016 if (tmp) {
2017 del_timer(&tmp->timer);
2018 tmp->status = ESI_FORWARD_DIRECT;
2019 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2020 tmp->vcc = entry->vcc;
2021 tmp->old_push = entry->old_push;
2022 tmp->last_used = jiffies;
2023 del_timer(&entry->timer);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002024 lec_arp_put(entry);
Chas Williamsd0732f62006-09-29 17:14:27 -07002025 entry = tmp;
2026 } else {
2027 entry->status = ESI_FORWARD_DIRECT;
2028 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2029 entry->last_used = jiffies;
2030 lec_arp_add(priv, entry);
2031 }
2032 if (remoteflag)
2033 entry->flags |= LEC_REMOTE_FLAG;
2034 else
2035 entry->flags &= ~LEC_REMOTE_FLAG;
Stephen Hemminger52240062007-08-28 15:22:09 -07002036 pr_debug("After update\n");
Chas Williamsd0732f62006-09-29 17:14:27 -07002037 dump_arp_table(priv);
2038 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002039 }
Chas Williams1fa99612006-09-29 17:11:47 -07002040 }
2041 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002042
Chas Williams1fa99612006-09-29 17:11:47 -07002043 entry = lec_arp_find(priv, mac_addr);
2044 if (!entry) {
2045 entry = make_entry(priv, mac_addr);
2046 if (!entry)
2047 goto out;
2048 entry->status = ESI_UNKNOWN;
2049 lec_arp_add(priv, entry);
2050 /* Temporary, changes before end of function */
2051 }
2052 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2053 del_timer(&entry->timer);
2054 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002055 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002056 if (entry != tmp &&
2057 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2058 /* Vcc to this host exists */
2059 if (tmp->status > ESI_VC_PENDING) {
2060 /*
2061 * ESI_FLUSH_PENDING,
2062 * ESI_FORWARD_DIRECT
2063 */
2064 entry->vcc = tmp->vcc;
2065 entry->old_push = tmp->old_push;
2066 }
2067 entry->status = tmp->status;
2068 break;
2069 }
2070 }
2071 }
2072 if (remoteflag)
2073 entry->flags |= LEC_REMOTE_FLAG;
2074 else
2075 entry->flags &= ~LEC_REMOTE_FLAG;
2076 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2077 entry->status = ESI_VC_PENDING;
Chas Williamsd0732f62006-09-29 17:14:27 -07002078 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
Chas Williams1fa99612006-09-29 17:11:47 -07002079 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002080 pr_debug("After update2\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002081 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082out:
2083 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2084}
2085
2086/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09002087 * Notifies: Vcc setup ready
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 */
2089static void
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002090lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
Chas Williams1fa99612006-09-29 17:11:47 -07002091 struct atm_vcc *vcc,
2092 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093{
2094 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002095 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002096 struct lec_arp_table *entry;
2097 int i, found_entry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
2099 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002100 if (ioc_data->receive == 2) {
2101 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
Stephen Hemminger52240062007-08-28 15:22:09 -07002103 pr_debug("LEC_ARP: Attaching mcast forward\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002105 entry = lec_arp_find(priv, bus_mac);
2106 if (!entry) {
2107 printk("LEC_ARP: Multicast entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002109 }
2110 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2111 entry->recv_vcc = vcc;
2112 entry->old_recv_push = old_push;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002114 entry = make_entry(priv, bus_mac);
2115 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002117 del_timer(&entry->timer);
2118 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2119 entry->recv_vcc = vcc;
2120 entry->old_recv_push = old_push;
Chas Williamsd0732f62006-09-29 17:14:27 -07002121 hlist_add_head(&entry->next, &priv->mcast_fwds);
Chas Williams1fa99612006-09-29 17:11:47 -07002122 goto out;
2123 } else if (ioc_data->receive == 1) {
2124 /*
2125 * Vcc which we don't want to make default vcc,
2126 * attach it anyway.
2127 */
Joe Perches99824462010-01-26 11:40:00 +00002128 pr_debug("LEC_ARP:Attaching data direct, not default: %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",
2129 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2130 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2131 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2132 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2133 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2134 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2135 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2136 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2137 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2138 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
Chas Williams1fa99612006-09-29 17:11:47 -07002139 entry = make_entry(priv, bus_mac);
2140 if (entry == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002142 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2143 memset(entry->mac_addr, 0, ETH_ALEN);
2144 entry->recv_vcc = vcc;
2145 entry->old_recv_push = old_push;
2146 entry->status = ESI_UNKNOWN;
2147 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2148 entry->timer.function = lec_arp_expire_vcc;
Chas Williamsd0732f62006-09-29 17:14:27 -07002149 hlist_add_head(&entry->next, &priv->lec_no_forward);
Chas Williams1fa99612006-09-29 17:11:47 -07002150 add_timer(&entry->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 dump_arp_table(priv);
2152 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002153 }
Joe Perches99824462010-01-26 11:40:00 +00002154 pr_debug("LEC_ARP:Attaching data direct, default: %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",
2155 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2156 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2157 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2158 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2159 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2160 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2161 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2162 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2163 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2164 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
Chas Williams1fa99612006-09-29 17:11:47 -07002165 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002166 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002167 if (memcmp
2168 (ioc_data->atm_addr, entry->atm_addr,
2169 ATM_ESA_LEN) == 0) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002170 pr_debug("LEC_ARP: Attaching data direct\n");
2171 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
Joe Perches99824462010-01-26 11:40:00 +00002172 entry->vcc ? entry->vcc->vci : 0,
2173 entry->recv_vcc ? entry->recv_vcc->
2174 vci : 0);
Chas Williams1fa99612006-09-29 17:11:47 -07002175 found_entry = 1;
2176 del_timer(&entry->timer);
2177 entry->vcc = vcc;
2178 entry->old_push = old_push;
2179 if (entry->status == ESI_VC_PENDING) {
2180 if (priv->maximum_unknown_frame_count
2181 == 0)
2182 entry->status =
2183 ESI_FORWARD_DIRECT;
2184 else {
2185 entry->timestamp = jiffies;
2186 entry->status =
2187 ESI_FLUSH_PENDING;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188#if 0
Chas Williams1fa99612006-09-29 17:11:47 -07002189 send_to_lecd(priv, l_flush_xmt,
2190 NULL,
2191 entry->atm_addr,
2192 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002194 }
2195 } else {
2196 /*
2197 * They were forming a connection
2198 * to us, and we to them. Our
2199 * ATM address is numerically lower
2200 * than theirs, so we make connection
2201 * we formed into default VCC (8.1.11).
2202 * Connection they made gets torn
2203 * down. This might confuse some
2204 * clients. Can be changed if
2205 * someone reports trouble...
2206 */
2207 ;
2208 }
2209 }
2210 }
2211 }
2212 if (found_entry) {
Stephen Hemminger52240062007-08-28 15:22:09 -07002213 pr_debug("After vcc was added\n");
Chas Williams1fa99612006-09-29 17:11:47 -07002214 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002216 }
2217 /*
2218 * Not found, snatch address from first data packet that arrives
2219 * from this vcc
2220 */
2221 entry = make_entry(priv, bus_mac);
2222 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002224 entry->vcc = vcc;
2225 entry->old_push = old_push;
2226 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2227 memset(entry->mac_addr, 0, ETH_ALEN);
2228 entry->status = ESI_UNKNOWN;
Chas Williamsd0732f62006-09-29 17:14:27 -07002229 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
Chas Williams1fa99612006-09-29 17:11:47 -07002230 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2231 entry->timer.function = lec_arp_expire_vcc;
2232 add_timer(&entry->timer);
Stephen Hemminger52240062007-08-28 15:22:09 -07002233 pr_debug("After vcc was added\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 dump_arp_table(priv);
2235out:
2236 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2237}
2238
Chas Williams1fa99612006-09-29 17:11:47 -07002239static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240{
2241 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002242 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002243 struct lec_arp_table *entry;
2244 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
Joe Perches99824462010-01-26 11:40:00 +00002246 pr_debug("%lx\n", tran_id);
Chas Williams6656e3c2006-09-29 17:17:17 -07002247restart:
Chas Williams1fa99612006-09-29 17:11:47 -07002248 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2249 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002250 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002251 if (entry->flush_tran_id == tran_id
2252 && entry->status == ESI_FLUSH_PENDING) {
2253 struct sk_buff *skb;
Chas Williams6656e3c2006-09-29 17:17:17 -07002254 struct atm_vcc *vcc = entry->vcc;
Chas Williams1fa99612006-09-29 17:11:47 -07002255
Chas Williams6656e3c2006-09-29 17:17:17 -07002256 lec_arp_hold(entry);
2257 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2258 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
Stephen Hemminger162619e2009-01-09 13:01:01 +00002259 lec_send(vcc, skb);
Chas Williams6656e3c2006-09-29 17:17:17 -07002260 entry->last_used = jiffies;
Chas Williams1fa99612006-09-29 17:11:47 -07002261 entry->status = ESI_FORWARD_DIRECT;
Chas Williams6656e3c2006-09-29 17:17:17 -07002262 lec_arp_put(entry);
Stephen Hemminger52240062007-08-28 15:22:09 -07002263 pr_debug("LEC_ARP: Flushed\n");
Chas Williams6656e3c2006-09-29 17:17:17 -07002264 goto restart;
Chas Williams1fa99612006-09-29 17:11:47 -07002265 }
2266 }
2267 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002269 dump_arp_table(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270}
2271
2272static void
2273lec_set_flush_tran_id(struct lec_priv *priv,
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -07002274 const unsigned char *atm_addr, unsigned long tran_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275{
2276 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002277 struct hlist_node *node;
Chas Williams1fa99612006-09-29 17:11:47 -07002278 struct lec_arp_table *entry;
2279 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
2281 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002282 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
Chas Williamsd0732f62006-09-29 17:14:27 -07002283 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002284 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2285 entry->flush_tran_id = tran_id;
Stephen Hemminger52240062007-08-28 15:22:09 -07002286 pr_debug("Set flush transaction id to %lx for %p\n",
Joe Perches99824462010-01-26 11:40:00 +00002287 tran_id, entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002288 }
Chas Williamsd0732f62006-09-29 17:14:27 -07002289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2291}
2292
Chas Williams1fa99612006-09-29 17:11:47 -07002293static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294{
2295 unsigned long flags;
Chas Williams1fa99612006-09-29 17:11:47 -07002296 unsigned char mac_addr[] = {
2297 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2298 };
2299 struct lec_arp_table *to_add;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 struct lec_vcc_priv *vpriv;
2301 int err = 0;
Chas Williams1fa99612006-09-29 17:11:47 -07002302
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2304 return -ENOMEM;
2305 vpriv->xoff = 0;
2306 vpriv->old_pop = vcc->pop;
2307 vcc->user_back = vpriv;
Chas Williams1fa99612006-09-29 17:11:47 -07002308 vcc->pop = lec_pop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002310 to_add = make_entry(priv, mac_addr);
2311 if (!to_add) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 vcc->pop = vpriv->old_pop;
2313 kfree(vpriv);
Chas Williams1fa99612006-09-29 17:11:47 -07002314 err = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002316 }
2317 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2318 to_add->status = ESI_FORWARD_DIRECT;
2319 to_add->flags |= LEC_PERMANENT_FLAG;
2320 to_add->vcc = vcc;
2321 to_add->old_push = vcc->push;
2322 vcc->push = lec_push;
2323 priv->mcast_vcc = vcc;
2324 lec_arp_add(priv, to_add);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325out:
2326 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
Chas Williams1fa99612006-09-29 17:11:47 -07002327 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328}
2329
Chas Williams1fa99612006-09-29 17:11:47 -07002330static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331{
2332 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002333 struct hlist_node *node, *next;
2334 struct lec_arp_table *entry;
Chas Williams1fa99612006-09-29 17:11:47 -07002335 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
Stephen Hemminger52240062007-08-28 15:22:09 -07002337 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
Chas Williams1fa99612006-09-29 17:11:47 -07002338 dump_arp_table(priv);
Chas Williamsd0732f62006-09-29 17:14:27 -07002339
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002341
Chas Williams1fa99612006-09-29 17:11:47 -07002342 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
Chas Williamsd0732f62006-09-29 17:14:27 -07002343 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002344 if (vcc == entry->vcc) {
2345 lec_arp_remove(priv, entry);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002346 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002347 if (priv->mcast_vcc == vcc) {
2348 priv->mcast_vcc = NULL;
2349 }
2350 }
2351 }
2352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353
Chas Williamsd0732f62006-09-29 17:14:27 -07002354 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2355 if (entry->vcc == vcc) {
Chas Williams1fa99612006-09-29 17:11:47 -07002356 lec_arp_clear_vccs(entry);
2357 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002358 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002359 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002360 }
Chas Williams1fa99612006-09-29 17:11:47 -07002361 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
Chas Williamsd0732f62006-09-29 17:14:27 -07002363 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002364 if (entry->recv_vcc == vcc) {
2365 lec_arp_clear_vccs(entry);
2366 del_timer(&entry->timer);
Chas Williamsd0732f62006-09-29 17:14:27 -07002367 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002368 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002369 }
Chas Williams1fa99612006-09-29 17:11:47 -07002370 }
2371
Chas Williamsd0732f62006-09-29 17:14:27 -07002372 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
Chas Williams1fa99612006-09-29 17:11:47 -07002373 if (entry->recv_vcc == vcc) {
2374 lec_arp_clear_vccs(entry);
2375 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
Chas Williamsd0732f62006-09-29 17:14:27 -07002376 hlist_del(&entry->next);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002377 lec_arp_put(entry);
Chas Williams1fa99612006-09-29 17:11:47 -07002378 }
Chas Williams1fa99612006-09-29 17:11:47 -07002379 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380
2381 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2382 dump_arp_table(priv);
2383}
2384
2385static void
2386lec_arp_check_empties(struct lec_priv *priv,
Chas Williams1fa99612006-09-29 17:11:47 -07002387 struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388{
Chas Williams1fa99612006-09-29 17:11:47 -07002389 unsigned long flags;
Chas Williamsd0732f62006-09-29 17:14:27 -07002390 struct hlist_node *node, *next;
2391 struct lec_arp_table *entry, *tmp;
Chas Williams1fa99612006-09-29 17:11:47 -07002392 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2393 unsigned char *src;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394#ifdef CONFIG_TR
Chas Williams1fa99612006-09-29 17:11:47 -07002395 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396
Chas Williams1fa99612006-09-29 17:11:47 -07002397 if (priv->is_trdev)
2398 src = tr_hdr->h_source;
2399 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400#endif
Chas Williams1fa99612006-09-29 17:11:47 -07002401 src = hdr->h_source;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
2403 spin_lock_irqsave(&priv->lec_arp_lock, flags);
Chas Williamsd0732f62006-09-29 17:14:27 -07002404 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2405 if (vcc == entry->vcc) {
2406 del_timer(&entry->timer);
2407 memcpy(entry->mac_addr, src, ETH_ALEN);
2408 entry->status = ESI_FORWARD_DIRECT;
2409 entry->last_used = jiffies;
2410 /* We might have got an entry */
2411 if ((tmp = lec_arp_find(priv, src))) {
2412 lec_arp_remove(priv, tmp);
Chas Williams33a9c2d2006-09-29 17:16:48 -07002413 lec_arp_put(tmp);
Chas Williamsd0732f62006-09-29 17:14:27 -07002414 }
2415 hlist_del(&entry->next);
2416 lec_arp_add(priv, entry);
2417 goto out;
Chas Williams1fa99612006-09-29 17:11:47 -07002418 }
Chas Williams1fa99612006-09-29 17:11:47 -07002419 }
Stephen Hemminger52240062007-08-28 15:22:09 -07002420 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421out:
2422 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2423}
Chas Williams1fa99612006-09-29 17:11:47 -07002424
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425MODULE_LICENSE("GPL");