Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 2 | * lec.c: Lan Emulation driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 4 | * Marko Kiiskila <mkiiskila@yahoo.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 7 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ |
| 8 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 9 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/kernel.h> |
| 11 | #include <linux/bitops.h> |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 12 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | /* We are ethernet device */ |
| 15 | #include <linux/if_ether.h> |
| 16 | #include <linux/netdevice.h> |
| 17 | #include <linux/etherdevice.h> |
| 18 | #include <net/sock.h> |
| 19 | #include <linux/skbuff.h> |
| 20 | #include <linux/ip.h> |
| 21 | #include <asm/byteorder.h> |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 22 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <net/arp.h> |
| 24 | #include <net/dst.h> |
| 25 | #include <linux/proc_fs.h> |
| 26 | #include <linux/spinlock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/seq_file.h> |
| 28 | |
| 29 | /* TokenRing if needed */ |
| 30 | #ifdef CONFIG_TR |
| 31 | #include <linux/trdevice.h> |
| 32 | #endif |
| 33 | |
| 34 | /* And atm device */ |
| 35 | #include <linux/atmdev.h> |
| 36 | #include <linux/atmlec.h> |
| 37 | |
| 38 | /* Proxy LEC knows about bridging */ |
| 39 | #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include "../bridge/br_private.h" |
| 41 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 42 | static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #endif |
| 44 | |
| 45 | /* Modular too */ |
| 46 | #include <linux/module.h> |
| 47 | #include <linux/init.h> |
| 48 | |
| 49 | #include "lec.h" |
| 50 | #include "lec_arpc.h" |
| 51 | #include "resources.h" |
| 52 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 53 | #define DUMP_PACKETS 0 /* |
| 54 | * 0 = None, |
| 55 | * 1 = 30 first bytes |
| 56 | * 2 = Whole packet |
| 57 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 59 | #define LEC_UNRES_QUE_LEN 8 /* |
| 60 | * number of tx packets to queue for a |
| 61 | * single destination while waiting for SVC |
| 62 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | static int lec_open(struct net_device *dev); |
Stephen Hemminger | 3c805a2 | 2009-08-31 19:50:42 +0000 | [diff] [blame] | 65 | static netdev_tx_t lec_start_xmit(struct sk_buff *skb, |
| 66 | struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | static int lec_close(struct net_device *dev); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 68 | static struct lec_arp_table *lec_arp_find(struct lec_priv *priv, |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 69 | const unsigned char *mac_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | static int lec_arp_remove(struct lec_priv *priv, |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 71 | struct lec_arp_table *to_remove); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | /* LANE2 functions */ |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 73 | static void lane2_associate_ind(struct net_device *dev, const u8 *mac_address, |
| 74 | const u8 *tlvs, u32 sizeoftlvs); |
| 75 | static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force, |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 76 | u8 **tlvs, u32 *sizeoftlvs); |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 77 | static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst, |
| 78 | const u8 *tlvs, u32 sizeoftlvs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 80 | static int lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | unsigned long permanent); |
| 82 | static void lec_arp_check_empties(struct lec_priv *priv, |
| 83 | struct atm_vcc *vcc, struct sk_buff *skb); |
| 84 | static void lec_arp_destroy(struct lec_priv *priv); |
| 85 | static void lec_arp_init(struct lec_priv *priv); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 86 | static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv, |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 87 | const unsigned char *mac_to_find, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | int is_rdesc, |
| 89 | struct lec_arp_table **ret_entry); |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 90 | static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr, |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 91 | const unsigned char *atm_addr, |
| 92 | unsigned long remoteflag, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | unsigned int targetless_le_arp); |
| 94 | static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id); |
| 95 | static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc); |
| 96 | static void lec_set_flush_tran_id(struct lec_priv *priv, |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 97 | const unsigned char *atm_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | unsigned long tran_id); |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 99 | static void lec_vcc_added(struct lec_priv *priv, |
| 100 | const struct atmlec_ioc *ioc_data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | struct atm_vcc *vcc, |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 102 | void (*old_push)(struct atm_vcc *vcc, |
| 103 | struct sk_buff *skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc); |
| 105 | |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 106 | /* must be done under lec_arp_lock */ |
| 107 | static inline void lec_arp_hold(struct lec_arp_table *entry) |
| 108 | { |
| 109 | atomic_inc(&entry->usage); |
| 110 | } |
| 111 | |
| 112 | static inline void lec_arp_put(struct lec_arp_table *entry) |
| 113 | { |
| 114 | if (atomic_dec_and_test(&entry->usage)) |
| 115 | kfree(entry); |
| 116 | } |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | static struct lane2_ops lane2_ops = { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 119 | lane2_resolve, /* resolve, spec 3.1.3 */ |
| 120 | lane2_associate_req, /* associate_req, spec 3.1.4 */ |
| 121 | NULL /* associate indicator, spec 3.1.5 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 124 | static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
| 126 | /* Device structures */ |
| 127 | static struct net_device *dev_lec[MAX_LEC_ITF]; |
| 128 | |
| 129 | #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) |
| 130 | static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev) |
| 131 | { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 132 | struct ethhdr *eth; |
| 133 | char *buff; |
| 134 | struct lec_priv *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 136 | /* |
| 137 | * Check if this is a BPDU. If so, ask zeppelin to send |
| 138 | * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit |
| 139 | * as the Config BPDU has |
| 140 | */ |
| 141 | eth = (struct ethhdr *)skb->data; |
| 142 | buff = skb->data + skb->dev->hard_header_len; |
| 143 | if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | struct sock *sk; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 145 | struct sk_buff *skb2; |
| 146 | struct atmlec_msg *mesg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 148 | skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC); |
| 149 | if (skb2 == NULL) |
| 150 | return; |
| 151 | skb2->len = sizeof(struct atmlec_msg); |
| 152 | mesg = (struct atmlec_msg *)skb2->data; |
| 153 | mesg->type = l_topology_change; |
| 154 | buff += 4; |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 155 | mesg->content.normal.flag = *buff & 0x01; |
| 156 | /* 0x01 is topology change */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 158 | priv = netdev_priv(dev); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 159 | atm_force_charge(priv->lecd, skb2->truesize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | sk = sk_atm(priv->lecd); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 161 | skb_queue_tail(&sk->sk_receive_queue, skb2); |
| 162 | sk->sk_data_ready(sk, skb2->len); |
| 163 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
| 165 | #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */ |
| 166 | |
| 167 | /* |
| 168 | * Modelled after tr_type_trans |
| 169 | * All multicast and ARE or STE frames go to BUS. |
| 170 | * Non source routed frames go by destination address. |
| 171 | * Last hop source routed frames go by destination address. |
| 172 | * Not last hop source routed frames go by _next_ route descriptor. |
| 173 | * Returns pointer to destination MAC address or fills in rdesc |
| 174 | * and returns NULL. |
| 175 | */ |
| 176 | #ifdef CONFIG_TR |
| 177 | static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc) |
| 178 | { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 179 | struct trh_hdr *trh; |
Eric Dumazet | 5c17d5f | 2008-01-15 03:29:50 -0800 | [diff] [blame] | 180 | unsigned int riflen, num_rdsc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 182 | trh = (struct trh_hdr *)packet; |
| 183 | if (trh->daddr[0] & (uint8_t) 0x80) |
| 184 | return bus_mac; /* multicast */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 186 | if (trh->saddr[0] & TR_RII) { |
| 187 | riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8; |
| 188 | if ((ntohs(trh->rcf) >> 13) != 0) |
| 189 | return bus_mac; /* ARE or STE */ |
| 190 | } else |
| 191 | return trh->daddr; /* not source routed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 193 | if (riflen < 6) |
| 194 | return trh->daddr; /* last hop, source routed */ |
| 195 | |
| 196 | /* riflen is 6 or more, packet has more than one route descriptor */ |
| 197 | num_rdsc = (riflen / 2) - 1; |
| 198 | memset(rdesc, 0, ETH_ALEN); |
| 199 | /* offset 4 comes from LAN destination field in LE control frames */ |
| 200 | if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT)) |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 201 | memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16)); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 202 | else { |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 203 | memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16)); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 204 | rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0)); |
| 205 | } |
| 206 | |
| 207 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | #endif /* CONFIG_TR */ |
| 210 | |
| 211 | /* |
| 212 | * Open/initialize the netdevice. This is called (in the current kernel) |
| 213 | * sometime after booting when the 'ifconfig' program is run. |
| 214 | * |
| 215 | * This routine should set everything up anew at each open, even |
| 216 | * registers that "should" only need to be set once at boot, so that |
| 217 | * there is non-reboot way to recover if something goes wrong. |
| 218 | */ |
| 219 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 220 | static int lec_open(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | netif_start_queue(dev); |
Stephen Hemminger | 162619e | 2009-01-09 13:01:01 +0000 | [diff] [blame] | 223 | memset(&dev->stats, 0, sizeof(struct net_device_stats)); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 224 | |
| 225 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Stephen Hemminger | 162619e | 2009-01-09 13:01:01 +0000 | [diff] [blame] | 228 | static void |
| 229 | lec_send(struct atm_vcc *vcc, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
Stephen Hemminger | 162619e | 2009-01-09 13:01:01 +0000 | [diff] [blame] | 231 | struct net_device *dev = skb->dev; |
| 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | ATM_SKB(skb)->vcc = vcc; |
| 234 | ATM_SKB(skb)->atm_options = vcc->atm_options; |
| 235 | |
| 236 | atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc); |
| 237 | if (vcc->send(vcc, skb) < 0) { |
Stephen Hemminger | 162619e | 2009-01-09 13:01:01 +0000 | [diff] [blame] | 238 | dev->stats.tx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | return; |
| 240 | } |
| 241 | |
Stephen Hemminger | 162619e | 2009-01-09 13:01:01 +0000 | [diff] [blame] | 242 | dev->stats.tx_packets++; |
| 243 | dev->stats.tx_bytes += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 246 | static void lec_tx_timeout(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 248 | pr_info("%s\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | dev->trans_start = jiffies; |
| 250 | netif_wake_queue(dev); |
| 251 | } |
| 252 | |
Stephen Hemminger | 3c805a2 | 2009-08-31 19:50:42 +0000 | [diff] [blame] | 253 | static netdev_tx_t lec_start_xmit(struct sk_buff *skb, |
| 254 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 256 | struct sk_buff *skb2; |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 257 | struct lec_priv *priv = netdev_priv(dev); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 258 | struct lecdatahdr_8023 *lec_h; |
| 259 | struct atm_vcc *vcc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | struct lec_arp_table *entry; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 261 | unsigned char *dst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | int min_frame_size; |
| 263 | #ifdef CONFIG_TR |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 264 | unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | #endif |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 266 | int is_rdesc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 268 | pr_debug("called\n"); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 269 | if (!priv->lecd) { |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 270 | pr_info("%s:No lecd attached\n", dev->name); |
Stephen Hemminger | 162619e | 2009-01-09 13:01:01 +0000 | [diff] [blame] | 271 | dev->stats.tx_errors++; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 272 | netif_stop_queue(dev); |
Patrick McHardy | 81fbbf6 | 2009-06-12 05:34:37 +0000 | [diff] [blame] | 273 | kfree_skb(skb); |
| 274 | return NETDEV_TX_OK; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 277 | pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n", |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 278 | (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb), |
| 279 | (long)skb_end_pointer(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 281 | if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0) |
| 282 | lec_handle_bridge(skb, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | #endif |
| 284 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 285 | /* Make sure we have room for lec_id */ |
| 286 | if (skb_headroom(skb) < 2) { |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 287 | pr_debug("reallocating skb\n"); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 288 | skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN); |
| 289 | kfree_skb(skb); |
| 290 | if (skb2 == NULL) |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 291 | return NETDEV_TX_OK; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 292 | skb = skb2; |
| 293 | } |
| 294 | skb_push(skb, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 296 | /* Put le header to place, works for TokenRing too */ |
| 297 | lec_h = (struct lecdatahdr_8023 *)skb->data; |
| 298 | lec_h->le_header = htons(priv->lecid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
| 300 | #ifdef CONFIG_TR |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 301 | /* |
| 302 | * Ugly. Use this to realign Token Ring packets for |
| 303 | * e.g. PCA-200E driver. |
| 304 | */ |
| 305 | if (priv->is_trdev) { |
| 306 | skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN); |
| 307 | kfree_skb(skb); |
| 308 | if (skb2 == NULL) |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 309 | return NETDEV_TX_OK; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 310 | skb = skb2; |
| 311 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | #endif |
| 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | #if DUMP_PACKETS >= 2 |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 315 | #define MAX_DUMP_SKB 99 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | #elif DUMP_PACKETS >= 1 |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 317 | #define MAX_DUMP_SKB 30 |
| 318 | #endif |
| 319 | #if DUMP_PACKETS >= 1 |
| 320 | printk(KERN_DEBUG "%s: send datalen:%ld lecid:%4.4x\n", |
| 321 | dev->name, skb->len, priv->lecid); |
| 322 | print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1, |
| 323 | skb->data, min(skb->len, MAX_DUMP_SKB), true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | #endif /* DUMP_PACKETS >= 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 326 | /* Minimum ethernet-frame size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | #ifdef CONFIG_TR |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 328 | if (priv->is_trdev) |
| 329 | min_frame_size = LEC_MINIMUM_8025_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | else |
| 331 | #endif |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 332 | min_frame_size = LEC_MINIMUM_8023_SIZE; |
| 333 | if (skb->len < min_frame_size) { |
| 334 | if ((skb->len + skb_tailroom(skb)) < min_frame_size) { |
| 335 | skb2 = skb_copy_expand(skb, 0, |
| 336 | min_frame_size - skb->truesize, |
| 337 | GFP_ATOMIC); |
| 338 | dev_kfree_skb(skb); |
| 339 | if (skb2 == NULL) { |
Stephen Hemminger | 162619e | 2009-01-09 13:01:01 +0000 | [diff] [blame] | 340 | dev->stats.tx_dropped++; |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 341 | return NETDEV_TX_OK; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 342 | } |
| 343 | skb = skb2; |
| 344 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | skb_put(skb, min_frame_size - skb->len); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | /* Send to right vcc */ |
| 349 | is_rdesc = 0; |
| 350 | dst = lec_h->h_dest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | #ifdef CONFIG_TR |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 352 | if (priv->is_trdev) { |
| 353 | dst = get_tr_dst(skb->data + 2, rdesc); |
| 354 | if (dst == NULL) { |
| 355 | dst = rdesc; |
| 356 | is_rdesc = 1; |
| 357 | } |
| 358 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | #endif |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 360 | entry = NULL; |
| 361 | vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry); |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 362 | pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n", |
| 363 | dev->name, vcc, vcc ? vcc->flags : 0, entry); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 364 | if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) { |
| 365 | if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) { |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 366 | pr_debug("%s:queuing packet, MAC address %pM\n", |
| 367 | dev->name, lec_h->h_dest); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 368 | skb_queue_tail(&entry->tx_wait, skb); |
| 369 | } else { |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 370 | pr_debug("%s:tx queue full or no arp entry, dropping, MAC address: %pM\n", |
| 371 | dev->name, lec_h->h_dest); |
Stephen Hemminger | 162619e | 2009-01-09 13:01:01 +0000 | [diff] [blame] | 372 | dev->stats.tx_dropped++; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 373 | dev_kfree_skb(skb); |
| 374 | } |
Chas Williams | 6656e3c | 2006-09-29 17:17:17 -0700 | [diff] [blame] | 375 | goto out; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 376 | } |
| 377 | #if DUMP_PACKETS > 0 |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 378 | printk(KERN_DEBUG "%s:sending to vpi:%d vci:%d\n", |
| 379 | dev->name, vcc->vpi, vcc->vci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | #endif /* DUMP_PACKETS > 0 */ |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 381 | |
| 382 | while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) { |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 383 | pr_debug("emptying tx queue, MAC address %pM\n", lec_h->h_dest); |
Stephen Hemminger | 162619e | 2009-01-09 13:01:01 +0000 | [diff] [blame] | 384 | lec_send(vcc, skb2); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
Stephen Hemminger | 162619e | 2009-01-09 13:01:01 +0000 | [diff] [blame] | 387 | lec_send(vcc, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | if (!atm_may_send(vcc, 0)) { |
| 390 | struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc); |
| 391 | |
| 392 | vpriv->xoff = 1; |
| 393 | netif_stop_queue(dev); |
| 394 | |
| 395 | /* |
| 396 | * vcc->pop() might have occurred in between, making |
| 397 | * the vcc usuable again. Since xmit is serialized, |
| 398 | * this is the only situation we have to re-test. |
| 399 | */ |
| 400 | |
| 401 | if (atm_may_send(vcc, 0)) |
| 402 | netif_wake_queue(dev); |
| 403 | } |
| 404 | |
Chas Williams | 6656e3c | 2006-09-29 17:17:17 -0700 | [diff] [blame] | 405 | out: |
| 406 | if (entry) |
| 407 | lec_arp_put(entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | dev->trans_start = jiffies; |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 409 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | /* The inverse routine to net_open(). */ |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 413 | static int lec_close(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 415 | netif_stop_queue(dev); |
| 416 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 419 | static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | { |
| 421 | unsigned long flags; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 422 | struct net_device *dev = (struct net_device *)vcc->proto_data; |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 423 | struct lec_priv *priv = netdev_priv(dev); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 424 | struct atmlec_msg *mesg; |
| 425 | struct lec_arp_table *entry; |
| 426 | int i; |
| 427 | char *tmp; /* FIXME */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
| 429 | atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 430 | mesg = (struct atmlec_msg *)skb->data; |
| 431 | tmp = skb->data; |
| 432 | tmp += sizeof(struct atmlec_msg); |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 433 | pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 434 | switch (mesg->type) { |
| 435 | case l_set_mac_addr: |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 436 | for (i = 0; i < 6; i++) |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 437 | dev->dev_addr[i] = mesg->content.normal.mac_addr[i]; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 438 | break; |
| 439 | case l_del_mac_addr: |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 440 | for (i = 0; i < 6; i++) |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 441 | dev->dev_addr[i] = 0; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 442 | break; |
| 443 | case l_addr_delete: |
| 444 | lec_addr_delete(priv, mesg->content.normal.atm_addr, |
| 445 | mesg->content.normal.flag); |
| 446 | break; |
| 447 | case l_topology_change: |
| 448 | priv->topology_change = mesg->content.normal.flag; |
| 449 | break; |
| 450 | case l_flush_complete: |
| 451 | lec_flush_complete(priv, mesg->content.normal.flag); |
| 452 | break; |
| 453 | case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 455 | entry = lec_arp_find(priv, mesg->content.normal.mac_addr); |
| 456 | lec_arp_remove(priv, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
| 458 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 459 | if (mesg->content.normal.no_source_le_narp) |
| 460 | break; |
| 461 | /* FALL THROUGH */ |
| 462 | case l_arp_update: |
| 463 | lec_arp_update(priv, mesg->content.normal.mac_addr, |
| 464 | mesg->content.normal.atm_addr, |
| 465 | mesg->content.normal.flag, |
| 466 | mesg->content.normal.targetless_le_arp); |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 467 | pr_debug("in l_arp_update\n"); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 468 | if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */ |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 469 | pr_debug("LANE2 3.1.5, got tlvs, size %d\n", |
| 470 | mesg->sizeoftlvs); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 471 | lane2_associate_ind(dev, mesg->content.normal.mac_addr, |
| 472 | tmp, mesg->sizeoftlvs); |
| 473 | } |
| 474 | break; |
| 475 | case l_config: |
| 476 | priv->maximum_unknown_frame_count = |
| 477 | mesg->content.config.maximum_unknown_frame_count; |
| 478 | priv->max_unknown_frame_time = |
| 479 | (mesg->content.config.max_unknown_frame_time * HZ); |
| 480 | priv->max_retry_count = mesg->content.config.max_retry_count; |
| 481 | priv->aging_time = (mesg->content.config.aging_time * HZ); |
| 482 | priv->forward_delay_time = |
| 483 | (mesg->content.config.forward_delay_time * HZ); |
| 484 | priv->arp_response_time = |
| 485 | (mesg->content.config.arp_response_time * HZ); |
| 486 | priv->flush_timeout = (mesg->content.config.flush_timeout * HZ); |
| 487 | priv->path_switching_delay = |
| 488 | (mesg->content.config.path_switching_delay * HZ); |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 489 | priv->lane_version = mesg->content.config.lane_version; |
| 490 | /* LANE2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | priv->lane2_ops = NULL; |
| 492 | if (priv->lane_version > 1) |
| 493 | priv->lane2_ops = &lane2_ops; |
Stephen Hemminger | 1f1900f | 2009-03-21 13:37:28 -0700 | [diff] [blame] | 494 | if (dev_set_mtu(dev, mesg->content.config.mtu)) |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 495 | pr_info("%s: change_mtu to %d failed\n", |
| 496 | dev->name, mesg->content.config.mtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | priv->is_proxy = mesg->content.config.is_proxy; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 498 | break; |
| 499 | case l_flush_tran_id: |
| 500 | lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr, |
| 501 | mesg->content.normal.flag); |
| 502 | break; |
| 503 | case l_set_lecid: |
| 504 | priv->lecid = |
| 505 | (unsigned short)(0xffff & mesg->content.normal.flag); |
| 506 | break; |
| 507 | case l_should_bridge: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) |
Joe Perches | b4c84ec | 2010-01-26 11:40:19 +0000 | [diff] [blame] | 509 | { |
| 510 | pr_debug("%s: bridge zeppelin asks about %pM\n", |
| 511 | dev->name, mesg->content.proxy.mac_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Joe Perches | b4c84ec | 2010-01-26 11:40:19 +0000 | [diff] [blame] | 513 | if (br_fdb_test_addr_hook == NULL) |
| 514 | break; |
| 515 | |
| 516 | if (br_fdb_test_addr_hook(dev, mesg->content.proxy.mac_addr)) { |
| 517 | /* hit from bridge table, send LE_ARP_RESPONSE */ |
| 518 | struct sk_buff *skb2; |
| 519 | struct sock *sk; |
| 520 | |
| 521 | pr_debug("%s: entry found, responding to zeppelin\n", |
| 522 | dev->name); |
| 523 | skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC); |
| 524 | if (skb2 == NULL) |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 525 | break; |
Joe Perches | b4c84ec | 2010-01-26 11:40:19 +0000 | [diff] [blame] | 526 | skb2->len = sizeof(struct atmlec_msg); |
| 527 | skb_copy_to_linear_data(skb2, mesg, sizeof(*mesg)); |
| 528 | atm_force_charge(priv->lecd, skb2->truesize); |
| 529 | sk = sk_atm(priv->lecd); |
| 530 | skb_queue_tail(&sk->sk_receive_queue, skb2); |
| 531 | sk->sk_data_ready(sk, skb2->len); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 532 | } |
Joe Perches | b4c84ec | 2010-01-26 11:40:19 +0000 | [diff] [blame] | 533 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */ |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 535 | break; |
| 536 | default: |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 537 | pr_info("%s: Unknown message type %d\n", dev->name, mesg->type); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 538 | dev_kfree_skb(skb); |
| 539 | return -EINVAL; |
| 540 | } |
| 541 | dev_kfree_skb(skb); |
| 542 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 545 | static void lec_atm_close(struct atm_vcc *vcc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 547 | struct sk_buff *skb; |
| 548 | struct net_device *dev = (struct net_device *)vcc->proto_data; |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 549 | struct lec_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 551 | priv->lecd = NULL; |
| 552 | /* Do something needful? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 554 | netif_stop_queue(dev); |
| 555 | lec_arp_destroy(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 557 | if (skb_peek(&sk_atm(vcc)->sk_receive_queue)) |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 558 | pr_info("%s closing with messages pending\n", dev->name); |
Joe Perches | b4c84ec | 2010-01-26 11:40:19 +0000 | [diff] [blame] | 559 | while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 560 | atm_return(vcc, skb->truesize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | dev_kfree_skb(skb); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 564 | pr_info("%s: Shut down!\n", dev->name); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 565 | module_put(THIS_MODULE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | static struct atmdev_ops lecdev_ops = { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 569 | .close = lec_atm_close, |
| 570 | .send = lec_atm_send |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | }; |
| 572 | |
| 573 | static struct atm_dev lecatm_dev = { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 574 | .ops = &lecdev_ops, |
| 575 | .type = "lec", |
| 576 | .number = 999, /* dummy device number */ |
Milind Arun Choudhary | 4ef8d0a | 2007-04-26 01:37:44 -0700 | [diff] [blame] | 577 | .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | }; |
| 579 | |
| 580 | /* |
| 581 | * LANE2: new argument struct sk_buff *data contains |
| 582 | * the LE_ARP based TLVs introduced in the LANE2 spec |
| 583 | */ |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 584 | static int |
| 585 | send_to_lecd(struct lec_priv *priv, atmlec_msg_type type, |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 586 | const unsigned char *mac_addr, const unsigned char *atm_addr, |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 587 | struct sk_buff *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | { |
| 589 | struct sock *sk; |
| 590 | struct sk_buff *skb; |
| 591 | struct atmlec_msg *mesg; |
| 592 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 593 | if (!priv || !priv->lecd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC); |
| 596 | if (!skb) |
| 597 | return -1; |
| 598 | skb->len = sizeof(struct atmlec_msg); |
| 599 | mesg = (struct atmlec_msg *)skb->data; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 600 | memset(mesg, 0, sizeof(struct atmlec_msg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | mesg->type = type; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 602 | if (data != NULL) |
| 603 | mesg->sizeoftlvs = data->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | if (mac_addr) |
| 605 | memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 606 | else |
| 607 | mesg->content.normal.targetless_le_arp = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | if (atm_addr) |
| 609 | memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN); |
| 610 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 611 | atm_force_charge(priv->lecd, skb->truesize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | sk = sk_atm(priv->lecd); |
| 613 | skb_queue_tail(&sk->sk_receive_queue, skb); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 614 | sk->sk_data_ready(sk, skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 616 | if (data != NULL) { |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 617 | pr_debug("about to send %d bytes of data\n", data->len); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 618 | atm_force_charge(priv->lecd, data->truesize); |
| 619 | skb_queue_tail(&sk->sk_receive_queue, data); |
| 620 | sk->sk_data_ready(sk, skb->len); |
| 621 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 623 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | /* shamelessly stolen from drivers/net/net_init.c */ |
| 627 | static int lec_change_mtu(struct net_device *dev, int new_mtu) |
| 628 | { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 629 | if ((new_mtu < 68) || (new_mtu > 18190)) |
| 630 | return -EINVAL; |
| 631 | dev->mtu = new_mtu; |
| 632 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | static void lec_set_multicast_list(struct net_device *dev) |
| 636 | { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 637 | /* |
| 638 | * by default, all multicast frames arrive over the bus. |
| 639 | * eventually support selective multicast service |
| 640 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Stephen Hemminger | 004b322 | 2009-01-09 13:01:02 +0000 | [diff] [blame] | 643 | static const struct net_device_ops lec_netdev_ops = { |
| 644 | .ndo_open = lec_open, |
| 645 | .ndo_stop = lec_close, |
| 646 | .ndo_start_xmit = lec_start_xmit, |
| 647 | .ndo_change_mtu = lec_change_mtu, |
| 648 | .ndo_tx_timeout = lec_tx_timeout, |
| 649 | .ndo_set_multicast_list = lec_set_multicast_list, |
| 650 | }; |
| 651 | |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 652 | static const unsigned char lec_ctrl_magic[] = { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 653 | 0xff, |
| 654 | 0x00, |
| 655 | 0x01, |
| 656 | 0x01 |
| 657 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
Scott Talbert | 4a7097f | 2005-09-29 17:30:54 -0700 | [diff] [blame] | 659 | #define LEC_DATA_DIRECT_8023 2 |
| 660 | #define LEC_DATA_DIRECT_8025 3 |
| 661 | |
| 662 | static int lec_is_data_direct(struct atm_vcc *vcc) |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 663 | { |
Scott Talbert | 4a7097f | 2005-09-29 17:30:54 -0700 | [diff] [blame] | 664 | return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) || |
| 665 | (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025)); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 666 | } |
Scott Talbert | 4a7097f | 2005-09-29 17:30:54 -0700 | [diff] [blame] | 667 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 668 | static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | { |
Scott Talbert | 4a7097f | 2005-09-29 17:30:54 -0700 | [diff] [blame] | 670 | unsigned long flags; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 671 | struct net_device *dev = (struct net_device *)vcc->proto_data; |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 672 | struct lec_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 674 | #if DUMP_PACKETS > 0 |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 675 | printk(KERN_DEBUG "%s: vcc vpi:%d vci:%d\n", |
| 676 | dev->name, vcc->vpi, vcc->vci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | #endif |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 678 | if (!skb) { |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 679 | pr_debug("%s: null skb\n", dev->name); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 680 | lec_vcc_close(priv, vcc); |
| 681 | return; |
| 682 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | #if DUMP_PACKETS >= 2 |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 684 | #define MAX_SKB_DUMP 99 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | #elif DUMP_PACKETS >= 1 |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 686 | #define MAX_SKB_DUMP 30 |
| 687 | #endif |
| 688 | #if DUMP_PACKETS > 0 |
| 689 | printk(KERN_DEBUG "%s: rcv datalen:%ld lecid:%4.4x\n", |
| 690 | dev->name, skb->len, priv->lecid); |
| 691 | print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1, |
| 692 | skb->data, min(MAX_SKB_DUMP, skb->len), true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | #endif /* DUMP_PACKETS > 0 */ |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 694 | if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) { |
| 695 | /* Control frame, to daemon */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | struct sock *sk = sk_atm(vcc); |
| 697 | |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 698 | pr_debug("%s: To daemon\n", dev->name); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 699 | skb_queue_tail(&sk->sk_receive_queue, skb); |
| 700 | sk->sk_data_ready(sk, skb->len); |
| 701 | } else { /* Data frame, queue to protocol handlers */ |
Scott Talbert | 4a7097f | 2005-09-29 17:30:54 -0700 | [diff] [blame] | 702 | struct lec_arp_table *entry; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 703 | unsigned char *src, *dst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 705 | atm_return(vcc, skb->truesize); |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 706 | if (*(__be16 *) skb->data == htons(priv->lecid) || |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 707 | !priv->lecd || !(dev->flags & IFF_UP)) { |
| 708 | /* |
| 709 | * Probably looping back, or if lecd is missing, |
| 710 | * lecd has gone down |
| 711 | */ |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 712 | pr_debug("Ignoring frame...\n"); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 713 | dev_kfree_skb(skb); |
| 714 | return; |
| 715 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | #ifdef CONFIG_TR |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 717 | if (priv->is_trdev) |
| 718 | dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest; |
| 719 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | #endif |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 721 | dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest; |
Scott Talbert | 4a7097f | 2005-09-29 17:30:54 -0700 | [diff] [blame] | 722 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 723 | /* |
| 724 | * If this is a Data Direct VCC, and the VCC does not match |
Scott Talbert | 4a7097f | 2005-09-29 17:30:54 -0700 | [diff] [blame] | 725 | * the LE_ARP cache entry, delete the LE_ARP cache entry. |
| 726 | */ |
| 727 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
| 728 | if (lec_is_data_direct(vcc)) { |
| 729 | #ifdef CONFIG_TR |
| 730 | if (priv->is_trdev) |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 731 | src = |
| 732 | ((struct lecdatahdr_8025 *)skb->data)-> |
| 733 | h_source; |
Scott Talbert | 4a7097f | 2005-09-29 17:30:54 -0700 | [diff] [blame] | 734 | else |
| 735 | #endif |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 736 | src = |
| 737 | ((struct lecdatahdr_8023 *)skb->data)-> |
| 738 | h_source; |
Scott Talbert | 4a7097f | 2005-09-29 17:30:54 -0700 | [diff] [blame] | 739 | entry = lec_arp_find(priv, src); |
| 740 | if (entry && entry->vcc != vcc) { |
| 741 | lec_arp_remove(priv, entry); |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 742 | lec_arp_put(entry); |
Scott Talbert | 4a7097f | 2005-09-29 17:30:54 -0700 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 747 | if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */ |
| 748 | !priv->is_proxy && /* Proxy wants all the packets */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | memcmp(dst, dev->dev_addr, dev->addr_len)) { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 750 | dev_kfree_skb(skb); |
| 751 | return; |
| 752 | } |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 753 | if (!hlist_empty(&priv->lec_arp_empty_ones)) |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 754 | lec_arp_check_empties(priv, vcc, skb); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 755 | skb_pull(skb, 2); /* skip lec_id */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | #ifdef CONFIG_TR |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 757 | if (priv->is_trdev) |
| 758 | skb->protocol = tr_type_trans(skb, dev); |
| 759 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | #endif |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 761 | skb->protocol = eth_type_trans(skb, dev); |
Stephen Hemminger | 162619e | 2009-01-09 13:01:01 +0000 | [diff] [blame] | 762 | dev->stats.rx_packets++; |
| 763 | dev->stats.rx_bytes += skb->len; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 764 | memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data)); |
| 765 | netif_rx(skb); |
| 766 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | } |
| 768 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 769 | static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | { |
| 771 | struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc); |
| 772 | struct net_device *dev = skb->dev; |
| 773 | |
| 774 | if (vpriv == NULL) { |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 775 | pr_info("vpriv = NULL!?!?!?\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | return; |
| 777 | } |
| 778 | |
| 779 | vpriv->old_pop(vcc, skb); |
| 780 | |
| 781 | if (vpriv->xoff && atm_may_send(vcc, 0)) { |
| 782 | vpriv->xoff = 0; |
| 783 | if (netif_running(dev) && netif_queue_stopped(dev)) |
| 784 | netif_wake_queue(dev); |
| 785 | } |
| 786 | } |
| 787 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 788 | static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | { |
| 790 | struct lec_vcc_priv *vpriv; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 791 | int bytes_left; |
| 792 | struct atmlec_ioc ioc_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 794 | /* Lecd must be up in this case */ |
| 795 | bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc)); |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 796 | if (bytes_left != 0) |
| 797 | pr_info("copy from user failed for %d bytes\n", bytes_left); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 798 | if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF || |
| 799 | !dev_lec[ioc_data.dev_num]) |
| 800 | return -EINVAL; |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 801 | vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL); |
| 802 | if (!vpriv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | return -ENOMEM; |
| 804 | vpriv->xoff = 0; |
| 805 | vpriv->old_pop = vcc->pop; |
| 806 | vcc->user_back = vpriv; |
| 807 | vcc->pop = lec_pop; |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 808 | lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]), |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 809 | &ioc_data, vcc, vcc->push); |
| 810 | vcc->proto_data = dev_lec[ioc_data.dev_num]; |
| 811 | vcc->push = lec_push; |
| 812 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 815 | static int lec_mcast_attach(struct atm_vcc *vcc, int arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 817 | if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg]) |
| 818 | return -EINVAL; |
| 819 | vcc->proto_data = dev_lec[arg]; |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 820 | return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]), |
| 821 | vcc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | /* Initialize device. */ |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 825 | static int lecd_attach(struct atm_vcc *vcc, int arg) |
| 826 | { |
| 827 | int i; |
| 828 | struct lec_priv *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 830 | if (arg < 0) |
| 831 | i = 0; |
| 832 | else |
| 833 | i = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | #ifdef CONFIG_TR |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 835 | if (arg >= MAX_LEC_ITF) |
| 836 | return -EINVAL; |
| 837 | #else /* Reserve the top NUM_TR_DEVS for TR */ |
| 838 | if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS)) |
| 839 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | #endif |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 841 | if (!dev_lec[i]) { |
| 842 | int is_trdev, size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 844 | is_trdev = 0; |
| 845 | if (i >= (MAX_LEC_ITF - NUM_TR_DEVS)) |
| 846 | is_trdev = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 848 | size = sizeof(struct lec_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | #ifdef CONFIG_TR |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 850 | if (is_trdev) |
| 851 | dev_lec[i] = alloc_trdev(size); |
| 852 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | #endif |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 854 | dev_lec[i] = alloc_etherdev(size); |
| 855 | if (!dev_lec[i]) |
| 856 | return -ENOMEM; |
chas williams - CONTRACTOR | eb04458 | 2009-12-04 05:19:30 +0000 | [diff] [blame] | 857 | dev_lec[i]->netdev_ops = &lec_netdev_ops; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 858 | snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i); |
| 859 | if (register_netdev(dev_lec[i])) { |
| 860 | free_netdev(dev_lec[i]); |
| 861 | return -EINVAL; |
| 862 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 864 | priv = netdev_priv(dev_lec[i]); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 865 | priv->is_trdev = is_trdev; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 866 | } else { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 867 | priv = netdev_priv(dev_lec[i]); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 868 | if (priv->lecd) |
| 869 | return -EADDRINUSE; |
| 870 | } |
| 871 | lec_arp_init(priv); |
| 872 | priv->itfnum = i; /* LANE2 addition */ |
| 873 | priv->lecd = vcc; |
| 874 | vcc->dev = &lecatm_dev; |
| 875 | vcc_insert_socket(sk_atm(vcc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 877 | vcc->proto_data = dev_lec[i]; |
| 878 | set_bit(ATM_VF_META, &vcc->flags); |
| 879 | set_bit(ATM_VF_READY, &vcc->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 881 | /* Set default values to these variables */ |
| 882 | priv->maximum_unknown_frame_count = 1; |
| 883 | priv->max_unknown_frame_time = (1 * HZ); |
| 884 | priv->vcc_timeout_period = (1200 * HZ); |
| 885 | priv->max_retry_count = 1; |
| 886 | priv->aging_time = (300 * HZ); |
| 887 | priv->forward_delay_time = (15 * HZ); |
| 888 | priv->topology_change = 0; |
| 889 | priv->arp_response_time = (1 * HZ); |
| 890 | priv->flush_timeout = (4 * HZ); |
| 891 | priv->path_switching_delay = (6 * HZ); |
| 892 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 893 | if (dev_lec[i]->flags & IFF_UP) |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 894 | netif_start_queue(dev_lec[i]); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 895 | __module_get(THIS_MODULE); |
| 896 | return i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | #ifdef CONFIG_PROC_FS |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 900 | static const char *lec_arp_get_status_string(unsigned char status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | { |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 902 | static const char *const lec_arp_status_string[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | "ESI_UNKNOWN ", |
| 904 | "ESI_ARP_PENDING ", |
| 905 | "ESI_VC_PENDING ", |
| 906 | "<Undefined> ", |
| 907 | "ESI_FLUSH_PENDING ", |
| 908 | "ESI_FORWARD_DIRECT" |
| 909 | }; |
| 910 | |
| 911 | if (status > ESI_FORWARD_DIRECT) |
| 912 | status = 3; /* ESI_UNDEFINED */ |
| 913 | return lec_arp_status_string[status]; |
| 914 | } |
| 915 | |
| 916 | static void lec_info(struct seq_file *seq, struct lec_arp_table *entry) |
| 917 | { |
| 918 | int i; |
| 919 | |
| 920 | for (i = 0; i < ETH_ALEN; i++) |
| 921 | seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff); |
| 922 | seq_printf(seq, " "); |
| 923 | for (i = 0; i < ATM_ESA_LEN; i++) |
| 924 | seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff); |
| 925 | seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status), |
| 926 | entry->flags & 0xffff); |
| 927 | if (entry->vcc) |
| 928 | seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci); |
| 929 | else |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 930 | seq_printf(seq, " "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | if (entry->recv_vcc) { |
| 932 | seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi, |
| 933 | entry->recv_vcc->vci); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 934 | } |
| 935 | seq_putc(seq, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | } |
| 937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | struct lec_state { |
| 939 | unsigned long flags; |
| 940 | struct lec_priv *locked; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 941 | struct hlist_node *node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | struct net_device *dev; |
| 943 | int itf; |
| 944 | int arp_table; |
| 945 | int misc_table; |
| 946 | }; |
| 947 | |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 948 | static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | loff_t *l) |
| 950 | { |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 951 | struct hlist_node *e = state->node; |
| 952 | struct lec_arp_table *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
| 954 | if (!e) |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 955 | e = tbl->first; |
Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 956 | if (e == SEQ_START_TOKEN) { |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 957 | e = tbl->first; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | --*l; |
| 959 | } |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 960 | |
| 961 | hlist_for_each_entry_from(tmp, e, next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | if (--*l < 0) |
| 963 | break; |
| 964 | } |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 965 | state->node = e; |
| 966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | return (*l < 0) ? state : NULL; |
| 968 | } |
| 969 | |
| 970 | static void *lec_arp_walk(struct lec_state *state, loff_t *l, |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 971 | struct lec_priv *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | { |
| 973 | void *v = NULL; |
| 974 | int p; |
| 975 | |
| 976 | for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) { |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 977 | v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | if (v) |
| 979 | break; |
| 980 | } |
| 981 | state->arp_table = p; |
| 982 | return v; |
| 983 | } |
| 984 | |
| 985 | static void *lec_misc_walk(struct lec_state *state, loff_t *l, |
| 986 | struct lec_priv *priv) |
| 987 | { |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 988 | struct hlist_head *lec_misc_tables[] = { |
| 989 | &priv->lec_arp_empty_ones, |
| 990 | &priv->lec_no_forward, |
| 991 | &priv->mcast_fwds |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | }; |
| 993 | void *v = NULL; |
| 994 | int q; |
| 995 | |
| 996 | for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) { |
| 997 | v = lec_tbl_walk(state, lec_misc_tables[q], l); |
| 998 | if (v) |
| 999 | break; |
| 1000 | } |
| 1001 | state->misc_table = q; |
| 1002 | return v; |
| 1003 | } |
| 1004 | |
| 1005 | static void *lec_priv_walk(struct lec_state *state, loff_t *l, |
| 1006 | struct lec_priv *priv) |
| 1007 | { |
| 1008 | if (!state->locked) { |
| 1009 | state->locked = priv; |
| 1010 | spin_lock_irqsave(&priv->lec_arp_lock, state->flags); |
| 1011 | } |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1012 | if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags); |
| 1014 | state->locked = NULL; |
| 1015 | /* Partial state reset for the next time we get called */ |
| 1016 | state->arp_table = state->misc_table = 0; |
| 1017 | } |
| 1018 | return state->locked; |
| 1019 | } |
| 1020 | |
| 1021 | static void *lec_itf_walk(struct lec_state *state, loff_t *l) |
| 1022 | { |
| 1023 | struct net_device *dev; |
| 1024 | void *v; |
| 1025 | |
| 1026 | dev = state->dev ? state->dev : dev_lec[state->itf]; |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1027 | v = (dev && netdev_priv(dev)) ? |
| 1028 | lec_priv_walk(state, l, netdev_priv(dev)) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | if (!v && dev) { |
| 1030 | dev_put(dev); |
| 1031 | /* Partial state reset for the next time we get called */ |
| 1032 | dev = NULL; |
| 1033 | } |
| 1034 | state->dev = dev; |
| 1035 | return v; |
| 1036 | } |
| 1037 | |
| 1038 | static void *lec_get_idx(struct lec_state *state, loff_t l) |
| 1039 | { |
| 1040 | void *v = NULL; |
| 1041 | |
| 1042 | for (; state->itf < MAX_LEC_ITF; state->itf++) { |
| 1043 | v = lec_itf_walk(state, &l); |
| 1044 | if (v) |
| 1045 | break; |
| 1046 | } |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1047 | return v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | static void *lec_seq_start(struct seq_file *seq, loff_t *pos) |
| 1051 | { |
| 1052 | struct lec_state *state = seq->private; |
| 1053 | |
| 1054 | state->itf = 0; |
| 1055 | state->dev = NULL; |
| 1056 | state->locked = NULL; |
| 1057 | state->arp_table = 0; |
| 1058 | state->misc_table = 0; |
Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 1059 | state->node = SEQ_START_TOKEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | |
Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 1061 | return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | static void lec_seq_stop(struct seq_file *seq, void *v) |
| 1065 | { |
| 1066 | struct lec_state *state = seq->private; |
| 1067 | |
| 1068 | if (state->dev) { |
| 1069 | spin_unlock_irqrestore(&state->locked->lec_arp_lock, |
| 1070 | state->flags); |
| 1071 | dev_put(state->dev); |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 1076 | { |
| 1077 | struct lec_state *state = seq->private; |
| 1078 | |
| 1079 | v = lec_get_idx(state, 1); |
| 1080 | *pos += !!PTR_ERR(v); |
| 1081 | return v; |
| 1082 | } |
| 1083 | |
| 1084 | static int lec_seq_show(struct seq_file *seq, void *v) |
| 1085 | { |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 1086 | static const char lec_banner[] = |
| 1087 | "Itf MAC ATM destination" |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1088 | " Status Flags " |
| 1089 | "VPI/VCI Recv VPI/VCI\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 1091 | if (v == SEQ_START_TOKEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | seq_puts(seq, lec_banner); |
| 1093 | else { |
| 1094 | struct lec_state *state = seq->private; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1095 | struct net_device *dev = state->dev; |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1096 | struct lec_arp_table *entry = hlist_entry(state->node, |
| 1097 | struct lec_arp_table, |
| 1098 | next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | |
| 1100 | seq_printf(seq, "%s ", dev->name); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1101 | lec_info(seq, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 1106 | static const struct seq_operations lec_seq_ops = { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1107 | .start = lec_seq_start, |
| 1108 | .next = lec_seq_next, |
| 1109 | .stop = lec_seq_stop, |
| 1110 | .show = lec_seq_show, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | }; |
| 1112 | |
| 1113 | static int lec_seq_open(struct inode *inode, struct file *file) |
| 1114 | { |
Pavel Emelyanov | 9a8c09e | 2008-02-29 11:37:02 -0800 | [diff] [blame] | 1115 | return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 1118 | static const struct file_operations lec_seq_fops = { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1119 | .owner = THIS_MODULE, |
| 1120 | .open = lec_seq_open, |
| 1121 | .read = seq_read, |
| 1122 | .llseek = seq_lseek, |
Pavel Emelyanov | 9a8c09e | 2008-02-29 11:37:02 -0800 | [diff] [blame] | 1123 | .release = seq_release_private, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | }; |
| 1125 | #endif |
| 1126 | |
| 1127 | static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) |
| 1128 | { |
| 1129 | struct atm_vcc *vcc = ATM_SD(sock); |
| 1130 | int err = 0; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | switch (cmd) { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1133 | case ATMLEC_CTRL: |
| 1134 | case ATMLEC_MCAST: |
| 1135 | case ATMLEC_DATA: |
| 1136 | if (!capable(CAP_NET_ADMIN)) |
| 1137 | return -EPERM; |
| 1138 | break; |
| 1139 | default: |
| 1140 | return -ENOIOCTLCMD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | switch (cmd) { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1144 | case ATMLEC_CTRL: |
| 1145 | err = lecd_attach(vcc, (int)arg); |
| 1146 | if (err >= 0) |
| 1147 | sock->state = SS_CONNECTED; |
| 1148 | break; |
| 1149 | case ATMLEC_MCAST: |
| 1150 | err = lec_mcast_attach(vcc, (int)arg); |
| 1151 | break; |
| 1152 | case ATMLEC_DATA: |
| 1153 | err = lec_vcc_attach(vcc, (void __user *)arg); |
| 1154 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | return err; |
| 1158 | } |
| 1159 | |
| 1160 | static struct atm_ioctl lane_ioctl_ops = { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1161 | .owner = THIS_MODULE, |
| 1162 | .ioctl = lane_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | }; |
| 1164 | |
| 1165 | static int __init lane_module_init(void) |
| 1166 | { |
| 1167 | #ifdef CONFIG_PROC_FS |
| 1168 | struct proc_dir_entry *p; |
| 1169 | |
Wang Chen | 16e297b | 2008-02-28 13:55:45 -0800 | [diff] [blame] | 1170 | p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops); |
Wang Chen | dbee0d3 | 2008-03-23 21:45:36 -0700 | [diff] [blame] | 1171 | if (!p) { |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1172 | pr_err("Unable to initialize /proc/net/atm/lec\n"); |
Wang Chen | dbee0d3 | 2008-03-23 21:45:36 -0700 | [diff] [blame] | 1173 | return -ENOMEM; |
| 1174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | #endif |
| 1176 | |
| 1177 | register_atm_ioctl(&lane_ioctl_ops); |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1178 | pr_info("lec.c: " __DATE__ " " __TIME__ " initialized\n"); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1179 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | static void __exit lane_module_cleanup(void) |
| 1183 | { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1184 | int i; |
| 1185 | struct lec_priv *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
| 1187 | remove_proc_entry("lec", atm_proc_root); |
| 1188 | |
| 1189 | deregister_atm_ioctl(&lane_ioctl_ops); |
| 1190 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1191 | for (i = 0; i < MAX_LEC_ITF; i++) { |
| 1192 | if (dev_lec[i] != NULL) { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1193 | priv = netdev_priv(dev_lec[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | unregister_netdev(dev_lec[i]); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1195 | free_netdev(dev_lec[i]); |
| 1196 | dev_lec[i] = NULL; |
| 1197 | } |
| 1198 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | module_init(lane_module_init); |
| 1202 | module_exit(lane_module_cleanup); |
| 1203 | |
| 1204 | /* |
| 1205 | * LANE2: 3.1.3, LE_RESOLVE.request |
| 1206 | * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs. |
| 1207 | * If sizeoftlvs == NULL the default TLVs associated with with this |
| 1208 | * lec will be used. |
| 1209 | * If dst_mac == NULL, targetless LE_ARP will be sent |
| 1210 | */ |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 1211 | static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force, |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1212 | u8 **tlvs, u32 *sizeoftlvs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | { |
| 1214 | unsigned long flags; |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1215 | struct lec_priv *priv = netdev_priv(dev); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1216 | struct lec_arp_table *table; |
| 1217 | struct sk_buff *skb; |
| 1218 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1220 | if (force == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1222 | table = lec_arp_find(priv, dst_mac); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1224 | if (table == NULL) |
| 1225 | return -1; |
| 1226 | |
Arnaldo Carvalho de Melo | 2afe37c | 2006-11-21 01:14:33 -0200 | [diff] [blame] | 1227 | *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1228 | if (*tlvs == NULL) |
| 1229 | return -1; |
| 1230 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1231 | *sizeoftlvs = table->sizeoftlvs; |
| 1232 | |
| 1233 | return 0; |
| 1234 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | |
| 1236 | if (sizeoftlvs == NULL) |
| 1237 | retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | else { |
| 1240 | skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC); |
| 1241 | if (skb == NULL) |
| 1242 | return -1; |
| 1243 | skb->len = *sizeoftlvs; |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 1244 | skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb); |
| 1246 | } |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1247 | return retval; |
| 1248 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | |
| 1250 | /* |
| 1251 | * LANE2: 3.1.4, LE_ASSOCIATE.request |
| 1252 | * Associate the *tlvs with the *lan_dst address. |
| 1253 | * Will overwrite any previous association |
| 1254 | * Returns 1 for success, 0 for failure (out of memory) |
| 1255 | * |
| 1256 | */ |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 1257 | static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst, |
| 1258 | const u8 *tlvs, u32 sizeoftlvs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | { |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1260 | int retval; |
| 1261 | struct sk_buff *skb; |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1262 | struct lec_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1264 | if (compare_ether_addr(lan_dst, dev->dev_addr)) |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1265 | return 0; /* not our mac address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1267 | kfree(priv->tlvs); /* NULL if there was no previous association */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
Arnaldo Carvalho de Melo | 2afe37c | 2006-11-21 01:14:33 -0200 | [diff] [blame] | 1269 | priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1270 | if (priv->tlvs == NULL) |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1271 | return 0; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1272 | priv->sizeoftlvs = sizeoftlvs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1274 | skb = alloc_skb(sizeoftlvs, GFP_ATOMIC); |
| 1275 | if (skb == NULL) |
| 1276 | return 0; |
| 1277 | skb->len = sizeoftlvs; |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 1278 | skb_copy_to_linear_data(skb, tlvs, sizeoftlvs); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1279 | retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb); |
| 1280 | if (retval != 0) |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1281 | pr_info("lec.c: lane2_associate_req() failed\n"); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1282 | /* |
| 1283 | * If the previous association has changed we must |
| 1284 | * somehow notify other LANE entities about the change |
| 1285 | */ |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1286 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | /* |
| 1290 | * LANE2: 3.1.5, LE_ASSOCIATE.indication |
| 1291 | * |
| 1292 | */ |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 1293 | static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr, |
| 1294 | const u8 *tlvs, u32 sizeoftlvs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | { |
| 1296 | #if 0 |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1297 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | #endif |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1299 | struct lec_priv *priv = netdev_priv(dev); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1300 | #if 0 /* |
| 1301 | * Why have the TLVs in LE_ARP entries |
| 1302 | * since we do not use them? When you |
| 1303 | * uncomment this code, make sure the |
| 1304 | * TLVs get freed when entry is killed |
| 1305 | */ |
| 1306 | struct lec_arp_table *entry = lec_arp_find(priv, mac_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1308 | if (entry == NULL) |
| 1309 | return; /* should not happen */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1311 | kfree(entry->tlvs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | |
Arnaldo Carvalho de Melo | 2afe37c | 2006-11-21 01:14:33 -0200 | [diff] [blame] | 1313 | entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1314 | if (entry->tlvs == NULL) |
| 1315 | return; |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1316 | entry->sizeoftlvs = sizeoftlvs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | #endif |
| 1318 | #if 0 |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1319 | pr_info("\n"); |
| 1320 | pr_info("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1321 | while (i < sizeoftlvs) |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1322 | pr_cont("%02x ", tlvs[i++]); |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1323 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1324 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | #endif |
| 1326 | |
Chas Williams | d44f774 | 2006-09-29 17:11:14 -0700 | [diff] [blame] | 1327 | /* tell MPOA about the TLVs we saw */ |
| 1328 | if (priv->lane2_ops && priv->lane2_ops->associate_indicator) { |
| 1329 | priv->lane2_ops->associate_indicator(dev, mac_addr, |
| 1330 | tlvs, sizeoftlvs); |
| 1331 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | /* |
| 1335 | * Here starts what used to lec_arpc.c |
| 1336 | * |
| 1337 | * lec_arpc.c was added here when making |
| 1338 | * lane client modular. October 1997 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | */ |
| 1340 | |
| 1341 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | #include <linux/timer.h> |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1343 | #include <linux/param.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | #include <asm/atomic.h> |
| 1345 | #include <linux/inetdevice.h> |
| 1346 | #include <net/route.h> |
| 1347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | #if 0 |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1349 | #define pr_debug(format, args...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | /* |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1351 | #define pr_debug printk |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | */ |
| 1353 | #endif |
| 1354 | #define DEBUG_ARP_TABLE 0 |
| 1355 | |
| 1356 | #define LEC_ARP_REFRESH_INTERVAL (3*HZ) |
| 1357 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1358 | static void lec_arp_check_expire(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | static void lec_arp_expire_arp(unsigned long data); |
| 1360 | |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1361 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | * Arp table funcs |
| 1363 | */ |
| 1364 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1365 | #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE - 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | |
| 1367 | /* |
| 1368 | * Initialization of arp-cache |
| 1369 | */ |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1370 | static void lec_arp_init(struct lec_priv *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1372 | unsigned short i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1374 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1375 | INIT_HLIST_HEAD(&priv->lec_arp_tables[i]); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1376 | INIT_HLIST_HEAD(&priv->lec_arp_empty_ones); |
| 1377 | INIT_HLIST_HEAD(&priv->lec_no_forward); |
| 1378 | INIT_HLIST_HEAD(&priv->mcast_fwds); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | spin_lock_init(&priv->lec_arp_lock); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1380 | INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire); |
Chas Williams | 987e46b | 2006-09-29 17:15:59 -0700 | [diff] [blame] | 1381 | schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1384 | static void lec_arp_clear_vccs(struct lec_arp_table *entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1386 | if (entry->vcc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | struct atm_vcc *vcc = entry->vcc; |
| 1388 | struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1389 | struct net_device *dev = (struct net_device *)vcc->proto_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1391 | vcc->pop = vpriv->old_pop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | if (vpriv->xoff) |
| 1393 | netif_wake_queue(dev); |
| 1394 | kfree(vpriv); |
| 1395 | vcc->user_back = NULL; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1396 | vcc->push = entry->old_push; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | vcc_release_async(vcc, -EPIPE); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1398 | entry->vcc = NULL; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1399 | } |
| 1400 | if (entry->recv_vcc) { |
| 1401 | entry->recv_vcc->push = entry->old_recv_push; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | vcc_release_async(entry->recv_vcc, -EPIPE); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1403 | entry->recv_vcc = NULL; |
| 1404 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | /* |
| 1408 | * Insert entry to lec_arp_table |
| 1409 | * LANE2: Add to the end of the list to satisfy 8.1.13 |
| 1410 | */ |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1411 | static inline void |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1412 | lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | { |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1414 | struct hlist_head *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1416 | tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])]; |
| 1417 | hlist_add_head(&entry->next, tmp); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1418 | |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1419 | pr_debug("Added entry:%pM\n", entry->mac_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | /* |
| 1423 | * Remove entry from lec_arp_table |
| 1424 | */ |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1425 | static int |
| 1426 | lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | { |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1428 | struct hlist_node *node; |
| 1429 | struct lec_arp_table *entry; |
| 1430 | int i, remove_vcc = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1432 | if (!to_remove) |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1433 | return -1; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1434 | |
| 1435 | hlist_del(&to_remove->next); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1436 | del_timer(&to_remove->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1438 | /* |
| 1439 | * If this is the only MAC connected to this VCC, |
| 1440 | * also tear down the VCC |
| 1441 | */ |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1442 | if (to_remove->status >= ESI_FLUSH_PENDING) { |
| 1443 | /* |
| 1444 | * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT |
| 1445 | */ |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1446 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1447 | hlist_for_each_entry(entry, node, |
| 1448 | &priv->lec_arp_tables[i], next) { |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1449 | if (memcmp(to_remove->atm_addr, |
| 1450 | entry->atm_addr, ATM_ESA_LEN) == 0) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1451 | remove_vcc = 0; |
| 1452 | break; |
| 1453 | } |
| 1454 | } |
| 1455 | } |
| 1456 | if (remove_vcc) |
| 1457 | lec_arp_clear_vccs(to_remove); |
| 1458 | } |
| 1459 | skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */ |
| 1460 | |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1461 | pr_debug("Removed entry:%pM\n", to_remove->mac_addr); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1462 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | #if DEBUG_ARP_TABLE |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 1466 | static const char *get_status_string(unsigned char st) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1468 | switch (st) { |
| 1469 | case ESI_UNKNOWN: |
| 1470 | return "ESI_UNKNOWN"; |
| 1471 | case ESI_ARP_PENDING: |
| 1472 | return "ESI_ARP_PENDING"; |
| 1473 | case ESI_VC_PENDING: |
| 1474 | return "ESI_VC_PENDING"; |
| 1475 | case ESI_FLUSH_PENDING: |
| 1476 | return "ESI_FLUSH_PENDING"; |
| 1477 | case ESI_FORWARD_DIRECT: |
| 1478 | return "ESI_FORWARD_DIRECT"; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1479 | } |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1480 | return "<UNKNOWN>"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1483 | static void dump_arp_table(struct lec_priv *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | { |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1485 | struct hlist_node *node; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1486 | struct lec_arp_table *rulla; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1487 | char buf[256]; |
| 1488 | int i, j, offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1490 | pr_info("Dump %p:\n", priv); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1491 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1492 | hlist_for_each_entry(rulla, node, |
| 1493 | &priv->lec_arp_tables[i], next) { |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1494 | offset = 0; |
| 1495 | offset += sprintf(buf, "%d: %p\n", i, rulla); |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1496 | offset += sprintf(buf + offset, "Mac: %pM", |
| 1497 | rulla->mac_addr); |
| 1498 | offset += sprintf(buf + offset, " Atm:"); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1499 | for (j = 0; j < ATM_ESA_LEN; j++) { |
| 1500 | offset += sprintf(buf + offset, |
| 1501 | "%2.2x ", |
| 1502 | rulla->atm_addr[j] & 0xff); |
| 1503 | } |
| 1504 | offset += sprintf(buf + offset, |
| 1505 | "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ", |
| 1506 | rulla->vcc ? rulla->vcc->vpi : 0, |
| 1507 | rulla->vcc ? rulla->vcc->vci : 0, |
| 1508 | rulla->recv_vcc ? rulla->recv_vcc-> |
| 1509 | vpi : 0, |
| 1510 | rulla->recv_vcc ? rulla->recv_vcc-> |
| 1511 | vci : 0, rulla->last_used, |
| 1512 | rulla->timestamp, rulla->no_tries); |
| 1513 | offset += |
| 1514 | sprintf(buf + offset, |
| 1515 | "Flags:%x, Packets_flooded:%x, Status: %s ", |
| 1516 | rulla->flags, rulla->packets_flooded, |
| 1517 | get_status_string(rulla->status)); |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1518 | pr_info("%s\n", buf); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1519 | } |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1520 | } |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1521 | |
| 1522 | if (!hlist_empty(&priv->lec_no_forward)) |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1523 | pr_info("No forward\n"); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1524 | hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1525 | offset = 0; |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1526 | offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr); |
| 1527 | offset += sprintf(buf + offset, " Atm:"); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1528 | for (j = 0; j < ATM_ESA_LEN; j++) { |
| 1529 | offset += sprintf(buf + offset, "%2.2x ", |
| 1530 | rulla->atm_addr[j] & 0xff); |
| 1531 | } |
| 1532 | offset += sprintf(buf + offset, |
| 1533 | "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ", |
| 1534 | rulla->vcc ? rulla->vcc->vpi : 0, |
| 1535 | rulla->vcc ? rulla->vcc->vci : 0, |
| 1536 | rulla->recv_vcc ? rulla->recv_vcc->vpi : 0, |
| 1537 | rulla->recv_vcc ? rulla->recv_vcc->vci : 0, |
| 1538 | rulla->last_used, |
| 1539 | rulla->timestamp, rulla->no_tries); |
| 1540 | offset += sprintf(buf + offset, |
| 1541 | "Flags:%x, Packets_flooded:%x, Status: %s ", |
| 1542 | rulla->flags, rulla->packets_flooded, |
| 1543 | get_status_string(rulla->status)); |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1544 | pr_info("%s\n", buf); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1545 | } |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1546 | |
| 1547 | if (!hlist_empty(&priv->lec_arp_empty_ones)) |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1548 | pr_info("Empty ones\n"); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1549 | hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1550 | offset = 0; |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1551 | offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr); |
| 1552 | offset += sprintf(buf + offset, " Atm:"); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 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)); |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1569 | pr_info("%s", buf); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1570 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1572 | if (!hlist_empty(&priv->mcast_fwds)) |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1573 | pr_info("Multicast Forward VCCs\n"); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1574 | hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1575 | offset = 0; |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1576 | offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr); |
| 1577 | offset += sprintf(buf + offset, " Atm:"); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1578 | for (j = 0; j < ATM_ESA_LEN; j++) { |
| 1579 | offset += sprintf(buf + offset, "%2.2x ", |
| 1580 | rulla->atm_addr[j] & 0xff); |
| 1581 | } |
| 1582 | offset += sprintf(buf + offset, |
| 1583 | "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ", |
| 1584 | rulla->vcc ? rulla->vcc->vpi : 0, |
| 1585 | rulla->vcc ? rulla->vcc->vci : 0, |
| 1586 | rulla->recv_vcc ? rulla->recv_vcc->vpi : 0, |
| 1587 | rulla->recv_vcc ? rulla->recv_vcc->vci : 0, |
| 1588 | rulla->last_used, |
| 1589 | rulla->timestamp, rulla->no_tries); |
| 1590 | offset += sprintf(buf + offset, |
| 1591 | "Flags:%x, Packets_flooded:%x, Status: %s ", |
| 1592 | rulla->flags, rulla->packets_flooded, |
| 1593 | get_status_string(rulla->status)); |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1594 | pr_info("%s\n", buf); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1595 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | } |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1598 | #else |
| 1599 | #define dump_arp_table(priv) do { } while (0) |
| 1600 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | |
| 1602 | /* |
| 1603 | * Destruction of arp-cache |
| 1604 | */ |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1605 | static void lec_arp_destroy(struct lec_priv *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | { |
| 1607 | unsigned long flags; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1608 | struct hlist_node *node, *next; |
| 1609 | struct lec_arp_table *entry; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1610 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | |
Chas Williams | 987e46b | 2006-09-29 17:15:59 -0700 | [diff] [blame] | 1612 | cancel_rearming_delayed_work(&priv->lec_arp_work); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1613 | |
| 1614 | /* |
| 1615 | * Remove all entries |
| 1616 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | |
| 1618 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1619 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1620 | hlist_for_each_entry_safe(entry, node, next, |
| 1621 | &priv->lec_arp_tables[i], next) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1622 | lec_arp_remove(priv, entry); |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 1623 | lec_arp_put(entry); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1624 | } |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1625 | INIT_HLIST_HEAD(&priv->lec_arp_tables[i]); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1626 | } |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1627 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1628 | hlist_for_each_entry_safe(entry, node, next, |
| 1629 | &priv->lec_arp_empty_ones, next) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1630 | del_timer_sync(&entry->timer); |
| 1631 | lec_arp_clear_vccs(entry); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1632 | hlist_del(&entry->next); |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 1633 | lec_arp_put(entry); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1634 | } |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1635 | INIT_HLIST_HEAD(&priv->lec_arp_empty_ones); |
| 1636 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1637 | hlist_for_each_entry_safe(entry, node, next, |
| 1638 | &priv->lec_no_forward, next) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1639 | del_timer_sync(&entry->timer); |
| 1640 | lec_arp_clear_vccs(entry); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1641 | hlist_del(&entry->next); |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 1642 | lec_arp_put(entry); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1643 | } |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1644 | INIT_HLIST_HEAD(&priv->lec_no_forward); |
| 1645 | |
| 1646 | hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1647 | /* No timer, LANEv2 7.1.20 and 2.3.5.3 */ |
| 1648 | lec_arp_clear_vccs(entry); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1649 | hlist_del(&entry->next); |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 1650 | lec_arp_put(entry); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1651 | } |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1652 | INIT_HLIST_HEAD(&priv->mcast_fwds); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1653 | priv->mcast_vcc = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
| 1655 | } |
| 1656 | |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1657 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | * Find entry by mac_address |
| 1659 | */ |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1660 | static struct lec_arp_table *lec_arp_find(struct lec_priv *priv, |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 1661 | const unsigned char *mac_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | { |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1663 | struct hlist_node *node; |
| 1664 | struct hlist_head *head; |
| 1665 | struct lec_arp_table *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1667 | pr_debug("%pM\n", mac_addr); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1668 | |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1669 | head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])]; |
| 1670 | hlist_for_each_entry(entry, node, head, next) { |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1671 | if (!compare_ether_addr(mac_addr, entry->mac_addr)) |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1672 | return entry; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1673 | } |
| 1674 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1677 | static struct lec_arp_table *make_entry(struct lec_priv *priv, |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 1678 | const unsigned char *mac_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1680 | struct lec_arp_table *to_return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1682 | to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC); |
| 1683 | if (!to_return) { |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1684 | pr_info("LEC: Arp entry kmalloc failed\n"); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1685 | return NULL; |
| 1686 | } |
| 1687 | memcpy(to_return->mac_addr, mac_addr, ETH_ALEN); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1688 | INIT_HLIST_NODE(&to_return->next); |
Pavel Emelyanov | b24b8a2 | 2008-01-23 21:20:07 -0800 | [diff] [blame] | 1689 | setup_timer(&to_return->timer, lec_arp_expire_arp, |
| 1690 | (unsigned long)to_return); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1691 | to_return->last_used = jiffies; |
| 1692 | to_return->priv = priv; |
| 1693 | skb_queue_head_init(&to_return->tx_wait); |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 1694 | atomic_set(&to_return->usage, 1); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1695 | return to_return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | } |
| 1697 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1698 | /* Arp sent timer expired */ |
| 1699 | static void lec_arp_expire_arp(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1701 | struct lec_arp_table *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1703 | entry = (struct lec_arp_table *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1705 | pr_debug("\n"); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1706 | if (entry->status == ESI_ARP_PENDING) { |
| 1707 | if (entry->no_tries <= entry->priv->max_retry_count) { |
| 1708 | if (entry->is_rdesc) |
| 1709 | send_to_lecd(entry->priv, l_rdesc_arp_xmt, |
| 1710 | entry->mac_addr, NULL, NULL); |
| 1711 | else |
| 1712 | send_to_lecd(entry->priv, l_arp_xmt, |
| 1713 | entry->mac_addr, NULL, NULL); |
| 1714 | entry->no_tries++; |
| 1715 | } |
| 1716 | mod_timer(&entry->timer, jiffies + (1 * HZ)); |
| 1717 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1720 | /* Unknown/unused vcc expire, remove associated entry */ |
| 1721 | static void lec_arp_expire_vcc(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | { |
| 1723 | unsigned long flags; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1724 | struct lec_arp_table *to_remove = (struct lec_arp_table *)data; |
| 1725 | struct lec_priv *priv = (struct lec_priv *)to_remove->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1727 | del_timer(&to_remove->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1729 | pr_debug("%p %p: vpi:%d vci:%d\n", |
| 1730 | to_remove, priv, |
| 1731 | to_remove->vcc ? to_remove->recv_vcc->vpi : 0, |
| 1732 | to_remove->vcc ? to_remove->recv_vcc->vci : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | |
| 1734 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1735 | hlist_del(&to_remove->next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
| 1737 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1738 | lec_arp_clear_vccs(to_remove); |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 1739 | lec_arp_put(to_remove); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
Joe Perches | b4c84ec | 2010-01-26 11:40:19 +0000 | [diff] [blame] | 1742 | static bool __lec_arp_check_expire(struct lec_arp_table *entry, |
| 1743 | unsigned long now, |
| 1744 | struct lec_priv *priv) |
| 1745 | { |
| 1746 | unsigned long time_to_check; |
| 1747 | |
| 1748 | if ((entry->flags) & LEC_REMOTE_FLAG && priv->topology_change) |
| 1749 | time_to_check = priv->forward_delay_time; |
| 1750 | else |
| 1751 | time_to_check = priv->aging_time; |
| 1752 | |
| 1753 | pr_debug("About to expire: %lx - %lx > %lx\n", |
| 1754 | now, entry->last_used, time_to_check); |
| 1755 | if (time_after(now, entry->last_used + time_to_check) && |
| 1756 | !(entry->flags & LEC_PERMANENT_FLAG) && |
| 1757 | !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */ |
| 1758 | /* Remove entry */ |
| 1759 | pr_debug("Entry timed out\n"); |
| 1760 | lec_arp_remove(priv, entry); |
| 1761 | lec_arp_put(entry); |
| 1762 | } else { |
| 1763 | /* Something else */ |
| 1764 | if ((entry->status == ESI_VC_PENDING || |
| 1765 | entry->status == ESI_ARP_PENDING) && |
| 1766 | time_after_eq(now, entry->timestamp + |
| 1767 | priv->max_unknown_frame_time)) { |
| 1768 | entry->timestamp = jiffies; |
| 1769 | entry->packets_flooded = 0; |
| 1770 | if (entry->status == ESI_VC_PENDING) |
| 1771 | send_to_lecd(priv, l_svc_setup, |
| 1772 | entry->mac_addr, |
| 1773 | entry->atm_addr, |
| 1774 | NULL); |
| 1775 | } |
| 1776 | if (entry->status == ESI_FLUSH_PENDING && |
| 1777 | time_after_eq(now, entry->timestamp + |
| 1778 | priv->path_switching_delay)) { |
| 1779 | lec_arp_hold(entry); |
| 1780 | return true; |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | return false; |
| 1785 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | /* |
| 1787 | * Expire entries. |
| 1788 | * 1. Re-set timer |
| 1789 | * 2. For each entry, delete entries that have aged past the age limit. |
| 1790 | * 3. For each entry, depending on the status of the entry, perform |
| 1791 | * the following maintenance. |
| 1792 | * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the |
| 1793 | * tick_count is above the max_unknown_frame_time, clear |
| 1794 | * the tick_count to zero and clear the packets_flooded counter |
| 1795 | * to zero. This supports the packet rate limit per address |
| 1796 | * while flooding unknowns. |
| 1797 | * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater |
| 1798 | * than or equal to the path_switching_delay, change the status |
| 1799 | * to ESI_FORWARD_DIRECT. This causes the flush period to end |
| 1800 | * regardless of the progress of the flush protocol. |
| 1801 | */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1802 | static void lec_arp_check_expire(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | { |
| 1804 | unsigned long flags; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1805 | struct lec_priv *priv = |
| 1806 | container_of(work, struct lec_priv, lec_arp_work.work); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1807 | struct hlist_node *node, *next; |
| 1808 | struct lec_arp_table *entry; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1809 | unsigned long now; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1810 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1812 | pr_debug("%p\n", priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | now = jiffies; |
Chas Williams | 6656e3c | 2006-09-29 17:17:17 -0700 | [diff] [blame] | 1814 | restart: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1816 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1817 | hlist_for_each_entry_safe(entry, node, next, |
| 1818 | &priv->lec_arp_tables[i], next) { |
Joe Perches | b4c84ec | 2010-01-26 11:40:19 +0000 | [diff] [blame] | 1819 | if (__lec_arp_check_expire(entry, now, priv)) { |
| 1820 | struct sk_buff *skb; |
| 1821 | struct atm_vcc *vcc = entry->vcc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | |
Joe Perches | b4c84ec | 2010-01-26 11:40:19 +0000 | [diff] [blame] | 1823 | spin_unlock_irqrestore(&priv->lec_arp_lock, |
| 1824 | flags); |
| 1825 | while ((skb = skb_dequeue(&entry->tx_wait))) |
| 1826 | lec_send(vcc, skb); |
| 1827 | entry->last_used = jiffies; |
| 1828 | entry->status = ESI_FORWARD_DIRECT; |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 1829 | lec_arp_put(entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | |
Joe Perches | b4c84ec | 2010-01-26 11:40:19 +0000 | [diff] [blame] | 1831 | goto restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | } |
| 1833 | } |
| 1834 | } |
| 1835 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
| 1836 | |
Chas Williams | 987e46b | 2006-09-29 17:15:59 -0700 | [diff] [blame] | 1837 | schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | } |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | /* |
| 1841 | * Try to find vcc where mac_address is attached. |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1842 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | */ |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1844 | static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv, |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1845 | const unsigned char *mac_to_find, |
| 1846 | int is_rdesc, |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1847 | struct lec_arp_table **ret_entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | { |
| 1849 | unsigned long flags; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1850 | struct lec_arp_table *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | struct atm_vcc *found; |
| 1852 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1853 | if (mac_to_find[0] & 0x01) { |
| 1854 | switch (priv->lane_version) { |
| 1855 | case 1: |
| 1856 | return priv->mcast_vcc; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1857 | case 2: /* LANE2 wants arp for multicast addresses */ |
| 1858 | if (!compare_ether_addr(mac_to_find, bus_mac)) |
| 1859 | return priv->mcast_vcc; |
| 1860 | break; |
| 1861 | default: |
| 1862 | break; |
| 1863 | } |
| 1864 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | |
| 1866 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1867 | entry = lec_arp_find(priv, mac_to_find); |
| 1868 | |
| 1869 | if (entry) { |
| 1870 | if (entry->status == ESI_FORWARD_DIRECT) { |
| 1871 | /* Connection Ok */ |
| 1872 | entry->last_used = jiffies; |
Chas Williams | 6656e3c | 2006-09-29 17:17:17 -0700 | [diff] [blame] | 1873 | lec_arp_hold(entry); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1874 | *ret_entry = entry; |
| 1875 | found = entry->vcc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | goto out; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1877 | } |
| 1878 | /* |
| 1879 | * If the LE_ARP cache entry is still pending, reset count to 0 |
Scott Talbert | 75b895c | 2005-09-29 17:31:30 -0700 | [diff] [blame] | 1880 | * so another LE_ARP request can be made for this frame. |
| 1881 | */ |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1882 | if (entry->status == ESI_ARP_PENDING) |
Scott Talbert | 75b895c | 2005-09-29 17:31:30 -0700 | [diff] [blame] | 1883 | entry->no_tries = 0; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1884 | /* |
| 1885 | * Data direct VC not yet set up, check to see if the unknown |
| 1886 | * frame count is greater than the limit. If the limit has |
| 1887 | * not been reached, allow the caller to send packet to |
| 1888 | * BUS. |
| 1889 | */ |
| 1890 | if (entry->status != ESI_FLUSH_PENDING && |
| 1891 | entry->packets_flooded < |
| 1892 | priv->maximum_unknown_frame_count) { |
| 1893 | entry->packets_flooded++; |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1894 | pr_debug("Flooding..\n"); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1895 | found = priv->mcast_vcc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | goto out; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1897 | } |
| 1898 | /* |
| 1899 | * We got here because entry->status == ESI_FLUSH_PENDING |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | * or BUS flood limit was reached for an entry which is |
| 1901 | * in ESI_ARP_PENDING or ESI_VC_PENDING state. |
| 1902 | */ |
Chas Williams | 6656e3c | 2006-09-29 17:17:17 -0700 | [diff] [blame] | 1903 | lec_arp_hold(entry); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1904 | *ret_entry = entry; |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1905 | pr_debug("entry->status %d entry->vcc %p\n", entry->status, |
| 1906 | entry->vcc); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1907 | found = NULL; |
| 1908 | } else { |
| 1909 | /* No matching entry was found */ |
| 1910 | entry = make_entry(priv, mac_to_find); |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1911 | pr_debug("Making entry\n"); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1912 | if (!entry) { |
| 1913 | found = priv->mcast_vcc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | goto out; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1915 | } |
| 1916 | lec_arp_add(priv, entry); |
| 1917 | /* We want arp-request(s) to be sent */ |
| 1918 | entry->packets_flooded = 1; |
| 1919 | entry->status = ESI_ARP_PENDING; |
| 1920 | entry->no_tries = 1; |
| 1921 | entry->last_used = entry->timestamp = jiffies; |
| 1922 | entry->is_rdesc = is_rdesc; |
| 1923 | if (entry->is_rdesc) |
| 1924 | send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL, |
| 1925 | NULL); |
| 1926 | else |
| 1927 | send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL); |
| 1928 | entry->timer.expires = jiffies + (1 * HZ); |
| 1929 | entry->timer.function = lec_arp_expire_arp; |
| 1930 | add_timer(&entry->timer); |
| 1931 | found = priv->mcast_vcc; |
| 1932 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | |
| 1934 | out: |
| 1935 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
| 1936 | return found; |
| 1937 | } |
| 1938 | |
| 1939 | static int |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 1940 | lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr, |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1941 | unsigned long permanent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | { |
| 1943 | unsigned long flags; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1944 | struct hlist_node *node, *next; |
| 1945 | struct lec_arp_table *entry; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1946 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1948 | pr_debug("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1950 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1951 | hlist_for_each_entry_safe(entry, node, next, |
| 1952 | &priv->lec_arp_tables[i], next) { |
| 1953 | if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN) && |
| 1954 | (permanent || |
| 1955 | !(entry->flags & LEC_PERMANENT_FLAG))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | lec_arp_remove(priv, entry); |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 1957 | lec_arp_put(entry); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1958 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1960 | return 0; |
| 1961 | } |
| 1962 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1964 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | /* |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1968 | * Notifies: Response to arp_request (atm_addr != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | */ |
| 1970 | static void |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 1971 | lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr, |
| 1972 | const unsigned char *atm_addr, unsigned long remoteflag, |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1973 | unsigned int targetless_le_arp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | { |
| 1975 | unsigned long flags; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1976 | struct hlist_node *node, *next; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1977 | struct lec_arp_table *entry, *tmp; |
| 1978 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1980 | pr_debug("%smac:%pM\n", |
| 1981 | (targetless_le_arp) ? "targetless " : "", mac_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | |
| 1983 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1984 | entry = lec_arp_find(priv, mac_addr); |
| 1985 | if (entry == NULL && targetless_le_arp) |
| 1986 | goto out; /* |
| 1987 | * LANE2: ignore targetless LE_ARPs for which |
| 1988 | * we have no entry in the cache. 7.1.30 |
| 1989 | */ |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1990 | if (!hlist_empty(&priv->lec_arp_empty_ones)) { |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 1991 | hlist_for_each_entry_safe(entry, node, next, |
| 1992 | &priv->lec_arp_empty_ones, next) { |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1993 | if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) { |
| 1994 | hlist_del(&entry->next); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 1995 | del_timer(&entry->timer); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 1996 | tmp = lec_arp_find(priv, mac_addr); |
| 1997 | if (tmp) { |
| 1998 | del_timer(&tmp->timer); |
| 1999 | tmp->status = ESI_FORWARD_DIRECT; |
| 2000 | memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN); |
| 2001 | tmp->vcc = entry->vcc; |
| 2002 | tmp->old_push = entry->old_push; |
| 2003 | tmp->last_used = jiffies; |
| 2004 | del_timer(&entry->timer); |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 2005 | lec_arp_put(entry); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2006 | entry = tmp; |
| 2007 | } else { |
| 2008 | entry->status = ESI_FORWARD_DIRECT; |
| 2009 | memcpy(entry->mac_addr, mac_addr, ETH_ALEN); |
| 2010 | entry->last_used = jiffies; |
| 2011 | lec_arp_add(priv, entry); |
| 2012 | } |
| 2013 | if (remoteflag) |
| 2014 | entry->flags |= LEC_REMOTE_FLAG; |
| 2015 | else |
| 2016 | entry->flags &= ~LEC_REMOTE_FLAG; |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 2017 | pr_debug("After update\n"); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2018 | dump_arp_table(priv); |
| 2019 | goto out; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2020 | } |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2021 | } |
| 2022 | } |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2023 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2024 | entry = lec_arp_find(priv, mac_addr); |
| 2025 | if (!entry) { |
| 2026 | entry = make_entry(priv, mac_addr); |
| 2027 | if (!entry) |
| 2028 | goto out; |
| 2029 | entry->status = ESI_UNKNOWN; |
| 2030 | lec_arp_add(priv, entry); |
| 2031 | /* Temporary, changes before end of function */ |
| 2032 | } |
| 2033 | memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN); |
| 2034 | del_timer(&entry->timer); |
| 2035 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 2036 | hlist_for_each_entry(tmp, node, |
| 2037 | &priv->lec_arp_tables[i], next) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2038 | if (entry != tmp && |
| 2039 | !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) { |
| 2040 | /* Vcc to this host exists */ |
| 2041 | if (tmp->status > ESI_VC_PENDING) { |
| 2042 | /* |
| 2043 | * ESI_FLUSH_PENDING, |
| 2044 | * ESI_FORWARD_DIRECT |
| 2045 | */ |
| 2046 | entry->vcc = tmp->vcc; |
| 2047 | entry->old_push = tmp->old_push; |
| 2048 | } |
| 2049 | entry->status = tmp->status; |
| 2050 | break; |
| 2051 | } |
| 2052 | } |
| 2053 | } |
| 2054 | if (remoteflag) |
| 2055 | entry->flags |= LEC_REMOTE_FLAG; |
| 2056 | else |
| 2057 | entry->flags &= ~LEC_REMOTE_FLAG; |
| 2058 | if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) { |
| 2059 | entry->status = ESI_VC_PENDING; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2060 | send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2061 | } |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 2062 | pr_debug("After update2\n"); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2063 | dump_arp_table(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | out: |
| 2065 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
| 2066 | } |
| 2067 | |
| 2068 | /* |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 2069 | * Notifies: Vcc setup ready |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | */ |
| 2071 | static void |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 2072 | lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data, |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2073 | struct atm_vcc *vcc, |
| 2074 | void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | { |
| 2076 | unsigned long flags; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2077 | struct hlist_node *node; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2078 | struct lec_arp_table *entry; |
| 2079 | int i, found_entry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | |
| 2081 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 2082 | /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */ |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2083 | if (ioc_data->receive == 2) { |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 2084 | pr_debug("LEC_ARP: Attaching mcast forward\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | #if 0 |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2086 | entry = lec_arp_find(priv, bus_mac); |
| 2087 | if (!entry) { |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 2088 | pr_info("LEC_ARP: Multicast entry not found!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | goto out; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2090 | } |
| 2091 | memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN); |
| 2092 | entry->recv_vcc = vcc; |
| 2093 | entry->old_recv_push = old_push; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | #endif |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2095 | entry = make_entry(priv, bus_mac); |
| 2096 | if (entry == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | goto out; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2098 | del_timer(&entry->timer); |
| 2099 | memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN); |
| 2100 | entry->recv_vcc = vcc; |
| 2101 | entry->old_recv_push = old_push; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2102 | hlist_add_head(&entry->next, &priv->mcast_fwds); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2103 | goto out; |
| 2104 | } else if (ioc_data->receive == 1) { |
| 2105 | /* |
| 2106 | * Vcc which we don't want to make default vcc, |
| 2107 | * attach it anyway. |
| 2108 | */ |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 2109 | 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", |
| 2110 | ioc_data->atm_addr[0], ioc_data->atm_addr[1], |
| 2111 | ioc_data->atm_addr[2], ioc_data->atm_addr[3], |
| 2112 | ioc_data->atm_addr[4], ioc_data->atm_addr[5], |
| 2113 | ioc_data->atm_addr[6], ioc_data->atm_addr[7], |
| 2114 | ioc_data->atm_addr[8], ioc_data->atm_addr[9], |
| 2115 | ioc_data->atm_addr[10], ioc_data->atm_addr[11], |
| 2116 | ioc_data->atm_addr[12], ioc_data->atm_addr[13], |
| 2117 | ioc_data->atm_addr[14], ioc_data->atm_addr[15], |
| 2118 | ioc_data->atm_addr[16], ioc_data->atm_addr[17], |
| 2119 | ioc_data->atm_addr[18], ioc_data->atm_addr[19]); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2120 | entry = make_entry(priv, bus_mac); |
| 2121 | if (entry == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | goto out; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2123 | memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN); |
| 2124 | memset(entry->mac_addr, 0, ETH_ALEN); |
| 2125 | entry->recv_vcc = vcc; |
| 2126 | entry->old_recv_push = old_push; |
| 2127 | entry->status = ESI_UNKNOWN; |
| 2128 | entry->timer.expires = jiffies + priv->vcc_timeout_period; |
| 2129 | entry->timer.function = lec_arp_expire_vcc; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2130 | hlist_add_head(&entry->next, &priv->lec_no_forward); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2131 | add_timer(&entry->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | dump_arp_table(priv); |
| 2133 | goto out; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2134 | } |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 2135 | 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", |
| 2136 | ioc_data->atm_addr[0], ioc_data->atm_addr[1], |
| 2137 | ioc_data->atm_addr[2], ioc_data->atm_addr[3], |
| 2138 | ioc_data->atm_addr[4], ioc_data->atm_addr[5], |
| 2139 | ioc_data->atm_addr[6], ioc_data->atm_addr[7], |
| 2140 | ioc_data->atm_addr[8], ioc_data->atm_addr[9], |
| 2141 | ioc_data->atm_addr[10], ioc_data->atm_addr[11], |
| 2142 | ioc_data->atm_addr[12], ioc_data->atm_addr[13], |
| 2143 | ioc_data->atm_addr[14], ioc_data->atm_addr[15], |
| 2144 | ioc_data->atm_addr[16], ioc_data->atm_addr[17], |
| 2145 | ioc_data->atm_addr[18], ioc_data->atm_addr[19]); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2146 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 2147 | hlist_for_each_entry(entry, node, |
| 2148 | &priv->lec_arp_tables[i], next) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2149 | if (memcmp |
| 2150 | (ioc_data->atm_addr, entry->atm_addr, |
| 2151 | ATM_ESA_LEN) == 0) { |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 2152 | pr_debug("LEC_ARP: Attaching data direct\n"); |
| 2153 | pr_debug("Currently -> Vcc: %d, Rvcc:%d\n", |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 2154 | entry->vcc ? entry->vcc->vci : 0, |
| 2155 | entry->recv_vcc ? entry->recv_vcc-> |
| 2156 | vci : 0); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2157 | found_entry = 1; |
| 2158 | del_timer(&entry->timer); |
| 2159 | entry->vcc = vcc; |
| 2160 | entry->old_push = old_push; |
| 2161 | if (entry->status == ESI_VC_PENDING) { |
| 2162 | if (priv->maximum_unknown_frame_count |
| 2163 | == 0) |
| 2164 | entry->status = |
| 2165 | ESI_FORWARD_DIRECT; |
| 2166 | else { |
| 2167 | entry->timestamp = jiffies; |
| 2168 | entry->status = |
| 2169 | ESI_FLUSH_PENDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | #if 0 |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2171 | send_to_lecd(priv, l_flush_xmt, |
| 2172 | NULL, |
| 2173 | entry->atm_addr, |
| 2174 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | #endif |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2176 | } |
| 2177 | } else { |
| 2178 | /* |
| 2179 | * They were forming a connection |
| 2180 | * to us, and we to them. Our |
| 2181 | * ATM address is numerically lower |
| 2182 | * than theirs, so we make connection |
| 2183 | * we formed into default VCC (8.1.11). |
| 2184 | * Connection they made gets torn |
| 2185 | * down. This might confuse some |
| 2186 | * clients. Can be changed if |
| 2187 | * someone reports trouble... |
| 2188 | */ |
| 2189 | ; |
| 2190 | } |
| 2191 | } |
| 2192 | } |
| 2193 | } |
| 2194 | if (found_entry) { |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 2195 | pr_debug("After vcc was added\n"); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2196 | dump_arp_table(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | goto out; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2198 | } |
| 2199 | /* |
| 2200 | * Not found, snatch address from first data packet that arrives |
| 2201 | * from this vcc |
| 2202 | */ |
| 2203 | entry = make_entry(priv, bus_mac); |
| 2204 | if (!entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | goto out; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2206 | entry->vcc = vcc; |
| 2207 | entry->old_push = old_push; |
| 2208 | memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN); |
| 2209 | memset(entry->mac_addr, 0, ETH_ALEN); |
| 2210 | entry->status = ESI_UNKNOWN; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2211 | hlist_add_head(&entry->next, &priv->lec_arp_empty_ones); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2212 | entry->timer.expires = jiffies + priv->vcc_timeout_period; |
| 2213 | entry->timer.function = lec_arp_expire_vcc; |
| 2214 | add_timer(&entry->timer); |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 2215 | pr_debug("After vcc was added\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | dump_arp_table(priv); |
| 2217 | out: |
| 2218 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
| 2219 | } |
| 2220 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2221 | static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | { |
| 2223 | unsigned long flags; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2224 | struct hlist_node *node; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2225 | struct lec_arp_table *entry; |
| 2226 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 2228 | pr_debug("%lx\n", tran_id); |
Chas Williams | 6656e3c | 2006-09-29 17:17:17 -0700 | [diff] [blame] | 2229 | restart: |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2230 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
| 2231 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 2232 | hlist_for_each_entry(entry, node, |
| 2233 | &priv->lec_arp_tables[i], next) { |
| 2234 | if (entry->flush_tran_id == tran_id && |
| 2235 | entry->status == ESI_FLUSH_PENDING) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2236 | struct sk_buff *skb; |
Chas Williams | 6656e3c | 2006-09-29 17:17:17 -0700 | [diff] [blame] | 2237 | struct atm_vcc *vcc = entry->vcc; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2238 | |
Chas Williams | 6656e3c | 2006-09-29 17:17:17 -0700 | [diff] [blame] | 2239 | lec_arp_hold(entry); |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 2240 | spin_unlock_irqrestore(&priv->lec_arp_lock, |
| 2241 | flags); |
Joe Perches | b4c84ec | 2010-01-26 11:40:19 +0000 | [diff] [blame] | 2242 | while ((skb = skb_dequeue(&entry->tx_wait))) |
Stephen Hemminger | 162619e | 2009-01-09 13:01:01 +0000 | [diff] [blame] | 2243 | lec_send(vcc, skb); |
Chas Williams | 6656e3c | 2006-09-29 17:17:17 -0700 | [diff] [blame] | 2244 | entry->last_used = jiffies; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2245 | entry->status = ESI_FORWARD_DIRECT; |
Chas Williams | 6656e3c | 2006-09-29 17:17:17 -0700 | [diff] [blame] | 2246 | lec_arp_put(entry); |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 2247 | pr_debug("LEC_ARP: Flushed\n"); |
Chas Williams | 6656e3c | 2006-09-29 17:17:17 -0700 | [diff] [blame] | 2248 | goto restart; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2249 | } |
| 2250 | } |
| 2251 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2253 | dump_arp_table(priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | static void |
| 2257 | lec_set_flush_tran_id(struct lec_priv *priv, |
Mitchell Blank Jr | 61c33e0 | 2008-06-17 16:20:06 -0700 | [diff] [blame] | 2258 | const unsigned char *atm_addr, unsigned long tran_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | { |
| 2260 | unsigned long flags; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2261 | struct hlist_node *node; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2262 | struct lec_arp_table *entry; |
| 2263 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | |
| 2265 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2266 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 2267 | hlist_for_each_entry(entry, node, |
| 2268 | &priv->lec_arp_tables[i], next) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2269 | if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) { |
| 2270 | entry->flush_tran_id = tran_id; |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 2271 | pr_debug("Set flush transaction id to %lx for %p\n", |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 2272 | tran_id, entry); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2273 | } |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2274 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
| 2276 | } |
| 2277 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2278 | static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | { |
| 2280 | unsigned long flags; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2281 | unsigned char mac_addr[] = { |
| 2282 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 2283 | }; |
| 2284 | struct lec_arp_table *to_add; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | struct lec_vcc_priv *vpriv; |
| 2286 | int err = 0; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2287 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 2288 | vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL); |
| 2289 | if (!vpriv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | return -ENOMEM; |
| 2291 | vpriv->xoff = 0; |
| 2292 | vpriv->old_pop = vcc->pop; |
| 2293 | vcc->user_back = vpriv; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2294 | vcc->pop = lec_pop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2296 | to_add = make_entry(priv, mac_addr); |
| 2297 | if (!to_add) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | vcc->pop = vpriv->old_pop; |
| 2299 | kfree(vpriv); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2300 | err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | goto out; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2302 | } |
| 2303 | memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN); |
| 2304 | to_add->status = ESI_FORWARD_DIRECT; |
| 2305 | to_add->flags |= LEC_PERMANENT_FLAG; |
| 2306 | to_add->vcc = vcc; |
| 2307 | to_add->old_push = vcc->push; |
| 2308 | vcc->push = lec_push; |
| 2309 | priv->mcast_vcc = vcc; |
| 2310 | lec_arp_add(priv, to_add); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | out: |
| 2312 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2313 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2316 | static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | { |
| 2318 | unsigned long flags; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2319 | struct hlist_node *node, *next; |
| 2320 | struct lec_arp_table *entry; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2321 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 2323 | pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2324 | dump_arp_table(priv); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2327 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2328 | for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 2329 | hlist_for_each_entry_safe(entry, node, next, |
| 2330 | &priv->lec_arp_tables[i], next) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2331 | if (vcc == entry->vcc) { |
| 2332 | lec_arp_remove(priv, entry); |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 2333 | lec_arp_put(entry); |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 2334 | if (priv->mcast_vcc == vcc) |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2335 | priv->mcast_vcc = NULL; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2336 | } |
| 2337 | } |
| 2338 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 2340 | hlist_for_each_entry_safe(entry, node, next, |
| 2341 | &priv->lec_arp_empty_ones, next) { |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2342 | if (entry->vcc == vcc) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2343 | lec_arp_clear_vccs(entry); |
| 2344 | del_timer(&entry->timer); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2345 | hlist_del(&entry->next); |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 2346 | lec_arp_put(entry); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2347 | } |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2348 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 2350 | hlist_for_each_entry_safe(entry, node, next, |
| 2351 | &priv->lec_no_forward, next) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2352 | if (entry->recv_vcc == vcc) { |
| 2353 | lec_arp_clear_vccs(entry); |
| 2354 | del_timer(&entry->timer); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2355 | hlist_del(&entry->next); |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 2356 | lec_arp_put(entry); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2357 | } |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2360 | hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2361 | if (entry->recv_vcc == vcc) { |
| 2362 | lec_arp_clear_vccs(entry); |
| 2363 | /* No timer, LANEv2 7.1.20 and 2.3.5.3 */ |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2364 | hlist_del(&entry->next); |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 2365 | lec_arp_put(entry); |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2366 | } |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2367 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | |
| 2369 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
| 2370 | dump_arp_table(priv); |
| 2371 | } |
| 2372 | |
| 2373 | static void |
| 2374 | lec_arp_check_empties(struct lec_priv *priv, |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2375 | struct atm_vcc *vcc, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | { |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2377 | unsigned long flags; |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2378 | struct hlist_node *node, *next; |
| 2379 | struct lec_arp_table *entry, *tmp; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2380 | struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data; |
| 2381 | unsigned char *src; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | #ifdef CONFIG_TR |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2383 | struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2385 | if (priv->is_trdev) |
| 2386 | src = tr_hdr->h_source; |
| 2387 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | #endif |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2389 | src = hdr->h_source; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | |
| 2391 | spin_lock_irqsave(&priv->lec_arp_lock, flags); |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 2392 | hlist_for_each_entry_safe(entry, node, next, |
| 2393 | &priv->lec_arp_empty_ones, next) { |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2394 | if (vcc == entry->vcc) { |
| 2395 | del_timer(&entry->timer); |
| 2396 | memcpy(entry->mac_addr, src, ETH_ALEN); |
| 2397 | entry->status = ESI_FORWARD_DIRECT; |
| 2398 | entry->last_used = jiffies; |
| 2399 | /* We might have got an entry */ |
Joe Perches | c48192a | 2010-01-26 11:40:08 +0000 | [diff] [blame] | 2400 | tmp = lec_arp_find(priv, src); |
| 2401 | if (tmp) { |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2402 | lec_arp_remove(priv, tmp); |
Chas Williams | 33a9c2d | 2006-09-29 17:16:48 -0700 | [diff] [blame] | 2403 | lec_arp_put(tmp); |
Chas Williams | d0732f6 | 2006-09-29 17:14:27 -0700 | [diff] [blame] | 2404 | } |
| 2405 | hlist_del(&entry->next); |
| 2406 | lec_arp_add(priv, entry); |
| 2407 | goto out; |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2408 | } |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2409 | } |
Stephen Hemminger | 5224006 | 2007-08-28 15:22:09 -0700 | [diff] [blame] | 2410 | pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | out: |
| 2412 | spin_unlock_irqrestore(&priv->lec_arp_lock, flags); |
| 2413 | } |
Chas Williams | 1fa9961 | 2006-09-29 17:11:47 -0700 | [diff] [blame] | 2414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | MODULE_LICENSE("GPL"); |