nullnet_callee.c 71.4 KB
Newer Older
1
2
#include <lcd_config/pre_hook.h>

3
4
5
6
7
8
9
10
#include <libcap.h>
#include <liblcd/liblcd.h>
#include <liblcd/sync_ipc_poll.h>
#include <liblcd/glue_cspace.h>
#include <liblcd/trampoline.h>
#include "../../glue_helper.h"
#include "../nullnet_callee.h"

11
#include <linux/hashtable.h>
12
13
#include <asm/cacheflush.h>

14
15
16
17
#include "../../rdtsc_helper.h"
#include "../../perf_counter_helper.h"
#include <linux/vmalloc.h>

18
#include "../../ipc_helper.h"
19
#include <linux/sort.h>
20
#include <linux/priv_mempool.h>
21

22
23
#include <lcd_config/post_hook.h>

Vikram Narayanan's avatar
Vikram Narayanan committed
24
#define NUM_PACKETS	(1000000)
25
26
#define VMALLOC_SZ	(NUM_PACKETS * sizeof(uint64_t))

Vikram Narayanan's avatar
Vikram Narayanan committed
27
28
29
#define CORRECTION_VALUE	44
//#define NDO_XMIT_TS

30
//#define INDIVIDUAL_MARKERS
Vikram Narayanan's avatar
Vikram Narayanan committed
31
//#define SKBC_PRIVATE_POOL
32
33
34
35
36
37
38
39
40
//#define TIMESTAMP
//#define DUMMY_RDTSC
//#define LCD_MEASUREMENT
//#define TS_SANITY_CHECK
//#define PERF_EVENTS
#ifdef TS_SANITY_CHECK
#define TIMESTAMP
#endif

Vikram Narayanan's avatar
Vikram Narayanan committed
41
42
//#define ONE_SLOT

43
44
45
46
47
48
49
50
51
#define LOOP_THRESHOLD		10000

#if defined(TIMESTAMP) && defined(LCD_MEASUREMENT)
#error "Cannot do both TIMESTAMP and LCD_MEASUREMENT"
#endif

extern bool tdiff_valid;
extern u64 tdiff_disp;

Vikram Narayanan's avatar
Vikram Narayanan committed
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifdef TS
// Events
static evt_sel_t ev[8];
static uint64_t  ev_val[8] = { 0 };

static uint32_t ev_num    = 4;
static uint8_t  ev_idx[8] = { 0x24, 0x24, 0x24, 0x24 };
static uint8_t  ev_msk[8] = { 0x1, 0x2, 0x4, 0x8 };

module_param_array( ev_idx, byte, &ev_num, 0 );
module_param_array( ev_msk, byte, NULL,    0 );
#endif

65
/* XXX: How to determine this? */
Vikram Narayanan's avatar
Vikram Narayanan committed
66
#define CPTR_HASH_BITS      8
67
68
static DEFINE_HASHTABLE(cptr_table, CPTR_HASH_BITS);

Vikram Narayanan's avatar
Vikram Narayanan committed
69
70
71
#define TID_HASH_BITS      8
static DEFINE_HASHTABLE(tid_table, TID_HASH_BITS);

72
struct rtnl_link_stats64 pkt_stats;
Vikram Narayanan's avatar
Vikram Narayanan committed
73
struct glue_cspace *c_cspace;
74
75
76
77
78
struct thc_channel *net_async;
struct cptr sync_ep;
extern struct cspace *klcd_cspace;
struct rtnl_link_ops_container *g_ops_container;
DEFINE_MUTEX(hash_lock);
79
DEFINE_SPINLOCK(hash_slock);
Vikram Narayanan's avatar
Vikram Narayanan committed
80

81
static unsigned long pool_pfn_start, pool_pfn_end;
Vikram Narayanan's avatar
Vikram Narayanan committed
82
83
84
85
86
87
88
89
90

#define NUM_CORES	32
#define NUM_THREADS	NUM_CORES

uint64_t *times_ndo_xmit[4] = {0};
u32 thread = 0;
struct ptstate_t *ptrs[NUM_THREADS] = {0};
struct rtnl_link_stats64 g_stats;
struct thc_channel *xmit_chnl;
91
priv_pool_t *pool;
92
priv_pool_t *skbc_pool;
93
94
void *pool_base = NULL;
size_t pool_size = 0;
Vikram Narayanan's avatar
Vikram Narayanan committed
95
96


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifdef TIMESTAMP
uint64_t *times_ndo_xmit = NULL;
uint64_t *times_ipc_send = NULL;
uint64_t *times_ipc_recv = NULL;
#endif
#ifdef LCD_MEASUREMENT
uint64_t *times_con_skb = NULL;
#endif
#ifdef PERF_EVENTS
uint64_t *perf1 = NULL;
uint64_t *perf2 = NULL;
uint64_t *perf3 = NULL;
uint64_t *perf4 = NULL;
#endif
struct kmem_cache *skb_c_cache = NULL;
Vikram Narayanan's avatar
Vikram Narayanan committed
112
113


Vikram Narayanan's avatar
Vikram Narayanan committed
114
int ndo_start_xmit_async_landing(struct sk_buff *first, struct net_device *dev, struct trampoline_hidden_args *hidden_args);
Vikram Narayanan's avatar
Vikram Narayanan committed
115

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#define MAX_POOLS	20

char *base_pools[MAX_POOLS];
int pool_order = 10;
int start_idx[MAX_POOLS/2] = {-1}, end_idx[MAX_POOLS/2] = {-1};
unsigned int best_diff = 0;
int best_idx = -1;
int pool_idx = 0;
struct {
	int start_idx;
	int end_idx;
	size_t size;
	bool valid;
} pools[MAX_POOLS] = { {0} };

int compare_addr(const void *a, const void *b)
{
	return *(unsigned int *)a - *(unsigned int *)b;
}

int pool_pick(void)
{
	int i;
	for (i = 0; i < MAX_POOLS; i++) {
		base_pools[i] = (char*) __get_free_pages(GFP_KERNEL | __GFP_ZERO,
	                            pool_order);
	}

	sort(base_pools, MAX_POOLS, sizeof(char*), compare_addr, NULL);

	printk("%s, sorted order:\n", __func__);
	for (i = 0; i < MAX_POOLS; i++) {
		printk("%s, got pool %p\n", __func__, base_pools[i]);
	}

	pools[pool_idx].start_idx = 0;
	pools[pool_idx].end_idx = MAX_POOLS - 1;
	pools[pool_idx].valid = true;
	for (i = 0; i < MAX_POOLS - 1; i++) {
		printk("%s, comparing pool[%d]=%llx and pool[%d]=%llx\n", __func__,
					i+1, (uint64_t)base_pools[i+1], i, (uint64_t) base_pools[i]);
		if (((uint64_t) base_pools[i+1] - (uint64_t) base_pools[i]) != ((1 << pool_order) * PAGE_SIZE)) {
			printk("%s, found discontinuity @ i %d\n", __func__, i);
			pools[pool_idx].valid = true;
			pools[pool_idx++].end_idx = i;
			pools[pool_idx].start_idx = i + 1;
		}
	}

	for (i = 0; i < MAX_POOLS; i++) {
		printk("%s, pool %d: start idx = %d | end idx = %d\n",
				__func__, i, pools[i].start_idx, pools[i].end_idx);
		if (!pools[i].valid)
			continue;
		if ((pools[i].end_idx - pools[i].start_idx + 1) > best_diff) {
			best_idx = i;
			best_diff = pools[i].end_idx - pools[i].start_idx + 1;
		}
	}
	printk("%s, best diff %u | best idx %d | start = %d | end = %d\n",
			__func__, best_diff, best_idx, pools[best_idx].start_idx, pools[best_idx].end_idx);
       	return best_idx;
}


