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