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