181
182
void skb_data_pool_init(void)
{
183
184
185
186
187
	//pool = priv_pool_init(SKB_DATA_POOL, 10, SKB_DATA_SIZE);
	pool_base = base_pools[pool_pick()];
	pool_size = best_diff * ((1 << pool_order) * PAGE_SIZE);
	pool = priv_pool_init(SKB_DATA_POOL, (void*) pool_base, pool_size, 2048);

188
189
190
191
#ifdef SKBC_PRIVATE_POOL
	skbc_pool = priv_pool_init(SKB_CONTAINER_POOL, 10,
				SKB_CONTAINER_SIZE * 2);
#endif
192
193
194
195
}

void skb_data_pool_free(void)
{
196
197
198
199
200
201
	if (pool)
		priv_pool_destroy(pool);
#ifdef SKBC_PRIVATE_POOL
	if (skbc_pool)
		priv_pool_destroy(skbc_pool);
#endif
202
203
}

Vikram Narayanan's avatar
Vikram Narayanan committed
204
inline xmit_type_t check_skb_range(struct sk_buff *skb)
205
206
207
208
209
210
211
212
213
{
	unsigned long pfn;
	pfn = ((unsigned long)skb->data) >> PAGE_SHIFT;
	if (pfn >= pool_pfn_start && pfn <= pool_pfn_end) {
		WARN_ON(!skb->private);
		return SHARED_DATA_XMIT;
	} else
		return VOLUNTEER_XMIT;
}
214
215
216

int glue_nullnet_init(void)
{
217
218
219
220
221
222
223
224
225
226
227
	int ret;
	ret = glue_cap_init();
	if (ret) {
		LIBLCD_ERR("cap init");
		goto fail1;
	}
	ret = glue_cap_create(&c_cspace);
	if (ret) {
		LIBLCD_ERR("cap create");
		goto fail2;
	}
228

Vikram Narayanan's avatar
Vikram Narayanan committed
229
230
//	hash_init(cptr_table);
	hash_init(tid_table);
231
232
233
234

	/* initialize our private pool */
	skb_data_pool_init();

235
236
237
238
239
240
241
242
243
244
245
#ifdef PERF_EVENTS
	perf1 = vzalloc(NUM_PACKETS * sizeof(uint64_t));
	perf2 = vzalloc(NUM_PACKETS * sizeof(uint64_t));
	perf3 = vzalloc(NUM_PACKETS * sizeof(uint64_t));
	perf4 = vzalloc(NUM_PACKETS * sizeof(uint64_t));

	if(!perf1 || !perf2 || !perf3 || !perf4)
		LIBLCD_ERR("%s, error allocating perf memory",
						__func__);
#endif

Vikram Narayanan's avatar
Vikram Narayanan committed
246
247
248
249
250
	times_ndo_xmit[0] = vzalloc(NUM_PACKETS * sizeof(uint64_t));
	times_ndo_xmit[1] = vzalloc(NUM_PACKETS * sizeof(uint64_t));
	times_ndo_xmit[2] = vzalloc(NUM_PACKETS * sizeof(uint64_t));
	times_ndo_xmit[3] = vzalloc(NUM_PACKETS * sizeof(uint64_t));

251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#ifdef TIMESTAMP
	times_ndo_xmit = vzalloc(NUM_PACKETS * sizeof(uint64_t));
	times_ipc_send = vzalloc(NUM_PACKETS * sizeof(uint64_t));
	times_ipc_recv = vzalloc(NUM_PACKETS * sizeof(uint64_t));

	if (!times_ndo_xmit || !times_ipc_send
			|| !times_ipc_recv)
		printk("%s, cannot alloc times var\n", __func__);
#endif

#ifdef LCD_MEASUREMENT
	times_con_skb = vzalloc(NUM_PACKETS * sizeof(uint64_t));
	if (!times_con_skb)
		printk("%s, cannot alloc times var\n", __func__);
#endif

	skb_c_cache = kmem_cache_create("skb_c_cache",
				sizeof(struct sk_buff_container),
				0,
				SLAB_HWCACHE_ALIGN|SLAB_PANIC,
				NULL);
	if (!skb_c_cache)
		printk("WARN: skb_container cache not created\n");
274
275
276
277
278
279
	return 0;
fail2:
	glue_cap_exit();
fail1:
	return ret;

280
281
}

282
void glue_nullnet_exit()
283
{
Vikram Narayanan's avatar
Vikram Narayanan committed
284
	int i;
285
286
	glue_cap_destroy(c_cspace);
	glue_cap_exit();
287
288
	skb_data_pool_free();

Vikram Narayanan's avatar
Vikram Narayanan committed
289
290
291
292
293
	for (i = 0; i < 4; i++) {
		if (times_ndo_xmit[i])
			vfree(times_ndo_xmit[i]);
	}

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#ifdef TIMESTAMP
	if (times_ndo_xmit)
		vfree(times_ndo_xmit);

	if (times_ipc_send)
		vfree(times_ipc_send);

	if (times_ipc_recv)
		vfree(times_ipc_recv);
#endif

#ifdef LCD_MEASUREMENT
	if (times_con_skb)
		vfree(times_con_skb);
#endif

#ifdef PERF_EVENTS
	if (perf1)
		vfree(perf1);

	if (perf2)
		vfree(perf2);
	if (perf3)
		vfree(perf3);
	if (perf4)
		vfree(perf4);
#endif
321
322
}

323
int inline glue_insert_skbuff(struct hlist_head *htable,
324
325
326
327
328
			struct sk_buff_container *skb_c)
{
	BUG_ON(!skb_c->skb);

	skb_c->my_ref = __cptr((unsigned long)skb_c->skb);
329
#if 0
330
331
332
333
	mutex_lock_interruptible(&hash_lock);
	hash_add_rcu(cptr_table, &skb_c->hentry,
			(unsigned long) skb_c->skb);
	mutex_unlock(&hash_lock);
334
335
336
337
338
#endif
	spin_lock(&hash_slock);
	hash_add(cptr_table, &skb_c->hentry,
			(unsigned long) skb_c->skb);
	spin_unlock(&hash_slock);
339
340
341
	return 0;
}

