35
34
// if set to 0, the update only happens when INT is received
37
36
#define HUGE_PAGE 1 // number of pages per huge page
38
#define TLP_SIZE 64 // TLP SIZE = 64 for 256B payload, 32 for 128B payload
37
#define TLP_SIZE 32 // TLP SIZE = 64 for 256B payload, 32 for 128B payload
39
38
#define PAGE_SIZE 4096 // other values are not supported in the kernel
41
#define USE_64 // Lorenzo: use 64bit addressing
40
#define USE_64 // Lorenzo: use 64bit addressing
43
42
//#define DUAL_CORE // Lorenzo: DUAL Core
45
44
//#define SHARED_MEMORY // Lorenzo: Test for fast GUI
47
#define CHECK_READY // Lorenzo: Check if PCI-Express is ready by reading 0x0
48
#define CHECK_RESULTS // Lorenzo: Check if data received is ok (only for counter!)
49
//#define PRINT_RESULTS // Lorenzo: Save the received data in "data.out"
46
#define CHECK_READY // Lorenzo: Check if PCI-Express is ready by reading 0x0
47
#define MEM_COPY // Lorenzo: CPY data
48
//#define CHECK_RESULTS // Lorenzo: Check if data received is ok (only for counter!)
49
//#define CHECK_RESULTS_LOG // Lorenzo: Check if data received is ok (only for counter!)
50
#define PRINT_RESULTS // Lorenzo: Save the received data in "data.out"
50
51
//#define EXIT_ON_EMPTY // Lorenzo: Exit if an "empty_detected" signal is received
52
//#define HEB // Lorenzo: Testing HEB
53
//#define SWITCH_GENERATOR // Lorenzo: Testing HEB -> Turn data gen on/off
55
//#define TEST_DDR // Lorenzo: Testing DDR
57
53
#define TIMEOUT 1000000
70
66
#define FPGA_CLOCK 250 // Lorenzo: in MHz !
74
68
//#define WR(addr, value) { val = value; pcilib_write(pci, BAR, addr, sizeof(val), &val); }
75
69
//#define RD(addr, value) { pcilib_read(pci, BAR, addr, sizeof(val), &val); value = val; }
76
70
#define WR(addr, value) { *(uint32_t*)(bar + addr + offset) = value; }
146
139
pcilib_kmem_handle_t *kdesc;
147
140
pcilib_kmem_handle_t *kbuf;
148
141
struct timeval start, end;
143
long long int size_mb;
151
144
void* volatile bar;
152
145
uintptr_t bus_addr[BUFFERS];
153
146
uintptr_t kdesc_bus;
158
151
#ifdef SWITCH_GENERATOR
159
152
int switch_generator = 0;
160
153
#endif /* SWITCH_GENERATOR */
154
#if defined(CHECK_RESULTS)||defined(CHECK_RESULTS_LOG)
157
#endif /* CHECK_RESULTS */
162
160
float performance, perf_counter;
163
161
pcilib_bar_t bar_tmp = BAR;
164
162
uintptr_t offset = 0;
166
164
unsigned int temp;
167
unsigned iterations_completed, buffers_filled;
165
int iterations_completed, buffers_filled;
173
171
printf("\n\n**** **** **** KIT-DMA TEST **** **** ****\n\n");
173
//size = ITERATIONS * BUFFERS * HUGE_PAGE * PAGE_SIZE;
175
174
size_mb = ITERATIONS * BUFFERS * HUGE_PAGE * 4 / 1024;
176
175
printf("Total size of memory buffer: \t %.3lf GBytes\n", (float)size_mb/1024 );
177
printf("Using %u Buffers with %u iterations\n\n", BUFFERS, ITERATIONS );
176
printf("Using %d Buffers with %d iterations\n\n", BUFFERS, ITERATIONS );
179
178
#ifdef ADD_DELAYS
180
179
long rpt = 0, rpt2 = 0;
187
186
pcilib_kmem_flags_t free_flags = PCILIB_KMEM_FLAG_HARDWARE/*|PCILIB_KMEM_FLAG_EXCLUSIVE|PCILIB_KMEM_FLAG_REUSE*/;
188
187
pcilib_kmem_flags_t clean_flags = PCILIB_KMEM_FLAG_HARDWARE|PCILIB_KMEM_FLAG_PERSISTENT|PCILIB_KMEM_FLAG_EXCLUSIVE;
190
pci = pcilib_open(DEVICE, PCILIB_MODEL_DETECT);
189
pci = pcilib_open(DEVICE, "pci");
191
190
if (!pci) fail("pcilib_open");
193
192
bar = pcilib_map_bar(pci, BAR);
239
238
// Pointers for Virtualized Mem
240
239
for (j = 0; j < BUFFERS; j++) {
241
240
ptr[j] = (volatile uint32_t*)pcilib_kmem_get_block_ua(pci, kbuf, j);
242
memset((void*)ptr[j], 0, HUGE_PAGE * PAGE_SIZE);
241
memset((void*)(ptr[j]), 0, HUGE_PAGE * PAGE_SIZE);
314
314
error_log = fopen ("error_log.txt", "w");
315
315
fclose(error_log);
317
// *************************************
318
Output = fopen("data.txt", "w");
321
317
// ******************************************************************
322
318
// **** PCIe TEST *****
323
319
// ******************************************************************
345
341
// **** DMA CONFIGURATION *****
346
342
// ******************************************************************
349
printf("* DMA: Start Data Generator...\n");
350
WR(0x04, 0x10) // Start data generator
352
printf("* DMA: Send Data Fill Pattern 55aa55aa\n");
355
344
printf("* DMA: Send Data Amount\n");
357
346
WR(0x10, (HUGE_PAGE * (PAGE_SIZE / (4 * TLP_SIZE)))/2);
383
373
printf ("32bit - 128B Payload\n");
387
377
printf("* DMA: Reset Desc Memory...\n");
388
378
WR(0x5C, 0x00); // RST Desc Memory
390
//printf("Writing SW Read Descriptor\n");
380
printf("Writing SW Read Descriptor\n");
391
381
WR(0x58, BUFFERS-1);
392
382
//WR(0x58, 0x01);
394
//printf("Writing the Descriptor Threshold\n");
384
printf("Writing the Descriptor Threshold\n");
395
385
WR(0x60, DESC_THRESHOLD);
397
//printf("Writing HW write Descriptor Address: %lx\n", kdesc_bus);
387
printf("Writing HW write Descriptor Address: %lx\n", kdesc_bus);
398
388
WR(0x54, kdesc_bus);
403
393
bus_addr[j] = pcilib_kmem_get_block_ba(pci, kbuf, j);
404
394
// LEAVE THIS DELAY???!?!?!?!
406
printf("Writing descriptor num. %d: \t %08lx \r", j, bus_addr[j]);
396
//printf("Writing descriptor num. %ld: \t %08lx \n", j, bus_addr[j]);
407
397
WR(0x50, bus_addr[j]);
410
400
// ******************************************************************
411
// **** HEB CONFIGURATION *****
412
// ******************************************************************
416
printf("* DDR REGISTERS: AXI_BUF_SIZE \n");
421
printf("* HEB: Control \n");
422
WR(0x9040, 0x00000001);
426
printf("* HEB: Control \n");
427
WR(0x9040, 0x00000004);
431
printf("* HEB: Control \n");
432
WR(0x9040, 0x00000000);
436
printf("* HEB: Writing Total Orbit Num\n");
439
printf("* HEB: Orbit Skip Num h9028\n");
442
//printf("* HEB: LVDS_DELAY h9080\n");
443
//WR(0x9080, 0x10101010);
445
//printf("* HEB: Delay ADCs \n");
451
//printf("* HEB: Delay TH \n");
454
//printf("* HEB: Delay_FPGA_reg \n");
457
//printf("* HEB: Control \n");
458
//WR(0x9040, 0x40000000);
462
printf("* HEB: Control \n");
463
WR(0x9040, 0x40000bf0);
467
printf("* HEB: Control \n");
468
WR(0x9040, 0x400003f0);
472
printf("* HEB: Control \n");
473
WR(0x9040, 0x480007F0);
477
printf("* HEB: Control \n");
478
WR(0x9040, 0x48000FF0);
483
// ******************************************************************
484
// **** TEST DDR conf *****
485
// ******************************************************************
489
printf("* DDR: AXI_BUF_SIZE_ADDR: 4k\n");
492
printf("* DDR: Control \n");
493
WR(0x9000, 0x000000F);
496
WR(0x9000, 0x00000008);
498
WR(0x9000, 0x08000008);
502
printf("* DDR: Control \n");
503
WR(0x9000, 0x08000208);
508
// ******************************************************************
509
401
// **** START DMA *****
510
402
// ******************************************************************
529
421
while (i < ITERATIONS) {
531
// printf("\ndesc0: %lx", htonl(desc[0]));
532
// printf("\ndesc1: %lx", htonl(desc[1]));
533
// printf("\ndesc2: %lx", htonl(desc[2]));
534
// printf("\ndesc3: %lx", htonl(desc[3]));
535
// printf("\ndesc4: %lx", htonl(desc[4]));
423
//printf("\ndesc0: %lx", desc[0]);
424
//printf("\ndesc1: %lx", desc[1]);
425
//printf("\ndesc2: %lx", desc[2]);
426
//printf("\ndesc3: %lx", desc[3]);
427
//printf("\ndesc4: %lx", desc[4]);
536
428
// printf("\ndesc5: %lx", htonl(desc[5]));
537
429
//printf("Iteration: %li of %li \r", i+1, ITERATIONS);
538
431
//loadBar(i+1, ITERATIONS, ITERATIONS, 30);
539
432
// printf("\nhwptr: %zu", hwptr);
540
433
// printf("\ncurptr: %zu", curptr);
553
446
pcilib_kmem_sync_block(pci, kbuf, PCILIB_KMEM_SYNC_FROMDEVICE, curbuf);
555
448
memcpy(temp_data[i][curbuf], (void*)ptr[curbuf], 4096);
451
for (k = 0; k < 1024 ; k++)
453
mem_diff = (ptr[curbuf][k] - ptr[curbuf][k]);
454
//if ((mem_diff == 1) || (mem_diff == (-7)) || (k == 1023) )
458
//fprintf(error_log, "Error in: \t IT %li \t BUF : %li \t OFFSET: %li \t | %08x --> %08x - DIFF: %d \n", i, j, k, temp_data[i][j][k], temp_data[i][j][k+1], mem_diff);
557
463
#ifdef SHARED_MEMORY
558
memcpy(shared_memory, (void*)ptr[curbuf], 4096);
464
memcpy(shared_memory, ptr[curbuf], 4096);
560
466
//printf("\ncurbuf: %08x", curbuf);
561
467
//printf("\nbus_addr[curbuf]\n: %08x",bus_addr[curbuf]);
600
506
//printf("WR %d\n", curbuf + 1);
601
507
//printf("%u (%lu)\n", curbuf, j);
608
512
// ******************************************************************
612
516
gettimeofday(&end, NULL);
615
519
RD(0x28, perf_counter);
619
526
iterations_completed = i;
620
527
buffers_filled = curbuf;
621
if (empty) printf("* DMA: Empty FIFO! Last iteration: %u of %u\n", i+1, ITERATIONS);
528
if (empty) printf("* DMA: Empty FIFO! Last iteration: %li of %i\n", i+1, ITERATIONS);
622
529
printf ("* DMA: Stop\n\n");
625
532
printf ("First value:\t %08x\n", temp_data[0][0][0]);
626
533
printf ("Last value:\t %08x\n\n", temp_data[ITERATIONS-1][BUFFERS-1][(PAGE_SIZE/4)-4]);
636
543
run_time = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec);
544
//size = (long long int) (( BUFFERS * (iterations_completed) + buffers_filled) * HUGE_PAGE * PAGE_SIZE);
637
545
size_mb = (long long int) (( BUFFERS * (iterations_completed) + buffers_filled) * HUGE_PAGE * 4 / 1024);
638
printf("Performance: transfered %zu Mbytes in %zu us using %u buffers\n", (size_mb), run_time, BUFFERS);
546
printf("Performance: transfered %llu Mbytes in %zu us using %d buffers\n", (size_mb), run_time, BUFFERS);
639
547
//printf("Buffers: \t %d \n", BUFFERS);
640
548
//printf("Buf_Size: \t %d \n", PAGE_SIZE);
641
549
//printf("Perf_counter: \t %f \n", perf_counter);
683
591
if ((mem_diff == -1) || (k == 1023) )
686
fprintf(error_log, "Error in: \t IT %u \t BUF : %u \t OFFSET: %u \t | %08x --> %08x - DIFF: %d \n", i, j, k, temp_data[i][j][k], temp_data[i][j][k+1], mem_diff);
594
fprintf(error_log, "Error in: \t IT %li \t BUF : %li \t OFFSET: %li \t | %08x --> %08x - DIFF: %d \n", i, j, k, temp_data[i][j][k], temp_data[i][j][k+1], mem_diff);
693
601
if (mem_diff == (1))
696
fprintf(error_log, "Error_2 in: \t IT %u \t BUF : %u \t OFFSET: %u \t | %08x --> %08x - DIFF: %d \n", i, j, k, temp_data[i][j+1][0], temp_data[i][j][1023], mem_diff);
604
fprintf(error_log, "Error_2 in: \t IT %li \t BUF : %li \t OFFSET: %li \t | %08x --> %08x - DIFF: %d \n", i, j, k, temp_data[i][j+1][0], temp_data[i][j][1023], mem_diff);
702
610
loadBar(i+1, ITERATIONS, ITERATIONS, 30);
704
612
for (j = 0; j < buffers_filled; j++) {
705
for (k = 0; k < 1024 ; k++) {
613
for (k = 0; k < 1024 ; k++)
706
615
mem_diff = ((uint32_t)temp_data[iterations_completed][j][k] - (uint32_t)temp_data[iterations_completed][j][k+1]);
707
if ((mem_diff == -1) || (k == 1023) ) {
710
fprintf(error_log, "Error in: \t IT %u \t BUF : %u \t OFFSET: %u \t | %08x --> %08x - DIFF: %d \n", iterations_completed, j, k, temp_data[iterations_completed][j][k], temp_data[iterations_completed][j][k+1], mem_diff);
616
if ((mem_diff == -1) || (k == 1023) )
619
fprintf(error_log, "Error in: \t IT %li \t BUF : %li \t OFFSET: %li \t | %08x --> %08x - DIFF: %d \n", iterations_completed, j, k, temp_data[iterations_completed][j][k], temp_data[iterations_completed][j][k+1], mem_diff);
714
if (j < (buffers_filled-1)) {
623
if (j != buffers_filled-1) {
715
624
// Check first and Last
716
625
mem_diff = (uint32_t)(temp_data[i][j+1][0] - temp_data[i][j][1023]);
717
if (mem_diff == (1)) {
720
fprintf(error_log, "Error_2 in: \t IT %u \t BUF : %u \t OFFSET: %u \t | %08x --> %08x - DIFF: %d \n", iterations_completed, j, k, temp_data[iterations_completed][j+1][0], temp_data[iterations_completed][j][1023], mem_diff);
629
fprintf(error_log, "Error_2 in: \t IT %li \t BUF : %li \t OFFSET: %li \t | %08x --> %08x - DIFF: %d \n", iterations_completed, j, k, temp_data[iterations_completed][j+1][0], temp_data[iterations_completed][j][1023], mem_diff);
725
634
if (err != 0) printf("\rChecking data: \xE2\x9C\x98 %d errors found \n See \"error_log.txt\" for details \n\n", err);
726
635
else printf("\rChecking data: \xE2\x9C\x93 no errors found \n\n");
727
636
fclose(error_log);
731
639
// *********** Free Memory
733
641
for (i=0; i < ITERATIONS; i++) {
734
642
for (j=0; j < BUFFERS; j++)
736
644
free(temp_data[i][j]);
739
#endif /* CHECK_RESULTS */
741
649
pcilib_free_kernel_memory(pci, kbuf, free_flags);
742
650
pcilib_free_kernel_memory(pci, kdesc, free_flags);