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