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