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