342
int inline glue_lookup_skbuff(struct hlist_head *htable, struct cptr c, struct sk_buff_container **skb_cout)
343
344
345
{
        struct sk_buff_container *skb_c;

346
347
348
	spin_lock(&hash_slock);
        //hash_for_each_possible_rcu(cptr_table, skb_c, hentry, (unsigned long) cptr_val(c)) {
        hash_for_each_possible(cptr_table, skb_c, hentry, (unsigned long) cptr_val(c)) {
349
350
351
352
353
354
355
356
		if (!skb_c) {
			WARN_ON(!skb_c);
			continue;
		}
		if (skb_c->skb == (struct sk_buff*) c.cptr) {
	                *skb_cout = skb_c;
		}
        }
357
	spin_unlock(&hash_slock);
358
359
360
        return 0;
}

361
void inline glue_remove_skbuff(struct sk_buff_container *skb_c)
362
{
363
#if 0
364
365
366
	mutex_lock_interruptible(&hash_lock);
	hash_del_rcu(&skb_c->hentry);
	mutex_unlock(&hash_lock);
367
368
369
370
#endif
	spin_lock(&hash_slock);
	hash_del(&skb_c->hentry);
	spin_unlock(&hash_slock);
371
372
}

Vikram Narayanan's avatar
Vikram Narayanan committed
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
int inline glue_insert_skbuff_2(struct ptstate_t *pts,
			struct sk_buff_container *skb_c)
{
	BUG_ON(!skb_c->skb);

	skb_c->my_ref = __cptr((unsigned long)skb_c->skb);

	spin_lock(&pts->hash_lock);
	hash_add(pts->cptr_table, &skb_c->hentry,
			(unsigned long) skb_c->skb);
	spin_unlock(&pts->hash_lock);
	return 0;
}

int inline glue_lookup_skbuff_2(struct ptstate_t *pts,
			struct cptr c,
			struct sk_buff_container **skb_cout)
{
        struct sk_buff_container *skb_c;

	spin_lock(&pts->hash_lock);
        //hash_for_each_possible_rcu(cptr_table, skb_c, hentry, (unsigned long) cptr_val(c)) {
        hash_for_each_possible(pts->cptr_table, skb_c, hentry, (unsigned long) cptr_val(c)) {
		if (!skb_c) {
			WARN_ON(!skb_c);
			continue;
		}
		if (skb_c->skb == (struct sk_buff*) c.cptr) {
	                *skb_cout = skb_c;
		}
        }
	spin_unlock(&pts->hash_lock);
        return 0;
}

void inline glue_remove_skbuff_2(struct ptstate_t *pts,
		struct sk_buff_container *skb_c)
{
	spin_lock(&pts->hash_lock);
	hash_del(&skb_c->hentry);
	spin_unlock(&pts->hash_lock);
}


int inline glue_insert_tid(struct hlist_head *htable,
			struct ptstate_t *pts)
{
//	spin_lock(&hash_tid_lock);
	hash_add_rcu(tid_table, &pts->hentry,
			(unsigned long) pts->pid);
//	spin_unlock(&hash_tid_lock);
	return 0;
}

int inline glue_lookup_tid(struct hlist_head *htable, unsigned long pid, struct ptstate_t **pts_out)
{
        struct ptstate_t *ptstate;

//	spin_lock(&hash_tid_lock);
        hash_for_each_possible_rcu(tid_table, ptstate, hentry, pid) {
		if (!ptstate) {
			WARN_ON(!ptstate);
			continue;
		}
		if (ptstate->pid == pid) {
	                *pts_out = ptstate;
		}
        }
//`	spin_unlock(&hash_tid_lock);
        return 0;
}

void inline glue_remove_tid(struct ptstate_t *pts)
{
//	spin_lock(&hash_tid_lock);
	hash_del_rcu(&pts->hentry);
//	spin_unlock(&hash_tid_lock);
}

452

453
454
455
456
457
int grant_sync_ep(cptr_t *sync_end, cptr_t ha_sync_ep)
{
	int ret;
	struct cspace *curr_cspace = get_current_cspace(current);
	lcd_cptr_alloc(sync_end);
458
459
460
461
	ret = cap_grant(klcd_cspace, ha_sync_ep,
			curr_cspace, *sync_end);
	PTS()->syncep_present = true;
	PTS()->sync_ep = sync_end->cptr;
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
	return ret;
}

int sync_setup_memory(void *data, size_t sz, unsigned long *order, cptr_t *data_cptr, unsigned long *data_offset)
{
        int ret;
        struct page *p;
        unsigned long data_len;
        unsigned long mem_len;
        /*
         * Determine page that contains (start of) data
         */
        p = virt_to_head_page(data);
        if (!p) {
                LIBLCD_ERR("failed to translate to page");
                ret = -EINVAL;
                goto fail1;
        }
        data_len = sz;
        mem_len = ALIGN(data + data_len - page_address(p), PAGE_SIZE);
        *order = ilog2(roundup_pow_of_two(mem_len >> PAGE_SHIFT));
        /*
         * Volunteer memory
         */
        *data_offset = data - page_address(p);
        ret = lcd_volunteer_pages(p, *order, data_cptr);
        if (ret) {
                LIBLCD_ERR("failed to volunteer memory");
                goto fail2;
        }
        /*
         * Done
         */
        return 0;
fail2:
fail1:
        return ret;
}

501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
static void destroy_async_fs_ring_channel(struct thc_channel *chnl)
{
	cptr_t tx, rx;
	gva_t tx_gva, rx_gva;
	unsigned long unused1, unused2;
	int ret;
	unsigned int pg_order = PMFS_ASYNC_RPC_BUFFER_ORDER - PAGE_SHIFT;
	/*
	 * Translate ring buffers to cptrs
	 */
	tx_gva = __gva((unsigned long)thc_channel_to_fipc(chnl)->tx.buffer);
	rx_gva = __gva((unsigned long)thc_channel_to_fipc(chnl)->rx.buffer);
	ret = lcd_virt_to_cptr(tx_gva, &tx, &unused1, &unused2);
	if (ret) {
		LIBLCD_ERR("failed to translate tx to cptr");
		goto fail1;
	}
	ret = lcd_virt_to_cptr(rx_gva, &rx, &unused1, &unused2);
	if (ret) {
		LIBLCD_ERR("failed to translate rx to cptr");
		goto fail2;
	}
	/*
	 * Unmap and kill tx/rx
	 */
	lcd_unmap_virt(tx_gva, pg_order);
	lcd_cap_delete(tx);
	lcd_unmap_virt(rx_gva, pg_order);
	lcd_cap_delete(rx);
	/*
	 * Free chnl header
	 */
	kfree(thc_channel_to_fipc(chnl));
	/*
	 * Free the thc channel
	 *
	 * XXX: We are assuming this is called *from the dispatch loop*
	 * (i.e., as part of handling a callee function), so no one
	 * else (no other awe) is going to try to use the channel
	 * after we kill it. (For the PMFS LCD, this is not possible,
	 * because the unregister happens from a *caller context*.)
	 */
	kfree(chnl);

	return;

fail2:
fail1:
	return;
}

