Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ |
| 2 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | #include <linux/kernel.h> |
| 4 | #include <linux/string.h> |
| 5 | #include <linux/timer.h> |
| 6 | #include <linux/init.h> |
| 7 | #include <linux/bitops.h> |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 8 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/seq_file.h> |
| 10 | |
| 11 | /* We are an 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> |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 18 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/byteorder.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <net/checksum.h> /* for ip_fast_csum() */ |
| 21 | #include <net/arp.h> |
| 22 | #include <net/dst.h> |
| 23 | #include <linux/proc_fs.h> |
| 24 | |
| 25 | /* And atm device */ |
| 26 | #include <linux/atmdev.h> |
| 27 | #include <linux/atmlec.h> |
| 28 | #include <linux/atmmpc.h> |
| 29 | /* Modular too */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/module.h> |
| 31 | |
| 32 | #include "lec.h" |
| 33 | #include "mpc.h" |
| 34 | #include "resources.h" |
| 35 | |
| 36 | /* |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 37 | * mpc.c: Implementation of MPOA client kernel part |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | */ |
| 39 | |
| 40 | #if 0 |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 41 | #define dprintk(format, args...) \ |
| 42 | printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args) |
| 43 | #define dprintk_cont(format, args...) printk(KERN_CONT format, ##args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #else |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 45 | #define dprintk(format, args...) \ |
| 46 | do { if (0) \ |
| 47 | printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args);\ |
| 48 | } while (0) |
| 49 | #define dprintk_cont(format, args...) \ |
| 50 | do { if (0) printk(KERN_CONT format, ##args); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #endif |
| 52 | |
| 53 | #if 0 |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 54 | #define ddprintk(format, args...) \ |
| 55 | printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args) |
| 56 | #define ddprintk_cont(format, args...) printk(KERN_CONT format, ##args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #else |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 58 | #define ddprintk(format, args...) \ |
| 59 | do { if (0) \ |
| 60 | printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args);\ |
| 61 | } while (0) |
| 62 | #define ddprintk_cont(format, args...) \ |
| 63 | do { if (0) printk(KERN_CONT format, ##args); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #endif |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #define MPOA_TAG_LEN 4 |
| 67 | |
| 68 | /* mpc_daemon -> kernel */ |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 69 | static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc); |
| 71 | static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc); |
| 72 | static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc); |
| 73 | static void mps_death(struct k_message *msg, struct mpoa_client *mpc); |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 74 | static void clean_up(struct k_message *msg, struct mpoa_client *mpc, |
| 75 | int action); |
| 76 | static void MPOA_cache_impos_rcvd(struct k_message *msg, |
| 77 | struct mpoa_client *mpc); |
| 78 | static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg, |
| 79 | struct mpoa_client *mpc); |
| 80 | static void set_mps_mac_addr_rcvd(struct k_message *mesg, |
| 81 | struct mpoa_client *mpc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
David Howells | cba5cbd | 2008-07-30 16:31:46 -0700 | [diff] [blame] | 83 | static const uint8_t *copy_macs(struct mpoa_client *mpc, |
| 84 | const uint8_t *router_mac, |
| 85 | const uint8_t *tlvs, uint8_t mps_macs, |
| 86 | uint8_t device_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry); |
| 88 | |
David Howells | cba5cbd | 2008-07-30 16:31:46 -0700 | [diff] [blame] | 89 | static void send_set_mps_ctrl_addr(const char *addr, struct mpoa_client *mpc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | static void mpoad_close(struct atm_vcc *vcc); |
| 91 | static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb); |
| 92 | |
| 93 | static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb); |
Stephen Hemminger | 3c805a2 | 2009-08-31 19:50:42 +0000 | [diff] [blame] | 94 | static netdev_tx_t mpc_send_packet(struct sk_buff *skb, |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 95 | struct net_device *dev); |
| 96 | static int mpoa_event_listener(struct notifier_block *mpoa_notifier, |
| 97 | unsigned long event, void *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | static void mpc_timer_refresh(void); |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 99 | static void mpc_cache_check(unsigned long checking_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | static struct llc_snap_hdr llc_snap_mpoa_ctrl = { |
| 102 | 0xaa, 0xaa, 0x03, |
| 103 | {0x00, 0x00, 0x5e}, |
| 104 | {0x00, 0x03} /* For MPOA control PDUs */ |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 105 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | static struct llc_snap_hdr llc_snap_mpoa_data = { |
| 107 | 0xaa, 0xaa, 0x03, |
| 108 | {0x00, 0x00, 0x00}, |
| 109 | {0x08, 0x00} /* This is for IP PDUs only */ |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 110 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | static struct llc_snap_hdr llc_snap_mpoa_data_tagged = { |
| 112 | 0xaa, 0xaa, 0x03, |
| 113 | {0x00, 0x00, 0x00}, |
| 114 | {0x88, 0x4c} /* This is for tagged data PDUs */ |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 115 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | static struct notifier_block mpoa_notifier = { |
| 118 | mpoa_event_listener, |
| 119 | NULL, |
| 120 | 0 |
| 121 | }; |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | struct mpoa_client *mpcs = NULL; /* FIXME */ |
| 124 | static struct atm_mpoa_qos *qos_head = NULL; |
Ingo Molnar | 8d06afa | 2005-09-09 13:10:40 -0700 | [diff] [blame] | 125 | static DEFINE_TIMER(mpc_timer, NULL, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
| 127 | |
| 128 | static struct mpoa_client *find_mpc_by_itfnum(int itf) |
| 129 | { |
| 130 | struct mpoa_client *mpc; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | mpc = mpcs; /* our global linked list */ |
| 133 | while (mpc != NULL) { |
| 134 | if (mpc->dev_num == itf) |
| 135 | return mpc; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 136 | mpc = mpc->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | return NULL; /* not found */ |
| 140 | } |
| 141 | |
| 142 | static struct mpoa_client *find_mpc_by_vcc(struct atm_vcc *vcc) |
| 143 | { |
| 144 | struct mpoa_client *mpc; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | mpc = mpcs; /* our global linked list */ |
| 147 | while (mpc != NULL) { |
| 148 | if (mpc->mpoad_vcc == vcc) |
| 149 | return mpc; |
| 150 | mpc = mpc->next; |
| 151 | } |
| 152 | |
| 153 | return NULL; /* not found */ |
| 154 | } |
| 155 | |
| 156 | static struct mpoa_client *find_mpc_by_lec(struct net_device *dev) |
| 157 | { |
| 158 | struct mpoa_client *mpc; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | mpc = mpcs; /* our global linked list */ |
| 161 | while (mpc != NULL) { |
| 162 | if (mpc->dev == dev) |
| 163 | return mpc; |
| 164 | mpc = mpc->next; |
| 165 | } |
| 166 | |
| 167 | return NULL; /* not found */ |
| 168 | } |
| 169 | |
| 170 | /* |
| 171 | * Functions for managing QoS list |
| 172 | */ |
| 173 | |
| 174 | /* |
| 175 | * Overwrites the old entry or makes a new one. |
| 176 | */ |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 177 | struct atm_mpoa_qos *atm_mpoa_add_qos(__be32 dst_ip, struct atm_qos *qos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { |
| 179 | struct atm_mpoa_qos *entry; |
| 180 | |
| 181 | entry = atm_mpoa_search_qos(dst_ip); |
| 182 | if (entry != NULL) { |
| 183 | entry->qos = *qos; |
| 184 | return entry; |
| 185 | } |
| 186 | |
| 187 | entry = kmalloc(sizeof(struct atm_mpoa_qos), GFP_KERNEL); |
| 188 | if (entry == NULL) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 189 | pr_info("mpoa: out of memory\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | return entry; |
| 191 | } |
| 192 | |
| 193 | entry->ipaddr = dst_ip; |
| 194 | entry->qos = *qos; |
| 195 | |
| 196 | entry->next = qos_head; |
| 197 | qos_head = entry; |
| 198 | |
| 199 | return entry; |
| 200 | } |
| 201 | |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 202 | struct atm_mpoa_qos *atm_mpoa_search_qos(__be32 dst_ip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
| 204 | struct atm_mpoa_qos *qos; |
| 205 | |
| 206 | qos = qos_head; |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 207 | while (qos) { |
| 208 | if (qos->ipaddr == dst_ip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | qos = qos->next; |
| 211 | } |
| 212 | |
| 213 | return qos; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 214 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | /* |
| 217 | * Returns 0 for failure |
| 218 | */ |
| 219 | int atm_mpoa_delete_qos(struct atm_mpoa_qos *entry) |
| 220 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | struct atm_mpoa_qos *curr; |
| 222 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 223 | if (entry == NULL) |
| 224 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | if (entry == qos_head) { |
| 226 | qos_head = qos_head->next; |
| 227 | kfree(entry); |
| 228 | return 1; |
| 229 | } |
| 230 | |
| 231 | curr = qos_head; |
| 232 | while (curr != NULL) { |
| 233 | if (curr->next == entry) { |
| 234 | curr->next = entry->next; |
| 235 | kfree(entry); |
| 236 | return 1; |
| 237 | } |
| 238 | curr = curr->next; |
| 239 | } |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | /* this is buggered - we need locking for qos_head */ |
| 245 | void atm_mpoa_disp_qos(struct seq_file *m) |
| 246 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | struct atm_mpoa_qos *qos; |
| 248 | |
| 249 | qos = qos_head; |
| 250 | seq_printf(m, "QoS entries for shortcuts:\n"); |
| 251 | seq_printf(m, "IP address\n TX:max_pcr pcr min_pcr max_cdv max_sdu\n RX:max_pcr pcr min_pcr max_cdv max_sdu\n"); |
| 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | while (qos != NULL) { |
Harvey Harrison | 21454aa | 2008-10-31 00:54:56 -0700 | [diff] [blame] | 254 | seq_printf(m, "%pI4\n %-7d %-7d %-7d %-7d %-7d\n %-7d %-7d %-7d %-7d %-7d\n", |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 255 | &qos->ipaddr, |
| 256 | qos->qos.txtp.max_pcr, |
| 257 | qos->qos.txtp.pcr, |
| 258 | qos->qos.txtp.min_pcr, |
| 259 | qos->qos.txtp.max_cdv, |
| 260 | qos->qos.txtp.max_sdu, |
| 261 | qos->qos.rxtp.max_pcr, |
| 262 | qos->qos.rxtp.pcr, |
| 263 | qos->qos.rxtp.min_pcr, |
| 264 | qos->qos.rxtp.max_cdv, |
| 265 | qos->qos.rxtp.max_sdu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | qos = qos->next; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | static struct net_device *find_lec_by_itfnum(int itf) |
| 271 | { |
| 272 | struct net_device *dev; |
| 273 | char name[IFNAMSIZ]; |
| 274 | |
| 275 | sprintf(name, "lec%d", itf); |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 276 | dev = dev_get_by_name(&init_net, name); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | return dev; |
| 279 | } |
| 280 | |
| 281 | static struct mpoa_client *alloc_mpc(void) |
| 282 | { |
| 283 | struct mpoa_client *mpc; |
| 284 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 285 | mpc = kzalloc(sizeof(struct mpoa_client), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | if (mpc == NULL) |
| 287 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | rwlock_init(&mpc->ingress_lock); |
| 289 | rwlock_init(&mpc->egress_lock); |
| 290 | mpc->next = mpcs; |
| 291 | atm_mpoa_init_cache(mpc); |
| 292 | |
| 293 | mpc->parameters.mpc_p1 = MPC_P1; |
| 294 | mpc->parameters.mpc_p2 = MPC_P2; |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 295 | memset(mpc->parameters.mpc_p3, 0, sizeof(mpc->parameters.mpc_p3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | mpc->parameters.mpc_p4 = MPC_P4; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 297 | mpc->parameters.mpc_p5 = MPC_P5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | mpc->parameters.mpc_p6 = MPC_P6; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | mpcs = mpc; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | return mpc; |
| 303 | } |
| 304 | |
| 305 | /* |
| 306 | * |
| 307 | * start_mpc() puts the MPC on line. All the packets destined |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 308 | * to the lec underneath us are now being monitored and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | * shortcuts will be established. |
| 310 | * |
| 311 | */ |
| 312 | static void start_mpc(struct mpoa_client *mpc, struct net_device *dev) |
| 313 | { |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 314 | |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 315 | dprintk("(%s)\n", mpc->dev->name); |
Stephen Hemminger | 788dee0 | 2009-03-20 19:35:28 +0000 | [diff] [blame] | 316 | if (!dev->netdev_ops) |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 317 | pr_info("(%s) not starting\n", dev->name); |
Stephen Hemminger | 788dee0 | 2009-03-20 19:35:28 +0000 | [diff] [blame] | 318 | else { |
| 319 | mpc->old_ops = dev->netdev_ops; |
| 320 | mpc->new_ops = *mpc->old_ops; |
| 321 | mpc->new_ops.ndo_start_xmit = mpc_send_packet; |
| 322 | dev->netdev_ops = &mpc->new_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static void stop_mpc(struct mpoa_client *mpc) |
| 327 | { |
Stephen Hemminger | 788dee0 | 2009-03-20 19:35:28 +0000 | [diff] [blame] | 328 | struct net_device *dev = mpc->dev; |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 329 | dprintk("(%s)", mpc->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | /* Lets not nullify lec device's dev->hard_start_xmit */ |
Stephen Hemminger | 788dee0 | 2009-03-20 19:35:28 +0000 | [diff] [blame] | 332 | if (dev->netdev_ops != &mpc->new_ops) { |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 333 | dprintk_cont(" mpc already stopped, not fatal\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | return; |
| 335 | } |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 336 | dprintk_cont("\n"); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 337 | |
Stephen Hemminger | 788dee0 | 2009-03-20 19:35:28 +0000 | [diff] [blame] | 338 | dev->netdev_ops = mpc->old_ops; |
| 339 | mpc->old_ops = NULL; |
| 340 | |
| 341 | /* close_shortcuts(mpc); ??? FIXME */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static const char *mpoa_device_type_string(char type) __attribute__ ((unused)); |
| 345 | |
| 346 | static const char *mpoa_device_type_string(char type) |
| 347 | { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 348 | switch (type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | case NON_MPOA: |
| 350 | return "non-MPOA device"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | case MPS: |
| 352 | return "MPS"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | case MPC: |
| 354 | return "MPC"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | case MPS_AND_MPC: |
| 356 | return "both MPS and MPC"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 359 | return "unspecified (non-MPOA) device"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | /* |
Wang Chen | b74ca3a | 2008-12-08 01:14:16 -0800 | [diff] [blame] | 363 | * lec device calls this via its netdev_priv(dev)->lane2_ops |
| 364 | * ->associate_indicator() when it sees a TLV in LE_ARP packet. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | * We fill in the pointer above when we see a LANE2 lec initializing |
| 366 | * See LANE2 spec 3.1.5 |
| 367 | * |
| 368 | * Quite a big and ugly function but when you look at it |
| 369 | * all it does is to try to locate and parse MPOA Device |
| 370 | * Type TLV. |
| 371 | * We give our lec a pointer to this function and when the |
| 372 | * lec sees a TLV it uses the pointer to call this function. |
| 373 | * |
| 374 | */ |
David Howells | cba5cbd | 2008-07-30 16:31:46 -0700 | [diff] [blame] | 375 | static void lane2_assoc_ind(struct net_device *dev, const u8 *mac_addr, |
| 376 | const u8 *tlvs, u32 sizeoftlvs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | { |
| 378 | uint32_t type; |
| 379 | uint8_t length, mpoa_device_type, number_of_mps_macs; |
David Howells | cba5cbd | 2008-07-30 16:31:46 -0700 | [diff] [blame] | 380 | const uint8_t *end_of_tlvs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | struct mpoa_client *mpc; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | mpoa_device_type = number_of_mps_macs = 0; /* silence gcc */ |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 384 | dprintk("(%s) received TLV(s), ", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | dprintk("total length of all TLVs %d\n", sizeoftlvs); |
| 386 | mpc = find_mpc_by_lec(dev); /* Sampo-Fix: moved here from below */ |
| 387 | if (mpc == NULL) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 388 | pr_info("(%s) no mpc\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | return; |
| 390 | } |
| 391 | end_of_tlvs = tlvs + sizeoftlvs; |
| 392 | while (end_of_tlvs - tlvs >= 5) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 393 | type = ((tlvs[0] << 24) | (tlvs[1] << 16) | |
| 394 | (tlvs[2] << 8) | tlvs[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | length = tlvs[4]; |
| 396 | tlvs += 5; |
| 397 | dprintk(" type 0x%x length %02x\n", type, length); |
| 398 | if (tlvs + length > end_of_tlvs) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 399 | pr_info("TLV value extends past its buffer, aborting parse\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | return; |
| 401 | } |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | if (type == 0) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 404 | pr_info("mpoa: (%s) TLV type was 0, returning\n", |
| 405 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | return; |
| 407 | } |
| 408 | |
| 409 | if (type != TLV_MPOA_DEVICE_TYPE) { |
| 410 | tlvs += length; |
| 411 | continue; /* skip other TLVs */ |
| 412 | } |
| 413 | mpoa_device_type = *tlvs++; |
| 414 | number_of_mps_macs = *tlvs++; |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 415 | dprintk("(%s) MPOA device type '%s', ", |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 416 | dev->name, mpoa_device_type_string(mpoa_device_type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | if (mpoa_device_type == MPS_AND_MPC && |
| 418 | length < (42 + number_of_mps_macs*ETH_ALEN)) { /* :) */ |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 419 | pr_info("(%s) short MPOA Device Type TLV\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | dev->name); |
| 421 | continue; |
| 422 | } |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 423 | if ((mpoa_device_type == MPS || mpoa_device_type == MPC) && |
| 424 | length < 22 + number_of_mps_macs*ETH_ALEN) { |
| 425 | pr_info("(%s) short MPOA Device Type TLV\n", dev->name); |
| 426 | continue; |
| 427 | } |
| 428 | if (mpoa_device_type != MPS && |
| 429 | mpoa_device_type != MPS_AND_MPC) { |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 430 | dprintk("ignoring non-MPS device "); |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 431 | if (mpoa_device_type == MPC) |
| 432 | tlvs += 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | continue; /* we are only interested in MPSs */ |
| 434 | } |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 435 | if (number_of_mps_macs == 0 && |
| 436 | mpoa_device_type == MPS_AND_MPC) { |
| 437 | pr_info("(%s) MPS_AND_MPC has zero MACs\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | continue; /* someone should read the spec */ |
| 439 | } |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 440 | dprintk_cont("this MPS has %d MAC addresses\n", |
| 441 | number_of_mps_macs); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 442 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 443 | /* |
| 444 | * ok, now we can go and tell our daemon |
| 445 | * the control address of MPS |
| 446 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | send_set_mps_ctrl_addr(tlvs, mpc); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 448 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 449 | tlvs = copy_macs(mpc, mac_addr, tlvs, |
| 450 | number_of_mps_macs, mpoa_device_type); |
| 451 | if (tlvs == NULL) |
| 452 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | } |
| 454 | if (end_of_tlvs - tlvs != 0) |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 455 | pr_info("(%s) ignoring %Zd bytes of trailing TLV garbage\n", |
| 456 | dev->name, end_of_tlvs - tlvs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | return; |
| 458 | } |
| 459 | |
| 460 | /* |
| 461 | * Store at least advertizing router's MAC address |
| 462 | * plus the possible MAC address(es) to mpc->mps_macs. |
| 463 | * For a freshly allocated MPOA client mpc->mps_macs == 0. |
| 464 | */ |
David Howells | cba5cbd | 2008-07-30 16:31:46 -0700 | [diff] [blame] | 465 | static const uint8_t *copy_macs(struct mpoa_client *mpc, |
| 466 | const uint8_t *router_mac, |
| 467 | const uint8_t *tlvs, uint8_t mps_macs, |
| 468 | uint8_t device_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | { |
| 470 | int num_macs; |
| 471 | num_macs = (mps_macs > 1) ? mps_macs : 1; |
| 472 | |
| 473 | if (mpc->number_of_mps_macs != num_macs) { /* need to reallocate? */ |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 474 | if (mpc->number_of_mps_macs != 0) |
| 475 | kfree(mpc->mps_macs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | mpc->number_of_mps_macs = 0; |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 477 | mpc->mps_macs = kmalloc(num_macs * ETH_ALEN, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | if (mpc->mps_macs == NULL) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 479 | pr_info("(%s) out of mem\n", mpc->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | return NULL; |
| 481 | } |
| 482 | } |
| 483 | memcpy(mpc->mps_macs, router_mac, ETH_ALEN); |
| 484 | tlvs += 20; if (device_type == MPS_AND_MPC) tlvs += 20; |
| 485 | if (mps_macs > 0) |
| 486 | memcpy(mpc->mps_macs, tlvs, mps_macs*ETH_ALEN); |
| 487 | tlvs += mps_macs*ETH_ALEN; |
| 488 | mpc->number_of_mps_macs = num_macs; |
| 489 | |
| 490 | return tlvs; |
| 491 | } |
| 492 | |
| 493 | static int send_via_shortcut(struct sk_buff *skb, struct mpoa_client *mpc) |
| 494 | { |
| 495 | in_cache_entry *entry; |
| 496 | struct iphdr *iph; |
| 497 | char *buff; |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 498 | __be32 ipaddr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
| 500 | static struct { |
| 501 | struct llc_snap_hdr hdr; |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 502 | __be32 tag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } tagged_llc_snap_hdr = { |
| 504 | {0xaa, 0xaa, 0x03, {0x00, 0x00, 0x00}, {0x88, 0x4c}}, |
| 505 | 0 |
| 506 | }; |
| 507 | |
| 508 | buff = skb->data + mpc->dev->hard_header_len; |
| 509 | iph = (struct iphdr *)buff; |
| 510 | ipaddr = iph->daddr; |
| 511 | |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 512 | ddprintk("(%s) ipaddr 0x%x\n", |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 513 | mpc->dev->name, ipaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | entry = mpc->in_ops->get(ipaddr, mpc); |
| 516 | if (entry == NULL) { |
| 517 | entry = mpc->in_ops->add_entry(ipaddr, mpc); |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 518 | if (entry != NULL) |
| 519 | mpc->in_ops->put(entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | return 1; |
| 521 | } |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 522 | /* threshold not exceeded or VCC not ready */ |
| 523 | if (mpc->in_ops->cache_hit(entry, mpc) != OPEN) { |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 524 | ddprintk("(%s) cache_hit: returns != OPEN\n", |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 525 | mpc->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | mpc->in_ops->put(entry); |
| 527 | return 1; |
| 528 | } |
| 529 | |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 530 | ddprintk("(%s) using shortcut\n", |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 531 | mpc->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | /* MPOA spec A.1.4, MPOA client must decrement IP ttl at least by one */ |
| 533 | if (iph->ttl <= 1) { |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 534 | ddprintk("(%s) IP ttl = %u, using LANE\n", |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 535 | mpc->dev->name, iph->ttl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | mpc->in_ops->put(entry); |
| 537 | return 1; |
| 538 | } |
| 539 | iph->ttl--; |
| 540 | iph->check = 0; |
| 541 | iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); |
| 542 | |
| 543 | if (entry->ctrl_info.tag != 0) { |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 544 | ddprintk("(%s) adding tag 0x%x\n", |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 545 | mpc->dev->name, entry->ctrl_info.tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | tagged_llc_snap_hdr.tag = entry->ctrl_info.tag; |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 547 | skb_pull(skb, ETH_HLEN); /* get rid of Eth header */ |
| 548 | skb_push(skb, sizeof(tagged_llc_snap_hdr)); |
| 549 | /* add LLC/SNAP header */ |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 550 | skb_copy_to_linear_data(skb, &tagged_llc_snap_hdr, |
| 551 | sizeof(tagged_llc_snap_hdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | } else { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 553 | skb_pull(skb, ETH_HLEN); /* get rid of Eth header */ |
| 554 | skb_push(skb, sizeof(struct llc_snap_hdr)); |
| 555 | /* add LLC/SNAP header + tag */ |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 556 | skb_copy_to_linear_data(skb, &llc_snap_mpoa_data, |
| 557 | sizeof(struct llc_snap_hdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | atomic_add(skb->truesize, &sk_atm(entry->shortcut)->sk_wmem_alloc); |
| 561 | ATM_SKB(skb)->atm_options = entry->shortcut->atm_options; |
| 562 | entry->shortcut->send(entry->shortcut, skb); |
| 563 | entry->packets_fwded++; |
| 564 | mpc->in_ops->put(entry); |
| 565 | |
| 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | /* |
| 570 | * Probably needs some error checks and locking, not sure... |
| 571 | */ |
Stephen Hemminger | 3c805a2 | 2009-08-31 19:50:42 +0000 | [diff] [blame] | 572 | static netdev_tx_t mpc_send_packet(struct sk_buff *skb, |
| 573 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | struct mpoa_client *mpc; |
| 576 | struct ethhdr *eth; |
| 577 | int i = 0; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | mpc = find_mpc_by_lec(dev); /* this should NEVER fail */ |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 580 | if (mpc == NULL) { |
| 581 | pr_info("(%s) no MPC found\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | goto non_ip; |
| 583 | } |
| 584 | |
| 585 | eth = (struct ethhdr *)skb->data; |
| 586 | if (eth->h_proto != htons(ETH_P_IP)) |
| 587 | goto non_ip; /* Multi-Protocol Over ATM :-) */ |
| 588 | |
Herbert Xu | 1c9b7aa | 2008-01-09 03:51:59 -0800 | [diff] [blame] | 589 | /* Weed out funny packets (e.g., AF_PACKET or raw). */ |
| 590 | if (skb->len < ETH_HLEN + sizeof(struct iphdr)) |
| 591 | goto non_ip; |
| 592 | skb_set_network_header(skb, ETH_HLEN); |
| 593 | if (skb->len < ETH_HLEN + ip_hdr(skb)->ihl * 4 || ip_hdr(skb)->ihl < 5) |
| 594 | goto non_ip; |
| 595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | while (i < mpc->number_of_mps_macs) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 597 | if (!compare_ether_addr(eth->h_dest, |
| 598 | (mpc->mps_macs + i*ETH_ALEN))) |
| 599 | if (send_via_shortcut(skb, mpc) == 0) /* try shortcut */ |
| 600 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | i++; |
| 602 | } |
| 603 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 604 | non_ip: |
| 605 | return mpc->old_ops->ndo_start_xmit(skb, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | static int atm_mpoa_vcc_attach(struct atm_vcc *vcc, void __user *arg) |
| 609 | { |
| 610 | int bytes_left; |
| 611 | struct mpoa_client *mpc; |
| 612 | struct atmmpc_ioc ioc_data; |
| 613 | in_cache_entry *in_entry; |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 614 | __be32 ipaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
| 616 | bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmmpc_ioc)); |
| 617 | if (bytes_left != 0) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 618 | pr_info("mpoa:Short read (missed %d bytes) from userland\n", |
| 619 | bytes_left); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | return -EFAULT; |
| 621 | } |
| 622 | ipaddr = ioc_data.ipaddr; |
| 623 | if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF) |
| 624 | return -EINVAL; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | mpc = find_mpc_by_itfnum(ioc_data.dev_num); |
| 627 | if (mpc == NULL) |
| 628 | return -EINVAL; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | if (ioc_data.type == MPC_SOCKET_INGRESS) { |
| 631 | in_entry = mpc->in_ops->get(ipaddr, mpc); |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 632 | if (in_entry == NULL || |
| 633 | in_entry->entry_state < INGRESS_RESOLVED) { |
| 634 | pr_info("(%s) did not find RESOLVED entry from ingress cache\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | mpc->dev->name); |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 636 | if (in_entry != NULL) |
| 637 | mpc->in_ops->put(in_entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | return -EINVAL; |
| 639 | } |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 640 | pr_info("(%s) attaching ingress SVC, entry = %pI4\n", |
| 641 | mpc->dev->name, &in_entry->ctrl_info.in_dst_ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | in_entry->shortcut = vcc; |
| 643 | mpc->in_ops->put(in_entry); |
| 644 | } else { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 645 | pr_info("(%s) attaching egress SVC\n", mpc->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | vcc->proto_data = mpc->dev; |
| 649 | vcc->push = mpc_push; |
| 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | /* |
| 655 | * |
| 656 | */ |
| 657 | static void mpc_vcc_close(struct atm_vcc *vcc, struct net_device *dev) |
| 658 | { |
| 659 | struct mpoa_client *mpc; |
| 660 | in_cache_entry *in_entry; |
| 661 | eg_cache_entry *eg_entry; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 662 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | mpc = find_mpc_by_lec(dev); |
| 664 | if (mpc == NULL) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 665 | pr_info("(%s) close for unknown MPC\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | return; |
| 667 | } |
| 668 | |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 669 | dprintk("(%s)\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | in_entry = mpc->in_ops->get_by_vcc(vcc, mpc); |
| 671 | if (in_entry) { |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 672 | dprintk("(%s) ingress SVC closed ip = %pI4\n", |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 673 | mpc->dev->name, &in_entry->ctrl_info.in_dst_ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | in_entry->shortcut = NULL; |
| 675 | mpc->in_ops->put(in_entry); |
| 676 | } |
| 677 | eg_entry = mpc->eg_ops->get_by_vcc(vcc, mpc); |
| 678 | if (eg_entry) { |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 679 | dprintk("(%s) egress SVC closed\n", mpc->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | eg_entry->shortcut = NULL; |
| 681 | mpc->eg_ops->put(eg_entry); |
| 682 | } |
| 683 | |
| 684 | if (in_entry == NULL && eg_entry == NULL) |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 685 | dprintk("(%s) unused vcc closed\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
| 687 | return; |
| 688 | } |
| 689 | |
| 690 | static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb) |
| 691 | { |
| 692 | struct net_device *dev = (struct net_device *)vcc->proto_data; |
| 693 | struct sk_buff *new_skb; |
| 694 | eg_cache_entry *eg; |
| 695 | struct mpoa_client *mpc; |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 696 | __be32 tag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | char *tmp; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 698 | |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 699 | ddprintk("(%s)\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | if (skb == NULL) { |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 701 | dprintk("(%s) null skb, closing VCC\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | mpc_vcc_close(vcc, dev); |
| 703 | return; |
| 704 | } |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | skb->dev = dev; |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 707 | if (memcmp(skb->data, &llc_snap_mpoa_ctrl, |
| 708 | sizeof(struct llc_snap_hdr)) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | struct sock *sk = sk_atm(vcc); |
| 710 | |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 711 | dprintk("(%s) control packet arrived\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | /* Pass control packets to daemon */ |
| 713 | skb_queue_tail(&sk->sk_receive_queue, skb); |
| 714 | sk->sk_data_ready(sk, skb->len); |
| 715 | return; |
| 716 | } |
| 717 | |
| 718 | /* data coming over the shortcut */ |
| 719 | atm_return(vcc, skb->truesize); |
| 720 | |
| 721 | mpc = find_mpc_by_lec(dev); |
| 722 | if (mpc == NULL) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 723 | pr_info("(%s) unknown MPC\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | return; |
| 725 | } |
| 726 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 727 | if (memcmp(skb->data, &llc_snap_mpoa_data_tagged, |
| 728 | sizeof(struct llc_snap_hdr)) == 0) { /* MPOA tagged data */ |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 729 | ddprintk("(%s) tagged data packet arrived\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 731 | } else if (memcmp(skb->data, &llc_snap_mpoa_data, |
| 732 | sizeof(struct llc_snap_hdr)) == 0) { /* MPOA data */ |
| 733 | pr_info("(%s) Unsupported non-tagged data packet arrived. Purging\n", |
| 734 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | dev_kfree_skb_any(skb); |
| 736 | return; |
| 737 | } else { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 738 | pr_info("(%s) garbage arrived, purging\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | dev_kfree_skb_any(skb); |
| 740 | return; |
| 741 | } |
| 742 | |
| 743 | tmp = skb->data + sizeof(struct llc_snap_hdr); |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 744 | tag = *(__be32 *)tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | |
| 746 | eg = mpc->eg_ops->get_by_tag(tag, mpc); |
| 747 | if (eg == NULL) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 748 | pr_info("mpoa: (%s) Didn't find egress cache entry, tag = %u\n", |
| 749 | dev->name, tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | purge_egress_shortcut(vcc, NULL); |
| 751 | dev_kfree_skb_any(skb); |
| 752 | return; |
| 753 | } |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 754 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | /* |
| 756 | * See if ingress MPC is using shortcut we opened as a return channel. |
| 757 | * This means we have a bi-directional vcc opened by us. |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 758 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | if (eg->shortcut == NULL) { |
| 760 | eg->shortcut = vcc; |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 761 | pr_info("(%s) egress SVC in use\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 764 | skb_pull(skb, sizeof(struct llc_snap_hdr) + sizeof(tag)); |
| 765 | /* get rid of LLC/SNAP header */ |
| 766 | new_skb = skb_realloc_headroom(skb, eg->ctrl_info.DH_length); |
| 767 | /* LLC/SNAP is shorter than MAC header :( */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | dev_kfree_skb_any(skb); |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 769 | if (new_skb == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | mpc->eg_ops->put(eg); |
| 771 | return; |
| 772 | } |
| 773 | skb_push(new_skb, eg->ctrl_info.DH_length); /* add MAC header */ |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 774 | skb_copy_to_linear_data(new_skb, eg->ctrl_info.DLL_header, |
| 775 | eg->ctrl_info.DH_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | new_skb->protocol = eth_type_trans(new_skb, dev); |
Arnaldo Carvalho de Melo | c1d2bbe | 2007-04-10 20:45:18 -0700 | [diff] [blame] | 777 | skb_reset_network_header(new_skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 779 | eg->latest_ip_addr = ip_hdr(new_skb)->saddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | eg->packets_rcvd++; |
| 781 | mpc->eg_ops->put(eg); |
| 782 | |
| 783 | memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data)); |
| 784 | netif_rx(new_skb); |
| 785 | |
| 786 | return; |
| 787 | } |
| 788 | |
| 789 | static struct atmdev_ops mpc_ops = { /* only send is required */ |
| 790 | .close = mpoad_close, |
| 791 | .send = msg_from_mpoad |
| 792 | }; |
| 793 | |
| 794 | static struct atm_dev mpc_dev = { |
| 795 | .ops = &mpc_ops, |
| 796 | .type = "mpc", |
| 797 | .number = 42, |
Milind Arun Choudhary | 4ef8d0a | 2007-04-26 01:37:44 -0700 | [diff] [blame] | 798 | .lock = __SPIN_LOCK_UNLOCKED(mpc_dev.lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | /* members not explicitly initialised will be 0 */ |
| 800 | }; |
| 801 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 802 | static int atm_mpoa_mpoad_attach(struct atm_vcc *vcc, int arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | { |
| 804 | struct mpoa_client *mpc; |
| 805 | struct lec_priv *priv; |
| 806 | int err; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | if (mpcs == NULL) { |
| 809 | init_timer(&mpc_timer); |
| 810 | mpc_timer_refresh(); |
| 811 | |
| 812 | /* This lets us now how our LECs are doing */ |
| 813 | err = register_netdevice_notifier(&mpoa_notifier); |
| 814 | if (err < 0) { |
| 815 | del_timer(&mpc_timer); |
| 816 | return err; |
| 817 | } |
| 818 | } |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 819 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | mpc = find_mpc_by_itfnum(arg); |
| 821 | if (mpc == NULL) { |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 822 | dprintk("allocating new mpc for itf %d\n", arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | mpc = alloc_mpc(); |
| 824 | if (mpc == NULL) |
| 825 | return -ENOMEM; |
| 826 | mpc->dev_num = arg; |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 827 | mpc->dev = find_lec_by_itfnum(arg); |
| 828 | /* NULL if there was no lec */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | } |
| 830 | if (mpc->mpoad_vcc) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 831 | pr_info("mpoad is already present for itf %d\n", arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | return -EADDRINUSE; |
| 833 | } |
| 834 | |
| 835 | if (mpc->dev) { /* check if the lec is LANE2 capable */ |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 836 | priv = netdev_priv(mpc->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | if (priv->lane_version < 2) { |
| 838 | dev_put(mpc->dev); |
| 839 | mpc->dev = NULL; |
| 840 | } else |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 841 | priv->lane2_ops->associate_indicator = lane2_assoc_ind; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | mpc->mpoad_vcc = vcc; |
| 845 | vcc->dev = &mpc_dev; |
| 846 | vcc_insert_socket(sk_atm(vcc)); |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 847 | set_bit(ATM_VF_META, &vcc->flags); |
| 848 | set_bit(ATM_VF_READY, &vcc->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
| 850 | if (mpc->dev) { |
| 851 | char empty[ATM_ESA_LEN]; |
| 852 | memset(empty, 0, ATM_ESA_LEN); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | start_mpc(mpc, mpc->dev); |
| 855 | /* set address if mpcd e.g. gets killed and restarted. |
| 856 | * If we do not do it now we have to wait for the next LE_ARP |
| 857 | */ |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 858 | if (memcmp(mpc->mps_ctrl_addr, empty, ATM_ESA_LEN) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | send_set_mps_ctrl_addr(mpc->mps_ctrl_addr, mpc); |
| 860 | } |
| 861 | |
| 862 | __module_get(THIS_MODULE); |
| 863 | return arg; |
| 864 | } |
| 865 | |
David Howells | cba5cbd | 2008-07-30 16:31:46 -0700 | [diff] [blame] | 866 | static void send_set_mps_ctrl_addr(const char *addr, struct mpoa_client *mpc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | { |
| 868 | struct k_message mesg; |
| 869 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 870 | memcpy(mpc->mps_ctrl_addr, addr, ATM_ESA_LEN); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | mesg.type = SET_MPS_CTRL_ADDR; |
| 873 | memcpy(mesg.MPS_ctrl, addr, ATM_ESA_LEN); |
| 874 | msg_to_mpoad(&mesg, mpc); |
| 875 | |
| 876 | return; |
| 877 | } |
| 878 | |
| 879 | static void mpoad_close(struct atm_vcc *vcc) |
| 880 | { |
| 881 | struct mpoa_client *mpc; |
| 882 | struct sk_buff *skb; |
| 883 | |
| 884 | mpc = find_mpc_by_vcc(vcc); |
| 885 | if (mpc == NULL) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 886 | pr_info("did not find MPC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | return; |
| 888 | } |
| 889 | if (!mpc->mpoad_vcc) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 890 | pr_info("close for non-present mpoad\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | return; |
| 892 | } |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | mpc->mpoad_vcc = NULL; |
| 895 | if (mpc->dev) { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 896 | struct lec_priv *priv = netdev_priv(mpc->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | priv->lane2_ops->associate_indicator = NULL; |
| 898 | stop_mpc(mpc); |
| 899 | dev_put(mpc->dev); |
| 900 | } |
| 901 | |
| 902 | mpc->in_ops->destroy_cache(mpc); |
| 903 | mpc->eg_ops->destroy_cache(mpc); |
| 904 | |
| 905 | while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) { |
| 906 | atm_return(vcc, skb->truesize); |
| 907 | kfree_skb(skb); |
| 908 | } |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 909 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 910 | pr_info("(%s) going down\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | (mpc->dev) ? mpc->dev->name : "<unknown>"); |
| 912 | module_put(THIS_MODULE); |
| 913 | |
| 914 | return; |
| 915 | } |
| 916 | |
| 917 | /* |
| 918 | * |
| 919 | */ |
| 920 | static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb) |
| 921 | { |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 922 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | struct mpoa_client *mpc = find_mpc_by_vcc(vcc); |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 924 | struct k_message *mesg = (struct k_message *)skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 926 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | if (mpc == NULL) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 928 | pr_info("no mpc found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | return 0; |
| 930 | } |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 931 | dprintk("(%s)", mpc->dev ? mpc->dev->name : "<unknown>"); |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 932 | switch (mesg->type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | case MPOA_RES_REPLY_RCVD: |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 934 | dprintk_cont("mpoa_res_reply_rcvd\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | MPOA_res_reply_rcvd(mesg, mpc); |
| 936 | break; |
| 937 | case MPOA_TRIGGER_RCVD: |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 938 | dprintk_cont("mpoa_trigger_rcvd\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | MPOA_trigger_rcvd(mesg, mpc); |
| 940 | break; |
| 941 | case INGRESS_PURGE_RCVD: |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 942 | dprintk_cont("nhrp_purge_rcvd\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | ingress_purge_rcvd(mesg, mpc); |
| 944 | break; |
| 945 | case EGRESS_PURGE_RCVD: |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 946 | dprintk_cont("egress_purge_reply_rcvd\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | egress_purge_rcvd(mesg, mpc); |
| 948 | break; |
| 949 | case MPS_DEATH: |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 950 | dprintk_cont("mps_death\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | mps_death(mesg, mpc); |
| 952 | break; |
| 953 | case CACHE_IMPOS_RCVD: |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 954 | dprintk_cont("cache_impos_rcvd\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | MPOA_cache_impos_rcvd(mesg, mpc); |
| 956 | break; |
| 957 | case SET_MPC_CTRL_ADDR: |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 958 | dprintk_cont("set_mpc_ctrl_addr\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | set_mpc_ctrl_addr_rcvd(mesg, mpc); |
| 960 | break; |
| 961 | case SET_MPS_MAC_ADDR: |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 962 | dprintk_cont("set_mps_mac_addr\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | set_mps_mac_addr_rcvd(mesg, mpc); |
| 964 | break; |
| 965 | case CLEAN_UP_AND_EXIT: |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 966 | dprintk_cont("clean_up_and_exit\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | clean_up(mesg, mpc, DIE); |
| 968 | break; |
| 969 | case RELOAD: |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 970 | dprintk_cont("reload\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | clean_up(mesg, mpc, RELOAD); |
| 972 | break; |
| 973 | case SET_MPC_PARAMS: |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 974 | dprintk_cont("set_mpc_params\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | mpc->parameters = mesg->content.params; |
| 976 | break; |
| 977 | default: |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 978 | dprintk_cont("unknown message %d\n", mesg->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | break; |
| 980 | } |
| 981 | kfree_skb(skb); |
| 982 | |
| 983 | return 0; |
| 984 | } |
| 985 | |
| 986 | /* Remember that this function may not do things that sleep */ |
| 987 | int msg_to_mpoad(struct k_message *mesg, struct mpoa_client *mpc) |
| 988 | { |
| 989 | struct sk_buff *skb; |
| 990 | struct sock *sk; |
| 991 | |
| 992 | if (mpc == NULL || !mpc->mpoad_vcc) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 993 | pr_info("mesg %d to a non-existent mpoad\n", mesg->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | return -ENXIO; |
| 995 | } |
| 996 | |
| 997 | skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC); |
| 998 | if (skb == NULL) |
| 999 | return -ENOMEM; |
| 1000 | skb_put(skb, sizeof(struct k_message)); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 1001 | skb_copy_to_linear_data(skb, mesg, sizeof(*mesg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | atm_force_charge(mpc->mpoad_vcc, skb->truesize); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1003 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | sk = sk_atm(mpc->mpoad_vcc); |
| 1005 | skb_queue_tail(&sk->sk_receive_queue, skb); |
| 1006 | sk->sk_data_ready(sk, skb->len); |
| 1007 | |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1011 | static int mpoa_event_listener(struct notifier_block *mpoa_notifier, |
| 1012 | unsigned long event, void *dev_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | { |
| 1014 | struct net_device *dev; |
| 1015 | struct mpoa_client *mpc; |
| 1016 | struct lec_priv *priv; |
| 1017 | |
| 1018 | dev = (struct net_device *)dev_ptr; |
Eric W. Biederman | e9dc865 | 2007-09-12 13:02:17 +0200 | [diff] [blame] | 1019 | |
YOSHIFUJI Hideaki | 721499e | 2008-07-19 22:34:43 -0700 | [diff] [blame] | 1020 | if (!net_eq(dev_net(dev), &init_net)) |
Eric W. Biederman | e9dc865 | 2007-09-12 13:02:17 +0200 | [diff] [blame] | 1021 | return NOTIFY_DONE; |
| 1022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | if (dev->name == NULL || strncmp(dev->name, "lec", 3)) |
| 1024 | return NOTIFY_DONE; /* we are only interested in lec:s */ |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1025 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | switch (event) { |
| 1027 | case NETDEV_REGISTER: /* a new lec device was allocated */ |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1028 | priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | if (priv->lane_version < 2) |
| 1030 | break; |
| 1031 | priv->lane2_ops->associate_indicator = lane2_assoc_ind; |
| 1032 | mpc = find_mpc_by_itfnum(priv->itfnum); |
| 1033 | if (mpc == NULL) { |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1034 | dprintk("allocating new mpc for %s\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | mpc = alloc_mpc(); |
| 1036 | if (mpc == NULL) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1037 | pr_info("no new mpc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | break; |
| 1039 | } |
| 1040 | } |
| 1041 | mpc->dev_num = priv->itfnum; |
| 1042 | mpc->dev = dev; |
| 1043 | dev_hold(dev); |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1044 | dprintk("(%s) was initialized\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | break; |
| 1046 | case NETDEV_UNREGISTER: |
| 1047 | /* the lec device was deallocated */ |
| 1048 | mpc = find_mpc_by_lec(dev); |
| 1049 | if (mpc == NULL) |
| 1050 | break; |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1051 | dprintk("device (%s) was deallocated\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | stop_mpc(mpc); |
| 1053 | dev_put(mpc->dev); |
| 1054 | mpc->dev = NULL; |
| 1055 | break; |
| 1056 | case NETDEV_UP: |
| 1057 | /* the dev was ifconfig'ed up */ |
| 1058 | mpc = find_mpc_by_lec(dev); |
| 1059 | if (mpc == NULL) |
| 1060 | break; |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1061 | if (mpc->mpoad_vcc != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | start_mpc(mpc, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | break; |
| 1064 | case NETDEV_DOWN: |
| 1065 | /* the dev was ifconfig'ed down */ |
| 1066 | /* this means that the flow of packets from the |
| 1067 | * upper layer stops |
| 1068 | */ |
| 1069 | mpc = find_mpc_by_lec(dev); |
| 1070 | if (mpc == NULL) |
| 1071 | break; |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1072 | if (mpc->mpoad_vcc != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | stop_mpc(mpc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | break; |
| 1075 | case NETDEV_REBOOT: |
| 1076 | case NETDEV_CHANGE: |
| 1077 | case NETDEV_CHANGEMTU: |
| 1078 | case NETDEV_CHANGEADDR: |
| 1079 | case NETDEV_GOING_DOWN: |
| 1080 | break; |
| 1081 | default: |
| 1082 | break; |
| 1083 | } |
| 1084 | |
| 1085 | return NOTIFY_DONE; |
| 1086 | } |
| 1087 | |
| 1088 | /* |
| 1089 | * Functions which are called after a message is received from mpcd. |
| 1090 | * Msg is reused on purpose. |
| 1091 | */ |
| 1092 | |
| 1093 | |
| 1094 | static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc) |
| 1095 | { |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 1096 | __be32 dst_ip = msg->content.in_info.in_dst_ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | in_cache_entry *entry; |
| 1098 | |
| 1099 | entry = mpc->in_ops->get(dst_ip, mpc); |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1100 | if (entry == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | entry = mpc->in_ops->add_entry(dst_ip, mpc); |
| 1102 | entry->entry_state = INGRESS_RESOLVING; |
| 1103 | msg->type = SND_MPOA_RES_RQST; |
| 1104 | msg->content.in_info = entry->ctrl_info; |
| 1105 | msg_to_mpoad(msg, mpc); |
| 1106 | do_gettimeofday(&(entry->reply_wait)); |
| 1107 | mpc->in_ops->put(entry); |
| 1108 | return; |
| 1109 | } |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1110 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1111 | if (entry->entry_state == INGRESS_INVALID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | entry->entry_state = INGRESS_RESOLVING; |
| 1113 | msg->type = SND_MPOA_RES_RQST; |
| 1114 | msg->content.in_info = entry->ctrl_info; |
| 1115 | msg_to_mpoad(msg, mpc); |
| 1116 | do_gettimeofday(&(entry->reply_wait)); |
| 1117 | mpc->in_ops->put(entry); |
| 1118 | return; |
| 1119 | } |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1120 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1121 | pr_info("(%s) entry already in resolving state\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | (mpc->dev) ? mpc->dev->name : "<unknown>"); |
| 1123 | mpc->in_ops->put(entry); |
| 1124 | return; |
| 1125 | } |
| 1126 | |
| 1127 | /* |
| 1128 | * Things get complicated because we have to check if there's an egress |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1129 | * shortcut with suitable traffic parameters we could use. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | */ |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1131 | static void check_qos_and_open_shortcut(struct k_message *msg, |
| 1132 | struct mpoa_client *client, |
| 1133 | in_cache_entry *entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | { |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 1135 | __be32 dst_ip = msg->content.in_info.in_dst_ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | struct atm_mpoa_qos *qos = atm_mpoa_search_qos(dst_ip); |
| 1137 | eg_cache_entry *eg_entry = client->eg_ops->get_by_src_ip(dst_ip, client); |
| 1138 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1139 | if (eg_entry && eg_entry->shortcut) { |
| 1140 | if (eg_entry->shortcut->qos.txtp.traffic_class & |
| 1141 | msg->qos.txtp.traffic_class & |
| 1142 | (qos ? qos->qos.txtp.traffic_class : ATM_UBR | ATM_CBR)) { |
| 1143 | if (eg_entry->shortcut->qos.txtp.traffic_class == ATM_UBR) |
| 1144 | entry->shortcut = eg_entry->shortcut; |
| 1145 | else if (eg_entry->shortcut->qos.txtp.max_pcr > 0) |
| 1146 | entry->shortcut = eg_entry->shortcut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | } |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1148 | if (entry->shortcut) { |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1149 | dprintk("(%s) using egress SVC to reach %pI4\n", |
Harvey Harrison | 21454aa | 2008-10-31 00:54:56 -0700 | [diff] [blame] | 1150 | client->dev->name, &dst_ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | client->eg_ops->put(eg_entry); |
| 1152 | return; |
| 1153 | } |
| 1154 | } |
| 1155 | if (eg_entry != NULL) |
| 1156 | client->eg_ops->put(eg_entry); |
| 1157 | |
| 1158 | /* No luck in the egress cache we must open an ingress SVC */ |
| 1159 | msg->type = OPEN_INGRESS_SVC; |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1160 | if (qos && |
| 1161 | (qos->qos.txtp.traffic_class == msg->qos.txtp.traffic_class)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | msg->qos = qos->qos; |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1163 | pr_info("(%s) trying to get a CBR shortcut\n", |
| 1164 | client->dev->name); |
| 1165 | } else |
| 1166 | memset(&msg->qos, 0, sizeof(struct atm_qos)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | msg_to_mpoad(msg, client); |
| 1168 | return; |
| 1169 | } |
| 1170 | |
| 1171 | static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc) |
| 1172 | { |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 1173 | __be32 dst_ip = msg->content.in_info.in_dst_ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | in_cache_entry *entry = mpc->in_ops->get(dst_ip, mpc); |
Andrew Morton | 1e4fd51 | 2006-06-26 00:01:58 -0700 | [diff] [blame] | 1175 | |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1176 | dprintk("(%s) ip %pI4\n", |
Harvey Harrison | 21454aa | 2008-10-31 00:54:56 -0700 | [diff] [blame] | 1177 | mpc->dev->name, &dst_ip); |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1178 | ddprintk("(%s) entry = %p", |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1179 | mpc->dev->name, entry); |
| 1180 | if (entry == NULL) { |
| 1181 | pr_info("(%s) ARGH, received res. reply for an entry that doesn't exist.\n", |
| 1182 | mpc->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | return; |
| 1184 | } |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1185 | ddprintk_cont(" entry_state = %d ", entry->entry_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
| 1187 | if (entry->entry_state == INGRESS_RESOLVED) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1188 | pr_info("(%s) RESOLVED entry!\n", mpc->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | mpc->in_ops->put(entry); |
| 1190 | return; |
| 1191 | } |
| 1192 | |
| 1193 | entry->ctrl_info = msg->content.in_info; |
| 1194 | do_gettimeofday(&(entry->tv)); |
| 1195 | do_gettimeofday(&(entry->reply_wait)); /* Used in refreshing func from now on */ |
| 1196 | entry->refresh_time = 0; |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1197 | ddprintk_cont("entry->shortcut = %p\n", entry->shortcut); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1199 | if (entry->entry_state == INGRESS_RESOLVING && |
| 1200 | entry->shortcut != NULL) { |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1201 | entry->entry_state = INGRESS_RESOLVED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | mpc->in_ops->put(entry); |
| 1203 | return; /* Shortcut already open... */ |
| 1204 | } |
| 1205 | |
| 1206 | if (entry->shortcut != NULL) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1207 | pr_info("(%s) entry->shortcut != NULL, impossible!\n", |
| 1208 | mpc->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | mpc->in_ops->put(entry); |
| 1210 | return; |
| 1211 | } |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | check_qos_and_open_shortcut(msg, mpc, entry); |
| 1214 | entry->entry_state = INGRESS_RESOLVED; |
| 1215 | mpc->in_ops->put(entry); |
| 1216 | |
| 1217 | return; |
| 1218 | |
| 1219 | } |
| 1220 | |
| 1221 | static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc) |
| 1222 | { |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 1223 | __be32 dst_ip = msg->content.in_info.in_dst_ip; |
| 1224 | __be32 mask = msg->ip_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | in_cache_entry *entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask); |
| 1226 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1227 | if (entry == NULL) { |
| 1228 | pr_info("(%s) purge for a non-existing entry, ip = %pI4\n", |
| 1229 | mpc->dev->name, &dst_ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | return; |
| 1231 | } |
| 1232 | |
| 1233 | do { |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1234 | dprintk("(%s) removing an ingress entry, ip = %pI4\n", |
Harvey Harrison | 21454aa | 2008-10-31 00:54:56 -0700 | [diff] [blame] | 1235 | mpc->dev->name, &dst_ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | write_lock_bh(&mpc->ingress_lock); |
| 1237 | mpc->in_ops->remove_entry(entry, mpc); |
| 1238 | write_unlock_bh(&mpc->ingress_lock); |
| 1239 | mpc->in_ops->put(entry); |
| 1240 | entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask); |
| 1241 | } while (entry != NULL); |
| 1242 | |
| 1243 | return; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1244 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | |
| 1246 | static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc) |
| 1247 | { |
Al Viro | 30d492d | 2006-11-14 21:11:29 -0800 | [diff] [blame] | 1248 | __be32 cache_id = msg->content.eg_info.cache_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(cache_id, mpc); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | if (entry == NULL) { |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1252 | dprintk("(%s) purge for a non-existing entry\n", |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1253 | mpc->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | return; |
| 1255 | } |
| 1256 | |
| 1257 | write_lock_irq(&mpc->egress_lock); |
| 1258 | mpc->eg_ops->remove_entry(entry, mpc); |
| 1259 | write_unlock_irq(&mpc->egress_lock); |
| 1260 | |
| 1261 | mpc->eg_ops->put(entry); |
| 1262 | |
| 1263 | return; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1264 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | |
| 1266 | static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry) |
| 1267 | { |
| 1268 | struct sock *sk; |
| 1269 | struct k_message *purge_msg; |
| 1270 | struct sk_buff *skb; |
| 1271 | |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1272 | dprintk("entering\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | if (vcc == NULL) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1274 | pr_info("vcc == NULL\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | return; |
| 1276 | } |
| 1277 | |
| 1278 | skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC); |
| 1279 | if (skb == NULL) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1280 | pr_info("out of memory\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | return; |
| 1282 | } |
| 1283 | |
| 1284 | skb_put(skb, sizeof(struct k_message)); |
| 1285 | memset(skb->data, 0, sizeof(struct k_message)); |
| 1286 | purge_msg = (struct k_message *)skb->data; |
| 1287 | purge_msg->type = DATA_PLANE_PURGE; |
| 1288 | if (entry != NULL) |
| 1289 | purge_msg->content.eg_info = entry->ctrl_info; |
| 1290 | |
| 1291 | atm_force_charge(vcc, skb->truesize); |
| 1292 | |
| 1293 | sk = sk_atm(vcc); |
| 1294 | skb_queue_tail(&sk->sk_receive_queue, skb); |
| 1295 | sk->sk_data_ready(sk, skb->len); |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1296 | dprintk("exiting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | |
| 1298 | return; |
| 1299 | } |
| 1300 | |
| 1301 | /* |
| 1302 | * Our MPS died. Tell our daemon to send NHRP data plane purge to each |
| 1303 | * of the egress shortcuts we have. |
| 1304 | */ |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1305 | static void mps_death(struct k_message *msg, struct mpoa_client *mpc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | { |
| 1307 | eg_cache_entry *entry; |
| 1308 | |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1309 | dprintk("(%s)\n", mpc->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1311 | if (memcmp(msg->MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN)) { |
| 1312 | pr_info("(%s) wrong MPS\n", mpc->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | return; |
| 1314 | } |
| 1315 | |
| 1316 | /* FIXME: This knows too much of the cache structure */ |
| 1317 | read_lock_irq(&mpc->egress_lock); |
| 1318 | entry = mpc->eg_cache; |
| 1319 | while (entry != NULL) { |
| 1320 | purge_egress_shortcut(entry->shortcut, entry); |
| 1321 | entry = entry->next; |
| 1322 | } |
| 1323 | read_unlock_irq(&mpc->egress_lock); |
| 1324 | |
| 1325 | mpc->in_ops->destroy_cache(mpc); |
| 1326 | mpc->eg_ops->destroy_cache(mpc); |
| 1327 | |
| 1328 | return; |
| 1329 | } |
| 1330 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1331 | static void MPOA_cache_impos_rcvd(struct k_message *msg, |
| 1332 | struct mpoa_client *mpc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | { |
| 1334 | uint16_t holding_time; |
| 1335 | eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(msg->content.eg_info.cache_id, mpc); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | holding_time = msg->content.eg_info.holding_time; |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1338 | dprintk("(%s) entry = %p, holding_time = %u\n", |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1339 | mpc->dev->name, entry, holding_time); |
| 1340 | if (entry == NULL && holding_time) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | entry = mpc->eg_ops->add_entry(msg, mpc); |
| 1342 | mpc->eg_ops->put(entry); |
| 1343 | return; |
| 1344 | } |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1345 | if (holding_time) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | mpc->eg_ops->update(entry, holding_time); |
| 1347 | return; |
| 1348 | } |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | write_lock_irq(&mpc->egress_lock); |
| 1351 | mpc->eg_ops->remove_entry(entry, mpc); |
| 1352 | write_unlock_irq(&mpc->egress_lock); |
| 1353 | |
| 1354 | mpc->eg_ops->put(entry); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | return; |
| 1357 | } |
| 1358 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1359 | static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg, |
| 1360 | struct mpoa_client *mpc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | { |
| 1362 | struct lec_priv *priv; |
| 1363 | int i, retval ; |
| 1364 | |
| 1365 | uint8_t tlv[4 + 1 + 1 + 1 + ATM_ESA_LEN]; |
| 1366 | |
| 1367 | tlv[0] = 00; tlv[1] = 0xa0; tlv[2] = 0x3e; tlv[3] = 0x2a; /* type */ |
| 1368 | tlv[4] = 1 + 1 + ATM_ESA_LEN; /* length */ |
| 1369 | tlv[5] = 0x02; /* MPOA client */ |
| 1370 | tlv[6] = 0x00; /* number of MPS MAC addresses */ |
| 1371 | |
| 1372 | memcpy(&tlv[7], mesg->MPS_ctrl, ATM_ESA_LEN); /* MPC ctrl ATM addr */ |
| 1373 | memcpy(mpc->our_ctrl_addr, mesg->MPS_ctrl, ATM_ESA_LEN); |
| 1374 | |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1375 | dprintk("(%s) setting MPC ctrl ATM address to", |
| 1376 | mpc->dev ? mpc->dev->name : "<unknown>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | for (i = 7; i < sizeof(tlv); i++) |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1378 | dprintk_cont(" %02x", tlv[i]); |
| 1379 | dprintk_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | |
| 1381 | if (mpc->dev) { |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1382 | priv = netdev_priv(mpc->dev); |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1383 | retval = priv->lane2_ops->associate_req(mpc->dev, |
| 1384 | mpc->dev->dev_addr, |
| 1385 | tlv, sizeof(tlv)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | if (retval == 0) |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1387 | pr_info("(%s) MPOA device type TLV association failed\n", |
| 1388 | mpc->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | retval = priv->lane2_ops->resolve(mpc->dev, NULL, 1, NULL, NULL); |
| 1390 | if (retval < 0) |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1391 | pr_info("(%s) targetless LE_ARP request failed\n", |
| 1392 | mpc->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | return; |
| 1396 | } |
| 1397 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1398 | static void set_mps_mac_addr_rcvd(struct k_message *msg, |
| 1399 | struct mpoa_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | { |
| 1401 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1402 | if (client->number_of_mps_macs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | kfree(client->mps_macs); |
| 1404 | client->number_of_mps_macs = 0; |
Arnaldo Carvalho de Melo | 2afe37c | 2006-11-21 01:14:33 -0200 | [diff] [blame] | 1405 | client->mps_macs = kmemdup(msg->MPS_ctrl, ETH_ALEN, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | if (client->mps_macs == NULL) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1407 | pr_info("out of memory\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | return; |
| 1409 | } |
| 1410 | client->number_of_mps_macs = 1; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | return; |
| 1413 | } |
| 1414 | |
| 1415 | /* |
| 1416 | * purge egress cache and tell daemon to 'action' (DIE, RELOAD) |
| 1417 | */ |
| 1418 | static void clean_up(struct k_message *msg, struct mpoa_client *mpc, int action) |
| 1419 | { |
| 1420 | |
| 1421 | eg_cache_entry *entry; |
| 1422 | msg->type = SND_EGRESS_PURGE; |
| 1423 | |
| 1424 | |
| 1425 | /* FIXME: This knows too much of the cache structure */ |
| 1426 | read_lock_irq(&mpc->egress_lock); |
| 1427 | entry = mpc->eg_cache; |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1428 | while (entry != NULL) { |
| 1429 | msg->content.eg_info = entry->ctrl_info; |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1430 | dprintk("cache_id %u\n", entry->ctrl_info.cache_id); |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1431 | msg_to_mpoad(msg, mpc); |
| 1432 | entry = entry->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | } |
| 1434 | read_unlock_irq(&mpc->egress_lock); |
| 1435 | |
| 1436 | msg->type = action; |
| 1437 | msg_to_mpoad(msg, mpc); |
| 1438 | return; |
| 1439 | } |
| 1440 | |
| 1441 | static void mpc_timer_refresh(void) |
| 1442 | { |
| 1443 | mpc_timer.expires = jiffies + (MPC_P2 * HZ); |
| 1444 | mpc_timer.data = mpc_timer.expires; |
| 1445 | mpc_timer.function = mpc_cache_check; |
| 1446 | add_timer(&mpc_timer); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | return; |
| 1449 | } |
| 1450 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1451 | static void mpc_cache_check(unsigned long checking_time) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | { |
| 1453 | struct mpoa_client *mpc = mpcs; |
| 1454 | static unsigned long previous_resolving_check_time; |
| 1455 | static unsigned long previous_refresh_time; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1456 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1457 | while (mpc != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | mpc->in_ops->clear_count(mpc); |
| 1459 | mpc->eg_ops->clear_expired(mpc); |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1460 | if (checking_time - previous_resolving_check_time > |
| 1461 | mpc->parameters.mpc_p4 * HZ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | mpc->in_ops->check_resolving(mpc); |
| 1463 | previous_resolving_check_time = checking_time; |
| 1464 | } |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1465 | if (checking_time - previous_refresh_time > |
| 1466 | mpc->parameters.mpc_p5 * HZ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | mpc->in_ops->refresh(mpc); |
| 1468 | previous_refresh_time = checking_time; |
| 1469 | } |
| 1470 | mpc = mpc->next; |
| 1471 | } |
| 1472 | mpc_timer_refresh(); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 1473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | return; |
| 1475 | } |
| 1476 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1477 | static int atm_mpoa_ioctl(struct socket *sock, unsigned int cmd, |
| 1478 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | { |
| 1480 | int err = 0; |
| 1481 | struct atm_vcc *vcc = ATM_SD(sock); |
| 1482 | |
| 1483 | if (cmd != ATMMPC_CTRL && cmd != ATMMPC_DATA) |
| 1484 | return -ENOIOCTLCMD; |
| 1485 | |
| 1486 | if (!capable(CAP_NET_ADMIN)) |
| 1487 | return -EPERM; |
| 1488 | |
| 1489 | switch (cmd) { |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1490 | case ATMMPC_CTRL: |
| 1491 | err = atm_mpoa_mpoad_attach(vcc, (int)arg); |
| 1492 | if (err >= 0) |
| 1493 | sock->state = SS_CONNECTED; |
| 1494 | break; |
| 1495 | case ATMMPC_DATA: |
| 1496 | err = atm_mpoa_vcc_attach(vcc, (void __user *)arg); |
| 1497 | break; |
| 1498 | default: |
| 1499 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | } |
| 1501 | return err; |
| 1502 | } |
| 1503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | static struct atm_ioctl atm_ioctl_ops = { |
| 1505 | .owner = THIS_MODULE, |
| 1506 | .ioctl = atm_mpoa_ioctl, |
| 1507 | }; |
| 1508 | |
| 1509 | static __init int atm_mpoa_init(void) |
| 1510 | { |
| 1511 | register_atm_ioctl(&atm_ioctl_ops); |
| 1512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | if (mpc_proc_init() != 0) |
Joe Perches | 9982446 | 2010-01-26 11:40:00 +0000 | [diff] [blame] | 1514 | pr_info("failed to initialize /proc/mpoa\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | |
Joe Perches | 5710044 | 2010-01-26 11:40:09 +0000 | [diff] [blame] | 1516 | pr_info("mpc.c: " __DATE__ " " __TIME__ " initialized\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | |
| 1518 | return 0; |
| 1519 | } |
| 1520 | |
| 1521 | static void __exit atm_mpoa_cleanup(void) |
| 1522 | { |
| 1523 | struct mpoa_client *mpc, *tmp; |
| 1524 | struct atm_mpoa_qos *qos, *nextqos; |
| 1525 | struct lec_priv *priv; |
| 1526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | mpc_proc_clean(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | |
| 1529 | del_timer(&mpc_timer); |
| 1530 | unregister_netdevice_notifier(&mpoa_notifier); |
| 1531 | deregister_atm_ioctl(&atm_ioctl_ops); |
| 1532 | |
| 1533 | mpc = mpcs; |
| 1534 | mpcs = NULL; |
| 1535 | while (mpc != NULL) { |
| 1536 | tmp = mpc->next; |
| 1537 | if (mpc->dev != NULL) { |
| 1538 | stop_mpc(mpc); |
Wang Chen | 524ad0a | 2008-11-12 23:39:10 -0800 | [diff] [blame] | 1539 | priv = netdev_priv(mpc->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | if (priv->lane2_ops != NULL) |
| 1541 | priv->lane2_ops->associate_indicator = NULL; |
| 1542 | } |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1543 | ddprintk("about to clear caches\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | mpc->in_ops->destroy_cache(mpc); |
| 1545 | mpc->eg_ops->destroy_cache(mpc); |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1546 | ddprintk("caches cleared\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | kfree(mpc->mps_macs); |
| 1548 | memset(mpc, 0, sizeof(struct mpoa_client)); |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1549 | ddprintk("about to kfree %p\n", mpc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | kfree(mpc); |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1551 | ddprintk("next mpc is at %p\n", tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | mpc = tmp; |
| 1553 | } |
| 1554 | |
| 1555 | qos = qos_head; |
| 1556 | qos_head = NULL; |
| 1557 | while (qos != NULL) { |
| 1558 | nextqos = qos->next; |
Joe Perches | b50c2ea | 2010-01-26 11:40:20 +0000 | [diff] [blame] | 1559 | dprintk("freeing qos entry %p\n", qos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | kfree(qos); |
| 1561 | qos = nextqos; |
| 1562 | } |
| 1563 | |
| 1564 | return; |
| 1565 | } |
| 1566 | |
| 1567 | module_init(atm_mpoa_init); |
| 1568 | module_exit(atm_mpoa_cleanup); |
| 1569 | |
| 1570 | MODULE_LICENSE("GPL"); |