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

Exposing the DMA's GIT Version and API Version to pyrogue variables #1003

Merged
merged 6 commits into from
Jun 21, 2024
Merged
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
6 changes: 6 additions & 0 deletions include/rogue/hardware/axi/AxiStreamDma.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ class AxiStreamDma : public rogue::interfaces::stream::Master, public rogue::int
// Process Buffer Return
void retBuffer(uint8_t* data, uint32_t meta, uint32_t rawSize);

//! Get the DMA Driver's Git Version
std::string getGitVersion();

//! Get the DMA Driver's API Version
uint32_t getApiVersion();

//! Get the size of buffers (RX/TX)
uint32_t getBuffSize();

Expand Down
164 changes: 164 additions & 0 deletions include/rogue/hardware/drivers/DmaDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <linux/types.h>
#else
#include <stdint.h>
#include <string>
#endif

/* API Version */
Expand Down Expand Up @@ -61,6 +62,7 @@
#define DMA_Get_RxBuffinPreHWQ_Count 0x1016
#define DMA_Get_RxBuffinSWQ_Count 0x1017
#define DMA_Get_RxBuffMiss_Count 0x1018
#define DMA_Get_GITV 0x1019

/* Mask size */
#define DMA_MASK_SIZE 512
Expand Down Expand Up @@ -476,6 +478,66 @@ static inline ssize_t dmaGetRxBuffCount(int32_t fd) {
return (ioctl(fd, DMA_Get_RxBuff_Count, 0));
}

/**
* dmaGetRxBuffinUserCount - Get the receive buffer count in user
* @fd: File descriptor to use.
*
* This function retrieves the count of receive buffers in user.
*
* Returns: The count of receive buffers in user
*/
static inline ssize_t dmaGetRxBuffinUserCount(int32_t fd) {
return (ioctl(fd, DMA_Get_RxBuffinUser_Count, 0));
}

/**
* dmaGetRxBuffinHwCount - Get the receive buffer count in hardware
* @fd: File descriptor to use.
*
* This function retrieves the count of receive buffers in hardware.
*
* Returns: The count of receive buffers in hardware
*/
static inline ssize_t dmaGetRxBuffinHwCount(int32_t fd) {
return (ioctl(fd, DMA_Get_RxBuffinHW_Count, 0));
}

/**
* dmaGetRxBuffinPreHwQCount - Get the receive buffer count in pre-hardware queue
* @fd: File descriptor to use.
*
* This function retrieves the count of receive buffers in pre-hardware queue
*
* Returns: The count of receive buffers in pre-hardware queue
*/
static inline ssize_t dmaGetRxBuffinPreHwQCount(int32_t fd) {
return (ioctl(fd, DMA_Get_RxBuffinPreHWQ_Count, 0));
}

/**
* dmaGetRxBuffinSwQCount - Get the receive buffer count in software queue
* @fd: File descriptor to use.
*
* This function retrieves the count of receive buffers in software queue
*
* Returns: The count of receive buffers in software queue
*/
static inline ssize_t dmaGetRxBuffinSwQCount(int32_t fd) {
return (ioctl(fd, DMA_Get_RxBuffinSWQ_Count, 0));
}

/**
* dmaGetRxBuffMissCount - Get the receive buffer missing count
* @fd: File descriptor to use.
*
* This function retrieves the count of receive buffer missing
*
* Returns: The count of receive buffers missing
*/
static inline ssize_t dmaGetRxBuffMissCount(int32_t fd) {
return (ioctl(fd, DMA_Get_RxBuffMiss_Count, 0));
}

/**
* dmaGetTxBuffCount - Get the transmit buffer count.
* @fd: File descriptor to use.
Expand All @@ -488,6 +550,66 @@ static inline ssize_t dmaGetTxBuffCount(int32_t fd) {
return (ioctl(fd, DMA_Get_TxBuff_Count, 0));
}

/**
* dmaGetTxBuffinUserCount - Get the transmit buffer count in user
* @fd: File descriptor to use.
*
* This function retrieves the count of transmit buffers in user.
*
* Returns: The count of transmit buffers in user
*/
static inline ssize_t dmaGetTxBuffinUserCount(int32_t fd) {
return (ioctl(fd, DMA_Get_TxBuffinUser_Count, 0));
}

/**
* dmaGetTxBuffinHwCount - Get the transmit buffer count in hardware
* @fd: File descriptor to use.
*
* This function retrieves the count of transmit buffers in hardware.
*
* Returns: The count of transmit buffers in hardware
*/
static inline ssize_t dmaGetTxBuffinHwCount(int32_t fd) {
return (ioctl(fd, DMA_Get_TxBuffinHW_Count, 0));
}

/**
* dmaGetTxBuffinPreHwQCount - Get the transmit buffer count in pre-hardware queue
* @fd: File descriptor to use.
*
* This function retrieves the count of transmit buffers in pre-hardware queue
*
* Returns: The count of transmit buffers in pre-hardware queue
*/
static inline ssize_t dmaGetTxBuffinPreHwQCount(int32_t fd) {
return (ioctl(fd, DMA_Get_TxBuffinPreHWQ_Count, 0));
}

