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