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