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