Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jerry Hicks #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions driver/linux/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Kbuild file for riffa driver

NAME ?= riffa
MAJOR_NUM ?= 100
VENDOR_ID0 ?= 10EE
VENDOR_ID1 ?= 1172

ccflags-y := -DMAJOR_NUM=$(MAJOR_NUM) \
-DDEVICE_NAME='"$(NAME)"' \
-DVENDOR_ID0=0x$(VENDOR_ID0) \
-DVENDOR_ID1=0x$(VENDOR_ID1)

obj-m := $(NAME).o
$(NAME)-y := riffa_driver.o circ_queue.o
29 changes: 13 additions & 16 deletions driver/linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
# like, but make sure they will work in your system.
# The VENDOR_ID _must_ match what is configured on your FPGA's PCIe endpoint
# header. Xilinx has a VENDOR_ID = 10EE.
NAME := riffa
VENDOR_ID0 := 10EE
VENDOR_ID1 := 1172
MAJNUM := 100
NAME ?= riffa
VENDOR_ID0 ?= 10EE
VENDOR_ID1 ?= 1172
MAJNUM ?= 100

# Build variables
KVER := $(shell uname -r)
KDIR := /lib/modules/`uname -r`/build
KVER ?= $(shell uname -r)
KDIR ?= /lib/modules/`uname -r`/build
RHR := /etc/redhat-release
LIB_SRCS := riffa.c
LIB_OBJS := $(patsubst %.c,%.o,$(LIB_SRCS))
Expand All @@ -61,8 +61,7 @@ LIB_VER := $(LIB_VER_MAJ).$(LIB_VER_MIN)
DRVR_HDR := riffa_driver.h
DBUGVAL := DBUG

obj-m += $(NAME).o
$(NAME)-y := riffa_driver.o circ_queue.o
CC=$(CROSS_COMPILE)cc

# Helper functions
define assert
Expand All @@ -88,17 +87,15 @@ all: builddvr
debug: CC += -DDEBUG -g
debug: DBUGVAL = DEBUG
debug: builddvr
$(NAME).so.$(LIB_VER): CC += -DDEVICE_NAME='"$(NAME)"' \
-DMAJOR_NUM=$(MAJNUM) \
-DVENDOR_ID0=0x$(VENDOR_ID0) \
-DVENDOR_ID1=0x$(VENDOR_ID1)
builddvr: $(NAME).ko $(NAME).so.$(LIB_VER)

$(NAME).ko: *.c *.h
$(call assert-variables)
sed -i 's/#define MAJOR_NUM [^\n]*/#define MAJOR_NUM $(MAJNUM)/g' $(DRVR_HDR)
sed -i 's/#define DEVICE_NAME [^\n]*/#define DEVICE_NAME "$(NAME)"/g' $(DRVR_HDR)
sed -i 's/#define VENDOR_ID0 [^\n]*/#define VENDOR_ID0 0x$(VENDOR_ID0)/g' $(DRVR_HDR)
sed -i 's/#define VENDOR_ID1 [^\n]*/#define VENDOR_ID1 0x$(VENDOR_ID1)/g' $(DRVR_HDR)
sed -i 's/#define DEBUG [^\n]*/#define DBUG 1/g' $(DRVR_HDR)
sed -i 's/#define DBUG [^\n]*/#define $(DBUGVAL) 1/g' $(DRVR_HDR)
make -C $(KDIR) SUBDIRS=`pwd` modules
make -C $(KDIR) M=$(PWD)
rm -rf $(LIB_OBJS)

$(NAME).so.$(LIB_VER): $(LIB_OBJS)
Expand All @@ -109,7 +106,7 @@ $(LIB_OBJS): $(LIB_SRCS)

load: $(NAME).ko
insmod $(NAME).ko

unload:
rmmod $(NAME)

Expand Down
27 changes: 17 additions & 10 deletions driver/linux/riffa_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,25 @@ static inline void write_reg(struct fpga_state * sc, int offset, unsigned int va
writel(val, sc->bar0 + (offset<<2));
}

#ifdef BUILD_32
/**
* Needed for 32 bit OS because dma_map_sg macro eventually does some 64 bit
* division.
* Converts a 64-bit RIFFA API timeout to 32-bit jiffies
*/
unsigned long long __udivdi3(unsigned long long num, unsigned long long den)
static inline long timeout64_to_jiffies(uint64_t timeout)
{
do_div(num, den);
return num;
}
#endif
uint32_t denom;

if (timeout == 0)
return MAX_SCHEDULE_TIMEOUT;
else {
denom = 1000;
timeout = timeout * HZ;
do_div(timeout, denom);
if (timeout > LONG_MAX)
return LONG_MAX;
else
return (long) timeout;
}
}

// These are not defined in the 2.x.y kernels, so just define them
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,39)
Expand Down Expand Up @@ -586,7 +593,7 @@ static inline unsigned int chnl_recv(struct fpga_state * sc, int chnl,
DEFINE_WAIT(wait);

// Convert timeout to jiffies.
tymeout = (timeout == 0 ? MAX_SCHEDULE_TIMEOUT : (timeout * HZ/1000 > LONG_MAX ? LONG_MAX : timeout * HZ/1000));
tymeout = timeout64_to_jiffies(timeout);
tymeouto = tymeout;

// Initialize the sg_maps
Expand Down Expand Up @@ -780,7 +787,7 @@ static inline unsigned int chnl_send(struct fpga_state * sc, int chnl,
DEFINE_WAIT(wait);

// Convert timeout to jiffies.
tymeout = (timeout == 0 ? MAX_SCHEDULE_TIMEOUT : (timeout * HZ/1000 > LONG_MAX ? LONG_MAX : timeout * HZ/1000));
tymeout = timeout64_to_jiffies(timeout);
tymeouto = tymeout;

// Clear the message queue.
Expand Down
11 changes: 11 additions & 0 deletions driver/linux/riffa_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,21 @@

// The major device number. We can't rely on dynamic registration because ioctls
// need to know it.
#ifndef MAJOR_NUM
#define MAJOR_NUM 100
#endif

#ifndef DEVICE_NAME
#define DEVICE_NAME "riffa"
#endif

#ifndef VENDOR_ID0
#define VENDOR_ID0 0x10EE
#endif

#ifndef VENDOR_ID1
#define VENDOR_ID1 0x1172
#endif

// Message events for readmsgs/writemsgs queues.
#define EVENT_TXN_LEN 1
Expand Down