blob: 55dba22e44b3b469b2122c86cf5cd86a577d3c53 [file] [log] [blame]
Joe Perches99824462010-01-26 11:40:00 +00001#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
2
Linus Torvalds1da177e2005-04-16 15:20:36 -07003#include <linux/kernel.h>
4#include <linux/string.h>
5#include <linux/timer.h>
6#include <linux/init.h>
7#include <linux/bitops.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -08008#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/seq_file.h>
10
11/* We are an ethernet device */
12#include <linux/if_ether.h>
13#include <linux/netdevice.h>
14#include <linux/etherdevice.h>
15#include <net/sock.h>
16#include <linux/skbuff.h>
17#include <linux/ip.h>
Joe Perches57100442010-01-26 11:40:09 +000018#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/byteorder.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <net/checksum.h> /* for ip_fast_csum() */
21#include <net/arp.h>
22#include <net/dst.h>
23#include <linux/proc_fs.h>
24
25/* And atm device */
26#include <linux/atmdev.h>
27#include <linux/atmlec.h>
28#include <linux/atmmpc.h>
29/* Modular too */
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/module.h>
31
32#include "lec.h"
33#include "mpc.h"
34#include "resources.h"
35
36/*
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +090037 * mpc.c: Implementation of MPOA client kernel part
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 */
39
40#if 0
Joe Perches57100442010-01-26 11:40:09 +000041#define dprintk(format, args...) printk(KERN_DEBUG format, ##args) /* debug */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#else
Joe Perches57100442010-01-26 11:40:09 +000043#define dprintk(format, args...) \
44 do { if (0) printk(KERN_DEBUG format, ##args); } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#endif
46
47#if 0
Joe Perches57100442010-01-26 11:40:09 +000048#define ddprintk printk(KERN_DEBUG format, ##args) /* more debug */
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#else
Joe Perches57100442010-01-26 11:40:09 +000050#define ddprintk(format, args...) \
51 do { if (0) printk(KERN_DEBUG format, ##args); } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#endif
53
54
55
56#define MPOA_TAG_LEN 4
57
58/* mpc_daemon -> kernel */
Joe Perches57100442010-01-26 11:40:09 +000059static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc);
61static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc);
62static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc);
63static void mps_death(struct k_message *msg, struct mpoa_client *mpc);
Joe Perches57100442010-01-26 11:40:09 +000064static void clean_up(struct k_message *msg, struct mpoa_client *mpc,
65 int action);
66static void MPOA_cache_impos_rcvd(struct k_message *msg,
67 struct mpoa_client *mpc);
68static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg,
69 struct mpoa_client *mpc);
70static void set_mps_mac_addr_rcvd(struct k_message *mesg,
71 struct mpoa_client *mpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
David Howellscba5cbd2008-07-30 16:31:46 -070073static const uint8_t *copy_macs(struct mpoa_client *mpc,
74 const uint8_t *router_mac,
75 const uint8_t *tlvs, uint8_t mps_macs,
76 uint8_t device_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry);
78
David Howellscba5cbd2008-07-30 16:31:46 -070079static void send_set_mps_ctrl_addr(const char *addr, struct mpoa_client *mpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080static void mpoad_close(struct atm_vcc *vcc);
81static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb);
82
83static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb);
Stephen Hemminger3c805a22009-08-31 19:50:42 +000084static netdev_tx_t mpc_send_packet(struct sk_buff *skb,
Joe Perches57100442010-01-26 11:40:09 +000085 struct net_device *dev);
86static int mpoa_event_listener(struct notifier_block *mpoa_notifier,
87 unsigned long event, void *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static void mpc_timer_refresh(void);
Joe Perches57100442010-01-26 11:40:09 +000089static void mpc_cache_check(unsigned long checking_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91static struct llc_snap_hdr llc_snap_mpoa_ctrl = {
92 0xaa, 0xaa, 0x03,
93 {0x00, 0x00, 0x5e},
94 {0x00, 0x03} /* For MPOA control PDUs */
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +090095};
Linus Torvalds1da177e2005-04-16 15:20:36 -070096static struct llc_snap_hdr llc_snap_mpoa_data = {
97 0xaa, 0xaa, 0x03,
98 {0x00, 0x00, 0x00},
99 {0x08, 0x00} /* This is for IP PDUs only */
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900100};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101static struct llc_snap_hdr llc_snap_mpoa_data_tagged = {
102 0xaa, 0xaa, 0x03,
103 {0x00, 0x00, 0x00},
104 {0x88, 0x4c} /* This is for tagged data PDUs */
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900105};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107static struct notifier_block mpoa_notifier = {
108 mpoa_event_listener,
109 NULL,
110 0
111};
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113struct mpoa_client *mpcs = NULL; /* FIXME */
114static struct atm_mpoa_qos *qos_head = NULL;
Ingo Molnar8d06afa2005-09-09 13:10:40 -0700115static DEFINE_TIMER(mpc_timer, NULL, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117
118static struct mpoa_client *find_mpc_by_itfnum(int itf)
119{
120 struct mpoa_client *mpc;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 mpc = mpcs; /* our global linked list */
123 while (mpc != NULL) {
124 if (mpc->dev_num == itf)
125 return mpc;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900126 mpc = mpc->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128
129 return NULL; /* not found */
130}
131
132static struct mpoa_client *find_mpc_by_vcc(struct atm_vcc *vcc)
133{
134 struct mpoa_client *mpc;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 mpc = mpcs; /* our global linked list */
137 while (mpc != NULL) {
138 if (mpc->mpoad_vcc == vcc)
139 return mpc;
140 mpc = mpc->next;
141 }
142
143 return NULL; /* not found */
144}
145
146static struct mpoa_client *find_mpc_by_lec(struct net_device *dev)
147{
148 struct mpoa_client *mpc;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 mpc = mpcs; /* our global linked list */
151 while (mpc != NULL) {
152 if (mpc->dev == dev)
153 return mpc;
154 mpc = mpc->next;
155 }
156
157 return NULL; /* not found */
158}
159
160/*
161 * Functions for managing QoS list
162 */
163
164/*
165 * Overwrites the old entry or makes a new one.
166 */
Al Viro30d492d2006-11-14 21:11:29 -0800167struct atm_mpoa_qos *atm_mpoa_add_qos(__be32 dst_ip, struct atm_qos *qos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
169 struct atm_mpoa_qos *entry;
170
171 entry = atm_mpoa_search_qos(dst_ip);
172 if (entry != NULL) {
173 entry->qos = *qos;
174 return entry;
175 }
176
177 entry = kmalloc(sizeof(struct atm_mpoa_qos), GFP_KERNEL);
178 if (entry == NULL) {
Joe Perches57100442010-01-26 11:40:09 +0000179 pr_info("mpoa: out of memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 return entry;
181 }
182
183 entry->ipaddr = dst_ip;
184 entry->qos = *qos;
185
186 entry->next = qos_head;
187 qos_head = entry;
188
189 return entry;
190}
191
Al Viro30d492d2006-11-14 21:11:29 -0800192struct atm_mpoa_qos *atm_mpoa_search_qos(__be32 dst_ip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
194 struct atm_mpoa_qos *qos;
195
196 qos = qos_head;
Joe Perches57100442010-01-26 11:40:09 +0000197 while (qos) {
198 if (qos->ipaddr == dst_ip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 qos = qos->next;
201 }
202
203 return qos;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900204}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206/*
207 * Returns 0 for failure
208 */
209int atm_mpoa_delete_qos(struct atm_mpoa_qos *entry)
210{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 struct atm_mpoa_qos *curr;
212
Joe Perches57100442010-01-26 11:40:09 +0000213 if (entry == NULL)
214 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 if (entry == qos_head) {
216 qos_head = qos_head->next;
217 kfree(entry);
218 return 1;
219 }
220
221 curr = qos_head;
222 while (curr != NULL) {
223 if (curr->next == entry) {
224 curr->next = entry->next;
225 kfree(entry);
226 return 1;
227 }
228 curr = curr->next;
229 }
230
231 return 0;
232}
233
234/* this is buggered - we need locking for qos_head */
235void atm_mpoa_disp_qos(struct seq_file *m)
236{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 struct atm_mpoa_qos *qos;
238
239 qos = qos_head;
240 seq_printf(m, "QoS entries for shortcuts:\n");
241 seq_printf(m, "IP address\n TX:max_pcr pcr min_pcr max_cdv max_sdu\n RX:max_pcr pcr min_pcr max_cdv max_sdu\n");
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 while (qos != NULL) {
Harvey Harrison21454aa2008-10-31 00:54:56 -0700244 seq_printf(m, "%pI4\n %-7d %-7d %-7d %-7d %-7d\n %-7d %-7d %-7d %-7d %-7d\n",
Joe Perches57100442010-01-26 11:40:09 +0000245 &qos->ipaddr,
246 qos->qos.txtp.max_pcr,
247 qos->qos.txtp.pcr,
248 qos->qos.txtp.min_pcr,
249 qos->qos.txtp.max_cdv,
250 qos->qos.txtp.max_sdu,
251 qos->qos.rxtp.max_pcr,
252 qos->qos.rxtp.pcr,
253 qos->qos.rxtp.min_pcr,
254 qos->qos.rxtp.max_cdv,
255 qos->qos.rxtp.max_sdu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 qos = qos->next;
257 }
258}
259
260static struct net_device *find_lec_by_itfnum(int itf)
261{
262 struct net_device *dev;
263 char name[IFNAMSIZ];
264
265 sprintf(name, "lec%d", itf);
Eric W. Biederman881d9662007-09-17 11:56:21 -0700266 dev = dev_get_by_name(&init_net, name);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 return dev;
269}
270
271static struct mpoa_client *alloc_mpc(void)
272{
273 struct mpoa_client *mpc;
274
Joe Perches57100442010-01-26 11:40:09 +0000275 mpc = kzalloc(sizeof(struct mpoa_client), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 if (mpc == NULL)
277 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 rwlock_init(&mpc->ingress_lock);
279 rwlock_init(&mpc->egress_lock);
280 mpc->next = mpcs;
281 atm_mpoa_init_cache(mpc);
282
283 mpc->parameters.mpc_p1 = MPC_P1;
284 mpc->parameters.mpc_p2 = MPC_P2;
Joe Perches57100442010-01-26 11:40:09 +0000285 memset(mpc->parameters.mpc_p3, 0, sizeof(mpc->parameters.mpc_p3));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 mpc->parameters.mpc_p4 = MPC_P4;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900287 mpc->parameters.mpc_p5 = MPC_P5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 mpc->parameters.mpc_p6 = MPC_P6;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 mpcs = mpc;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 return mpc;
293}
294
295/*
296 *
297 * start_mpc() puts the MPC on line. All the packets destined
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900298 * to the lec underneath us are now being monitored and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 * shortcuts will be established.
300 *
301 */
302static void start_mpc(struct mpoa_client *mpc, struct net_device *dev)
303{
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900304
305 dprintk("mpoa: (%s) start_mpc:\n", mpc->dev->name);
Stephen Hemminger788dee02009-03-20 19:35:28 +0000306 if (!dev->netdev_ops)
Joe Perches57100442010-01-26 11:40:09 +0000307 pr_info("(%s) not starting\n", dev->name);
Stephen Hemminger788dee02009-03-20 19:35:28 +0000308 else {
309 mpc->old_ops = dev->netdev_ops;
310 mpc->new_ops = *mpc->old_ops;
311 mpc->new_ops.ndo_start_xmit = mpc_send_packet;
312 dev->netdev_ops = &mpc->new_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
315
316static void stop_mpc(struct mpoa_client *mpc)
317{
Stephen Hemminger788dee02009-03-20 19:35:28 +0000318 struct net_device *dev = mpc->dev;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900319 dprintk("mpoa: (%s) stop_mpc:", mpc->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 /* Lets not nullify lec device's dev->hard_start_xmit */
Stephen Hemminger788dee02009-03-20 19:35:28 +0000322 if (dev->netdev_ops != &mpc->new_ops) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 dprintk(" mpc already stopped, not fatal\n");
324 return;
325 }
326 dprintk("\n");
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900327
Stephen Hemminger788dee02009-03-20 19:35:28 +0000328 dev->netdev_ops = mpc->old_ops;
329 mpc->old_ops = NULL;
330
331 /* close_shortcuts(mpc); ??? FIXME */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
333
334static const char *mpoa_device_type_string(char type) __attribute__ ((unused));
335
336static const char *mpoa_device_type_string(char type)
337{
Joe Perches57100442010-01-26 11:40:09 +0000338 switch (type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 case NON_MPOA:
340 return "non-MPOA device";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 case MPS:
342 return "MPS";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 case MPC:
344 return "MPC";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 case MPS_AND_MPC:
346 return "both MPS and MPC";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 }
348
Joe Perches57100442010-01-26 11:40:09 +0000349 return "unspecified (non-MPOA) device";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
352/*
Wang Chenb74ca3a2008-12-08 01:14:16 -0800353 * lec device calls this via its netdev_priv(dev)->lane2_ops
354 * ->associate_indicator() when it sees a TLV in LE_ARP packet.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 * We fill in the pointer above when we see a LANE2 lec initializing
356 * See LANE2 spec 3.1.5
357 *
358 * Quite a big and ugly function but when you look at it
359 * all it does is to try to locate and parse MPOA Device
360 * Type TLV.
361 * We give our lec a pointer to this function and when the
362 * lec sees a TLV it uses the pointer to call this function.
363 *
364 */
David Howellscba5cbd2008-07-30 16:31:46 -0700365static void lane2_assoc_ind(struct net_device *dev, const u8 *mac_addr,
366 const u8 *tlvs, u32 sizeoftlvs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
368 uint32_t type;
369 uint8_t length, mpoa_device_type, number_of_mps_macs;
David Howellscba5cbd2008-07-30 16:31:46 -0700370 const uint8_t *end_of_tlvs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 struct mpoa_client *mpc;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 mpoa_device_type = number_of_mps_macs = 0; /* silence gcc */
374 dprintk("mpoa: (%s) lane2_assoc_ind: received TLV(s), ", dev->name);
375 dprintk("total length of all TLVs %d\n", sizeoftlvs);
376 mpc = find_mpc_by_lec(dev); /* Sampo-Fix: moved here from below */
377 if (mpc == NULL) {
Joe Perches57100442010-01-26 11:40:09 +0000378 pr_info("(%s) no mpc\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 return;
380 }
381 end_of_tlvs = tlvs + sizeoftlvs;
382 while (end_of_tlvs - tlvs >= 5) {
Joe Perches57100442010-01-26 11:40:09 +0000383 type = ((tlvs[0] << 24) | (tlvs[1] << 16) |
384 (tlvs[2] << 8) | tlvs[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 length = tlvs[4];
386 tlvs += 5;
387 dprintk(" type 0x%x length %02x\n", type, length);
388 if (tlvs + length > end_of_tlvs) {
Joe Perches57100442010-01-26 11:40:09 +0000389 pr_info("TLV value extends past its buffer, aborting parse\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 return;
391 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 if (type == 0) {
Joe Perches57100442010-01-26 11:40:09 +0000394 pr_info("mpoa: (%s) TLV type was 0, returning\n",
395 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 return;
397 }
398
399 if (type != TLV_MPOA_DEVICE_TYPE) {
400 tlvs += length;
401 continue; /* skip other TLVs */
402 }
403 mpoa_device_type = *tlvs++;
404 number_of_mps_macs = *tlvs++;
Joe Perches57100442010-01-26 11:40:09 +0000405 dprintk("mpoa: (%s) MPOA device type '%s', ",
406 dev->name, mpoa_device_type_string(mpoa_device_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 if (mpoa_device_type == MPS_AND_MPC &&
408 length < (42 + number_of_mps_macs*ETH_ALEN)) { /* :) */
Joe Perches57100442010-01-26 11:40:09 +0000409 pr_info("(%s) short MPOA Device Type TLV\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 dev->name);
411 continue;
412 }
Joe Perches57100442010-01-26 11:40:09 +0000413 if ((mpoa_device_type == MPS || mpoa_device_type == MPC) &&
414 length < 22 + number_of_mps_macs*ETH_ALEN) {
415 pr_info("(%s) short MPOA Device Type TLV\n", dev->name);
416 continue;
417 }
418 if (mpoa_device_type != MPS &&
419 mpoa_device_type != MPS_AND_MPC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 dprintk("ignoring non-MPS device\n");
Joe Perches57100442010-01-26 11:40:09 +0000421 if (mpoa_device_type == MPC)
422 tlvs += 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 continue; /* we are only interested in MPSs */
424 }
Joe Perches57100442010-01-26 11:40:09 +0000425 if (number_of_mps_macs == 0 &&
426 mpoa_device_type == MPS_AND_MPC) {
427 pr_info("(%s) MPS_AND_MPC has zero MACs\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 continue; /* someone should read the spec */
429 }
430 dprintk("this MPS has %d MAC addresses\n", number_of_mps_macs);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900431
Joe Perches57100442010-01-26 11:40:09 +0000432 /*
433 * ok, now we can go and tell our daemon
434 * the control address of MPS
435 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 send_set_mps_ctrl_addr(tlvs, mpc);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900437
Joe Perches57100442010-01-26 11:40:09 +0000438 tlvs = copy_macs(mpc, mac_addr, tlvs,
439 number_of_mps_macs, mpoa_device_type);
440 if (tlvs == NULL)
441 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 }
443 if (end_of_tlvs - tlvs != 0)
Joe Perches57100442010-01-26 11:40:09 +0000444 pr_info("(%s) ignoring %Zd bytes of trailing TLV garbage\n",
445 dev->name, end_of_tlvs - tlvs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 return;
447}
448
449/*
450 * Store at least advertizing router's MAC address
451 * plus the possible MAC address(es) to mpc->mps_macs.
452 * For a freshly allocated MPOA client mpc->mps_macs == 0.
453 */
David Howellscba5cbd2008-07-30 16:31:46 -0700454static const uint8_t *copy_macs(struct mpoa_client *mpc,
455 const uint8_t *router_mac,
456 const uint8_t *tlvs, uint8_t mps_macs,
457 uint8_t device_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
459 int num_macs;
460 num_macs = (mps_macs > 1) ? mps_macs : 1;
461
462 if (mpc->number_of_mps_macs != num_macs) { /* need to reallocate? */
Joe Perches57100442010-01-26 11:40:09 +0000463 if (mpc->number_of_mps_macs != 0)
464 kfree(mpc->mps_macs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 mpc->number_of_mps_macs = 0;
Joe Perches57100442010-01-26 11:40:09 +0000466 mpc->mps_macs = kmalloc(num_macs * ETH_ALEN, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 if (mpc->mps_macs == NULL) {
Joe Perches57100442010-01-26 11:40:09 +0000468 pr_info("(%s) out of mem\n", mpc->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 return NULL;
470 }
471 }
472 memcpy(mpc->mps_macs, router_mac, ETH_ALEN);
473 tlvs += 20; if (device_type == MPS_AND_MPC) tlvs += 20;
474 if (mps_macs > 0)
475 memcpy(mpc->mps_macs, tlvs, mps_macs*ETH_ALEN);
476 tlvs += mps_macs*ETH_ALEN;
477 mpc->number_of_mps_macs = num_macs;
478
479 return tlvs;
480}
481
482static int send_via_shortcut(struct sk_buff *skb, struct mpoa_client *mpc)
483{
484 in_cache_entry *entry;
485 struct iphdr *iph;
486 char *buff;
Al Viro30d492d2006-11-14 21:11:29 -0800487 __be32 ipaddr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489 static struct {
490 struct llc_snap_hdr hdr;
Al Viro30d492d2006-11-14 21:11:29 -0800491 __be32 tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 } tagged_llc_snap_hdr = {
493 {0xaa, 0xaa, 0x03, {0x00, 0x00, 0x00}, {0x88, 0x4c}},
494 0
495 };
496
497 buff = skb->data + mpc->dev->hard_header_len;
498 iph = (struct iphdr *)buff;
499 ipaddr = iph->daddr;
500
Joe Perches57100442010-01-26 11:40:09 +0000501 ddprintk("mpoa: (%s) send_via_shortcut: ipaddr 0x%x\n",
502 mpc->dev->name, ipaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504 entry = mpc->in_ops->get(ipaddr, mpc);
505 if (entry == NULL) {
506 entry = mpc->in_ops->add_entry(ipaddr, mpc);
Joe Perches57100442010-01-26 11:40:09 +0000507 if (entry != NULL)
508 mpc->in_ops->put(entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 return 1;
510 }
Joe Perches57100442010-01-26 11:40:09 +0000511 /* threshold not exceeded or VCC not ready */
512 if (mpc->in_ops->cache_hit(entry, mpc) != OPEN) {
513 ddprintk("mpoa: (%s) send_via_shortcut: cache_hit: returns != OPEN\n",
514 mpc->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 mpc->in_ops->put(entry);
516 return 1;
517 }
518
Joe Perches57100442010-01-26 11:40:09 +0000519 ddprintk("mpoa: (%s) send_via_shortcut: using shortcut\n",
520 mpc->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 /* MPOA spec A.1.4, MPOA client must decrement IP ttl at least by one */
522 if (iph->ttl <= 1) {
Joe Perches57100442010-01-26 11:40:09 +0000523 ddprintk("mpoa: (%s) send_via_shortcut: IP ttl = %u, using LANE\n",
524 mpc->dev->name, iph->ttl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 mpc->in_ops->put(entry);
526 return 1;
527 }
528 iph->ttl--;
529 iph->check = 0;
530 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
531
532 if (entry->ctrl_info.tag != 0) {
Joe Perches57100442010-01-26 11:40:09 +0000533 ddprintk("mpoa: (%s) send_via_shortcut: adding tag 0x%x\n",
534 mpc->dev->name, entry->ctrl_info.tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 tagged_llc_snap_hdr.tag = entry->ctrl_info.tag;
Joe Perches57100442010-01-26 11:40:09 +0000536 skb_pull(skb, ETH_HLEN); /* get rid of Eth header */
537 skb_push(skb, sizeof(tagged_llc_snap_hdr));
538 /* add LLC/SNAP header */
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300539 skb_copy_to_linear_data(skb, &tagged_llc_snap_hdr,
540 sizeof(tagged_llc_snap_hdr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 } else {
Joe Perches57100442010-01-26 11:40:09 +0000542 skb_pull(skb, ETH_HLEN); /* get rid of Eth header */
543 skb_push(skb, sizeof(struct llc_snap_hdr));
544 /* add LLC/SNAP header + tag */
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300545 skb_copy_to_linear_data(skb, &llc_snap_mpoa_data,
546 sizeof(struct llc_snap_hdr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 }
548
549 atomic_add(skb->truesize, &sk_atm(entry->shortcut)->sk_wmem_alloc);
550 ATM_SKB(skb)->atm_options = entry->shortcut->atm_options;
551 entry->shortcut->send(entry->shortcut, skb);
552 entry->packets_fwded++;
553 mpc->in_ops->put(entry);
554
555 return 0;
556}
557
558/*
559 * Probably needs some error checks and locking, not sure...
560 */
Stephen Hemminger3c805a22009-08-31 19:50:42 +0000561static netdev_tx_t mpc_send_packet(struct sk_buff *skb,
562 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 struct mpoa_client *mpc;
565 struct ethhdr *eth;
566 int i = 0;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 mpc = find_mpc_by_lec(dev); /* this should NEVER fail */
Joe Perches57100442010-01-26 11:40:09 +0000569 if (mpc == NULL) {
570 pr_info("(%s) no MPC found\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 goto non_ip;
572 }
573
574 eth = (struct ethhdr *)skb->data;
575 if (eth->h_proto != htons(ETH_P_IP))
576 goto non_ip; /* Multi-Protocol Over ATM :-) */
577
Herbert Xu1c9b7aa2008-01-09 03:51:59 -0800578 /* Weed out funny packets (e.g., AF_PACKET or raw). */
579 if (skb->len < ETH_HLEN + sizeof(struct iphdr))
580 goto non_ip;
581 skb_set_network_header(skb, ETH_HLEN);
582 if (skb->len < ETH_HLEN + ip_hdr(skb)->ihl * 4 || ip_hdr(skb)->ihl < 5)
583 goto non_ip;
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 while (i < mpc->number_of_mps_macs) {
Joe Perches57100442010-01-26 11:40:09 +0000586 if (!compare_ether_addr(eth->h_dest,
587 (mpc->mps_macs + i*ETH_ALEN)))
588 if (send_via_shortcut(skb, mpc) == 0) /* try shortcut */
589 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 i++;
591 }
592
Joe Perches57100442010-01-26 11:40:09 +0000593non_ip:
594 return mpc->old_ops->ndo_start_xmit(skb, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
596
597static int atm_mpoa_vcc_attach(struct atm_vcc *vcc, void __user *arg)
598{
599 int bytes_left;
600 struct mpoa_client *mpc;
601 struct atmmpc_ioc ioc_data;
602 in_cache_entry *in_entry;
Al Viro30d492d2006-11-14 21:11:29 -0800603 __be32 ipaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmmpc_ioc));
606 if (bytes_left != 0) {
Joe Perches57100442010-01-26 11:40:09 +0000607 pr_info("mpoa:Short read (missed %d bytes) from userland\n",
608 bytes_left);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 return -EFAULT;
610 }
611 ipaddr = ioc_data.ipaddr;
612 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF)
613 return -EINVAL;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 mpc = find_mpc_by_itfnum(ioc_data.dev_num);
616 if (mpc == NULL)
617 return -EINVAL;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 if (ioc_data.type == MPC_SOCKET_INGRESS) {
620 in_entry = mpc->in_ops->get(ipaddr, mpc);
Joe Perches57100442010-01-26 11:40:09 +0000621 if (in_entry == NULL ||
622 in_entry->entry_state < INGRESS_RESOLVED) {
623 pr_info("(%s) did not find RESOLVED entry from ingress cache\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 mpc->dev->name);
Joe Perches57100442010-01-26 11:40:09 +0000625 if (in_entry != NULL)
626 mpc->in_ops->put(in_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 return -EINVAL;
628 }
Joe Perches57100442010-01-26 11:40:09 +0000629 pr_info("(%s) attaching ingress SVC, entry = %pI4\n",
630 mpc->dev->name, &in_entry->ctrl_info.in_dst_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 in_entry->shortcut = vcc;
632 mpc->in_ops->put(in_entry);
633 } else {
Joe Perches57100442010-01-26 11:40:09 +0000634 pr_info("(%s) attaching egress SVC\n", mpc->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 }
636
637 vcc->proto_data = mpc->dev;
638 vcc->push = mpc_push;
639
640 return 0;
641}
642
643/*
644 *
645 */
646static void mpc_vcc_close(struct atm_vcc *vcc, struct net_device *dev)
647{
648 struct mpoa_client *mpc;
649 in_cache_entry *in_entry;
650 eg_cache_entry *eg_entry;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 mpc = find_mpc_by_lec(dev);
653 if (mpc == NULL) {
Joe Perches57100442010-01-26 11:40:09 +0000654 pr_info("(%s) close for unknown MPC\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 return;
656 }
657
658 dprintk("mpoa: (%s) mpc_vcc_close:\n", dev->name);
659 in_entry = mpc->in_ops->get_by_vcc(vcc, mpc);
660 if (in_entry) {
Harvey Harrison21454aa2008-10-31 00:54:56 -0700661 dprintk("mpoa: (%s) mpc_vcc_close: ingress SVC closed ip = %pI4\n",
Joe Perches57100442010-01-26 11:40:09 +0000662 mpc->dev->name, &in_entry->ctrl_info.in_dst_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 in_entry->shortcut = NULL;
664 mpc->in_ops->put(in_entry);
665 }
666 eg_entry = mpc->eg_ops->get_by_vcc(vcc, mpc);
667 if (eg_entry) {
Joe Perches57100442010-01-26 11:40:09 +0000668 dprintk("mpoa: (%s) mpc_vcc_close: egress SVC closed\n",
669 mpc->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 eg_entry->shortcut = NULL;
671 mpc->eg_ops->put(eg_entry);
672 }
673
674 if (in_entry == NULL && eg_entry == NULL)
Joe Perches57100442010-01-26 11:40:09 +0000675 dprintk("mpoa: (%s) mpc_vcc_close: unused vcc closed\n",
676 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
678 return;
679}
680
681static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb)
682{
683 struct net_device *dev = (struct net_device *)vcc->proto_data;
684 struct sk_buff *new_skb;
685 eg_cache_entry *eg;
686 struct mpoa_client *mpc;
Al Viro30d492d2006-11-14 21:11:29 -0800687 __be32 tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 char *tmp;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 ddprintk("mpoa: (%s) mpc_push:\n", dev->name);
691 if (skb == NULL) {
Joe Perches57100442010-01-26 11:40:09 +0000692 dprintk("mpoa: (%s) mpc_push: null skb, closing VCC\n",
693 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 mpc_vcc_close(vcc, dev);
695 return;
696 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 skb->dev = dev;
Joe Perches57100442010-01-26 11:40:09 +0000699 if (memcmp(skb->data, &llc_snap_mpoa_ctrl,
700 sizeof(struct llc_snap_hdr)) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 struct sock *sk = sk_atm(vcc);
702
Joe Perches57100442010-01-26 11:40:09 +0000703 dprintk("mpoa: (%s) mpc_push: control packet arrived\n",
704 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 /* Pass control packets to daemon */
706 skb_queue_tail(&sk->sk_receive_queue, skb);
707 sk->sk_data_ready(sk, skb->len);
708 return;
709 }
710
711 /* data coming over the shortcut */
712 atm_return(vcc, skb->truesize);
713
714 mpc = find_mpc_by_lec(dev);
715 if (mpc == NULL) {
Joe Perches57100442010-01-26 11:40:09 +0000716 pr_info("(%s) unknown MPC\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 return;
718 }
719
Joe Perches57100442010-01-26 11:40:09 +0000720 if (memcmp(skb->data, &llc_snap_mpoa_data_tagged,
721 sizeof(struct llc_snap_hdr)) == 0) { /* MPOA tagged data */
722 ddprintk("mpoa: (%s) mpc_push: tagged data packet arrived\n",
723 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Joe Perches57100442010-01-26 11:40:09 +0000725 } else if (memcmp(skb->data, &llc_snap_mpoa_data,
726 sizeof(struct llc_snap_hdr)) == 0) { /* MPOA data */
727 pr_info("(%s) Unsupported non-tagged data packet arrived. Purging\n",
728 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 dev_kfree_skb_any(skb);
730 return;
731 } else {
Joe Perches57100442010-01-26 11:40:09 +0000732 pr_info("(%s) garbage arrived, purging\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 dev_kfree_skb_any(skb);
734 return;
735 }
736
737 tmp = skb->data + sizeof(struct llc_snap_hdr);
Al Viro30d492d2006-11-14 21:11:29 -0800738 tag = *(__be32 *)tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
740 eg = mpc->eg_ops->get_by_tag(tag, mpc);
741 if (eg == NULL) {
Joe Perches57100442010-01-26 11:40:09 +0000742 pr_info("mpoa: (%s) Didn't find egress cache entry, tag = %u\n",
743 dev->name, tag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 purge_egress_shortcut(vcc, NULL);
745 dev_kfree_skb_any(skb);
746 return;
747 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 /*
750 * See if ingress MPC is using shortcut we opened as a return channel.
751 * This means we have a bi-directional vcc opened by us.
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900752 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 if (eg->shortcut == NULL) {
754 eg->shortcut = vcc;
Joe Perches57100442010-01-26 11:40:09 +0000755 pr_info("(%s) egress SVC in use\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 }
757
Joe Perches57100442010-01-26 11:40:09 +0000758 skb_pull(skb, sizeof(struct llc_snap_hdr) + sizeof(tag));
759 /* get rid of LLC/SNAP header */
760 new_skb = skb_realloc_headroom(skb, eg->ctrl_info.DH_length);
761 /* LLC/SNAP is shorter than MAC header :( */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 dev_kfree_skb_any(skb);
Joe Perches57100442010-01-26 11:40:09 +0000763 if (new_skb == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 mpc->eg_ops->put(eg);
765 return;
766 }
767 skb_push(new_skb, eg->ctrl_info.DH_length); /* add MAC header */
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300768 skb_copy_to_linear_data(new_skb, eg->ctrl_info.DLL_header,
769 eg->ctrl_info.DH_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 new_skb->protocol = eth_type_trans(new_skb, dev);
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -0700771 skb_reset_network_header(new_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700773 eg->latest_ip_addr = ip_hdr(new_skb)->saddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 eg->packets_rcvd++;
775 mpc->eg_ops->put(eg);
776
777 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
778 netif_rx(new_skb);
779
780 return;
781}
782
783static struct atmdev_ops mpc_ops = { /* only send is required */
784 .close = mpoad_close,
785 .send = msg_from_mpoad
786};
787
788static struct atm_dev mpc_dev = {
789 .ops = &mpc_ops,
790 .type = "mpc",
791 .number = 42,
Milind Arun Choudhary4ef8d0a2007-04-26 01:37:44 -0700792 .lock = __SPIN_LOCK_UNLOCKED(mpc_dev.lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 /* members not explicitly initialised will be 0 */
794};
795
Joe Perches57100442010-01-26 11:40:09 +0000796static int atm_mpoa_mpoad_attach(struct atm_vcc *vcc, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797{
798 struct mpoa_client *mpc;
799 struct lec_priv *priv;
800 int err;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900801
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 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 Hideakif7d57452007-02-09 23:24:29 +0900813
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 mpc = find_mpc_by_itfnum(arg);
815 if (mpc == NULL) {
Joe Perches57100442010-01-26 11:40:09 +0000816 dprintk("mpoa: mpoad_attach: allocating new mpc for itf %d\n",
817 arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 mpc = alloc_mpc();
819 if (mpc == NULL)
820 return -ENOMEM;
821 mpc->dev_num = arg;
Joe Perches57100442010-01-26 11:40:09 +0000822 mpc->dev = find_lec_by_itfnum(arg);
823 /* NULL if there was no lec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 }
825 if (mpc->mpoad_vcc) {
Joe Perches57100442010-01-26 11:40:09 +0000826 pr_info("mpoad is already present for itf %d\n", arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 return -EADDRINUSE;
828 }
829
830 if (mpc->dev) { /* check if the lec is LANE2 capable */
Wang Chen524ad0a2008-11-12 23:39:10 -0800831 priv = netdev_priv(mpc->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 if (priv->lane_version < 2) {
833 dev_put(mpc->dev);
834 mpc->dev = NULL;
835 } else
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900836 priv->lane2_ops->associate_indicator = lane2_assoc_ind;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 }
838
839 mpc->mpoad_vcc = vcc;
840 vcc->dev = &mpc_dev;
841 vcc_insert_socket(sk_atm(vcc));
Joe Perches57100442010-01-26 11:40:09 +0000842 set_bit(ATM_VF_META, &vcc->flags);
843 set_bit(ATM_VF_READY, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
845 if (mpc->dev) {
846 char empty[ATM_ESA_LEN];
847 memset(empty, 0, ATM_ESA_LEN);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900848
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 start_mpc(mpc, mpc->dev);
850 /* set address if mpcd e.g. gets killed and restarted.
851 * If we do not do it now we have to wait for the next LE_ARP
852 */
Joe Perches57100442010-01-26 11:40:09 +0000853 if (memcmp(mpc->mps_ctrl_addr, empty, ATM_ESA_LEN) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 send_set_mps_ctrl_addr(mpc->mps_ctrl_addr, mpc);
855 }
856
857 __module_get(THIS_MODULE);
858 return arg;
859}
860
David Howellscba5cbd2008-07-30 16:31:46 -0700861static void send_set_mps_ctrl_addr(const char *addr, struct mpoa_client *mpc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862{
863 struct k_message mesg;
864
Joe Perches57100442010-01-26 11:40:09 +0000865 memcpy(mpc->mps_ctrl_addr, addr, ATM_ESA_LEN);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900866
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 mesg.type = SET_MPS_CTRL_ADDR;
868 memcpy(mesg.MPS_ctrl, addr, ATM_ESA_LEN);
869 msg_to_mpoad(&mesg, mpc);
870
871 return;
872}
873
874static void mpoad_close(struct atm_vcc *vcc)
875{
876 struct mpoa_client *mpc;
877 struct sk_buff *skb;
878
879 mpc = find_mpc_by_vcc(vcc);
880 if (mpc == NULL) {
Joe Perches57100442010-01-26 11:40:09 +0000881 pr_info("did not find MPC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 return;
883 }
884 if (!mpc->mpoad_vcc) {
Joe Perches57100442010-01-26 11:40:09 +0000885 pr_info("close for non-present mpoad\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 return;
887 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900888
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 mpc->mpoad_vcc = NULL;
890 if (mpc->dev) {
Wang Chen524ad0a2008-11-12 23:39:10 -0800891 struct lec_priv *priv = netdev_priv(mpc->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 priv->lane2_ops->associate_indicator = NULL;
893 stop_mpc(mpc);
894 dev_put(mpc->dev);
895 }
896
897 mpc->in_ops->destroy_cache(mpc);
898 mpc->eg_ops->destroy_cache(mpc);
899
900 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) {
901 atm_return(vcc, skb->truesize);
902 kfree_skb(skb);
903 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900904
Joe Perches57100442010-01-26 11:40:09 +0000905 pr_info("(%s) going down\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 (mpc->dev) ? mpc->dev->name : "<unknown>");
907 module_put(THIS_MODULE);
908
909 return;
910}
911
912/*
913 *
914 */
915static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb)
916{
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900917
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 struct mpoa_client *mpc = find_mpc_by_vcc(vcc);
Joe Perches57100442010-01-26 11:40:09 +0000919 struct k_message *mesg = (struct k_message *)skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 if (mpc == NULL) {
Joe Perches57100442010-01-26 11:40:09 +0000923 pr_info("no mpc found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 return 0;
925 }
Joe Perches57100442010-01-26 11:40:09 +0000926 dprintk("mpoa: (%s) msg_from_mpoad:",
927 (mpc->dev) ? mpc->dev->name : "<unknown>");
928 switch (mesg->type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 case MPOA_RES_REPLY_RCVD:
930 dprintk(" mpoa_res_reply_rcvd\n");
931 MPOA_res_reply_rcvd(mesg, mpc);
932 break;
933 case MPOA_TRIGGER_RCVD:
934 dprintk(" mpoa_trigger_rcvd\n");
935 MPOA_trigger_rcvd(mesg, mpc);
936 break;
937 case INGRESS_PURGE_RCVD:
938 dprintk(" nhrp_purge_rcvd\n");
939 ingress_purge_rcvd(mesg, mpc);
940 break;
941 case EGRESS_PURGE_RCVD:
942 dprintk(" egress_purge_reply_rcvd\n");
943 egress_purge_rcvd(mesg, mpc);
944 break;
945 case MPS_DEATH:
946 dprintk(" mps_death\n");
947 mps_death(mesg, mpc);
948 break;
949 case CACHE_IMPOS_RCVD:
950 dprintk(" cache_impos_rcvd\n");
951 MPOA_cache_impos_rcvd(mesg, mpc);
952 break;
953 case SET_MPC_CTRL_ADDR:
954 dprintk(" set_mpc_ctrl_addr\n");
955 set_mpc_ctrl_addr_rcvd(mesg, mpc);
956 break;
957 case SET_MPS_MAC_ADDR:
958 dprintk(" set_mps_mac_addr\n");
959 set_mps_mac_addr_rcvd(mesg, mpc);
960 break;
961 case CLEAN_UP_AND_EXIT:
962 dprintk(" clean_up_and_exit\n");
963 clean_up(mesg, mpc, DIE);
964 break;
965 case RELOAD:
966 dprintk(" reload\n");
967 clean_up(mesg, mpc, RELOAD);
968 break;
969 case SET_MPC_PARAMS:
970 dprintk(" set_mpc_params\n");
971 mpc->parameters = mesg->content.params;
972 break;
973 default:
974 dprintk(" unknown message %d\n", mesg->type);
975 break;
976 }
977 kfree_skb(skb);
978
979 return 0;
980}
981
982/* Remember that this function may not do things that sleep */
983int msg_to_mpoad(struct k_message *mesg, struct mpoa_client *mpc)
984{
985 struct sk_buff *skb;
986 struct sock *sk;
987
988 if (mpc == NULL || !mpc->mpoad_vcc) {
Joe Perches57100442010-01-26 11:40:09 +0000989 pr_info("mesg %d to a non-existent mpoad\n", mesg->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 return -ENXIO;
991 }
992
993 skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC);
994 if (skb == NULL)
995 return -ENOMEM;
996 skb_put(skb, sizeof(struct k_message));
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300997 skb_copy_to_linear_data(skb, mesg, sizeof(*mesg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 atm_force_charge(mpc->mpoad_vcc, skb->truesize);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 sk = sk_atm(mpc->mpoad_vcc);
1001 skb_queue_tail(&sk->sk_receive_queue, skb);
1002 sk->sk_data_ready(sk, skb->len);
1003
1004 return 0;
1005}
1006
Joe Perches57100442010-01-26 11:40:09 +00001007static int mpoa_event_listener(struct notifier_block *mpoa_notifier,
1008 unsigned long event, void *dev_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009{
1010 struct net_device *dev;
1011 struct mpoa_client *mpc;
1012 struct lec_priv *priv;
1013
1014 dev = (struct net_device *)dev_ptr;
Eric W. Biedermane9dc8652007-09-12 13:02:17 +02001015
YOSHIFUJI Hideaki721499e2008-07-19 22:34:43 -07001016 if (!net_eq(dev_net(dev), &init_net))
Eric W. Biedermane9dc8652007-09-12 13:02:17 +02001017 return NOTIFY_DONE;
1018
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 if (dev->name == NULL || strncmp(dev->name, "lec", 3))
1020 return NOTIFY_DONE; /* we are only interested in lec:s */
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 switch (event) {
1023 case NETDEV_REGISTER: /* a new lec device was allocated */
Wang Chen524ad0a2008-11-12 23:39:10 -08001024 priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 if (priv->lane_version < 2)
1026 break;
1027 priv->lane2_ops->associate_indicator = lane2_assoc_ind;
1028 mpc = find_mpc_by_itfnum(priv->itfnum);
1029 if (mpc == NULL) {
1030 dprintk("mpoa: mpoa_event_listener: allocating new mpc for %s\n",
Joe Perches57100442010-01-26 11:40:09 +00001031 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 mpc = alloc_mpc();
1033 if (mpc == NULL) {
Joe Perches57100442010-01-26 11:40:09 +00001034 pr_info("no new mpc");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 break;
1036 }
1037 }
1038 mpc->dev_num = priv->itfnum;
1039 mpc->dev = dev;
1040 dev_hold(dev);
1041 dprintk("mpoa: (%s) was initialized\n", dev->name);
1042 break;
1043 case NETDEV_UNREGISTER:
1044 /* the lec device was deallocated */
1045 mpc = find_mpc_by_lec(dev);
1046 if (mpc == NULL)
1047 break;
1048 dprintk("mpoa: device (%s) was deallocated\n", dev->name);
1049 stop_mpc(mpc);
1050 dev_put(mpc->dev);
1051 mpc->dev = NULL;
1052 break;
1053 case NETDEV_UP:
1054 /* the dev was ifconfig'ed up */
1055 mpc = find_mpc_by_lec(dev);
1056 if (mpc == NULL)
1057 break;
Joe Perches57100442010-01-26 11:40:09 +00001058 if (mpc->mpoad_vcc != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 start_mpc(mpc, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 break;
1061 case NETDEV_DOWN:
1062 /* the dev was ifconfig'ed down */
1063 /* this means that the flow of packets from the
1064 * upper layer stops
1065 */
1066 mpc = find_mpc_by_lec(dev);
1067 if (mpc == NULL)
1068 break;
Joe Perches57100442010-01-26 11:40:09 +00001069 if (mpc->mpoad_vcc != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 stop_mpc(mpc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 break;
1072 case NETDEV_REBOOT:
1073 case NETDEV_CHANGE:
1074 case NETDEV_CHANGEMTU:
1075 case NETDEV_CHANGEADDR:
1076 case NETDEV_GOING_DOWN:
1077 break;
1078 default:
1079 break;
1080 }
1081
1082 return NOTIFY_DONE;
1083}
1084
1085/*
1086 * Functions which are called after a message is received from mpcd.
1087 * Msg is reused on purpose.
1088 */
1089
1090
1091static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc)
1092{
Al Viro30d492d2006-11-14 21:11:29 -08001093 __be32 dst_ip = msg->content.in_info.in_dst_ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 in_cache_entry *entry;
1095
1096 entry = mpc->in_ops->get(dst_ip, mpc);
Joe Perches57100442010-01-26 11:40:09 +00001097 if (entry == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 entry = mpc->in_ops->add_entry(dst_ip, mpc);
1099 entry->entry_state = INGRESS_RESOLVING;
1100 msg->type = SND_MPOA_RES_RQST;
1101 msg->content.in_info = entry->ctrl_info;
1102 msg_to_mpoad(msg, mpc);
1103 do_gettimeofday(&(entry->reply_wait));
1104 mpc->in_ops->put(entry);
1105 return;
1106 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001107
Joe Perches57100442010-01-26 11:40:09 +00001108 if (entry->entry_state == INGRESS_INVALID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 entry->entry_state = INGRESS_RESOLVING;
1110 msg->type = SND_MPOA_RES_RQST;
1111 msg->content.in_info = entry->ctrl_info;
1112 msg_to_mpoad(msg, mpc);
1113 do_gettimeofday(&(entry->reply_wait));
1114 mpc->in_ops->put(entry);
1115 return;
1116 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001117
Joe Perches57100442010-01-26 11:40:09 +00001118 pr_info("(%s) entry already in resolving state\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 (mpc->dev) ? mpc->dev->name : "<unknown>");
1120 mpc->in_ops->put(entry);
1121 return;
1122}
1123
1124/*
1125 * Things get complicated because we have to check if there's an egress
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001126 * shortcut with suitable traffic parameters we could use.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 */
Joe Perches57100442010-01-26 11:40:09 +00001128static void check_qos_and_open_shortcut(struct k_message *msg,
1129 struct mpoa_client *client,
1130 in_cache_entry *entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131{
Al Viro30d492d2006-11-14 21:11:29 -08001132 __be32 dst_ip = msg->content.in_info.in_dst_ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 struct atm_mpoa_qos *qos = atm_mpoa_search_qos(dst_ip);
1134 eg_cache_entry *eg_entry = client->eg_ops->get_by_src_ip(dst_ip, client);
1135
Joe Perches57100442010-01-26 11:40:09 +00001136 if (eg_entry && eg_entry->shortcut) {
1137 if (eg_entry->shortcut->qos.txtp.traffic_class &
1138 msg->qos.txtp.traffic_class &
1139 (qos ? qos->qos.txtp.traffic_class : ATM_UBR | ATM_CBR)) {
1140 if (eg_entry->shortcut->qos.txtp.traffic_class == ATM_UBR)
1141 entry->shortcut = eg_entry->shortcut;
1142 else if (eg_entry->shortcut->qos.txtp.max_pcr > 0)
1143 entry->shortcut = eg_entry->shortcut;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 }
Joe Perches57100442010-01-26 11:40:09 +00001145 if (entry->shortcut) {
Harvey Harrison21454aa2008-10-31 00:54:56 -07001146 dprintk("mpoa: (%s) using egress SVC to reach %pI4\n",
1147 client->dev->name, &dst_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 client->eg_ops->put(eg_entry);
1149 return;
1150 }
1151 }
1152 if (eg_entry != NULL)
1153 client->eg_ops->put(eg_entry);
1154
1155 /* No luck in the egress cache we must open an ingress SVC */
1156 msg->type = OPEN_INGRESS_SVC;
Joe Perches57100442010-01-26 11:40:09 +00001157 if (qos &&
1158 (qos->qos.txtp.traffic_class == msg->qos.txtp.traffic_class)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 msg->qos = qos->qos;
Joe Perches57100442010-01-26 11:40:09 +00001160 pr_info("(%s) trying to get a CBR shortcut\n",
1161 client->dev->name);
1162 } else
1163 memset(&msg->qos, 0, sizeof(struct atm_qos));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 msg_to_mpoad(msg, client);
1165 return;
1166}
1167
1168static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc)
1169{
Al Viro30d492d2006-11-14 21:11:29 -08001170 __be32 dst_ip = msg->content.in_info.in_dst_ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 in_cache_entry *entry = mpc->in_ops->get(dst_ip, mpc);
Andrew Morton1e4fd512006-06-26 00:01:58 -07001172
Harvey Harrison21454aa2008-10-31 00:54:56 -07001173 dprintk("mpoa: (%s) MPOA_res_reply_rcvd: ip %pI4\n",
1174 mpc->dev->name, &dst_ip);
Joe Perches57100442010-01-26 11:40:09 +00001175 ddprintk("mpoa: (%s) MPOA_res_reply_rcvd() entry = %p",
1176 mpc->dev->name, entry);
1177 if (entry == NULL) {
1178 pr_info("(%s) ARGH, received res. reply for an entry that doesn't exist.\n",
1179 mpc->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 return;
1181 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001182 ddprintk(" entry_state = %d ", entry->entry_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
1184 if (entry->entry_state == INGRESS_RESOLVED) {
Joe Perches57100442010-01-26 11:40:09 +00001185 pr_info("(%s) RESOLVED entry!\n", mpc->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 mpc->in_ops->put(entry);
1187 return;
1188 }
1189
1190 entry->ctrl_info = msg->content.in_info;
1191 do_gettimeofday(&(entry->tv));
1192 do_gettimeofday(&(entry->reply_wait)); /* Used in refreshing func from now on */
1193 entry->refresh_time = 0;
1194 ddprintk("entry->shortcut = %p\n", entry->shortcut);
1195
Joe Perches57100442010-01-26 11:40:09 +00001196 if (entry->entry_state == INGRESS_RESOLVING &&
1197 entry->shortcut != NULL) {
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001198 entry->entry_state = INGRESS_RESOLVED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 mpc->in_ops->put(entry);
1200 return; /* Shortcut already open... */
1201 }
1202
1203 if (entry->shortcut != NULL) {
Joe Perches57100442010-01-26 11:40:09 +00001204 pr_info("(%s) entry->shortcut != NULL, impossible!\n",
1205 mpc->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 mpc->in_ops->put(entry);
1207 return;
1208 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001209
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 check_qos_and_open_shortcut(msg, mpc, entry);
1211 entry->entry_state = INGRESS_RESOLVED;
1212 mpc->in_ops->put(entry);
1213
1214 return;
1215
1216}
1217
1218static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc)
1219{
Al Viro30d492d2006-11-14 21:11:29 -08001220 __be32 dst_ip = msg->content.in_info.in_dst_ip;
1221 __be32 mask = msg->ip_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 in_cache_entry *entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask);
1223
Joe Perches57100442010-01-26 11:40:09 +00001224 if (entry == NULL) {
1225 pr_info("(%s) purge for a non-existing entry, ip = %pI4\n",
1226 mpc->dev->name, &dst_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 return;
1228 }
1229
1230 do {
Harvey Harrison21454aa2008-10-31 00:54:56 -07001231 dprintk("mpoa: (%s) ingress_purge_rcvd: removing an ingress entry, ip = %pI4\n",
1232 mpc->dev->name, &dst_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 write_lock_bh(&mpc->ingress_lock);
1234 mpc->in_ops->remove_entry(entry, mpc);
1235 write_unlock_bh(&mpc->ingress_lock);
1236 mpc->in_ops->put(entry);
1237 entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask);
1238 } while (entry != NULL);
1239
1240 return;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001241}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
1243static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc)
1244{
Al Viro30d492d2006-11-14 21:11:29 -08001245 __be32 cache_id = msg->content.eg_info.cache_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(cache_id, mpc);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001247
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 if (entry == NULL) {
Joe Perches57100442010-01-26 11:40:09 +00001249 dprintk("mpoa: (%s) egress_purge_rcvd: purge for a non-existing entry\n",
1250 mpc->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 return;
1252 }
1253
1254 write_lock_irq(&mpc->egress_lock);
1255 mpc->eg_ops->remove_entry(entry, mpc);
1256 write_unlock_irq(&mpc->egress_lock);
1257
1258 mpc->eg_ops->put(entry);
1259
1260 return;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001261}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
1263static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry)
1264{
1265 struct sock *sk;
1266 struct k_message *purge_msg;
1267 struct sk_buff *skb;
1268
1269 dprintk("mpoa: purge_egress_shortcut: entering\n");
1270 if (vcc == NULL) {
Joe Perches57100442010-01-26 11:40:09 +00001271 pr_info("vcc == NULL\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 return;
1273 }
1274
1275 skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC);
1276 if (skb == NULL) {
Joe Perches57100442010-01-26 11:40:09 +00001277 pr_info("out of memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 return;
1279 }
1280
1281 skb_put(skb, sizeof(struct k_message));
1282 memset(skb->data, 0, sizeof(struct k_message));
1283 purge_msg = (struct k_message *)skb->data;
1284 purge_msg->type = DATA_PLANE_PURGE;
1285 if (entry != NULL)
1286 purge_msg->content.eg_info = entry->ctrl_info;
1287
1288 atm_force_charge(vcc, skb->truesize);
1289
1290 sk = sk_atm(vcc);
1291 skb_queue_tail(&sk->sk_receive_queue, skb);
1292 sk->sk_data_ready(sk, skb->len);
1293 dprintk("mpoa: purge_egress_shortcut: exiting:\n");
1294
1295 return;
1296}
1297
1298/*
1299 * Our MPS died. Tell our daemon to send NHRP data plane purge to each
1300 * of the egress shortcuts we have.
1301 */
Joe Perches57100442010-01-26 11:40:09 +00001302static void mps_death(struct k_message *msg, struct mpoa_client *mpc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303{
1304 eg_cache_entry *entry;
1305
1306 dprintk("mpoa: (%s) mps_death:\n", mpc->dev->name);
1307
Joe Perches57100442010-01-26 11:40:09 +00001308 if (memcmp(msg->MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN)) {
1309 pr_info("(%s) wrong MPS\n", mpc->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 return;
1311 }
1312
1313 /* FIXME: This knows too much of the cache structure */
1314 read_lock_irq(&mpc->egress_lock);
1315 entry = mpc->eg_cache;
1316 while (entry != NULL) {
1317 purge_egress_shortcut(entry->shortcut, entry);
1318 entry = entry->next;
1319 }
1320 read_unlock_irq(&mpc->egress_lock);
1321
1322 mpc->in_ops->destroy_cache(mpc);
1323 mpc->eg_ops->destroy_cache(mpc);
1324
1325 return;
1326}
1327
Joe Perches57100442010-01-26 11:40:09 +00001328static void MPOA_cache_impos_rcvd(struct k_message *msg,
1329 struct mpoa_client *mpc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330{
1331 uint16_t holding_time;
1332 eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(msg->content.eg_info.cache_id, mpc);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001333
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 holding_time = msg->content.eg_info.holding_time;
1335 dprintk("mpoa: (%s) MPOA_cache_impos_rcvd: entry = %p, holding_time = %u\n",
Joe Perches57100442010-01-26 11:40:09 +00001336 mpc->dev->name, entry, holding_time);
1337 if (entry == NULL && holding_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 entry = mpc->eg_ops->add_entry(msg, mpc);
1339 mpc->eg_ops->put(entry);
1340 return;
1341 }
Joe Perches57100442010-01-26 11:40:09 +00001342 if (holding_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 mpc->eg_ops->update(entry, holding_time);
1344 return;
1345 }
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001346
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 write_lock_irq(&mpc->egress_lock);
1348 mpc->eg_ops->remove_entry(entry, mpc);
1349 write_unlock_irq(&mpc->egress_lock);
1350
1351 mpc->eg_ops->put(entry);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001352
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 return;
1354}
1355
Joe Perches57100442010-01-26 11:40:09 +00001356static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg,
1357 struct mpoa_client *mpc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358{
1359 struct lec_priv *priv;
1360 int i, retval ;
1361
1362 uint8_t tlv[4 + 1 + 1 + 1 + ATM_ESA_LEN];
1363
1364 tlv[0] = 00; tlv[1] = 0xa0; tlv[2] = 0x3e; tlv[3] = 0x2a; /* type */
1365 tlv[4] = 1 + 1 + ATM_ESA_LEN; /* length */
1366 tlv[5] = 0x02; /* MPOA client */
1367 tlv[6] = 0x00; /* number of MPS MAC addresses */
1368
1369 memcpy(&tlv[7], mesg->MPS_ctrl, ATM_ESA_LEN); /* MPC ctrl ATM addr */
1370 memcpy(mpc->our_ctrl_addr, mesg->MPS_ctrl, ATM_ESA_LEN);
1371
1372 dprintk("mpoa: (%s) setting MPC ctrl ATM address to ",
Joe Perches57100442010-01-26 11:40:09 +00001373 (mpc->dev) ? mpc->dev->name : "<unknown>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 for (i = 7; i < sizeof(tlv); i++)
1375 dprintk("%02x ", tlv[i]);
1376 dprintk("\n");
1377
1378 if (mpc->dev) {
Wang Chen524ad0a2008-11-12 23:39:10 -08001379 priv = netdev_priv(mpc->dev);
Joe Perches57100442010-01-26 11:40:09 +00001380 retval = priv->lane2_ops->associate_req(mpc->dev,
1381 mpc->dev->dev_addr,
1382 tlv, sizeof(tlv));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 if (retval == 0)
Joe Perches57100442010-01-26 11:40:09 +00001384 pr_info("(%s) MPOA device type TLV association failed\n",
1385 mpc->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 retval = priv->lane2_ops->resolve(mpc->dev, NULL, 1, NULL, NULL);
1387 if (retval < 0)
Joe Perches57100442010-01-26 11:40:09 +00001388 pr_info("(%s) targetless LE_ARP request failed\n",
1389 mpc->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 }
1391
1392 return;
1393}
1394
Joe Perches57100442010-01-26 11:40:09 +00001395static void set_mps_mac_addr_rcvd(struct k_message *msg,
1396 struct mpoa_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397{
1398
Joe Perches57100442010-01-26 11:40:09 +00001399 if (client->number_of_mps_macs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 kfree(client->mps_macs);
1401 client->number_of_mps_macs = 0;
Arnaldo Carvalho de Melo2afe37c2006-11-21 01:14:33 -02001402 client->mps_macs = kmemdup(msg->MPS_ctrl, ETH_ALEN, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 if (client->mps_macs == NULL) {
Joe Perches57100442010-01-26 11:40:09 +00001404 pr_info("out of memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 return;
1406 }
1407 client->number_of_mps_macs = 1;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001408
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 return;
1410}
1411
1412/*
1413 * purge egress cache and tell daemon to 'action' (DIE, RELOAD)
1414 */
1415static void clean_up(struct k_message *msg, struct mpoa_client *mpc, int action)
1416{
1417
1418 eg_cache_entry *entry;
1419 msg->type = SND_EGRESS_PURGE;
1420
1421
1422 /* FIXME: This knows too much of the cache structure */
1423 read_lock_irq(&mpc->egress_lock);
1424 entry = mpc->eg_cache;
Joe Perches57100442010-01-26 11:40:09 +00001425 while (entry != NULL) {
1426 msg->content.eg_info = entry->ctrl_info;
1427 dprintk("mpoa: cache_id %u\n", entry->ctrl_info.cache_id);
1428 msg_to_mpoad(msg, mpc);
1429 entry = entry->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 }
1431 read_unlock_irq(&mpc->egress_lock);
1432
1433 msg->type = action;
1434 msg_to_mpoad(msg, mpc);
1435 return;
1436}
1437
1438static void mpc_timer_refresh(void)
1439{
1440 mpc_timer.expires = jiffies + (MPC_P2 * HZ);
1441 mpc_timer.data = mpc_timer.expires;
1442 mpc_timer.function = mpc_cache_check;
1443 add_timer(&mpc_timer);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001444
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 return;
1446}
1447
Joe Perches57100442010-01-26 11:40:09 +00001448static void mpc_cache_check(unsigned long checking_time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449{
1450 struct mpoa_client *mpc = mpcs;
1451 static unsigned long previous_resolving_check_time;
1452 static unsigned long previous_refresh_time;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001453
Joe Perches57100442010-01-26 11:40:09 +00001454 while (mpc != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 mpc->in_ops->clear_count(mpc);
1456 mpc->eg_ops->clear_expired(mpc);
Joe Perches57100442010-01-26 11:40:09 +00001457 if (checking_time - previous_resolving_check_time >
1458 mpc->parameters.mpc_p4 * HZ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 mpc->in_ops->check_resolving(mpc);
1460 previous_resolving_check_time = checking_time;
1461 }
Joe Perches57100442010-01-26 11:40:09 +00001462 if (checking_time - previous_refresh_time >
1463 mpc->parameters.mpc_p5 * HZ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 mpc->in_ops->refresh(mpc);
1465 previous_refresh_time = checking_time;
1466 }
1467 mpc = mpc->next;
1468 }
1469 mpc_timer_refresh();
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +09001470
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 return;
1472}
1473
Joe Perches57100442010-01-26 11:40:09 +00001474static int atm_mpoa_ioctl(struct socket *sock, unsigned int cmd,
1475 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
1477 int err = 0;
1478 struct atm_vcc *vcc = ATM_SD(sock);
1479
1480 if (cmd != ATMMPC_CTRL && cmd != ATMMPC_DATA)
1481 return -ENOIOCTLCMD;
1482
1483 if (!capable(CAP_NET_ADMIN))
1484 return -EPERM;
1485
1486 switch (cmd) {
Joe Perches57100442010-01-26 11:40:09 +00001487 case ATMMPC_CTRL:
1488 err = atm_mpoa_mpoad_attach(vcc, (int)arg);
1489 if (err >= 0)
1490 sock->state = SS_CONNECTED;
1491 break;
1492 case ATMMPC_DATA:
1493 err = atm_mpoa_vcc_attach(vcc, (void __user *)arg);
1494 break;
1495 default:
1496 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 }
1498 return err;
1499}
1500
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501static struct atm_ioctl atm_ioctl_ops = {
1502 .owner = THIS_MODULE,
1503 .ioctl = atm_mpoa_ioctl,
1504};
1505
1506static __init int atm_mpoa_init(void)
1507{
1508 register_atm_ioctl(&atm_ioctl_ops);
1509
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 if (mpc_proc_init() != 0)
Joe Perches99824462010-01-26 11:40:00 +00001511 pr_info("failed to initialize /proc/mpoa\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
Joe Perches57100442010-01-26 11:40:09 +00001513 pr_info("mpc.c: " __DATE__ " " __TIME__ " initialized\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
1515 return 0;
1516}
1517
1518static void __exit atm_mpoa_cleanup(void)
1519{
1520 struct mpoa_client *mpc, *tmp;
1521 struct atm_mpoa_qos *qos, *nextqos;
1522 struct lec_priv *priv;
1523
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 mpc_proc_clean();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526 del_timer(&mpc_timer);
1527 unregister_netdevice_notifier(&mpoa_notifier);
1528 deregister_atm_ioctl(&atm_ioctl_ops);
1529
1530 mpc = mpcs;
1531 mpcs = NULL;
1532 while (mpc != NULL) {
1533 tmp = mpc->next;
1534 if (mpc->dev != NULL) {
1535 stop_mpc(mpc);
Wang Chen524ad0a2008-11-12 23:39:10 -08001536 priv = netdev_priv(mpc->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 if (priv->lane2_ops != NULL)
1538 priv->lane2_ops->associate_indicator = NULL;
1539 }
1540 ddprintk("mpoa: cleanup_module: about to clear caches\n");
1541 mpc->in_ops->destroy_cache(mpc);
1542 mpc->eg_ops->destroy_cache(mpc);
1543 ddprintk("mpoa: cleanup_module: caches cleared\n");
1544 kfree(mpc->mps_macs);
1545 memset(mpc, 0, sizeof(struct mpoa_client));
1546 ddprintk("mpoa: cleanup_module: about to kfree %p\n", mpc);
1547 kfree(mpc);
1548 ddprintk("mpoa: cleanup_module: next mpc is at %p\n", tmp);
1549 mpc = tmp;
1550 }
1551
1552 qos = qos_head;
1553 qos_head = NULL;
1554 while (qos != NULL) {
1555 nextqos = qos->next;
1556 dprintk("mpoa: cleanup_module: freeing qos entry %p\n", qos);
1557 kfree(qos);
1558 qos = nextqos;
1559 }
1560
1561 return;
1562}
1563
1564module_init(atm_mpoa_init);
1565module_exit(atm_mpoa_cleanup);
1566
1567MODULE_LICENSE("GPL");