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