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