/**
* dmaGetTxBuffinSwQCount - Get the transmit buffer count in software queue
* @fd: File descriptor to use.
*
* This function retrieves the count of transmit buffers in software queue
*
* Returns: The count of transmit buffers in software queue
*/
static inline ssize_t dmaGetTxBuffinSwQCount(int32_t fd) {
return (ioctl(fd, DMA_Get_TxBuffinSWQ_Count, 0));
}

/**
* dmaGetTxBuffMissCount - Get the transmit buffer missing count
* @fd: File descriptor to use.
*
* This function retrieves the count of transmit buffer missing
*
* Returns: The count of transmit buffers missing
*/
static inline ssize_t dmaGetTxBuffMissCount(int32_t fd) {
return (ioctl(fd, DMA_Get_TxBuffMiss_Count, 0));
}

/**
* dmaGetBuffSize - Get the buffer size.
* @fd: File descriptor to use.
Expand All @@ -500,6 +622,36 @@ static inline ssize_t dmaGetBuffSize(int32_t fd) {
return (ioctl(fd, DMA_Get_Buff_Size, 0));
}

/**
* dmaGetBuffCount - Get the buffer count.
* @fd: File descriptor to use.
*
* This function retrieves the count of DMA buffers.
*
* Returns: The count of DMA buffers.
*/
static inline ssize_t dmaGetBuffCount(int32_t fd) {
return (ioctl(fd, DMA_Get_Buff_Count, 0));
}


/**
* dmaGetGitVersion - Get the DMA Driver's Git Version
* @fd: File descriptor to use.
*
* This function retrieves the DMA Driver's Git Version string
*
* Returns: The DMA Driver's Git Version string
*/
static inline std::string dmaGetGitVersion(int32_t fd) {
char gitv[32] = {0}; // Initialize with zeros to ensure null-termination
if (ioctl(fd, DMA_Get_GITV, gitv) < 0) {
return "";
}
gitv[32 - 1] = '\0'; // Ensure null-termination
return std::string(gitv);
}

/**
* dmaMapDma - Map user space to DMA buffers.
* @fd: File descriptor to use.
Expand Down Expand Up @@ -673,6 +825,18 @@ static inline ssize_t dmaCheckVersion(int32_t fd) {
return ((version == DMA_VERSION) ? 0 : -1);
}

/**
* dmaGetApiVersion - Get API version of the DMA driver.
* @fd: File descriptor for the DMA device.
*
* Get the API version of the DMA driver
*
* Return: The API version of the DMA driver
*/
static inline ssize_t dmaGetApiVersion(int32_t fd) {
return (ioctl(fd, DMA_Get_Version, 0));
}

/**
* dmaWriteRegister - Write to a DMA register.
* @fd: File descriptor for the DMA device.
Expand Down
19 changes: 19 additions & 0 deletions python/pyrogue/hardware/axi/_AxiStreamDmaMon.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,25 @@ def __init__(self, axiStreamDma, pollInterval=1, **kwargs):
self._dma = axiStreamDma

# Add variables
self.add(pr.LocalVariable(
name = 'GitVersion',
description = 'DMA\'s Driver GIT Version string',
mode = 'RO',
value = '',
localGet = lambda: self._dma.getGitVersion(),
))

self.add(pr.LocalVariable(
name = 'ApiVersion',
description = 'DMA\'s Driver API Version',
mode = 'RO',
value = 0x0,
typeStr = 'UInt8',
units = 'Bytes',
disp = '{:#x}',
localGet = lambda: self._dma.getApiVersion(),
))

self.add(pr.LocalVariable(
name = 'BuffSize',
description = 'Size of buffers (RX/TX)',
Expand Down
12 changes: 10 additions & 2 deletions src/rogue/hardware/axi/AxiMemMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,21 @@ rha::AxiMemMap::AxiMemMap(std::string path) : rim::Slave(4, 0xFFFFFFFF) {
if (fd_ < 0)
throw(rogue::GeneralError::create("AxiMemMap::AxiMemMap", "Failed to open device file: %s", path.c_str()));

// Check driver version
if (dmaCheckVersion(fd_) < 0)
// Check driver version ( ApiVersion 0x05 (or less) is the 32-bit address version)
if (dmaGetApiVersion(fd_) < 0x06) {
throw(rogue::GeneralError("AxiMemMap::AxiMemMap",
"Bad kernel driver version detected. Please re-compile kernel driver.\n \
Note that aes-stream-driver (v5.15.2 or earlier) and rogue (v5.11.1 or earlier) are compatible with the 32-bit address API. \
To use later versions (64-bit address API),, you will need to upgrade both rogue and aes-stream-driver at the same time to:\n \
\t\taes-stream-driver = v5.16.0 (or later)\n\t\trogue = v5.13.0 (or later)"));
}

// Check for mismatch in the rogue/loaded_driver API versions
if (dmaCheckVersion(fd_) < 0) {
::close(fd_);
throw(rogue::GeneralError("AxiMemMap::AxiMemMap",
"Rogue DmaDriver.h API Version (DMA_VERSION) does not match the aes-stream-driver API version"));
}

// Start read thread
threadEn_ = true;
Expand Down
Loading
Loading