552
static int setup_async_net_ring_channel(cptr_t tx, cptr_t rx, 
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
				struct thc_channel **chnl_out)
{
	gva_t tx_gva, rx_gva;
	int ret;
	struct fipc_ring_channel *fchnl;
	struct thc_channel *chnl;
	unsigned int pg_order = PMFS_ASYNC_RPC_BUFFER_ORDER - PAGE_SHIFT;
	/*
	 * Map tx and rx buffers (caller has already prep'd buffers)
	 */
	ret = lcd_map_virt(tx, pg_order, &tx_gva);
	if (ret) {
		LIBLCD_ERR("failed to map tx");
		goto fail1;
	}
	ret = lcd_map_virt(rx, pg_order, &rx_gva);
	if (ret) {
		LIBLCD_ERR("failed to map rx");
		goto fail2;
	}
	/*
	 * Alloc and init channel header
	 */
	fchnl = kmalloc(sizeof(*fchnl), GFP_KERNEL);
	if (!fchnl) {
		ret = -ENOMEM;
		LIBLCD_ERR("malloc failed");
		goto fail3;
	}
	ret = fipc_ring_channel_init(fchnl,
				PMFS_ASYNC_RPC_BUFFER_ORDER,
				/* (note: gva == hva for non-isolated) */
				(void *)gva_val(tx_gva),
				(void *)gva_val(rx_gva));
	if (ret) {
		LIBLCD_ERR("channel init failed");
		goto fail4;
	}
	/*
	 * Add to async channel group
	 */
	chnl = kzalloc(sizeof(*chnl), GFP_KERNEL);
	if (!chnl) {
		ret = -ENOMEM;
		LIBLCD_ERR("malloc failed");
		goto fail5;
	}
	ret = thc_channel_init(chnl, fchnl);
	if (ret) {
		LIBLCD_ERR("async group item init failed");
		goto fail6;
	}

	*chnl_out = chnl;
	return 0;

fail6:
	kfree(chnl);
fail5:
fail4:
	kfree(fchnl);
fail3:
	lcd_unmap_virt(rx_gva, pg_order);
fail2:
	lcd_unmap_virt(tx_gva, pg_order);
fail1:
	return ret;
}

622
623
624
625
626
627
628
629
630
631
632
int ndo_init_user(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
{
	int ret;
	struct fipc_message *request;
	struct fipc_message *response;
	struct net_device_container *net_dev_container;

	thc_init();

	net_dev_container = container_of(dev, struct net_device_container, net_device);

633
	ret = fipc_test_blocking_send_start(hidden_args->async_chnl, &request);
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
	if (ret) {
		LIBLCD_ERR("failed to get a send slot");
		goto fail_async;
	}

	async_msg_set_fn_type(request, NDO_INIT);
	fipc_set_reg1(request, net_dev_container->other_ref.cptr);

	DO_FINISH_(ndo_init, {
		ASYNC_( {
		ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
		}, ndo_init);
	});

	if (ret) {
		LIBLCD_ERR("thc_ipc_call");
		goto fail_ipc;
	}

	ret = fipc_get_reg1(response);
	fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);

fail_ipc:
fail_async:
	lcd_exit(0);
	return ret;
}


