22#ifndef __DMA_DRIVER_H__
23#define __DMA_DRIVER_H__
26 #include <linux/types.h>
34#define DMA_VERSION 0x06
37#define DMA_ERR_FIFO 0x01
38#define DMA_ERR_LEN 0x02
39#define DMA_ERR_MAX 0x04
40#define DMA_ERR_BUS 0x08
45#define DMA_Get_Buff_Count 0x1001
48#define DMA_Get_Buff_Size 0x1002
51#define DMA_Set_Debug 0x1003
54#define DMA_Set_Mask 0x1004
58#define DMA_Ret_Index 0x1005
61#define DMA_Get_Index 0x1006
64#define DMA_Read_Ready 0x1007
67#define DMA_Set_MaskBytes 0x1008
70#define DMA_Get_Version 0x1009
73#define DMA_Write_Register 0x100A
76#define DMA_Read_Register 0x100B
79#define DMA_Get_RxBuff_Count 0x100C
82#define DMA_Get_TxBuff_Count 0x100D
85#define DMA_Get_TxBuffinUser_Count 0x100F
88#define DMA_Get_TxBuffinHW_Count 0x1010
91#define DMA_Get_TxBuffinPreHWQ_Count 0x1011
94#define DMA_Get_TxBuffinSWQ_Count 0x1012
97#define DMA_Get_TxBuffMiss_Count 0x1013
100#define DMA_Get_RxBuffinUser_Count 0x1014
103#define DMA_Get_RxBuffinHW_Count 0x1015
106#define DMA_Get_RxBuffinPreHWQ_Count 0x1016
109#define DMA_Get_RxBuffinSWQ_Count 0x1017
112#define DMA_Get_RxBuffMiss_Count 0x1018
115#define DMA_Get_GITV 0x1019
118#define DMA_MASK_SIZE 512
195 #include <sys/fcntl.h>
196 #include <sys/ioctl.h>
197 #include <sys/mman.h>
198 #include <sys/signal.h>
199 #include <sys/socket.h>
218static inline ssize_t
dmaWrite(int32_t fd,
const void* buf,
size_t size, uint32_t flags, uint32_t dest) {
225 w.
is32 = (
sizeof(
void*) == 4);
226 w.
data = (uint64_t)buf;
253 w.
is32 = (
sizeof(
void*) == 4);
292 for (x = 0; x < iovlen; x++) {
295 w.
flags = (x == 0) ? begFlags : ((x == (iovlen - 1)) ? endFlags : midFlags);
296 w.
size = iov[x].iov_len;
297 w.
is32 = (
sizeof(
void*) == 4);
298 w.
data = (uint64_t)iov[x].iov_base;
344 for (x = 0; x < iovlen; x++) {
347 w.
flags = (x == 0) ? begFlags : ((x == (iovlen - 1)) ? endFlags : midFlags);
348 w.
size = iov[x].iov_len;
349 w.
is32 = (
sizeof(
void*) == 4);
350 w.
index = (uint32_t)(((uint64_t)iov[x].iov_base) & 0xFFFFFFFF);
380static inline ssize_t
dmaRead(int32_t fd,
void* buf,
size_t maxSize, uint32_t*
flags, uint32_t* error, uint32_t*
dest) {
386 r.
is32 = (
sizeof(
void*) == 4);
387 r.
data = (uint64_t)buf;
391 if (
ret <= 0)
return (
ret);
422 if (
ret <= 0)
return (
ret);
462 res = read(fd, r, count *
sizeof(
struct DmaReadData));
464 for (x = 0; x < res; ++x) {
489 return (ioctl(fd, cmd, &
index));
504static inline ssize_t
dmaRetIndexes(int32_t fd, uint32_t count, uint32_t* indexes) {
507 return (ioctl(fd, cmd, indexes));
733 return std::string(gitv);
747static inline void**
dmaMapDma(int32_t fd, uint32_t* count, uint32_t*
size) {
758 if (count != NULL) *count = bCount;
761 if ((
ret =
reinterpret_cast<void**
>(calloc(
sizeof(
void*), bCount))) == 0)
return (NULL);
765 while (gCount < bCount) {
766 offset = (off_t)bSize * (off_t)gCount;
768 if ((temp = mmap(0, bSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)) == MAP_FAILED)
break;
769 ret[gCount++] = temp;
773 if (gCount != bCount) {
774 while (gCount != 0) munmap(
ret[--gCount], bSize);
799 for (x = 0; x < bCount; x++) munmap(buffer[x], bSize);
832 struct sigaction act;
835 act.sa_handler = handler;
836 sigemptyset(&act.sa_mask);
839 sigaction(SIGIO, &act, NULL);
840 fcntl(fd, F_SETOWN, getpid());
841 oflags = fcntl(fd, F_GETFL);
842 fcntl(fd, F_SETFL, oflags | FASYNC);
888 mask[byte] += (1 << bit);
1005 intOffset = ((off_t)bSize * bCount) + offset;
1008 return mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, intOffset);
static ssize_t dmaSetMask(int32_t fd, uint32_t mask)
Set DMA mask.
static std::string dmaGetGitVersion(int32_t fd)
Get the DMA Driver's Git Version.
#define DMA_Set_Debug
ioctl command code: set the kernel debug verbosity level (0 = off).
#define DMA_Get_Index
ioctl command code: get the index of the next available write buffer.
#define DMA_Get_Buff_Size
ioctl command code: get the size in bytes of each DMA buffer.
#define DMA_Get_GITV
ioctl command code: get the driver git version string into a caller-supplied char[32] buffer.
static ssize_t dmaGetTxBuffinPreHwQCount(int32_t fd)
Get the transmit buffer count in pre-hardware queue.
static ssize_t dmaGetTxBuffCount(int32_t fd)
Get the transmit buffer count.
static ssize_t dmaGetTxBuffMissCount(int32_t fd)
Get the transmit buffer missing count.
static ssize_t dmaGetRxBuffinHwCount(int32_t fd)
Get the receive buffer count in hardware.
#define DMA_Get_Buff_Count
ioctl command code: get the total number of DMA buffers in the pool.
#define DMA_Write_Register
ioctl command code: write a 32-bit value to a device BAR register; argument is struct DmaRegisterData...
#define DMA_Get_RxBuff_Count
ioctl command code: get the total number of receive DMA buffers in the pool.
static ssize_t dmaGetApiVersion(int32_t fd)
Get API version of the DMA driver.
static ssize_t dmaWriteIndex(int32_t fd, uint32_t index, size_t size, uint32_t flags, uint32_t dest)
Writes data to a DMA channel using an index.
#define DMA_Get_TxBuffinUser_Count
ioctl command code: get the count of TX buffers currently held in user space.
static ssize_t dmaReadRegister(int32_t fd, uint64_t address, uint32_t *data)
Read a value from a DMA register.
#define DMA_Get_RxBuffinPreHWQ_Count
ioctl command code: get the count of RX buffers in the pre-hardware queue.
#define DMA_Get_TxBuffinHW_Count
ioctl command code: get the count of TX buffers currently submitted to hardware.
static ssize_t dmaWriteRegister(int32_t fd, uint64_t address, uint32_t data)
Write to a DMA register.
#define DMA_Get_TxBuff_Count
ioctl command code: get the total number of transmit DMA buffers in the pool.
static void dmaInitMaskBytes(uint8_t *mask)
Initialize DMA mask byte array.
#define DMA_Set_Mask
ioctl command code: set the 32-bit destination channel mask (convenience wrapper for single-mask use)...
#define DMA_Ret_Index
ioctl command code: return one or more buffer indices to the DMA free pool. The upper 16 bits of the ...
#define DMA_Get_RxBuffinHW_Count
ioctl command code: get the count of RX buffers currently submitted to hardware.
static void dmaAddMaskBytes(uint8_t *mask, uint32_t dest)
Add a destination to the DMA mask byte array.
#define DMA_Get_TxBuffMiss_Count
ioctl command code: get the TX buffer allocation miss count (buffers requested but unavailable).
#define DMA_Set_MaskBytes
ioctl command code: set the destination channel mask using a 512-byte bitmap (DMA_MASK_SIZE bytes).
static ssize_t dmaReadBulkIndex(int32_t fd, uint32_t count, int32_t *ret, uint32_t *index, uint32_t *flags, uint32_t *error, uint32_t *dest)
Receive frame and access memory-mapped buffer.
static ssize_t dmaUnMapRegister(int32_t fd, void *ptr, uint32_t size)
Unmap a DMA register space from user space.
static ssize_t dmaSetMaskBytes(int32_t fd, uint8_t *mask)
Set mask byte array to the driver.
static ssize_t dmaGetRxBuffinUserCount(int32_t fd)
Get the receive buffer count in user.
#define DMA_Get_Version
ioctl command code: get the driver API version integer; compare to DMA_VERSION for compatibility.
static void * dmaMapRegister(int32_t fd, off_t offset, uint32_t size)
Map a DMA register space to user space.
static ssize_t dmaGetTxBuffinHwCount(int32_t fd)
Get the transmit buffer count in hardware.
static ssize_t dmaGetBuffSize(int32_t fd)
Get the buffer size.
static ssize_t dmaGetRxBuffinSwQCount(int32_t fd)
Get the receive buffer count in software queue.
static ssize_t dmaGetRxBuffCount(int32_t fd)
Get the receive buffer count.
static int32_t dmaGetIndex(int32_t fd)
Get the current write buffer index.
static ssize_t dmaReadIndex(int32_t fd, uint32_t *index, uint32_t *flags, uint32_t *error, uint32_t *dest)
Receive Frame, access memory mapped buffer.
static ssize_t dmaGetRxBuffinPreHwQCount(int32_t fd)
Get the receive buffer count in pre-hardware queue.
#define DMA_Get_RxBuffinUser_Count
ioctl command code: get the count of RX buffers currently held in user space.
static ssize_t dmaRetIndex(int32_t fd, uint32_t index)
Post an index back to the DMA.
static ssize_t dmaWriteVector(int32_t fd, struct iovec *iov, size_t iovlen, uint32_t begFlags, uint32_t midFlags, uint32_t endFlags, uint32_t dest)
Writes an array of data frames to a DMA channel.
#define DMA_Get_TxBuffinPreHWQ_Count
ioctl command code: get the count of TX buffers in the pre-hardware queue.
static ssize_t dmaSetDebug(int32_t fd, uint32_t level)
Set debugging level for DMA operations.
static void dmaAssignHandler(int32_t fd, void(*handler)(int32_t))
Assign a signal handler for asynchronous DMA operations.
static ssize_t dmaWriteIndexVector(int32_t fd, struct iovec *iov, size_t iovlen, uint32_t begFlags, uint32_t midFlags, uint32_t endFlags, uint32_t dest)
Write Frame, memory mapped from iovector.
#define DMA_Get_RxBuffinSWQ_Count
ioctl command code: get the count of RX buffers in the software queue.
static ssize_t dmaGetTxBuffinSwQCount(int32_t fd)
Get the transmit buffer count in software queue.
static ssize_t dmaReadReady(int32_t fd)
Check if read is ready.
static ssize_t dmaGetBuffCount(int32_t fd)
Get the buffer count.
static ssize_t dmaCheckVersion(int32_t fd)
Check API version of the DMA driver.
static void ** dmaMapDma(int32_t fd, uint32_t *count, uint32_t *size)
Map user space to DMA buffers.
static ssize_t dmaUnMapDma(int32_t fd, void **buffer)
Unmap user space from DMA buffers.
#define DMA_Get_TxBuffinSWQ_Count
ioctl command code: get the count of TX buffers in the software queue.
#define DMA_Get_RxBuffMiss_Count
ioctl command code: get the RX buffer allocation miss count (buffers requested but unavailable).
static ssize_t dmaRead(int32_t fd, void *buf, size_t maxSize, uint32_t *flags, uint32_t *error, uint32_t *dest)
Receive Frame.
static ssize_t dmaGetTxBuffinUserCount(int32_t fd)
Get the transmit buffer count in user.
#define DMA_Read_Ready
ioctl command code: check whether a receive frame is pending (returns 1 if data ready).
static ssize_t dmaWrite(int32_t fd, const void *buf, size_t size, uint32_t flags, uint32_t dest)
Writes data to a DMA channel.
static ssize_t dmaGetRxBuffMissCount(int32_t fd)
Get the receive buffer missing count.
#define DMA_Read_Register
ioctl command code: read a 32-bit value from a device BAR register; argument is struct DmaRegisterDat...
static ssize_t dmaRetIndexes(int32_t fd, uint32_t count, uint32_t *indexes)
Post multiple indices back to the DMA.
Structure representing a DMA read operation.
Structure representing a DMA write operation.