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