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