663
664
665
666
667
int ndo_init(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
{
	int ret;
	struct fipc_message *request;
	struct fipc_message *response;
668
669
	struct net_device_container *net_dev_container;

670
	if (!get_current()->ptstate) {
671
672
673
674
675
		LIBLCD_MSG("%s:Called from userland - can't process", __func__);
		LCD_MAIN({
			ret = ndo_init_user(dev, hidden_args);
		});
		return ret;
676
677
	}

Vikram Narayanan's avatar
Vikram Narayanan committed
678
	net_dev_container = container_of(dev, struct net_device_container, net_device);
679

Vikram Narayanan's avatar
Vikram Narayanan committed
680
	ret = async_msg_blocking_send_start(hidden_args->async_chnl, &request);
681
682
	if (ret) {
		LIBLCD_ERR("failed to get a send slot");
683
		goto fail_async;
684
	}
685

Vikram Narayanan's avatar
Vikram Narayanan committed
686
687
	async_msg_set_fn_type(request, NDO_INIT);
	fipc_set_reg1(request, net_dev_container->other_ref.cptr);
688

Vikram Narayanan's avatar
Vikram Narayanan committed
689
690
691
692
693
	ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
	if (ret) {
		LIBLCD_ERR("thc_ipc_call");
		goto fail_ipc;
	}
694

Vikram Narayanan's avatar
Vikram Narayanan committed
695
696
697
698
699
700
	ret = fipc_get_reg1(response);
	fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
fail_ipc:
fail_async:
	return ret;
}
701
702


Vikram Narayanan's avatar
Vikram Narayanan committed
703
704
705
706
707
708
709
710
LCD_TRAMPOLINE_DATA(ndo_init_trampoline);
int LCD_TRAMPOLINE_LINKAGE(ndo_init_trampoline) ndo_init_trampoline(struct net_device *dev)
{
	int ( *volatile ndo_init_fp )(struct net_device *, struct trampoline_hidden_args *);
	struct trampoline_hidden_args *hidden_args;
	LCD_TRAMPOLINE_PROLOGUE(hidden_args, ndo_init_trampoline);
	ndo_init_fp = ndo_init;
	return ndo_init_fp(dev, hidden_args);
711

Vikram Narayanan's avatar
Vikram Narayanan committed
712
}
713

Vikram Narayanan's avatar
Vikram Narayanan committed
714
715
716
717
718
719
void ndo_uninit_user(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
{
	int ret;
	struct fipc_message *request;
	struct fipc_message *response;
	struct net_device_container *net_dev_container;
720

Vikram Narayanan's avatar
Vikram Narayanan committed
721
	thc_init();
722

Vikram Narayanan's avatar
Vikram Narayanan committed
723
	net_dev_container = container_of(dev, struct net_device_container, net_device);
724

725
	ret = fipc_test_blocking_send_start(hidden_args->async_chnl, &request);
Vikram Narayanan's avatar
Vikram Narayanan committed
726
727
728
729
730
731
	if (ret) {
		LIBLCD_ERR("failed to get a send slot");
		goto fail_async;
	}
	async_msg_set_fn_type(request, NDO_UNINIT);
	fipc_set_reg1(request, net_dev_container->other_ref.cptr);
732

Vikram Narayanan's avatar
Vikram Narayanan committed
733
734
735
736
737
	DO_FINISH_(ndo_uninit, {
		ASYNC_( {
		ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
		}, ndo_uninit);
	});
738

Vikram Narayanan's avatar
Vikram Narayanan committed
739
740
741
	if (ret) {
		LIBLCD_ERR("thc_ipc_call");
		goto fail_ipc;
742
	}
743

Vikram Narayanan's avatar
Vikram Narayanan committed
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
	fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
fail_ipc:
fail_async:
	lcd_exit(0);
	return;
}

void ndo_uninit(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
{
	int ret;
	struct fipc_message *request;
	struct fipc_message *response;
	struct net_device_container *net_dev_container;

	if (!get_current()->ptstate) {
		LIBLCD_MSG("%s:Called from userland - can't process", __func__);
760
		LCD_MAIN({
Vikram Narayanan's avatar
Vikram Narayanan committed
761
			ndo_uninit_user(dev, hidden_args);
762
		});
Vikram Narayanan's avatar
Vikram Narayanan committed
763
764
765
766
767
768
769
770
771
		return;	
	}

	net_dev_container = container_of(dev, struct net_device_container, net_device);

	ret = async_msg_blocking_send_start(hidden_args->async_chnl, &request);
	if (ret) {
		LIBLCD_ERR("failed to get a send slot");
		goto fail_async;
772
	}
Vikram Narayanan's avatar
Vikram Narayanan committed
773
774
	async_msg_set_fn_type(request, NDO_UNINIT);
	fipc_set_reg1(request, net_dev_container->other_ref.cptr);
775

Vikram Narayanan's avatar
Vikram Narayanan committed
776
	ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
777
	if (ret) {
778
		LIBLCD_ERR("thc_ipc_call");
779
		goto fail_ipc;
780
	}
Vikram Narayanan's avatar
Vikram Narayanan committed
781

Vikram Narayanan's avatar
Vikram Narayanan committed
782
783
784
785
786
	fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
fail_ipc:
fail_async:
	return;
}
Vikram Narayanan's avatar
Vikram Narayanan committed
787

Vikram Narayanan's avatar
Vikram Narayanan committed
788
789
790
791
792
793
794
795
796
LCD_TRAMPOLINE_DATA(ndo_uninit_trampoline);
void LCD_TRAMPOLINE_LINKAGE(ndo_uninit_trampoline)
ndo_uninit_trampoline(struct net_device *dev)
{
	void ( *volatile ndo_uninit_fp )(struct net_device *, struct trampoline_hidden_args *);
	struct trampoline_hidden_args *hidden_args;
	LCD_TRAMPOLINE_PROLOGUE(hidden_args, ndo_uninit_trampoline);
	ndo_uninit_fp = ndo_uninit;
	return ndo_uninit_fp(dev, hidden_args);
797

Vikram Narayanan's avatar
Vikram Narayanan committed
798
}
799

Vikram Narayanan's avatar
Vikram Narayanan committed
800
801
802
803
804
805
806
/**
 * This function will block until a message is received and stored in out.
 */
static inline
int fipc_test_blocking_recv_start_cnt ( struct thc_channel *chnl, struct fipc_message** out, u64 *count )
{
	int ret;
Vikram Narayanan's avatar
Vikram Narayanan committed
807

Vikram Narayanan's avatar
Vikram Narayanan committed
808
809
810
811
812
813
	while ( 1 )
	{
		(*count)++;
		// Poll until we get a message or error
		ret = fipc_recv_msg_start( thc_channel_to_fipc(chnl),
						out );
Vikram Narayanan's avatar
Vikram Narayanan committed
814

Vikram Narayanan's avatar
Vikram Narayanan committed
815
816
817
818
819
820
821
822
		if ( !ret || ret != -EWOULDBLOCK )
		{
			return ret;
		}
		
		fipc_test_pause();
		asm volatile("xchg %rax, %rax");
//		asm volatile("xchg %rax, %rax");
Vikram Narayanan's avatar
Vikram Narayanan committed
823
824
	}

Vikram Narayanan's avatar
Vikram Narayanan committed
825
	return 0;
826
827
828
829
830
831
832
833
834
}

LCD_TRAMPOLINE_DATA(ndo_start_xmit_trampoline);
int LCD_TRAMPOLINE_LINKAGE(ndo_start_xmit_trampoline)
 ndo_start_xmit_trampoline(struct sk_buff *skb, struct net_device *dev)
{
	int ( *volatile ndo_start_xmit_fp )(struct sk_buff *, struct net_device *, struct trampoline_hidden_args *);
	struct trampoline_hidden_args *hidden_args;
	LCD_TRAMPOLINE_PROLOGUE(hidden_args, ndo_start_xmit_trampoline);
Vikram Narayanan's avatar
Vikram Narayanan committed
835
	ndo_start_xmit_fp = ndo_start_xmit_async_landing;
836
837
838
839
	return ndo_start_xmit_fp(skb, dev, hidden_args);

}

840
841
842
843
844
845
846
847
848
849
850
int ndo_validate_addr_user(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
{
	int ret;
	struct fipc_message *request;
	struct fipc_message *response;
	struct net_device_container *net_dev_container;

	thc_init();

	net_dev_container = container_of(dev, struct net_device_container, net_device);

851
	ret = fipc_test_blocking_send_start(hidden_args->async_chnl, &request);
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
	if (ret) {
		LIBLCD_ERR("failed to get a send slot");
		goto fail_async;
	}
	async_msg_set_fn_type(request, NDO_VALIDATE_ADDR);

	fipc_set_reg1(request, net_dev_container->other_ref.cptr);

	LIBLCD_MSG("%s, cptr klcd %lu", __func__, net_dev_container->other_ref.cptr);

	DO_FINISH_(ndo_validate_addr, {
	  ASYNC_({
	    ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
	  }, ndo_validate_addr);
	});

	if (ret) {
		LIBLCD_ERR("thc_ipc_call");
		goto fail_ipc;
	}

	ret = fipc_get_reg1(response);
	fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
fail_ipc:
fail_async:
	lcd_exit(0);
	return ret;
}

881
882
883
884
885
int ndo_validate_addr(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
{
	int ret;
	struct fipc_message *request;
	struct fipc_message *response;
886
887
888
	struct net_device_container *net_dev_container;

	if (!get_current()->ptstate) {
889
890
891
892
		LIBLCD_MSG("%s:Called from userland %p", __func__, dev);
		LCD_MAIN({
			ret = ndo_validate_addr_user(dev, hidden_args);
		});
Vikram Narayanan's avatar
Vikram Narayanan committed
893
		printk("%s, returns to userspace \n", __func__);
894
		return ret;
895
896
897
898
899
	}

	net_dev_container = container_of(dev, struct net_device_container, net_device);

	ret = async_msg_blocking_send_start(hidden_args->async_chnl, &request);
900
901
	if (ret) {
		LIBLCD_ERR("failed to get a send slot");
902
		goto fail_async;
903
904
	}
	async_msg_set_fn_type(request, NDO_VALIDATE_ADDR);
905
906
907
908
909

	fipc_set_reg1(request, net_dev_container->other_ref.cptr);

	ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
	if (ret) {
910
		LIBLCD_ERR("thc_ipc_call");
911
		goto fail_ipc;
912
913
	}
	ret = fipc_get_reg1(response);
914
915
916
	fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
fail_ipc:
fail_async:
917
918
919
920
921
922
923
924
925
926
927
928
929
930
	return ret;
}

LCD_TRAMPOLINE_DATA(ndo_validate_addr_trampoline);
int LCD_TRAMPOLINE_LINKAGE(ndo_validate_addr_trampoline) ndo_validate_addr_trampoline(struct net_device *dev)
{
	int ( *volatile ndo_validate_addr_fp )(struct net_device *, struct trampoline_hidden_args *);
	struct trampoline_hidden_args *hidden_args;
	LCD_TRAMPOLINE_PROLOGUE(hidden_args, ndo_validate_addr_trampoline);
	ndo_validate_addr_fp = ndo_validate_addr;
	return ndo_validate_addr_fp(dev, hidden_args);

}

931
932
933
934
935
936
937
938
939
940
941
void ndo_set_rx_mode_user(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
{
	int ret;
	struct fipc_message *request;
	struct fipc_message *response;
	struct net_device_container *net_dev_container;

	thc_init();

	net_dev_container = container_of(dev, struct net_device_container, net_device);

942
	ret = fipc_test_blocking_send_start(hidden_args->async_chnl, &request);
943
944
945
946
947
948
949
	if (ret) {
		LIBLCD_ERR("failed to get a send slot");
		goto fail_async;
	}
	async_msg_set_fn_type(request, NDO_SET_RX_MODE);
	fipc_set_reg1(request, net_dev_container->other_ref.cptr);

Vikram Narayanan's avatar
Vikram Narayanan committed
950
	printk("%s, before async \n", __func__);
951
952
953
	DO_FINISH_(ndo_set_rx_mode, {
	  ASYNC_({
	    ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
Vikram Narayanan's avatar
Vikram Narayanan committed
954
	  printk("%s, after async \n", __func__);
955
	  }, ndo_set_rx_mode);
Vikram Narayanan's avatar
Vikram Narayanan committed
956
	  printk("%s, after async2 \n", __func__);
957
958
	});

Vikram Narayanan's avatar
Vikram Narayanan committed
959
	 printk("%s, after dofin \n", __func__);
960
961
962
963
964
965
966
967
968
969
970
971
972
	if (ret) {
		LIBLCD_ERR("thc_ipc_call");
		goto fail_ipc;
	}

	fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);

fail_ipc:
fail_async:
	lcd_exit(0);
	return;
}

973
974
975
976
977
void ndo_set_rx_mode(struct net_device *dev, struct trampoline_hidden_args *hidden_args)
{
	int ret;
	struct fipc_message *request;
	struct fipc_message *response;
978
979
980
	struct net_device_container *net_dev_container;

	if (!get_current()->ptstate) {
981
982
983
984
		LIBLCD_MSG("%s:Called from userland - can't process", __func__);
		LCD_MAIN({
			ndo_set_rx_mode_user(dev, hidden_args);
		});
Vikram Narayanan's avatar
Vikram Narayanan committed
985
		printk("%s, returns to userspace \n", __func__);
986
987
988
989
990
991
		return;
	}

	net_dev_container = container_of(dev, struct net_device_container, net_device);

	ret = async_msg_blocking_send_start(hidden_args->async_chnl, &request);
992
993
	if (ret) {
		LIBLCD_ERR("failed to get a send slot");
994
		goto fail_async;
995
996
	}
	async_msg_set_fn_type(request, NDO_SET_RX_MODE);
997
998
	fipc_set_reg1(request, net_dev_container->other_ref.cptr);

Vikram Narayanan's avatar
Vikram Narayanan committed
999
	printk("%s, ipc call \n", __func__);
1000
	ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
Vikram Narayanan's avatar
Vikram Narayanan committed
1001
	printk("%s, ipc call done\n", __func__);
1002
	if (ret) {
1003
		LIBLCD_ERR("thc_ipc_call");
1004
		goto fail_ipc;
1005
	}
1006
1007
1008
1009
1010

	fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);

fail_ipc:
fail_async:
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
	return;
}

LCD_TRAMPOLINE_DATA(ndo_set_rx_mode_trampoline);
void LCD_TRAMPOLINE_LINKAGE(ndo_set_rx_mode_trampoline) ndo_set_rx_mode_trampoline(struct net_device *dev)
{
	void ( *volatile ndo_set_rx_mode_fp )(struct net_device *, struct trampoline_hidden_args *);
	struct trampoline_hidden_args *hidden_args;
	LCD_TRAMPOLINE_PROLOGUE(hidden_args, ndo_set_rx_mode_trampoline);
	ndo_set_rx_mode_fp = ndo_set_rx_mode;
	return ndo_set_rx_mode_fp(dev, hidden_args);

}

1025

1026
1027

//DONE
1028
1029
1030
1031
1032
1033
1034
1035
1036
int ndo_set_mac_address_user(struct net_device *dev, void *addr, struct trampoline_hidden_args *hidden_args)
{
	int ret;
	struct fipc_message *request;
	struct fipc_message *response;
	int sync_ret;
	unsigned 	long addr_mem_sz;
	unsigned 	long addr_offset;
	cptr_t addr_cptr;
1037
	unsigned 	int request_cookie;
1038
	struct net_device_container *net_dev_container;
1039
1040
	cptr_t sync_end;
	net_dev_container = container_of(dev, struct net_device_container, net_device);
1041

1042
1043
	/* creates lcd and cspace */
	lcd_enter();
1044
	ret = grant_sync_ep(&sync_end, hidden_args->sync_ep);
1045

1046
	ret = fipc_test_blocking_send_start(hidden_args->async_chnl, &request);
1047
1048
1049
1050
1051
1052
1053
	if (ret) {
		LIBLCD_ERR("failed to get a send slot");
		goto fail_async;
	}
	async_msg_set_fn_type(request, NDO_SET_MAC_ADDRESS);
	fipc_set_reg1(request, net_dev_container->other_ref.cptr);

1054
1055
1056
	ret = sync_setup_memory(addr, sizeof(struct sockaddr), &addr_mem_sz, &addr_cptr, &addr_offset);

	if (ret) {
1057
1058
1059
1060
		LIBLCD_ERR("virt to cptr failed");
		goto fail_virt;
	}

1061
	ret = thc_ipc_send_request(hidden_args->async_chnl, request, &request_cookie);
1062
1063
1064
1065
1066

	if (ret) {
		LIBLCD_ERR("thc_ipc_call");
		goto fail_ipc;
	}
1067
	lcd_set_cr0(addr_cptr);
1068
1069
	lcd_set_r0(addr_mem_sz);
	lcd_set_r1(addr_offset);
1070
1071
1072
1073
1074

	LIBLCD_MSG("%s: cptr %lu | order %lu | offset %lu",
		__func__, addr_cptr.cptr, addr_mem_sz, addr_offset);

	sync_ret = lcd_sync_send(sync_end);
1075
1076
1077
1078
1079
	lcd_set_cr0(CAP_CPTR_NULL);
	if (sync_ret) {
		LIBLCD_ERR("failed to send");
		goto fail_sync;
	}
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094

	lcd_cap_delete(sync_end);
	DO_FINISH_(ndo_set_mac_address, {
	  ASYNC_({
	ret = thc_ipc_recv_response(hidden_args->async_chnl,
				request_cookie,
				&response);
	 }, ndo_set_mac_address);
	});

	if (ret) {
		LIBLCD_ERR("async recv failed");
		goto fail_ipcresp;
	}

1095
	ret = fipc_get_reg1(response);
1096
1097
1098

	LIBLCD_MSG("%s: returned %d", __func__, ret);

1099
	fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
1100
1101

fail_ipcresp:
1102
1103
1104
1105
1106
1107
1108
1109
fail_virt:
fail_sync:
fail_ipc:
fail_async:
	lcd_exit(0);
	return ret;
}

1110
//DONE
1111
1112
1113
1114
1115
1116
1117
1118
1119
int ndo_set_mac_address(struct net_device *dev, void *addr, struct trampoline_hidden_args *hidden_args)
{
	int ret;
	struct fipc_message *request;
	struct fipc_message *response;
	int sync_ret;
	unsigned 	long addr_mem_sz;
	unsigned 	long addr_offset;
	cptr_t addr_cptr;
1120
1121
1122
	struct net_device_container *net_dev_container;

	if (!get_current()->ptstate) {
1123
		LIBLCD_MSG("%s:Called from userland - can't process", __func__);
1124
1125
1126
1127
		for (ret = 0; ret < 14; ret++) {
			printk("%02X:",((char*)addr)[ret]);
		}
		if (1) {
1128
1129
1130
1131
		LCD_MAIN({
			ret = ndo_set_mac_address_user(dev, addr, hidden_args); 
		});
		}
1132
		return ret;//eth_mac_addr(dev, addr);
1133
1134
1135
1136
1137
	}

	net_dev_container = container_of(dev, struct net_device_container, net_device);

	ret = async_msg_blocking_send_start(hidden_args->async_chnl, &request);
1138
1139
	if (ret) {
		LIBLCD_ERR("failed to get a send slot");
1140
		goto fail_async;
1141
1142
	}
	async_msg_set_fn_type(request, NDO_SET_MAC_ADDRESS);
1143
1144
	fipc_set_reg1(request, net_dev_container->other_ref.cptr);

1145
1146
1147
	sync_ret = lcd_virt_to_cptr(__gva(( unsigned  long   )addr), &addr_cptr, &addr_mem_sz, &addr_offset);
	if (sync_ret) {
		LIBLCD_ERR("virt to cptr failed");
1148
		goto fail_virt;
1149
	}
1150
1151
	ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
	if (ret) {
1152
		LIBLCD_ERR("thc_ipc_call");
1153
		goto fail_ipc;
1154
1155
1156
1157
	}
	lcd_set_r0(addr_mem_sz);
	lcd_set_r1(addr_offset);
	lcd_set_cr0(addr_cptr);
1158
	sync_ret = lcd_sync_send(hidden_args->sync_ep);
1159
1160
1161
	lcd_set_cr0(CAP_CPTR_NULL);
	if (sync_ret) {
		LIBLCD_ERR("failed to send");
1162
		goto fail_sync;
1163
1164
	}
	ret = fipc_get_reg1(response);
1165
1166
1167
1168
1169
1170
	fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
	return ret;
fail_virt:
fail_sync:
fail_ipc:
fail_async:
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
	return ret;
}

LCD_TRAMPOLINE_DATA(ndo_set_mac_address_trampoline);
int LCD_TRAMPOLINE_LINKAGE(ndo_set_mac_address_trampoline) ndo_set_mac_address_trampoline(struct net_device *dev, void *addr)
{
	int ( *volatile ndo_set_mac_address_fp )(struct net_device *, void *, struct trampoline_hidden_args *);
	struct trampoline_hidden_args *hidden_args;
	LCD_TRAMPOLINE_PROLOGUE(hidden_args, ndo_set_mac_address_trampoline);
	ndo_set_mac_address_fp = ndo_set_mac_address;
	return ndo_set_mac_address_fp(dev, addr, hidden_args);

}

1185
struct rtnl_link_stats64 *ndo_get_stats64_user(struct net_device *dev,
1186
		struct rtnl_link_stats64 *stats,
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
		struct trampoline_hidden_args *hidden_args)
{
	int ret;
	struct fipc_message *request;
	struct fipc_message *response;
	struct net_device_container *net_dev_container;

	thc_init();

	net_dev_container = container_of(dev, struct net_device_container, net_device);

1198
	ret = fipc_test_blocking_send_start(hidden_args->async_chnl, &request);
1199
1200
1201
1202
1203
1204
1205
1206
1207
	if (ret) {
		LIBLCD_MSG("failed to get a send slot");
		goto fail_async;
	}

	async_msg_set_fn_type(request, NDO_GET_STATS64);

	fipc_set_reg1(request, net_dev_container->other_ref.cptr);

1208
	LIBLCD_MSG("%s, klcd netdev other ref %p | %lu",__func__, net_dev_container, net_dev_container->other_ref.cptr);
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219

	DO_FINISH_(ndo_get_stats64, {
	  ASYNC_({
	    ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
	  }, ndo_get_stats64);
	});

	if (ret) {
		LIBLCD_ERR("thc_ipc_call");
		goto fail_ipc;
	}
1220
1221
	stats->tx_packets += fipc_get_reg1(response);
	stats->tx_bytes += fipc_get_reg2(response);
1222
1223
1224
1225
1226
1227

	fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);

fail_ipc:
fail_async:
	lcd_exit(0);
1228
	return stats;
1229
1230
}

1231
//DONE
1232
struct rtnl_link_stats64 *ndo_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats, struct trampoline_hidden_args *hidden_args)
1233
1234
{
	int ret;
Vikram Narayanan's avatar
Vikram Narayanan committed
1235
	//int i;
1236
1237
	struct fipc_message *request;
	struct fipc_message *response;
1238
1239
1240
	struct net_device_container *net_dev_container;

	if (!get_current()->ptstate) {
1241
1242
1243
1244
1245
1246
1247
1248
1249
#ifdef TIMESTAMP
#ifndef INDIVIDUAL_MARKERS
		printk("----> stat ndo_xmit <------\n");
#else
		printk("----> stat p1.kzalloc + hash <------\n");
#endif
		if (times_ndo_xmit)
			fipc_test_stat_print_info(times_ndo_xmit,
						NUM_PACKETS);
Vikram Narayanan's avatar
Vikram Narayanan committed
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260

#endif

#if 0
		for (i = 0; i < NUM_CORES; i++) {
			if (ptrs[i]) {
				printk("----> stat ndo_xmit %llu <----\n", ptrs[i]->pid);
				fipc_test_stat_print_info(ptrs[i]->times_ndo_xmit,
						NUM_PACKETS);
			}
		}
1261
#endif
Vikram Narayanan's avatar
Vikram Narayanan committed
1262

1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
#ifdef LCD_MEASUREMENT
		printk("----> stat LCD con_skb <------\n");

		if (times_con_skb)
			fipc_test_stat_print_info(times_con_skb,
						NUM_PACKETS);
#endif
#ifdef INDIVIDUAL_MARKERS
		printk("----> stat lcd ipc_send <------\n");
		if (times_ipc_send)
			fipc_test_stat_print_info(times_ipc_send,
						NUM_PACKETS);

		printk("----> stat p2.ipc_recv+msG_end <------\n");
		if (times_ipc_recv)
			fipc_test_stat_print_info(times_ipc_recv,
						NUM_PACKETS);
#endif
#ifdef PERF_EVENTS
		printk("----> perf event 1 <------\n");
		if (perf1)
			fipc_test_stat_print_info(perf1, NUM_PACKETS);

		printk("----> perf event 2 <------\n");
		if (perf2)
			fipc_test_stat_print_info(perf2, NUM_PACKETS);

		printk("----> perf event 3 <------\n");
		if (perf3)
			fipc_test_stat_print_info(perf3, NUM_PACKETS);

		printk("----> perf event 4 <------\n");
		if (perf4)
			fipc_test_stat_print_info(perf4, NUM_PACKETS);
#endif
Vikram Narayanan's avatar
Vikram Narayanan committed
1298
/*		LCD_MAIN( {
1299
			ndo_get_stats64_user(dev, stats, hidden_args);
Vikram Narayanan's avatar
Vikram Narayanan committed
1300
1301
1302
1303
1304
		});*/

		stats->tx_packets = g_stats.tx_packets;
		stats->tx_bytes = g_stats.tx_bytes;

1305
		return stats;
1306
1307
1308
1309
1310
	}

	net_dev_container = container_of(dev, struct net_device_container, net_device);

	ret = async_msg_blocking_send_start(hidden_args->async_chnl, &request);
1311
1312
	if (ret) {
		LIBLCD_ERR("failed to get a send slot");
1313
		goto fail_async;
1314
	}
1315

1316
	async_msg_set_fn_type(request, NDO_GET_STATS64);
1317
1318
1319

	fipc_set_reg1(request, net_dev_container->other_ref.cptr);

1320
1321
	ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
	if (ret) {
1322
		LIBLCD_ERR("thc_ipc_call");
1323
		goto fail_ipc;
1324
	}
1325
1326
	stats->tx_packets = fipc_get_reg1(response);
	stats->tx_bytes = fipc_get_reg2(response);
1327
1328

	fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
1329

1330
1331
fail_ipc:
fail_async:
1332
	return stats;
1333
1334
1335
}

LCD_TRAMPOLINE_DATA(ndo_get_stats64_trampoline);
1336
struct rtnl_link_stats64 LCD_TRAMPOLINE_LINKAGE(ndo_get_stats64_trampoline) *ndo_get_stats64_trampoline(struct net_device *dev, struct rtnl_link_stats64 *stats)
1337
1338
1339
1340
1341
{
	struct rtnl_link_stats64* ( *volatile ndo_get_stats64_fp )(struct net_device *, struct rtnl_link_stats64 *, struct trampoline_hidden_args *);
	struct trampoline_hidden_args *hidden_args;
	LCD_TRAMPOLINE_PROLOGUE(hidden_args, ndo_get_stats64_trampoline);
	ndo_get_stats64_fp = ndo_get_stats64;
1342
	return ndo_get_stats64_fp(dev, stats, hidden_args);
1343
1344
1345

}

1346
//DONE
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
int ndo_change_carrier_user(struct net_device *dev, bool new_carrier, struct trampoline_hidden_args *hidden_args)
{
	int ret;
	struct fipc_message *request;
	struct fipc_message *response;
	struct net_device_container *net_dev_container;

	thc_init();

	net_dev_container = container_of(dev, struct net_device_container, net_device);

1358
	ret = fipc_test_blocking_send_start(hidden_args->async_chnl, &request);
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
	if (ret) {
		LIBLCD_ERR("failed to get a send slot");
		goto fail_async;
	}
	async_msg_set_fn_type(request, NDO_CHANGE_CARRIER);
	fipc_set_reg1(request, net_dev_container->other_ref.cptr);
	fipc_set_reg2(request, new_carrier);

	DO_FINISH_(ndo_change_carrier, {
	  ASYNC_({
		ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
	  }, ndo_change_carrier);
	});

	if (ret) {
		LIBLCD_ERR("thc_ipc_call");
		goto fail_ipc;
	}
	ret = fipc_get_reg1(response);
	fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);

fail_async:
fail_ipc:
	lcd_exit(0);
	return ret;
}

1386
//DONE
1387
1388
1389
1390
1391
int ndo_change_carrier(struct net_device *dev, bool new_carrier, struct trampoline_hidden_args *hidden_args)
{
	int ret;
	struct fipc_message *request;
	struct fipc_message *response;
1392
1393
1394
1395
	struct net_device_container *net_dev_container;

	if (!get_current()->ptstate) {
		LIBLCD_ERR("%s:Called from userland - can't process", __func__);
1396
1397
1398
1399
		LCD_MAIN( {
			ret = ndo_change_carrier_user(dev, new_carrier, hidden_args);
		});
		return ret;
1400
1401
1402
1403
1404
	}

	net_dev_container = container_of(dev, struct net_device_container, net_device);

	ret = async_msg_blocking_send_start(hidden_args->async_chnl, &request);
1405
1406
	if (ret) {
		LIBLCD_ERR("failed to get a send slot");
1407
		goto fail_async;
1408
1409
	}
	async_msg_set_fn_type(request, NDO_CHANGE_CARRIER);
1410
1411
1412
1413
	fipc_set_reg1(request, net_dev_container->other_ref.cptr);

	ret = thc_ipc_call(hidden_args->async_chnl, request, &response);
	if (ret) {
1414
		LIBLCD_ERR("thc_ipc_call");
1415
		goto fail_ipc;
1416
1417
	}
	ret = fipc_get_reg1(response);
1418
	fipc_recv_msg_end(thc_channel_to_fipc(hidden_args->async_chnl), response);
1419

1420
1421
1422
fail_async:
fail_ipc:
	return ret;
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
}

LCD_TRAMPOLINE_DATA(ndo_change_carrier_trampoline);
int LCD_TRAMPOLINE_LINKAGE(ndo_change_carrier_trampoline) ndo_change_carrier_trampoline(struct net_device *dev, bool new_carrier)
{
	int ( *volatile ndo_change_carrier_fp )(struct net_device *, bool , struct trampoline_hidden_args *);
	struct trampoline_hidden_args *hidden_args;
	LCD_TRAMPOLINE_PROLOGUE(hidden_args, ndo_change_carrier_trampoline);
	ndo_change_carrier_fp = ndo_change_carrier;
	return ndo_change_carrier_fp(dev, new_carrier, hidden_args);

}

1436
//TODO:
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
int validate(struct nlattr **tb, struct nlattr **data, struct trampoline_hidden_args *hidden_args)
{
	int ret;
	struct fipc_message *request;
	struct fipc_message *response;
	int err;
	ret = async_msg_blocking_send_start(net_async, &request);
	if (ret) {
		LIBLCD_ERR("failed to get a send slot");
		lcd_exit(-1);
	}
	async_msg_set_fn_type(request, VALIDATE);
	err = thc_ipc_call(net_async, request, &response);
	if (err) {
		LIBLCD_ERR("thc_ipc_call");
		lcd_exit(-1);
	}
	ret = fipc_get_reg1(response);
	fipc_recv_msg_end(thc_channel_to_fipc(net_async), response);
	return ret;

}

LCD_TRAMPOLINE_DATA(validate_trampoline);
int LCD_TRAMPOLINE_LINKAGE(validate_trampoline) validate_trampoline(struct nlattr **tb, struct nlattr **data)
{
	int ( *volatile validate_fp )(struct nlattr **, struct nlattr **, struct trampoline_hidden_args *);
	struct trampoline_hidden_args *hidden_args;
	LCD_TRAMPOLINE_PROLOGUE(hidden_args, validate_trampoline);
	validate_fp = validate;
	return validate_fp(tb, data, hidden_args);

}

1471
//DONE
1472
void setup_device_ops_trampolines(struct net_device_ops_container *netdev_ops_container, struct trampoline_hidden_args *hargs)
1473
{
1474
1475
	struct thc_channel *</