Skip to content

Commit

Permalink
reverting back changes to AxiMemMap/AxiStreamDma
Browse files Browse the repository at this point in the history
  • Loading branch information
ruck314 committed Jul 6, 2024
1 parent f8f7a09 commit 0c03eb3
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 17 deletions.
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
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
50 changes: 35 additions & 15 deletions src/rogue/hardware/axi/AxiStreamDma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ rha::AxiStreamDmaSharedPtr rha::AxiStreamDma::openShared(std::string path, rogue
if ((ret->fd = ::open(path.c_str(), O_RDWR)) < 0)
throw(rogue::GeneralError::create("AxiStreamDma::openShared", "Failed to open device file: %s", path.c_str()));

if (dmaCheckVersion(ret->fd) < 0) {
// Check driver version ( ApiVersion 0x05 (or less) is the 32-bit address version)
if (dmaGetApiVersion(ret->fd) < 0x06) {
::close(ret->fd);
throw(rogue::GeneralError("AxiStreamDma::openShared",
"Bad kernel driver version detected. Please re-compile kernel driver.\n \
Expand All @@ -97,11 +98,18 @@ rha::AxiStreamDmaSharedPtr rha::AxiStreamDma::openShared(std::string path, rogue
\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(ret->fd) < 0) {
::close(ret->fd);
throw(rogue::GeneralError("AxiStreamDma::openShared",
"Rogue DmaDriver.h API Version (DMA_VERSION) does not match the aes-stream-driver API version"));
}

// Result may be that rawBuff = NULL
// Should this just be a warning?
ret->rawBuff = dmaMapDma(ret->fd, &(ret->bCount), &(ret->bSize));
if (ret->rawBuff == NULL) {
ret->bCount = ioctl(ret->fd, DMA_Get_Buff_Count, 0);
ret->bCount = dmaGetBuffCount(ret->fd);

// New map limit should be 8K more than the total number of buffers we require
uint32_t mapSize = ret->bCount + 8192;
Expand Down Expand Up @@ -566,69 +574,79 @@ void rha::AxiStreamDma::runThread(std::weak_ptr<int> lockPtr) {
}
}

//! Get the DMA Driver's Git Version
std::string rha::AxiStreamDma::getGitVersion() {
return dmaGetGitVersion(fd_);
}

//! Get the DMA Driver's API Version
uint32_t rha::AxiStreamDma::getApiVersion() {
return dmaGetApiVersion(fd_);
}

//! Get the size of buffers (RX/TX)
uint32_t rha::AxiStreamDma::getBuffSize() {
return uint32_t(ioctl(fd_, DMA_Get_Buff_Size, 0));
return dmaGetBuffSize(fd_);
}

//! Get the number of RX buffers
uint32_t rha::AxiStreamDma::getRxBuffCount() {
return uint32_t(ioctl(fd_, DMA_Get_RxBuff_Count, 0));
return dmaGetRxBuffCount(fd_);
}

//! Get RX buffer in User count
uint32_t rha::AxiStreamDma::getRxBuffinUserCount() {
return ioctl(fd_, DMA_Get_RxBuffinUser_Count, 0);
return dmaGetRxBuffinUserCount(fd_);
}

//! Get RX buffer in HW count
uint32_t rha::AxiStreamDma::getRxBuffinHwCount() {
return ioctl(fd_, DMA_Get_RxBuffinHW_Count, 0);
return dmaGetRxBuffinHwCount(fd_);
}

//! Get RX buffer in Pre-HW Queue count
uint32_t rha::AxiStreamDma::getRxBuffinPreHwQCount() {
return ioctl(fd_, DMA_Get_RxBuffinPreHWQ_Count, 0);
return dmaGetRxBuffinPreHwQCount(fd_);
}

//! Get RX buffer in SW Queue count
uint32_t rha::AxiStreamDma::getRxBuffinSwQCount() {
return ioctl(fd_, DMA_Get_RxBuffinSWQ_Count, 0);
return dmaGetRxBuffinSwQCount(fd_);
}

//! Get RX buffer missing count
uint32_t rha::AxiStreamDma::getRxBuffMissCount() {
return ioctl(fd_, DMA_Get_RxBuffMiss_Count, 0);
return dmaGetRxBuffMissCount(fd_);
}

//! Get the number of TX buffers
uint32_t rha::AxiStreamDma::getTxBuffCount() {
return uint32_t(ioctl(fd_, DMA_Get_TxBuff_Count, 0));
return dmaGetTxBuffCount(fd_);
}

//! Get TX buffer in User count
uint32_t rha::AxiStreamDma::getTxBuffinUserCount() {
return ioctl(fd_, DMA_Get_TxBuffinUser_Count, 0);
return dmaGetTxBuffinUserCount(fd_);
}

//! Get TX buffer in HW count
uint32_t rha::AxiStreamDma::getTxBuffinHwCount() {
return ioctl(fd_, DMA_Get_TxBuffinHW_Count, 0);
return dmaGetTxBuffinHwCount(fd_);
}

//! Get TX buffer in Pre-HW Queue count
uint32_t rha::AxiStreamDma::getTxBuffinPreHwQCount() {
return ioctl(fd_, DMA_Get_TxBuffinPreHWQ_Count, 0);
return dmaGetTxBuffinPreHwQCount(fd_);
}

//! Get TX buffer in SW Queue count
uint32_t rha::AxiStreamDma::getTxBuffinSwQCount() {
return ioctl(fd_, DMA_Get_TxBuffinSWQ_Count, 0);
return dmaGetTxBuffinSwQCount(fd_);
}

//! Get TX buffer missing count
uint32_t rha::AxiStreamDma::getTxBuffMissCount() {
return ioctl(fd_, DMA_Get_TxBuffMiss_Count, 0);
return dmaGetTxBuffMissCount(fd_);
}

void rha::AxiStreamDma::setup_python() {
Expand All @@ -640,6 +658,8 @@ void rha::AxiStreamDma::setup_python() {
.def("setDriverDebug", &rha::AxiStreamDma::setDriverDebug)
.def("dmaAck", &rha::AxiStreamDma::dmaAck)
.def("setTimeout", &rha::AxiStreamDma::setTimeout)
.def("getGitVersion", &rha::AxiStreamDma::getGitVersion)
.def("getApiVersion", &rha::AxiStreamDma::getApiVersion)
.def("getBuffSize", &rha::AxiStreamDma::getBuffSize)
.def("getRxBuffCount", &rha::AxiStreamDma::getRxBuffCount)
.def("getRxBuffinUserCount", &rha::AxiStreamDma::getRxBuffinUserCount)
Expand Down

0 comments on commit 0c03eb3

Please sign in to comment.