Browse Source

Functional

Timo Dritschler 7 years ago
parent
commit
dfc45e4371
4 changed files with 112 additions and 3 deletions
  1. 5 1
      Makefile
  2. 6 2
      infini_fpga.c
  3. 1 0
      test.h
  4. 100 0
      test_with_kiro.c

+ 5 - 1
Makefile

@@ -15,13 +15,17 @@ all:
 	cp -rf $(OFA_KERNEL)/Module.symvers .
 	cat nv.symvers >> Module.symvers
 	make -C $(KDIR) M=$(PWD) NOSTDINC_FLAGS="$(EXTRA_CFLAGS)" modules
+	make clean
+	gcc -g -o test test_with_kiro.c -lpcilib $(shell (pkg-config --libs --cflags kiro))
 
 clean:
+	mv *.ko infini_fpga.ko_backup
 	make -C $(KDIR)  M=$(PWD) clean
+	mv infini_fpga.ko_backup infini_fpga.ko
 
 install:
 	mkdir -p $(DESTDIR)/$(MODULE_DESTDIR);
-	cp -f $(PWD)/nv_peer_mem.ko $(DESTDIR)/$(MODULE_DESTDIR);
+	cp -f $(PWD)/infini_fpga.ko $(DESTDIR)/$(MODULE_DESTDIR);
 	if [ ! -n "$(DESTDIR)" ]; then $(DEPMOD) -r -ae $(KVER);fi;
 
 uninstall:

+ 6 - 2
infini_fpga.c

@@ -59,7 +59,7 @@ MODULE_DESCRIPTION("ALPS pcie memory plug-in for Mellanox InfiniBand");
 MODULE_LICENSE("GPL 2.2");
 MODULE_VERSION(DRV_VERSION);
 
-#define BAR_SIZE 64
+#define BAR_SIZE 0x1024
 
 invalidate_peer_memory mem_invalidate_callback;
 static void *reg_handle;
@@ -73,8 +73,10 @@ static int alps_mem_acquire(unsigned long addr, size_t size, void *peer_mem_priv
     unsigned long phys_addr = pcidriver_resolve_bar (addr);
 
     if (phys_addr) {
+        pr_info ("ALPS detected 0x%lx as it's own. Mapped to physical: 0x%lx\n", addr, phys_addr);
         *client_context = kmalloc (sizeof(unsigned long), GFP_KERNEL);
         **(unsigned long **)client_context = phys_addr;
+        __module_get (THIS_MODULE);
         return 1;
     }
 
@@ -95,8 +97,10 @@ static int alps_dma_map(struct sg_table *sg_head, void *context,
 
 	for_each_sg(sg_head->sgl, sg, 1, i) {
 		sg_set_page(sg, NULL, BAR_SIZE, 0);
-		sg->dma_address = *(unsigned long *)context;
+		//sg->dma_address = *(unsigned long *)context;
+		sg->dma_address = 0xfb009100;
 		sg->dma_length = BAR_SIZE;
+        pr_info ("ALPS mapped 0x%lx for access\n", *(unsigned long *)context);
 	}
 
 	*nmap = 1;

+ 1 - 0
test.h

@@ -0,0 +1 @@
+#define TEST_SIZE 4

+ 100 - 0
test_with_kiro.c

@@ -0,0 +1,100 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <time.h>
+#include <sched.h>
+#include <sys/time.h>
+
+#include <pcilib.h>
+#include <pcilib/bar.h>
+
+#include <kiro/kiro-client.h>
+#include <kiro/kiro-server.h>
+
+#define DEVICE "/dev/fpga0"
+
+#define BAR PCILIB_BAR0
+
+#include "test.h"
+
+
+int main(int argc, char *argv[]) {
+
+
+    pcilib_t *pci;
+    void* volatile bar;
+    const pcilib_bar_info_t *bar_info;
+
+    pci = pcilib_open(DEVICE, PCILIB_MODEL_DETECT);
+    if (!pci) {
+        printf("pcilib_open\n");
+        exit(1);
+    }
+
+    bar = pcilib_resolve_bar_address(pci, BAR, 0);
+    if (!bar) {
+        pcilib_close(pci);
+        printf("map bar\n");
+        exit(1);
+    }
+    printf("BAR mapped to: %p\n", bar);
+
+    bar_info = pcilib_get_bar_info(pci, BAR);
+    printf("%p (Phys: 0x%lx, Size: 0x%x)\n", bar_info[BAR].virt_addr, bar_info[BAR].phys_addr, bar_info[BAR].size);
+
+    //Clear debugging
+    /*
+    volatile int *reset_enable = ((int *)(((unsigned long)bar)+0x9040));
+    volatile int *reset = ((int *)(((unsigned long)bar)+0x93a4));
+    volatile int *reset_slave_tx = ((int *)(((unsigned long)bar)+0x92e4));
+    *reset_enable = 4; //bit 2
+    *reset_slave_tx = 1;
+    *reset_slave_tx = 0;
+    *reset = 1;        //bit 0
+    *reset = 0;
+    *reset_enable = 0;
+    */
+
+    sleep (1);
+
+
+    //write some test data to the BAR
+    int *test = ((int *)(((unsigned long)bar)+0x10000));
+    //int *test = (int *)malloc(4);
+    //int *test = bar;
+    //printf ("Pointing to: %lx\n",test); 
+    *test = 0xdeadbeef;
+    //test[1] = 0xdeadbeef; 
+    //printf ("Set BAR to: 0x%x\n", test); 
+
+    KiroClient *client = kiro_client_new ();
+
+    kiro_client_set_prealloc (client, test, 1024);
+    kiro_client_connect (client, "192.168.11.71", "60010");
+    kiro_client_sync (client);
+
+    
+    unsigned long length = kiro_client_get_memory_size (client);
+    printf ("Transferred %lu bytes from server.\n", length);
+    KiroServer *server = kiro_server_new ();
+    kiro_server_start (server, NULL, "60011", test, length);
+
+    while (0)
+    {
+        sleep (1);
+        kiro_client_sync (client);
+    }
+    
+
+    printf ("BAR now reads: 0x%x\n", *test);
+    //printf("Read '%s' from the server\n", (char *)kiro_client_get_memory (client));
+    /* free (mem); */
+
+
+end:
+    kiro_server_free (server);
+    kiro_client_free (client);
+    pcilib_close(pci);
+    printf("PCI closed\n");
+}