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