diff --git a/fpga/CMakeLists.txt b/fpga/CMakeLists.txt index a331b46d..98328990 100644 --- a/fpga/CMakeLists.txt +++ b/fpga/CMakeLists.txt @@ -16,6 +16,7 @@ INCLUDE_DIRECTORIES(include) ADD_SUBDIRECTORY(hls) ADD_SUBDIRECTORY(pcie_driver) +ADD_SUBDIRECTORY(host_library) IF(VIVADO_HLS AND VIVADO) ADD_CUSTOM_COMMAND(OUTPUT action/hw/hdl/action_config.v diff --git a/fpga/README.md b/fpga/README.md index 9a8f27bc..abd280ac 100644 --- a/fpga/README.md +++ b/fpga/README.md @@ -8,6 +8,7 @@ Currently supported FPGA is only Xilinx Alveo U55C CPU Part: * `pcie_driver` Linux kernel driver for PCIe version of the FPGA board +* `host_library` Library that should be used to access the driver + some simple diagnostic tools FPGA part: diff --git a/fpga/host_library/CMakeLists.txt b/fpga/host_library/CMakeLists.txt new file mode 100644 index 00000000..3bfa4fbb --- /dev/null +++ b/fpga/host_library/CMakeLists.txt @@ -0,0 +1,20 @@ +ADD_LIBRARY(JungfraujochDevice STATIC + JungfraujochDevice.cpp JungfraujochDevice.h) + +TARGET_LINK_LIBRARIES(JungfraujochDevice CommonFunctions) + +ADD_EXECUTABLE(jfjoch_pcie_status jfjoch_pcie_status.cpp) +TARGET_LINK_LIBRARIES(jfjoch_pcie_status JungfraujochDevice ) +INSTALL(TARGETS jfjoch_pcie_status RUNTIME) + +ADD_EXECUTABLE(jfjoch_pcie_set_network jfjoch_pcie_set_network.cpp) +TARGET_LINK_LIBRARIES(jfjoch_pcie_set_network JungfraujochDevice ) +INSTALL(TARGETS jfjoch_pcie_set_network RUNTIME) + +ADD_EXECUTABLE(jfjoch_pcie_cancel_data_collection jfjoch_pcie_cancel_data_collection.cpp) +TARGET_LINK_LIBRARIES(jfjoch_pcie_cancel_data_collection JungfraujochDevice ) +INSTALL(TARGETS jfjoch_pcie_cancel_data_collection RUNTIME) + +ADD_EXECUTABLE(jfjoch_pcie_clear_net_counters jfjoch_pcie_clear_net_counters.cpp) +TARGET_LINK_LIBRARIES(jfjoch_pcie_clear_net_counters JungfraujochDevice ) +INSTALL(TARGETS jfjoch_pcie_clear_net_counters RUNTIME) diff --git a/fpga/host_library/JungfraujochDevice.cpp b/fpga/host_library/JungfraujochDevice.cpp new file mode 100644 index 00000000..919e7bdb --- /dev/null +++ b/fpga/host_library/JungfraujochDevice.cpp @@ -0,0 +1,206 @@ +// Copyright (2019-2023) Paul Scherrer Institute + +#include +#include +#include +#include "../../common/Definitions.h" +#include "JungfraujochDevice.h" + +#include "../../common/JFJochException.h" +#include "../pcie_driver/jfjoch_ioctl.h" + +JungfraujochDevice::JungfraujochDevice(const std::string &device_name, bool write_access) { + fd = open(device_name.c_str(), write_access ? O_RDWR : O_RDONLY); + if (fd == -1) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Cannot open device"); + + auto action_type = GetDataCollectionStatus().action_type; + if (action_type != ACTION_TYPE) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Wrong device type"); +} + +JungfraujochDevice::~JungfraujochDevice() { + close(fd); +} + +void JungfraujochDevice::Start() { + if (ioctl(fd, IOCTL_JFJOCH_START) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed starting action", errno); +} + +void JungfraujochDevice::Cancel() { + if (ioctl(fd, IOCTL_JFJOCH_CANCEL) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed setting cancel bit", errno); +} + +void JungfraujochDevice::End() { + if (ioctl(fd, IOCTL_JFJOCH_END) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed ending action", errno); +} + +bool JungfraujochDevice::IsIdle() const { + uint32_t tmp; + if (ioctl(fd, IOCTL_JFJOCH_ISIDLE, &tmp) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed checking if idle", errno); + return tmp; +} + +DataCollectionStatus JungfraujochDevice::GetDataCollectionStatus() const { + DataCollectionStatus ret{}; + if (ioctl(fd, IOCTL_JFJOCH_STATUS, &ret) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed reading status", errno); + return ret; +} + +DataCollectionConfig JungfraujochDevice::GetConfig() const { + DataCollectionConfig ret{}; + if (ioctl(fd, IOCTL_JFJOCH_READ_CONFIG, &ret) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed reading config", errno); + return ret; +} + +DeviceStatus JungfraujochDevice::GetDeviceStatus() const { + DeviceStatus ret{}; + if (ioctl(fd, IOCTL_JFJOCH_GET_DEV_STATUS, &ret) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed reading env. data", errno); + return ret; +} + +void JungfraujochDevice::ClearNetworkCounters() { + if (ioctl(fd, IOCTL_JFJOCH_CLR_CNTRS) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed clearing network counters", errno); +} + +void JungfraujochDevice::Reset() { + +} + +uint32_t JungfraujochDevice::GetNumaNode() const { + int32_t tmp; + if (ioctl(fd, IOCTL_JFJOCH_NUMA, &tmp) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed reading NUMA node", errno); + return tmp; +} + +uint32_t JungfraujochDevice::GetCompletedDescriptors() const { + uint32_t ret = 0; + if (ioctl(fd, IOCTL_JFJOCH_C2H_DMA_DESC, &ret) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed geting C2H completed descriptor count", errno); + return ret; +} + +void JungfraujochDevice::SetConfig(const DataCollectionConfig &config) { + if (ioctl(fd, IOCTL_JFJOCH_SET_CONFIG, &config) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed writing config", errno); +} + +bool JungfraujochDevice::ReadWorkCompletion(uint32_t output[16]) { + int tmp = ioctl(fd, IOCTL_JFJOCH_READ_WC_MBOX, output); + if (tmp != 0) { + if (errno == EAGAIN) + return false; + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed receiving work completion", errno); + } + return true; +} + +bool JungfraujochDevice::SendWorkRequest(uint32_t id) { + int tmp = ioctl(fd, IOCTL_JFJOCH_SEND_WR, &id); + if (tmp != 0) { + if (errno == EAGAIN) + return false; + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed sending work request", errno); + } + return true; +} + +uint32_t JungfraujochDevice::GetBufferCount() const { + uint32_t tmp; + if (ioctl(fd, IOCTL_JFJOCH_BUF_COUNT, &tmp) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed getting buffer count", errno); + return tmp; +} + +void JungfraujochDevice::SetMACAddress(uint64_t addr) { + if (ioctl(fd, IOCTL_JFJOCH_SET_MAC, &addr) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed setting MAC address", errno); +} + +uint64_t JungfraujochDevice::GetMACAddress() const { + uint64_t tmp; + if (ioctl(fd, IOCTL_JFJOCH_GET_MAC, &tmp) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed getting MAC address", errno); + return tmp; +} + +void JungfraujochDevice::SetDefaultMACAddress() { + if (ioctl(fd, IOCTL_JFJOCH_DEFAULT_MAC) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed setting default MAC", errno); +} + +uint32_t JungfraujochDevice::GetIPv4Address() const { + uint32_t tmp; + if (ioctl(fd, IOCTL_JFJOCH_GET_IPV4, &tmp) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed getting IPv4 address", errno); + return tmp; +} + +void JungfraujochDevice::SetIPv4Address(uint32_t input) { + if (ioctl(fd, IOCTL_JFJOCH_SET_IPV4, &input) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed setting IPv4 address", errno); +} + +void JungfraujochDevice::RunFrameGenerator(const FrameGeneratorConfig &config) { + if (ioctl(fd, IOCTL_JFJOCH_RUN_FRAME_GEN, &config) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed starting frame generator", errno); +} + +void JungfraujochDevice::WriteRegister(uint32_t addr, uint32_t val) { + RegisterConfig config{.addr = addr, .val = val}; + if (ioctl(fd, IOCTL_JFJOCH_WRITE_REGISTER, &config) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed writing to register", errno); +} + +uint32_t JungfraujochDevice::ReadRegister(uint32_t addr) const { + RegisterConfig config; + config.addr = addr; + if (ioctl(fd, IOCTL_JFJOCH_READ_REGISTER, &config) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed reading register", errno); + return config.val; +} + +void JungfraujochDevice::LoadCalibration(uint32_t modules, uint32_t storage_cells) { + DataCollectionConfig config{ + .nmodules = modules, + .nstorage_cells = storage_cells + }; + if (ioctl(fd, IOCTL_JFJOCH_LOAD_CALIB, &config) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed uploading calibration", errno); +} + +void JungfraujochDevice::LoadInternalGeneratorFrame(uint32_t modules) { + DataCollectionConfig config{ + .nmodules = modules + }; + if (ioctl(fd, IOCTL_JFJOCH_LOAD_INT_GEN, &config) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed uploading internal generator frame", errno); +} + +void JungfraujochDevice::LoadIntegrationMap(uint32_t modules) { + DataCollectionConfig config{ + .nmodules = modules, + }; + if (ioctl(fd, IOCTL_JFJOCH_LOAD_INT_MAP, &config) != 0) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed uploading integration map", errno); +} + +uint16_t *JungfraujochDevice::MapKernelBuffer(uint32_t id) { + auto tmp = (uint16_t *) mmap(nullptr, FPGA_BUFFER_LOCATION_SIZE, + PROT_READ | PROT_WRITE, MAP_SHARED, + fd, FPGA_BUFFER_LOCATION_SIZE * id); + + if (tmp == nullptr) + throw JFJochException(JFJochExceptionCategory::PCIeError, "Mmap of kernel buffer error", errno); + + return tmp; +} diff --git a/fpga/host_library/JungfraujochDevice.h b/fpga/host_library/JungfraujochDevice.h new file mode 100644 index 00000000..5c7cf149 --- /dev/null +++ b/fpga/host_library/JungfraujochDevice.h @@ -0,0 +1,97 @@ +// Copyright (2019-2023) Paul Scherrer Institute + +#ifndef JUNGFRAUJOCH_JUNGFRAUJOCHDEVICE_H +#define JUNGFRAUJOCH_JUNGFRAUJOCHDEVICE_H + +#include +#include "../pcie_driver/ActionConfig.h" + +class JungfraujochDevice { + int fd; +public: + JungfraujochDevice(const std::string& device_name, bool write_access); + ~JungfraujochDevice(); + + // Starts data collection + void Start(); + // Cancels data collection + void Cancel(); + // Cancels data collection + disables DMA + void End(); + // Checks if action is idle + bool IsIdle() const; + + // Gets current status + DataCollectionStatus GetDataCollectionStatus() const; + // Gets current env. parameters + DeviceStatus GetDeviceStatus() const; + + // Clears network counters + void ClearNetworkCounters(); + + // Sets configuration + void SetConfig(const DataCollectionConfig &config); + // Get configuration + DataCollectionConfig GetConfig() const; + + // Resets FPGA - not safe at the moment + void Reset(); + + + // Returns current NUMA node + uint32_t GetNumaNode() const; + + // Returns number of completed card-to-host descriptors = number of full modules transferred to the host memory + uint32_t GetCompletedDescriptors() const; + + // Read work completion + // returns true if there was completion in the mailbox - output is then saved + // returns false if mailbox was empty - output is invalid + bool ReadWorkCompletion(uint32_t output[16]); + + // Sends work request of buffer location id + // returns true if there was space in the mailbox + // returns false if mailbox was full + bool SendWorkRequest(uint32_t id); + + // Sets MAC address + // input has to be in network order + void SetMACAddress(uint64_t addr); + // Sets default MAC address of the FPGA board + void SetDefaultMACAddress(); + // Returns MAC address in network order + uint64_t GetMACAddress() const; + // Returns IPv4 address in network order + uint32_t GetIPv4Address() const; + // Set IPv4 address + // input has to be in network order + void SetIPv4Address(uint32_t input); + + // Start internal frame generator + // Doesn't wait for the result + void RunFrameGenerator(const FrameGeneratorConfig &config); + + // Write to any FPGA register + // UNSAFE! only if you know what you are doing + // Can only be done by root user + void WriteRegister(uint32_t addr, uint32_t val); + // Read to any FPGA register + uint32_t ReadRegister(uint32_t addr) const; + + // Load calibration parameters + void LoadCalibration(uint32_t modules, uint32_t storage_cells); + // Load frames for internal generator + // Must be placed in first kernel buffer locations + void LoadInternalGeneratorFrame(uint32_t modules); + // Load map of radial integration + // Must be placed in first kernel buffer locations + void LoadIntegrationMap(uint32_t modules); + + // Get number of kernel buffers + uint32_t GetBufferCount() const; + // Allocate id kernel buffer ( id must be less than GetBufferCount() ) + // buffer has to be unmapped using munmap + uint16_t *MapKernelBuffer(uint32_t id); +}; + +#endif //JUNGFRAUJOCH_JUNGFRAUJOCHDEVICE_H diff --git a/receiver/jfjoch_pcie_cancel_data_collection.cpp b/fpga/host_library/jfjoch_pcie_cancel_data_collection.cpp similarity index 81% rename from receiver/jfjoch_pcie_cancel_data_collection.cpp rename to fpga/host_library/jfjoch_pcie_cancel_data_collection.cpp index 0a578299..6bf95372 100644 --- a/receiver/jfjoch_pcie_cancel_data_collection.cpp +++ b/fpga/host_library/jfjoch_pcie_cancel_data_collection.cpp @@ -1,9 +1,11 @@ // Copyright (2019-2023) Paul Scherrer Institute +// Copyright (2019-2023) Paul Scherrer Institute + #include #include "../common/JFJochException.h" -#include "PCIExpressDevice.h" +#include "JungfraujochDevice.h" #include "../common/Logger.h" int main(int argc, char **argv) { @@ -16,7 +18,7 @@ int main(int argc, char **argv) { logger.Info("Device {}", argv[1]); std::cout << std::endl; try { - PCIExpressDevice test(argv[1], 0); + JungfraujochDevice test(argv[1], true); test.Cancel(); logger.Info("Done"); } catch (const JFJochException &e) { diff --git a/receiver/jfjoch_pcie_clear_net_counters.cpp b/fpga/host_library/jfjoch_pcie_clear_net_counters.cpp similarity index 81% rename from receiver/jfjoch_pcie_clear_net_counters.cpp rename to fpga/host_library/jfjoch_pcie_clear_net_counters.cpp index ea6692fd..d7a5e0a2 100644 --- a/receiver/jfjoch_pcie_clear_net_counters.cpp +++ b/fpga/host_library/jfjoch_pcie_clear_net_counters.cpp @@ -3,7 +3,7 @@ #include #include "../common/JFJochException.h" -#include "PCIExpressDevice.h" +#include "JungfraujochDevice.h" #include "../common/Logger.h" int main(int argc, char **argv) { @@ -16,8 +16,8 @@ int main(int argc, char **argv) { logger.Info("Device {}", argv[1]); std::cout << std::endl; try { - PCIExpressDevice test(argv[1], 0); - test.ClearNetworkCounters(); + JungfraujochDevice device(argv[1], true); + device.ClearNetworkCounters(); logger.Info("Done"); } catch (const JFJochException &e) { logger.ErrorException(e); diff --git a/receiver/jfjoch_pcie_set_network.cpp b/fpga/host_library/jfjoch_pcie_set_network.cpp similarity index 70% rename from receiver/jfjoch_pcie_set_network.cpp rename to fpga/host_library/jfjoch_pcie_set_network.cpp index bc8c38e3..abacff28 100644 --- a/receiver/jfjoch_pcie_set_network.cpp +++ b/fpga/host_library/jfjoch_pcie_set_network.cpp @@ -1,8 +1,10 @@ // Copyright (2019-2023) Paul Scherrer Institute +// Copyright (2019-2023) Paul Scherrer Institute + #include "../common/Logger.h" #include "../common/JFJochException.h" -#include "PCIExpressDevice.h" +#include "JungfraujochDevice.h" #include "../common/NetworkAddressConvert.h" int main(int argc, char **argv) { @@ -16,9 +18,9 @@ int main(int argc, char **argv) { logger.Info("Device {} IPv4 address {}", argv[1], argv[2]); try { - PCIExpressDevice test(argv[1], 0); - test.SetDefaultMAC(); - test.SetIPv4Address(IPv4AddressFromStr(std::string(argv[2]))); + JungfraujochDevice device(argv[1], true); + device.SetDefaultMACAddress(); + device.SetIPv4Address(IPv4AddressFromStr(std::string(argv[2]))); logger.Info("Done"); } catch (const JFJochException &e) { logger.ErrorException(e); diff --git a/fpga/host_library/jfjoch_pcie_status.cpp b/fpga/host_library/jfjoch_pcie_status.cpp new file mode 100644 index 00000000..fb241b02 --- /dev/null +++ b/fpga/host_library/jfjoch_pcie_status.cpp @@ -0,0 +1,78 @@ +// Copyright (2019-2023) Paul Scherrer Institute + +#include +#include + +#include "../common/NetworkAddressConvert.h" +#include "../common/JFJochException.h" +#include "JungfraujochDevice.h" + +int main(int argc, char **argv) { + + if (argc != 2) { + std::cout << "Usage: ./jfjoch_pcie_status " << std::endl; + exit(EXIT_FAILURE); + } + std::cout << "Device " << argv[1] << std::endl; + std::cout << std::endl; + try { + JungfraujochDevice device(argv[1], false); + auto fpga_status = device.GetDataCollectionStatus(); + auto fpga_env_data = device.GetDeviceStatus(); + + std::cout << "PCIe/JFJoch card detected " << std::endl; + std::cout << "Git SHA1 " << std::hex << fpga_status.git_sha1 << std::endl; + std::cout << "Max modules " << std::dec << fpga_status.max_modules << std::endl; + std::cout << "NUMA node " << device.GetNumaNode() << std::endl; + std::cout << "Ethernet aligned " << (fpga_env_data.ethernet_aligned ? "Yes" : "No") << std::endl; + + std::cout << "FPGA 12V rail current [A] " << fpga_env_data.fpga_pcie_12V_I_mA / 1000.0 << std::endl; + std::cout << "FPGA 12V rail voltage [V] " << fpga_env_data.fpga_pcie_12V_V_mV / 1000.0 << std::endl; + std::cout << "FPGA 3.3V rail current [A] " << fpga_env_data.fpga_pcie_3p3V_I_mA / 1000.0 << std::endl; + std::cout << "FPGA 3.3V rail voltage [V] " << fpga_env_data.fpga_pcie_3p3V_V_mV / 1000.0 << std::endl; + std::cout << "FPGA temperature " << fpga_env_data.fpga_temp_C << std::endl; + std::cout << "HBM temperature #0 " << fpga_env_data.hbm_0_temp_C << std::endl; + std::cout << "HBM temperature #1 " << fpga_env_data.hbm_1_temp_C << std::endl; + std::cout << "HBM size (MiB) " << fpga_status.hbm_size_bytes / static_cast(1024 * 1024) << std::endl; + std::cout << "Data collection idle " << device.IsIdle() << std::endl; + std::cout << "Host writer idle " << (fpga_status.ctrl_reg & (1<<4)) << std::endl; + std::cout << "Data collection cancel " << (fpga_status.ctrl_reg & (1<<2)) << std::endl; + + std::cout << "Full status register " << std::bitset<32>(fpga_status.ctrl_reg) << std::endl; + + std::cout << "Stalls HBM " << fpga_status.pipeline_stalls_hbm << std::endl; + std::cout << "Stalls host mem " << fpga_status.pipeline_stalls_host << std::endl; + + DataCollectionConfig cfg = device.GetConfig(); + std::cout << "MAC address " << MacAddressToStr(device.GetMACAddress()) << std::endl; + std::cout << "IPv4 address " << IPv4AddressToStr(device.GetIPv4Address()) << std::endl; + std::cout << "Data collection mode (hex) " << std::hex << (cfg.mode & 0xFFFF) << std::dec << std::endl; + std::cout << "Data collection ID (hex) " << std::hex << ((cfg.mode & 0xFFFF0000) >> 16) << std::dec << std::endl; + std::cout << "Modules " << std::dec << cfg.nmodules << std::endl; + std::cout << "Frames int. pkt. gen. " << std::dec << cfg.nframes << std::endl; + std::cout << std::endl; + std::cout << "FPGA FIFO status: " << std::bitset<32>(fpga_status.fifo_status) << std::endl; + std::cout << std::endl; + std::cout << "Packet counters - ETH " << fpga_status.packets_eth << std::endl; + std::cout << " - UDP " << fpga_status.packets_udp << std::endl; + std::cout << " - SLS " << fpga_status.packets_sls << std::endl; + std::cout << " - ICMP " << fpga_status.packets_icmp << std::endl; + std::cout << " - JFJoch " << fpga_status.packets_processed << std::endl; + std::cout << std::endl; + + std::cout << " - err. ETH " << fpga_status.udp_err_eth << std::endl; + std::cout << " - err. len. " << fpga_status.udp_err_len << std::endl; + std::cout << std::endl; + + std::cout << "H2C descriptors:" << fpga_env_data.pcie_h2c_descriptors << " beats: " << fpga_env_data.pcie_h2c_beats + << " status:" << fpga_env_data.pcie_h2c_status << std::endl; + std::cout << "C2H descriptors:" << fpga_env_data.pcie_c2h_descriptors << " beats: " << fpga_env_data.pcie_c2h_beats + << " status:" << fpga_env_data.pcie_c2h_status << std::endl; + + std::cout << std::endl; + } catch (const JFJochException &e) { + std::cout << e.what() << std::endl; + std::cout << std::endl; + } + +} \ No newline at end of file diff --git a/fpga/pcie_driver/ActionConfig.h b/fpga/pcie_driver/ActionConfig.h index 9cb991e3..ccc1f4c6 100644 --- a/fpga/pcie_driver/ActionConfig.h +++ b/fpga/pcie_driver/ActionConfig.h @@ -13,7 +13,7 @@ typedef __u64 uint64_t; #pragma pack(push) #pragma pack(4) -struct ActionConfig { +struct DataCollectionConfig { uint32_t nmodules; uint32_t mode; uint32_t one_over_energy; @@ -21,7 +21,7 @@ struct ActionConfig { uint32_t nstorage_cells; }; -struct ActionStatus { +struct DataCollectionStatus { uint32_t ctrl_reg; uint32_t reserved_0; uint32_t set_led; @@ -45,7 +45,7 @@ struct ActionStatus { uint32_t udp_err_eth; }; -struct ActionEnvParams { +struct DeviceStatus { uint32_t mailbox_status_reg; uint32_t mailbox_err_reg; uint32_t fpga_temp_C; diff --git a/fpga/pcie_driver/README.md b/fpga/pcie_driver/README.md index ee8668aa..7bb54cd9 100644 --- a/fpga/pcie_driver/README.md +++ b/fpga/pcie_driver/README.md @@ -16,9 +16,7 @@ For each FPGA device a character device is created called /dev/jfjoch<number When device is opened two operations are possible: mmap() to map device buffers ioctl() to communicate with the cards - -(more documentation will come later) +Interfacing should be done through the JungfraujochDevice class. ## TODO /sys filesystem for diagnostics -Don't cancel when opened in read-only mode. diff --git a/fpga/pcie_driver/jfjoch_drv.c b/fpga/pcie_driver/jfjoch_drv.c index 1bc0bed4..dc0a337d 100644 --- a/fpga/pcie_driver/jfjoch_drv.c +++ b/fpga/pcie_driver/jfjoch_drv.c @@ -29,7 +29,7 @@ static int jfjoch_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id int err; struct device *const dev = &pdev->dev; struct jfjoch_drvdata *drvdata; - struct ActionStatus status; + struct DataCollectionStatus status; if ((nbuffer < 64) || (nbuffer > 65536)) { dev_err(dev, "nbuffer parameter must be in range 64-65536\n"); diff --git a/fpga/pcie_driver/jfjoch_drv.h b/fpga/pcie_driver/jfjoch_drv.h index 89c6f90f..78e79fcf 100644 --- a/fpga/pcie_driver/jfjoch_drv.h +++ b/fpga/pcie_driver/jfjoch_drv.h @@ -115,16 +115,16 @@ void jfjoch_end(struct jfjoch_drvdata *drvdata); int jfjoch_send_wr(struct jfjoch_drvdata *drvdata, u32 handle); int jfjoch_read_wc(struct jfjoch_drvdata *drvdata, u32 *output); -void jfjoch_set_config(struct jfjoch_drvdata *drvdata, const struct ActionConfig *config); -void jfjoch_get_config(struct jfjoch_drvdata *drvdata, struct ActionConfig *config); -void jfjoch_get_status(struct jfjoch_drvdata *drvdata, struct ActionStatus *status); +void jfjoch_set_config(struct jfjoch_drvdata *drvdata, const struct DataCollectionConfig *config); +void jfjoch_get_config(struct jfjoch_drvdata *drvdata, struct DataCollectionConfig *config); +void jfjoch_get_status(struct jfjoch_drvdata *drvdata, struct DataCollectionStatus *status); void jfjoch_set_mac_addr(struct jfjoch_drvdata *drvdata, u64 *mac_addr); void jfjoch_get_mac_addr(struct jfjoch_drvdata *drvdata, u64 *mac_addr); void jfjoch_set_ipv4_addr(struct jfjoch_drvdata *drvdata, const u32 *addr); void jfjoch_get_ipv4_addr(struct jfjoch_drvdata *drvdata, u32 *addr); -int jfjoch_load_internal_generator_frame(struct jfjoch_drvdata *drvdata, struct ActionConfig *config); -int jfjoch_load_calibration(struct jfjoch_drvdata *drvdata, struct ActionConfig *config); -int jfjoch_load_integration_map(struct jfjoch_drvdata *drvdata, struct ActionConfig *config); +int jfjoch_load_internal_generator_frame(struct jfjoch_drvdata *drvdata, struct DataCollectionConfig *config); +int jfjoch_load_calibration(struct jfjoch_drvdata *drvdata, struct DataCollectionConfig *config); +int jfjoch_load_integration_map(struct jfjoch_drvdata *drvdata, struct DataCollectionConfig *config); int jfjoch_run_frame_gen(struct jfjoch_drvdata *drvdata, struct FrameGeneratorConfig *config); u32 jfjoch_get_c2h_descriptors(struct jfjoch_drvdata *drvdata); @@ -134,7 +134,7 @@ void jfjoch_clr_net_counters(struct jfjoch_drvdata *drvdata); void jfjoch_is_idle(struct jfjoch_drvdata *drvdata, uint32_t *output); -void jfjoch_get_env_data(struct jfjoch_drvdata *drvdata, struct ActionEnvParams *env_params); +void jfjoch_get_env_data(struct jfjoch_drvdata *drvdata, struct DeviceStatus *env_params); void jfjoch_reset(struct jfjoch_drvdata *drvdata); diff --git a/fpga/pcie_driver/jfjoch_function.c b/fpga/pcie_driver/jfjoch_function.c index 4dec7804..cc62a56c 100644 --- a/fpga/pcie_driver/jfjoch_function.c +++ b/fpga/pcie_driver/jfjoch_function.c @@ -99,18 +99,18 @@ int jfjoch_read_wc(struct jfjoch_drvdata *drvdata, u32 *output) { return 0; } -void jfjoch_set_config(struct jfjoch_drvdata *drvdata, const struct ActionConfig *config) { +void jfjoch_set_config(struct jfjoch_drvdata *drvdata, const struct DataCollectionConfig *config) { mutex_lock(&set_config_mutex); - memcpy_toio((drvdata->bar0) + ACTION_CONFIG_OFFSET + ADDR_NMODULES, config, sizeof(struct ActionConfig)); + memcpy_toio((drvdata->bar0) + ACTION_CONFIG_OFFSET + ADDR_NMODULES, config, sizeof(struct DataCollectionConfig)); mutex_unlock(&set_config_mutex); } -void jfjoch_get_config(struct jfjoch_drvdata *drvdata, struct ActionConfig *config) { - memcpy_fromio(config, (drvdata->bar0) + ACTION_CONFIG_OFFSET + ADDR_NMODULES, sizeof(struct ActionConfig)); +void jfjoch_get_config(struct jfjoch_drvdata *drvdata, struct DataCollectionConfig *config) { + memcpy_fromio(config, (drvdata->bar0) + ACTION_CONFIG_OFFSET + ADDR_NMODULES, sizeof(struct DataCollectionConfig)); } -void jfjoch_get_status(struct jfjoch_drvdata *drvdata, struct ActionStatus *status) { - memcpy_fromio(status, drvdata->bar0 + ACTION_CONFIG_OFFSET, sizeof(struct ActionStatus)); +void jfjoch_get_status(struct jfjoch_drvdata *drvdata, struct DataCollectionStatus *status) { + memcpy_fromio(status, drvdata->bar0 + ACTION_CONFIG_OFFSET, sizeof(struct DataCollectionStatus)); } void jfjoch_set_mac_addr(struct jfjoch_drvdata *drvdata, u64 *mac_addr) { @@ -253,7 +253,7 @@ void jfjoch_setup_network(struct jfjoch_drvdata *drvdata) { iowrite32(0, drvdata->bar0 + ACTION_CONFIG_OFFSET); } -void jfjoch_get_env_data(struct jfjoch_drvdata *drvdata, struct ActionEnvParams *env_params) { +void jfjoch_get_env_data(struct jfjoch_drvdata *drvdata, struct DeviceStatus *env_params) { env_params->mailbox_status_reg = ioread32(drvdata->bar0 + MAILBOX_OFFSET + 0x10); env_params->mailbox_err_reg = ioread32(drvdata->bar0 + MAILBOX_OFFSET + 0x14); @@ -285,7 +285,7 @@ void jfjoch_clr_net_counters(struct jfjoch_drvdata *drvdata) { iowrite32(0, drvdata->bar0 + ACTION_CONFIG_OFFSET); } -int jfjoch_load_calibration(struct jfjoch_drvdata *drvdata, struct ActionConfig *config) { +int jfjoch_load_calibration(struct jfjoch_drvdata *drvdata, struct DataCollectionConfig *config) { struct device *const dev = &drvdata->pdev->dev; u32 i; u32 cell_count = config->nmodules * (3 + 3 * config->nstorage_cells); @@ -331,7 +331,7 @@ int jfjoch_load_calibration(struct jfjoch_drvdata *drvdata, struct ActionConfig return 0; } -int jfjoch_load_integration_map(struct jfjoch_drvdata *drvdata, struct ActionConfig *config) { +int jfjoch_load_integration_map(struct jfjoch_drvdata *drvdata, struct DataCollectionConfig *config) { struct device *const dev = &drvdata->pdev->dev; u32 i; u32 cell_count = config->nmodules; @@ -377,7 +377,7 @@ int jfjoch_load_integration_map(struct jfjoch_drvdata *drvdata, struct ActionCon } -int jfjoch_load_internal_generator_frame(struct jfjoch_drvdata *drvdata, struct ActionConfig *config) { +int jfjoch_load_internal_generator_frame(struct jfjoch_drvdata *drvdata, struct DataCollectionConfig *config) { struct device *const dev = &drvdata->pdev->dev; u32 i; u32 cell_count = config->nmodules; diff --git a/fpga/pcie_driver/jfjoch_ioctl.c b/fpga/pcie_driver/jfjoch_ioctl.c index 87083ca7..4b1d5e99 100644 --- a/fpga/pcie_driver/jfjoch_ioctl.c +++ b/fpga/pcie_driver/jfjoch_ioctl.c @@ -5,9 +5,9 @@ long jfjoch_cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct jfjoch_drvdata *drvdata = container_of(file->private_data, struct jfjoch_drvdata, miscdev); - struct ActionStatus status; - struct ActionConfig config; - struct ActionEnvParams env_params; + struct DataCollectionStatus status; + struct DataCollectionConfig config; + struct DeviceStatus env_params; struct FrameGeneratorConfig frame_generator_config; struct RegisterConfig reg_config; u32 exchange[16]; @@ -31,36 +31,36 @@ long jfjoch_cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { return 0; case IOCTL_JFJOCH_STATUS: jfjoch_get_status(drvdata, &status); - if (copy_to_user((char *) arg, &status, sizeof(struct ActionStatus)) != 0) + if (copy_to_user((char *) arg, &status, sizeof(struct DataCollectionStatus)) != 0) return -EFAULT; return 0; case IOCTL_JFJOCH_READ_CONFIG: jfjoch_get_config(drvdata, &config); - if (copy_to_user((char *) arg, &config, sizeof(struct ActionConfig)) != 0) + if (copy_to_user((char *) arg, &config, sizeof(struct DataCollectionConfig)) != 0) return -EFAULT; return 0; case IOCTL_JFJOCH_SET_CONFIG: if (!(file->f_mode & FMODE_WRITE)) return -EACCES; - if (copy_from_user(&config, (char *) arg, sizeof(struct ActionConfig)) != 0) + if (copy_from_user(&config, (char *) arg, sizeof(struct DataCollectionConfig)) != 0) return -EFAULT; jfjoch_set_config(drvdata, &config); return 0; case IOCTL_JFJOCH_LOAD_CALIB: if (!(file->f_mode & FMODE_WRITE)) return -EACCES; - if (copy_from_user(&config, (char *) arg, sizeof(struct ActionConfig)) != 0) + if (copy_from_user(&config, (char *) arg, sizeof(struct DataCollectionConfig)) != 0) return -EFAULT; return jfjoch_load_calibration(drvdata, &config); case IOCTL_JFJOCH_LOAD_INT_MAP: if (!(file->f_mode & FMODE_WRITE)) return -EACCES; - if (copy_from_user(&config, (char *) arg, sizeof(struct ActionConfig)) != 0) + if (copy_from_user(&config, (char *) arg, sizeof(struct DataCollectionConfig)) != 0) return -EFAULT; return jfjoch_load_integration_map(drvdata, &config); - case IOCTL_JFJOCH_GET_ENV_DATA: + case IOCTL_JFJOCH_GET_DEV_STATUS: jfjoch_get_env_data(drvdata, &env_params); - if (copy_to_user((char *) arg, &env_params, sizeof(struct ActionEnvParams)) != 0) + if (copy_to_user((char *) arg, &env_params, sizeof(struct DeviceStatus)) != 0) return -EFAULT; return 0; case IOCTL_JFJOCH_SEND_WR: @@ -137,7 +137,7 @@ long jfjoch_cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { case IOCTL_JFJOCH_LOAD_INT_GEN: if (!(file->f_mode & FMODE_WRITE)) return -EACCES; - if (copy_from_user(&config, (char *) arg, sizeof(struct ActionConfig)) != 0) + if (copy_from_user(&config, (char *) arg, sizeof(struct DataCollectionConfig)) != 0) return -EFAULT; return jfjoch_load_internal_generator_frame(drvdata, &config); case IOCTL_JFJOCH_C2H_DMA_DESC: diff --git a/fpga/pcie_driver/jfjoch_ioctl.h b/fpga/pcie_driver/jfjoch_ioctl.h index cd5778b9..33595be1 100644 --- a/fpga/pcie_driver/jfjoch_ioctl.h +++ b/fpga/pcie_driver/jfjoch_ioctl.h @@ -11,33 +11,33 @@ #include #endif -#define IOCTL_JFJOCH_MAGIC 0xE1 +#define IOCTL_JFJOCH_MAGIC 0xE1 -#define IOCTL_JFJOCH_START _IO (IOCTL_JFJOCH_MAGIC, 0) -#define IOCTL_JFJOCH_STATUS _IOR(IOCTL_JFJOCH_MAGIC, 1, struct ActionStatus) -#define IOCTL_JFJOCH_READ_CONFIG _IOR(IOCTL_JFJOCH_MAGIC, 2, struct ActionConfig) -#define IOCTL_JFJOCH_SET_CONFIG _IOW(IOCTL_JFJOCH_MAGIC, 3, struct ActionConfig) -#define IOCTL_JFJOCH_CANCEL _IO (IOCTL_JFJOCH_MAGIC, 4) -#define IOCTL_JFJOCH_READ_WC_MBOX _IOR(IOCTL_JFJOCH_MAGIC, 5, uint32_t[12]) -#define IOCTL_JFJOCH_SEND_WR _IOW(IOCTL_JFJOCH_MAGIC, 6, uint32_t) -#define IOCTL_JFJOCH_BUF_COUNT _IOR(IOCTL_JFJOCH_MAGIC, 7, uint32_t) -#define IOCTL_JFJOCH_SET_MAC _IOW(IOCTL_JFJOCH_MAGIC, 8, uint64_t) -#define IOCTL_JFJOCH_GET_MAC _IOR(IOCTL_JFJOCH_MAGIC, 9, uint64_t) -#define IOCTL_JFJOCH_ISIDLE _IOR(IOCTL_JFJOCH_MAGIC, 10, uint32_t) -#define IOCTL_JFJOCH_GET_ENV_DATA _IOR(IOCTL_JFJOCH_MAGIC, 11, struct ActionEnvParams) -#define IOCTL_JFJOCH_END _IO (IOCTL_JFJOCH_MAGIC, 12) -#define IOCTL_JFJOCH_RESET _IO (IOCTL_JFJOCH_MAGIC, 13) -#define IOCTL_JFJOCH_NUMA _IOR(IOCTL_JFJOCH_MAGIC, 14, uint32_t) -#define IOCTL_JFJOCH_CLR_CNTRS _IO (IOCTL_JFJOCH_MAGIC, 15) -#define IOCTL_JFJOCH_DEFAULT_MAC _IO (IOCTL_JFJOCH_MAGIC, 16) -#define IOCTL_JFJOCH_SET_IPV4 _IOW(IOCTL_JFJOCH_MAGIC, 17, uint32_t) -#define IOCTL_JFJOCH_GET_IPV4 _IOR(IOCTL_JFJOCH_MAGIC, 18, uint32_t) -#define IOCTL_JFJOCH_LOAD_INT_GEN _IOW(IOCTL_JFJOCH_MAGIC, 19, struct ActionConfig) -#define IOCTL_JFJOCH_LOAD_CALIB _IOW(IOCTL_JFJOCH_MAGIC, 21, struct ActionConfig) -#define IOCTL_JFJOCH_LOAD_INT_MAP _IOW(IOCTL_JFJOCH_MAGIC, 22, struct ActionConfig) -#define IOCTL_JFJOCH_RUN_FRAME_GEN _IOW(IOCTL_JFJOCH_MAGIC, 23, struct FrameGeneratorConfig) -#define IOCTL_JFJOCH_C2H_DMA_DESC _IOR(IOCTL_JFJOCH_MAGIC, 24, uint32_t) -#define IOCTL_JFJOCH_WRITE_REGISTER _IOW(IOCTL_JFJOCH_MAGIC, 25, struct RegisterConfig ) -#define IOCTL_JFJOCH_READ_REGISTER _IOWR(IOCTL_JFJOCH_MAGIC, 26, struct RegisterConfig ) +#define IOCTL_JFJOCH_START _IO (IOCTL_JFJOCH_MAGIC, 0) +#define IOCTL_JFJOCH_STATUS _IOR(IOCTL_JFJOCH_MAGIC, 1, struct DataCollectionStatus) +#define IOCTL_JFJOCH_READ_CONFIG _IOR(IOCTL_JFJOCH_MAGIC, 2, struct DataCollectionConfig) +#define IOCTL_JFJOCH_SET_CONFIG _IOW(IOCTL_JFJOCH_MAGIC, 3, struct DataCollectionConfig) +#define IOCTL_JFJOCH_CANCEL _IO (IOCTL_JFJOCH_MAGIC, 4) +#define IOCTL_JFJOCH_READ_WC_MBOX _IOR(IOCTL_JFJOCH_MAGIC, 5, uint32_t[16]) +#define IOCTL_JFJOCH_SEND_WR _IOW(IOCTL_JFJOCH_MAGIC, 6, uint32_t) +#define IOCTL_JFJOCH_BUF_COUNT _IOR(IOCTL_JFJOCH_MAGIC, 7, uint32_t) +#define IOCTL_JFJOCH_SET_MAC _IOW(IOCTL_JFJOCH_MAGIC, 8, uint64_t) +#define IOCTL_JFJOCH_GET_MAC _IOR(IOCTL_JFJOCH_MAGIC, 9, uint64_t) +#define IOCTL_JFJOCH_ISIDLE _IOR(IOCTL_JFJOCH_MAGIC, 10, uint32_t) +#define IOCTL_JFJOCH_GET_DEV_STATUS _IOR(IOCTL_JFJOCH_MAGIC, 11, struct DeviceStatus) +#define IOCTL_JFJOCH_END _IO (IOCTL_JFJOCH_MAGIC, 12) +#define IOCTL_JFJOCH_RESET _IO (IOCTL_JFJOCH_MAGIC, 13) +#define IOCTL_JFJOCH_NUMA _IOR(IOCTL_JFJOCH_MAGIC, 14, uint32_t) +#define IOCTL_JFJOCH_CLR_CNTRS _IO (IOCTL_JFJOCH_MAGIC, 15) +#define IOCTL_JFJOCH_DEFAULT_MAC _IO (IOCTL_JFJOCH_MAGIC, 16) +#define IOCTL_JFJOCH_SET_IPV4 _IOW(IOCTL_JFJOCH_MAGIC, 17, uint32_t) +#define IOCTL_JFJOCH_GET_IPV4 _IOR(IOCTL_JFJOCH_MAGIC, 18, uint32_t) +#define IOCTL_JFJOCH_LOAD_INT_GEN _IOW(IOCTL_JFJOCH_MAGIC, 19, struct DataCollectionConfig) +#define IOCTL_JFJOCH_LOAD_CALIB _IOW(IOCTL_JFJOCH_MAGIC, 21, struct DataCollectionConfig) +#define IOCTL_JFJOCH_LOAD_INT_MAP _IOW(IOCTL_JFJOCH_MAGIC, 22, struct DataCollectionConfig) +#define IOCTL_JFJOCH_RUN_FRAME_GEN _IOW(IOCTL_JFJOCH_MAGIC, 23, struct FrameGeneratorConfig) +#define IOCTL_JFJOCH_C2H_DMA_DESC _IOR(IOCTL_JFJOCH_MAGIC, 24, uint32_t) +#define IOCTL_JFJOCH_WRITE_REGISTER _IOW(IOCTL_JFJOCH_MAGIC, 25, struct RegisterConfig ) +#define IOCTL_JFJOCH_READ_REGISTER _IOWR(IOCTL_JFJOCH_MAGIC, 26, struct RegisterConfig ) #endif //JUNGFRAUJOCH_JFJOCH_IOCTL_H diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index 999b8d4a..2e79e9e0 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -11,7 +11,7 @@ ADD_LIBRARY(JungfraujochHost STATIC LinuxSocketDevice.cpp LinuxSocketDevice.h FPGAAcquisitionDevice.cpp FPGAAcquisitionDevice.h) -TARGET_LINK_LIBRARIES(JungfraujochHost CommonFunctions HLSSimulation JFCalibration) +TARGET_LINK_LIBRARIES(JungfraujochHost JungfraujochDevice CommonFunctions HLSSimulation JFCalibration) FIND_LIBRARY(IBVERBS NAMES ibverbs DOC "Infiniband verbs") @@ -29,26 +29,6 @@ ADD_EXECUTABLE(jfjoch_lxsocket_test jfjoch_lxsocket_test.cpp) TARGET_LINK_LIBRARIES(jfjoch_lxsocket_test JungfraujochHost) INSTALL(TARGETS jfjoch_lxsocket_test RUNTIME) -ADD_EXECUTABLE(jfjoch_pcie_status jfjoch_pcie_status.cpp) -TARGET_LINK_LIBRARIES(jfjoch_pcie_status JungfraujochHost) -INSTALL(TARGETS jfjoch_pcie_status RUNTIME) - -ADD_EXECUTABLE(jfjoch_pcie_set_network jfjoch_pcie_set_network.cpp) -TARGET_LINK_LIBRARIES(jfjoch_pcie_set_network JungfraujochHost) -INSTALL(TARGETS jfjoch_pcie_set_network RUNTIME) - -ADD_EXECUTABLE(jfjoch_pcie_cancel_data_collection jfjoch_pcie_cancel_data_collection.cpp) -TARGET_LINK_LIBRARIES(jfjoch_pcie_cancel_data_collection JungfraujochHost) -INSTALL(TARGETS jfjoch_pcie_cancel_data_collection RUNTIME) - -ADD_EXECUTABLE(jfjoch_pcie_clear_net_counters jfjoch_pcie_clear_net_counters.cpp) -TARGET_LINK_LIBRARIES(jfjoch_pcie_clear_net_counters JungfraujochHost) -INSTALL(TARGETS jfjoch_pcie_clear_net_counters RUNTIME) - -ADD_EXECUTABLE(jfjoch_pcie_read_int_packet_gen jfjoch_pcie_read_int_packet_gen.cpp) -TARGET_LINK_LIBRARIES(jfjoch_pcie_read_int_packet_gen JungfraujochHost) -INSTALL(TARGETS jfjoch_pcie_read_int_packet_gen RUNTIME) - ADD_LIBRARY(JFJochReceiver STATIC JFJochReceiverService.cpp JFJochReceiverService.h JFJochReceiverTest.cpp JFJochReceiverTest.h diff --git a/receiver/FPGAAcquisitionDevice.cpp b/receiver/FPGAAcquisitionDevice.cpp index 8795fafb..c6ea267a 100644 --- a/receiver/FPGAAcquisitionDevice.cpp +++ b/receiver/FPGAAcquisitionDevice.cpp @@ -155,7 +155,7 @@ void FPGAAcquisitionDevice::InitializeCalibration(const DiffractionExperiment &e } -void FPGAAcquisitionDevice::FillActionRegister(const DiffractionExperiment& x, ActionConfig &job) { +void FPGAAcquisitionDevice::FillActionRegister(const DiffractionExperiment& x, DataCollectionConfig &job) { std::random_device rd; std::uniform_int_distribution dist; data_collection_id = dist(rd); @@ -175,7 +175,7 @@ void FPGAAcquisitionDevice::Start(const DiffractionExperiment &experiment) { if (!HW_IsIdle()) throw(JFJochException(JFJochExceptionCategory::AcquisitionDeviceError, "Hardware action running prior to start of data acquisition")); - ActionConfig cfg_in{}, cfg_out{}; + DataCollectionConfig cfg_in{}, cfg_out{}; FillActionRegister(experiment, cfg_in); HW_WriteActionRegister(&cfg_in); @@ -196,8 +196,8 @@ void FPGAAcquisitionDevice::Start(const DiffractionExperiment &experiment) { read_work_completion_future = std::async(std::launch::async, &FPGAAcquisitionDevice::ReadWorkCompletionThread, this); } -ActionConfig FPGAAcquisitionDevice::ReadActionRegister() { - ActionConfig cfg{}; +DataCollectionConfig FPGAAcquisitionDevice::ReadActionRegister() { + DataCollectionConfig cfg{}; HW_ReadActionRegister(&cfg); return cfg; } @@ -226,8 +226,8 @@ inline void CheckHostWriterErr(JFJochProtoBuf::FPGAStatus &output, uint32_t stat JFJochProtoBuf::FPGAStatus FPGAAcquisitionDevice::GetStatus() const { - ActionStatus status{}; - ActionEnvParams env{}; + DataCollectionStatus status{}; + DeviceStatus env{}; HW_GetStatus(&status); HW_GetEnvParams(&env); diff --git a/receiver/FPGAAcquisitionDevice.h b/receiver/FPGAAcquisitionDevice.h index e8466533..f37ffcb9 100644 --- a/receiver/FPGAAcquisitionDevice.h +++ b/receiver/FPGAAcquisitionDevice.h @@ -12,10 +12,10 @@ class FPGAAcquisitionDevice : public AcquisitionDevice { virtual void FPGA_StartAction(const DiffractionExperiment &experiment) = 0; virtual void FPGA_EndAction() = 0; - virtual void HW_WriteActionRegister(const ActionConfig *job) = 0; - virtual void HW_ReadActionRegister(ActionConfig *job) = 0; + virtual void HW_WriteActionRegister(const DataCollectionConfig *job) = 0; + virtual void HW_ReadActionRegister(DataCollectionConfig *job) = 0; virtual bool HW_IsIdle() const = 0; - void FillActionRegister(const DiffractionExperiment& x, ActionConfig& job); + void FillActionRegister(const DiffractionExperiment& x, DataCollectionConfig& job); void Finalize() final; @@ -36,12 +36,12 @@ class FPGAAcquisitionDevice : public AcquisitionDevice { protected: std::vector internal_pkt_gen_frame; explicit FPGAAcquisitionDevice(uint16_t data_stream); - virtual void HW_GetStatus(ActionStatus *status) const = 0; - virtual void HW_GetEnvParams(ActionEnvParams *status) const { - memset(status, 0, sizeof(ActionEnvParams)); + virtual void HW_GetStatus(DataCollectionStatus *status) const = 0; + virtual void HW_GetEnvParams(DeviceStatus *status) const { + memset(status, 0, sizeof(DeviceStatus)); } public: - ActionConfig ReadActionRegister(); + DataCollectionConfig ReadActionRegister(); JFJochProtoBuf::FPGAStatus GetStatus() const override; void InitializeCalibration(const DiffractionExperiment &experiment, const JFCalibration &calib) override; void InitializeIntegrationMap(const DiffractionExperiment &experiment, const std::vector &v) override; diff --git a/receiver/HLSSimulatedDevice.cpp b/receiver/HLSSimulatedDevice.cpp index 2ab3ed02..50339526 100644 --- a/receiver/HLSSimulatedDevice.cpp +++ b/receiver/HLSSimulatedDevice.cpp @@ -122,12 +122,12 @@ AXI_STREAM & HLSSimulatedDevice::OutputStream() { return dout_eth; } -void HLSSimulatedDevice::HW_ReadActionRegister(ActionConfig *job) { - memcpy(job, &cfg, sizeof(ActionConfig)); +void HLSSimulatedDevice::HW_ReadActionRegister(DataCollectionConfig *job) { + memcpy(job, &cfg, sizeof(DataCollectionConfig)); } -void HLSSimulatedDevice::HW_WriteActionRegister(const ActionConfig *job) { - memcpy(&cfg, job, sizeof(ActionConfig)); +void HLSSimulatedDevice::HW_WriteActionRegister(const DataCollectionConfig *job) { + memcpy(&cfg, job, sizeof(DataCollectionConfig)); } void HLSSimulatedDevice::FPGA_StartAction(const DiffractionExperiment &experiment) { @@ -459,8 +459,8 @@ void HLSSimulatedDevice::HLSMainThread() { idle = true; } -void HLSSimulatedDevice::HW_GetStatus(ActionStatus *status) const { - memset(status, 0, sizeof(ActionStatus)); +void HLSSimulatedDevice::HW_GetStatus(DataCollectionStatus *status) const { + memset(status, 0, sizeof(DataCollectionStatus)); status->ctrl_reg = ap_uint<1>(host_writer_idle) ? (1 << 4) : 0; status->modules_internal_packet_generator = 1; diff --git a/receiver/HLSSimulatedDevice.h b/receiver/HLSSimulatedDevice.h index 15015273..341a8f00 100644 --- a/receiver/HLSSimulatedDevice.h +++ b/receiver/HLSSimulatedDevice.h @@ -18,7 +18,7 @@ class HLSSimulatedDevice : public FPGAAcquisitionDevice { AXI_STREAM din_frame_generator; AXI_STREAM dout_eth; - ActionConfig cfg; + DataCollectionConfig cfg; volatile bool idle; @@ -43,8 +43,8 @@ class HLSSimulatedDevice : public FPGAAcquisitionDevice { uint64_t calibration_addr_bram[LOAD_CALIBRATION_BRAM_SIZE]; - void HW_ReadActionRegister(ActionConfig *job) override; - void HW_WriteActionRegister(const ActionConfig *job) override; + void HW_ReadActionRegister(DataCollectionConfig *job) override; + void HW_WriteActionRegister(const DataCollectionConfig *job) override; void FPGA_StartAction(const DiffractionExperiment &experiment) override; void FPGA_EndAction() override; @@ -54,7 +54,7 @@ class HLSSimulatedDevice : public FPGAAcquisitionDevice { void HW_LoadCalibration(uint32_t modules, uint32_t storage_cells) override; void HW_LoadIntegrationMap(uint32_t modules) override; void HW_LoadInternalGeneratorFrame(uint32_t modules) override; - void HW_GetStatus(ActionStatus *status) const override; + void HW_GetStatus(DataCollectionStatus *status) const override; void HLSMainThread() ; void RunFrameGenerator(const FrameGeneratorConfig& config); public: diff --git a/receiver/PCIExpressDevice.cpp b/receiver/PCIExpressDevice.cpp index 9be789fc..fe5672b0 100644 --- a/receiver/PCIExpressDevice.cpp +++ b/receiver/PCIExpressDevice.cpp @@ -1,29 +1,19 @@ // Copyright (2019-2023) Paul Scherrer Institute -#include -#include -#include -#include - #include "PCIExpressDevice.h" -#include "../fpga/pcie_driver/jfjoch_ioctl.h" #include "../common/NetworkAddressConvert.h" PCIExpressDevice::PCIExpressDevice(uint16_t data_stream, uint16_t pci_slot) : - PCIExpressDevice("/dev/jfjoch" + std::to_string(pci_slot), data_stream) { + PCIExpressDevice("/dev/jfjoch" + std::to_string(pci_slot), data_stream) {} -} PCIExpressDevice::PCIExpressDevice(uint16_t data_stream) : PCIExpressDevice("/dev/jfjoch" + std::to_string(data_stream), data_stream) {} PCIExpressDevice::PCIExpressDevice(const std::string &device_name, uint16_t data_stream) -: FPGAAcquisitionDevice(data_stream) { - fd = open(device_name.c_str(), O_RDWR); - if (fd == -1) - throw JFJochException(JFJochExceptionCategory::PCIeError, "Cannot open device"); +: FPGAAcquisitionDevice(data_stream), dev(device_name, true) { + + DataCollectionStatus status = dev.GetDataCollectionStatus(); - ActionStatus status{}; - GetStatus_Internal(&status); max_modules = status.max_modules; if (max_modules == 0) throw JFJochException(JFJochExceptionCategory::PCIeError, "Max modules cannot be zero"); @@ -37,229 +27,103 @@ PCIExpressDevice::PCIExpressDevice(const std::string &device_name, uint16_t data buffer_device.resize(num_buf, nullptr); try { for (int i = 0; i < num_buf; i++) - buffer_device[i] = MapKernelBuffer(i); + buffer_device[i] = dev.MapKernelBuffer(i); } catch (JFJochException &e) { UnmapBuffers(); throw; } } -PCIExpressDevice::~PCIExpressDevice() { - close(fd); -} - -uint16_t *PCIExpressDevice::MapKernelBuffer(uint32_t n_buf) { - auto tmp = (uint16_t *) mmap(nullptr, FPGA_BUFFER_LOCATION_SIZE, - PROT_READ | PROT_WRITE, MAP_SHARED, - fd, FPGA_BUFFER_LOCATION_SIZE * n_buf); - - if (tmp == nullptr) - throw JFJochException(JFJochExceptionCategory::PCIeError, "Mmap of kernel buffer error: " - + std::string(strerror(errno))); - - return tmp; -} - bool PCIExpressDevice::HW_ReadMailbox(uint32_t *values) { - int tmp = ioctl(fd, IOCTL_JFJOCH_READ_WC_MBOX, values); - - if (tmp != 0) { - if (errno == EAGAIN) - return false; - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed receiving work completion", errno); - } - - return true; - + return dev.ReadWorkCompletion(values); } void PCIExpressDevice::Cancel() { - if (ioctl(fd, IOCTL_JFJOCH_CANCEL) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed setting cancel bit", errno); + dev.Cancel(); } bool PCIExpressDevice::HW_SendWorkRequest(uint32_t handle) { - int tmp = ioctl(fd, IOCTL_JFJOCH_SEND_WR, &handle); - if (tmp != 0) { - if (errno == EAGAIN) - return false; - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed sending work request", errno); - } - return true; + return dev.SendWorkRequest(handle); } void PCIExpressDevice::FPGA_StartAction(const DiffractionExperiment &experiment) { - if (ioctl(fd, IOCTL_JFJOCH_START) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed starting action", errno); - + dev.Start(); if (experiment.IsUsingInternalPacketGen()) { FrameGeneratorConfig config{}; config.frames = experiment.GetFrameNum() + DELAY_FRAMES_STOP_AND_QUIT + 1; config.modules = experiment.GetModulesNum(data_stream); - if (ioctl(fd, IOCTL_JFJOCH_GET_MAC, &config.dest_mac_addr) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed getting MAC address", errno); - if (ioctl(fd, IOCTL_JFJOCH_GET_IPV4, &config.dest_ipv4_addr) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed getting MAC address", errno); - - if (ioctl(fd, IOCTL_JFJOCH_RUN_FRAME_GEN, &config) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed starting frame generator", errno); + config.dest_mac_addr = dev.GetMACAddress(); + config.dest_ipv4_addr = dev.GetIPv4Address(); + dev.RunFrameGenerator(config); } } void PCIExpressDevice::FPGA_EndAction() { - if (ioctl(fd, IOCTL_JFJOCH_END) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed ending action", errno); + dev.End(); } bool PCIExpressDevice::HW_IsIdle() const { - uint32_t tmp; - if (ioctl(fd, IOCTL_JFJOCH_ISIDLE, &tmp) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed checking if idle", errno); - return tmp; + return dev.IsIdle(); } -void PCIExpressDevice::HW_WriteActionRegister(const ActionConfig *config) { - if (ioctl(fd, IOCTL_JFJOCH_SET_CONFIG, config) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed writing config", errno); +void PCIExpressDevice::HW_WriteActionRegister(const DataCollectionConfig *config) { + dev.SetConfig(*config); } -void PCIExpressDevice::HW_ReadActionRegister(ActionConfig *config) { - if (ioctl(fd, IOCTL_JFJOCH_READ_CONFIG, config) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed reading config", errno); +void PCIExpressDevice::HW_ReadActionRegister(DataCollectionConfig *config) { + *config = dev.GetConfig(); } std::string PCIExpressDevice::GetMACAddress() const { - uint64_t tmp; - if (ioctl(fd, IOCTL_JFJOCH_GET_MAC, &tmp) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed getting MAC address", errno); - return MacAddressToStr(tmp); + return MacAddressToStr(dev.GetMACAddress()); } void PCIExpressDevice::SetMACAddress(uint64_t mac_addr_network_order) { - if (ioctl(fd, IOCTL_JFJOCH_SET_MAC, &mac_addr_network_order) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed setting MAC address", errno); + dev.SetMACAddress(mac_addr_network_order); } -void PCIExpressDevice::HW_GetStatus(ActionStatus *status) const { - GetStatus_Internal(status); +void PCIExpressDevice::HW_GetStatus(DataCollectionStatus *status) const { + *status = dev.GetDataCollectionStatus(); } -void PCIExpressDevice::GetStatus_Internal(ActionStatus *status) const { - if (ioctl(fd, IOCTL_JFJOCH_STATUS, status) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed reading status", errno); -} - -void PCIExpressDevice::HW_GetEnvParams(ActionEnvParams *status) const { - if (ioctl(fd, IOCTL_JFJOCH_GET_ENV_DATA, status) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed reading env. data", errno); +void PCIExpressDevice::HW_GetEnvParams(DeviceStatus *status) const { + *status = dev.GetDeviceStatus(); } uint32_t PCIExpressDevice::GetNumKernelBuffers() const { - uint32_t tmp; - if (ioctl(fd, IOCTL_JFJOCH_BUF_COUNT, &tmp) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed reading env. data", errno); - return tmp; -} - -void PCIExpressDevice::Reset() { - if (ioctl(fd, IOCTL_JFJOCH_RESET) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed reset", errno); + return dev.GetBufferCount(); } int32_t PCIExpressDevice::GetNUMANode() const { - int32_t tmp; - if (ioctl(fd, IOCTL_JFJOCH_NUMA, &tmp) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed reading NUMA node", errno); - return tmp; + return dev.GetNumaNode(); } -void PCIExpressDevice::ClearNetworkCounters() { - if (ioctl(fd, IOCTL_JFJOCH_CLR_CNTRS) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed clearing network counters", errno); -} - -void PCIExpressDevice::SetDefaultMAC() const { - if (ioctl(fd, IOCTL_JFJOCH_DEFAULT_MAC) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed setting default MAC", errno); +void PCIExpressDevice::SetDefaultMAC() { + dev.SetDefaultMACAddress(); } void PCIExpressDevice::SetIPv4Address(uint32_t ipv4_addr_network_order) { - if (ioctl(fd, IOCTL_JFJOCH_SET_IPV4, &ipv4_addr_network_order) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed setting IPv4 address", errno); + dev.SetIPv4Address(ipv4_addr_network_order); } std::string PCIExpressDevice::GetIPv4Address() const { - uint32_t tmp; - if (ioctl(fd, IOCTL_JFJOCH_GET_IPV4, &tmp) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, - "Failed getting MAC address", errno); - return IPv4AddressToStr(tmp); + return IPv4AddressToStr(dev.GetIPv4Address()); } void PCIExpressDevice::HW_LoadCalibration(uint32_t in_modules, uint32_t in_storage_cells) { - ActionConfig config{ - .nmodules = in_modules, - .nstorage_cells = in_storage_cells - }; - if (ioctl(fd, IOCTL_JFJOCH_LOAD_CALIB, &config) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed uploading calibration", errno); + dev.LoadCalibration(in_modules, in_storage_cells); } void PCIExpressDevice::HW_LoadIntegrationMap(uint32_t in_modules) { - ActionConfig config{ - .nmodules = in_modules, - }; - if (ioctl(fd, IOCTL_JFJOCH_LOAD_INT_MAP, &config) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed uploading integration map", errno); + dev.LoadIntegrationMap(in_modules); } uint32_t PCIExpressDevice::GetCompletedDescriptors() const { - uint32_t ret = 0; - if (ioctl(fd, IOCTL_JFJOCH_C2H_DMA_DESC, &ret) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed geting C2H completed descriptor count", errno); - return ret; -} - -uint32_t PCIExpressDevice::ReadRegister(uint32_t addr) const { - RegisterConfig config; - config.addr = addr; - if (ioctl(fd, IOCTL_JFJOCH_READ_REGISTER, &config) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed reading register", errno); - return config.val; -} - -void PCIExpressDevice::WriteRegister(uint32_t addr, uint32_t val) { - RegisterConfig config{.addr = addr, .val = val}; - if (ioctl(fd, IOCTL_JFJOCH_WRITE_REGISTER, &config) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed writing to register", errno); - + return dev.GetCompletedDescriptors(); } void PCIExpressDevice::HW_LoadInternalGeneratorFrame(uint32_t in_modules) { - ActionConfig config{ - .nmodules = in_modules - }; - if (ioctl(fd, IOCTL_JFJOCH_LOAD_INT_GEN, &config) != 0) - throw JFJochException(JFJochExceptionCategory::PCIeError, "Failed uploading internal generator frame", errno); + dev.LoadInternalGeneratorFrame(in_modules); } diff --git a/receiver/PCIExpressDevice.h b/receiver/PCIExpressDevice.h index f2cd98c9..8545e722 100644 --- a/receiver/PCIExpressDevice.h +++ b/receiver/PCIExpressDevice.h @@ -4,48 +4,40 @@ #define JUNGFRAUJOCH_PCIEXPRESSDEVICE_H #include "FPGAAcquisitionDevice.h" +#include "../fpga/host_library/JungfraujochDevice.h" class PCIExpressDevice : public FPGAAcquisitionDevice { - int fd; + JungfraujochDevice dev; bool HW_ReadMailbox(uint32_t values[16]) override; bool HW_SendWorkRequest(uint32_t handle) override; void FPGA_StartAction(const DiffractionExperiment &experiment) override; bool HW_IsIdle() const final; - void HW_WriteActionRegister(const ActionConfig *job) override; - void HW_ReadActionRegister(ActionConfig *job) override; + void HW_WriteActionRegister(const DataCollectionConfig *job) override; + void HW_ReadActionRegister(DataCollectionConfig *job) override; void HW_LoadCalibration(uint32_t modules, uint32_t storage_cells) override; void HW_LoadIntegrationMap(uint32_t modules) override; void HW_LoadInternalGeneratorFrame(uint32_t modules) override; void FPGA_EndAction() override; - - void Reset(); - void GetStatus_Internal(ActionStatus *status) const; - - uint16_t *MapKernelBuffer(uint32_t n_buf); public: explicit PCIExpressDevice(uint16_t data_stream); PCIExpressDevice(uint16_t data_stream, uint16_t pci_slot); PCIExpressDevice(const std::string &device_name, uint16_t data_stream); - ~PCIExpressDevice() override; void Cancel() override; - void HW_GetStatus(ActionStatus *status) const override; - void HW_GetEnvParams(ActionEnvParams *status) const override; + void HW_GetStatus(DataCollectionStatus *status) const override; + void HW_GetEnvParams(DeviceStatus *status) const override; uint32_t GetNumKernelBuffers() const; int32_t GetNUMANode() const override; - void ClearNetworkCounters(); void SetMACAddress(uint64_t mac_addr_network_order); - void SetDefaultMAC() const; + void SetDefaultMAC(); void SetIPv4Address(uint32_t ipv4_addr_network_order); std::string GetMACAddress() const override; std::string GetIPv4Address() const override; uint32_t GetCompletedDescriptors() const override; - uint32_t ReadRegister(uint32_t addr) const; - void WriteRegister(uint32_t addr, uint32_t val); }; #endif //JUNGFRAUJOCH_PCIEXPRESSDEVICE_H diff --git a/receiver/jfjoch_pcie_read_int_packet_gen.cpp b/receiver/jfjoch_pcie_read_int_packet_gen.cpp deleted file mode 100644 index 7a2fbfc3..00000000 --- a/receiver/jfjoch_pcie_read_int_packet_gen.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (2019-2023) Paul Scherrer Institute - -#include - -#include "../common/JFJochException.h" -#include "PCIExpressDevice.h" -#include "../common/Logger.h" -#include - -int main(int argc, char **argv) { - Logger logger("jfjoch_pcie_read_int_packet_gen"); - - if (argc != 2) { - logger.Error("Usage: ./jfjoch_pcie_read_int_packet_gen "); - exit(EXIT_FAILURE); - } - logger.Info("Device {}", argv[1]); - std::cout << std::endl; - try { - PCIExpressDevice test(argv[1], 0); - - std::vector data(RAW_MODULE_SIZE*2); - - test.HW_ReadInternalPacketGen((uint16_t *) data.data()); - - std::ofstream file("out.bin", std::ios::binary); - file.write((char *) data.data(), data.size()); - file.close(); - - logger.Info("Done"); - } catch (const JFJochException &e) { - logger.ErrorException(e); - } -} \ No newline at end of file diff --git a/receiver/jfjoch_pcie_status.cpp b/receiver/jfjoch_pcie_status.cpp deleted file mode 100644 index 7a159b72..00000000 --- a/receiver/jfjoch_pcie_status.cpp +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (2019-2023) Paul Scherrer Institute - -#include -#include - -#include "../common/NetworkAddressConvert.h" -#include "../common/JFJochException.h" -#include "PCIExpressDevice.h" - -int main(int argc, char **argv) { - - if (argc != 2) { - std::cout << "Usage: ./jfjoch_pcie_status " << std::endl; - exit(EXIT_FAILURE); - } - std::cout << "Device " << argv[1] << std::endl; - std::cout << std::endl; - try { - PCIExpressDevice test(argv[1], 0); - auto status = test.GetStatus(); - - std::cout << "PCIe/JFJoch card detected " << std::endl; - std::cout << "Git SHA1 " << std::hex << status.git_sha1() << std::endl; - std::cout << "Max modules " << std::dec << status.max_modules() << std::endl; - std::cout << "NUMA node " << test.GetNUMANode() << std::endl; - std::cout << "Ethernet aligned " << (status.ethernet_rx_aligned() ? "Yes" : "No") << std::endl; - - std::cout << "FPGA 12V rail current [A] " << status.current_edge_12v_a() << std::endl; - std::cout << "FPGA 12V rail voltage [V] " << status.voltage_edge_12v_v() << std::endl; - std::cout << "FPGA 3.3V rail current [A] " << status.current_edge_3p3v_a() << std::endl; - std::cout << "FPGA 3.3V rail voltage [V] " << status.voltage_edge_3p3v_v() << std::endl; - std::cout << "FPGA temperature " << status.fpga_temp_degc() << std::endl; - std::cout << "HBM temperature #0 " << status.hbm_temp_0_degc() << std::endl; - std::cout << "HBM temperature #1 " << status.hbm_temp_1_degc() << std::endl; - std::cout << "HBM size (MiB) " << status.hbm_size_bytes() / static_cast(1024 * 1024) << std::endl; - std::cout << "Data collection idle " << status.fpga_idle() << std::endl; - std::cout << "Host writer idle " << status.host_writer_idle() << std::endl; - std::cout << "Data collection cancel " << status.cancel_bit() << std::endl; - - std::cout << "Full status register " << std::bitset<32>(status.full_status_register()) << std::endl; - - std::cout << "Stalls HBM " << status.stalls_hbm() << std::endl; - std::cout << "Stalls host mem " << status.stalls_host() << std::endl; - - ActionConfig cfg = test.ReadActionRegister(); - std::cout << "MAC address " << test.GetMACAddress() << std::endl; - std::cout << "IPv4 address " << test.GetIPv4Address() << std::endl; - std::cout << "Data collection mode (hex) " << std::hex << (cfg.mode & 0xFFFF) << std::dec << std::endl; - std::cout << "Data collection ID (hex) " << std::hex << ((cfg.mode & 0xFFFF0000) >> 16) << std::dec << std::endl; - std::cout << "Modules " << std::dec << cfg.nmodules << std::endl; - std::cout << "Frames int. pkt. gen. " << std::dec << cfg.nframes << std::endl; - std::cout << std::endl; - std::cout << "FPGA FIFO status: " << std::endl; - for (const auto &i: status.fifo_status()) { - std::string s = i.name(); - s.resize(28, ' '); - switch (i.value()) { - case JFJochProtoBuf::FPGAFIFOStatusEnum::EMPTY: - s += "Empty"; - break; - case JFJochProtoBuf::FPGAFIFOStatusEnum::FULL: - s += "Full"; - break; - case JFJochProtoBuf::FPGAFIFOStatusEnum::PARTIAL: - s += "Partial"; - break; - default: - break; - } - std::cout << s << std::endl; - } - - if (!status.host_writer_err().empty()) { - std::cout << "FPGA host writer errors: " << std::endl; - for (const auto &i: status.host_writer_err()) - std::cout << " " << i << std::endl; - } - - std::cout << std::endl; - std::cout << "Packet counters - ETH " << status.packets_ether() << std::endl; - std::cout << " - UDP " << status.packets_udp() << std::endl; - std::cout << " - SLS " << status.packets_sls() << std::endl; - std::cout << " - ICMP " << status.packets_icmp() << std::endl; - std::cout << " - JFJoch " << status.packets_jfjoch() << std::endl; - std::cout << std::endl; - - std::cout << " - err. ETH " << status.error_eth() << std::endl; - std::cout << " - err. len. " << status.error_packet_len() << std::endl; - std::cout << std::endl; - - std::cout << "H2C descriptors:" << status.pcie_h2c_descriptors() << " beats: " << status.pcie_h2c_beats() - << " status:" << status.pcie_h2c_status() << std::endl; - std::cout << "C2H descriptors:" << status.pcie_c2h_descriptors() << " beats: " << status.pcie_c2h_beats() - << " status:" << status.pcie_c2h_status() << std::endl; - - std::cout << std::endl; - } catch (const JFJochException &e) { - std::cout << e.what() << std::endl; - std::cout << std::endl; - } - -} \ No newline at end of file diff --git a/tests/ActionConfigTest.cpp b/tests/ActionConfigTest.cpp index bf2ba30d..3dc1e75e 100644 --- a/tests/ActionConfigTest.cpp +++ b/tests/ActionConfigTest.cpp @@ -5,7 +5,7 @@ #include "../fpga/pcie_driver/ActionConfig.h" TEST_CASE("ActionStatus") { - ActionStatus status{}; + DataCollectionStatus status{}; status.packets_icmp = (1uL<<56) + (1uL<<9); status.packets_eth = 21321321321212L; status.packets_processed = 5454545455454545454L; @@ -47,11 +47,11 @@ TEST_CASE("ActionStatus") { TEST_CASE("ActionConfigSize") { - REQUIRE(sizeof(ActionConfig) == 5 * sizeof(uint32_t)); + REQUIRE(sizeof(DataCollectionConfig) == 5 * sizeof(uint32_t)); } TEST_CASE("ActionConfig") { - ActionConfig config{}; + DataCollectionConfig config{}; auto config32 = (uint32_t *) &config; config.nmodules = 456; diff --git a/tests/FPGAIntegrationTest.cpp b/tests/FPGAIntegrationTest.cpp index 06be0d8b..0a53fadb 100644 --- a/tests/FPGAIntegrationTest.cpp +++ b/tests/FPGAIntegrationTest.cpp @@ -708,7 +708,7 @@ TEST_CASE("HLS_C_Simulation_check_wrong_packet_size", "[FPGA][Full]") { } TEST_CASE("HLS_DataCollectionFSM","[OpenCAPI]") { - ActionConfig act_reg; + DataCollectionConfig act_reg; STREAM_512 raw0; STREAM_512 raw1;