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