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