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