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