From 03f8d0782e126e177296a69b790134bfd537ea76 Mon Sep 17 00:00:00 2001 From: Niklas Eiling Date: Mon, 5 Dec 2022 10:05:12 +0100 Subject: [PATCH] Revert "core: move configuration of polling mode to parse()" The changes lead to crashing because intc will not be configured properly. Also revert removing configDone in ips/dma This reverts commit 3b8949afe9d4536fa1071eba391f1155816c44de. Signed-off-by: Niklas Eiling --- fpga/etc/fpgas.json | 3 ++- fpga/include/villas/fpga/card.hpp | 1 + fpga/include/villas/fpga/core.hpp | 9 ++++++++ fpga/include/villas/fpga/ips/dma.hpp | 6 +++++ fpga/lib/card.cpp | 33 +++++++++++++++------------- fpga/lib/core.cpp | 3 +++ fpga/lib/ips/dma.cpp | 13 ++++++----- 7 files changed, 46 insertions(+), 22 deletions(-) diff --git a/fpga/etc/fpgas.json b/fpga/etc/fpgas.json index 42865c011..c5c471d49 100644 --- a/fpga/etc/fpgas.json +++ b/fpga/etc/fpgas.json @@ -4,7 +4,8 @@ "id": "10ee:7021", "slot": "0000:88:00.0", "do_reset": true, - "ips": "etc/vc707-xbar-pcie/vc707-xbar-pcie.json" + "ips": "etc/vc707-xbar-pcie/vc707-xbar-pcie.json", + "polling": false } } } diff --git a/fpga/include/villas/fpga/card.hpp b/fpga/include/villas/fpga/card.hpp index f368d2bcc..d9574a7f8 100644 --- a/fpga/include/villas/fpga/card.hpp +++ b/fpga/include/villas/fpga/card.hpp @@ -104,6 +104,7 @@ public: // TODO: make this private bool doReset; // Reset VILLASfpga during startup? int affinity; // Affinity for MSI interrupts + bool polling; // Poll on interrupts? std::string name; // The name of the FPGA card diff --git a/fpga/include/villas/fpga/core.hpp b/fpga/include/villas/fpga/core.hpp index 3996f732b..bc39fd170 100644 --- a/fpga/include/villas/fpga/core.hpp +++ b/fpga/include/villas/fpga/core.hpp @@ -293,6 +293,11 @@ public: } protected: + enum PollingMode { + POLL, + IRQ, + }; + Logger getLogger() const { return villas::logging.get(getName()); @@ -307,6 +312,10 @@ private: // Create a concrete IP instance virtual Core* create() = 0; + virtual + void configurePollingMode(Core &, PollingMode) + { } + virtual Vlnv getCompatibleVlnv() const = 0; diff --git a/fpga/include/villas/fpga/ips/dma.hpp b/fpga/include/villas/fpga/ips/dma.hpp index 75716b4d8..0d32f1468 100644 --- a/fpga/include/villas/fpga/ips/dma.hpp +++ b/fpga/include/villas/fpga/ips/dma.hpp @@ -180,6 +180,12 @@ public: virtual void parse(Core& ip, json_t* json) override; + + virtual void + configurePollingMode(Core& ip, PollingMode mode) override + { + dynamic_cast(ip).polling = (mode == POLL); + } }; } /* namespace ip */ diff --git a/fpga/lib/card.cpp b/fpga/lib/card.cpp index ec5dfe557..7dcf103af 100644 --- a/fpga/lib/card.cpp +++ b/fpga/lib/card.cpp @@ -38,7 +38,7 @@ using namespace villas; using namespace villas::fpga; // Instantiate factory to register -static PCIeCardFactory villas::fpga::PCIeCardFactory; +static PCIeCardFactory PCIeCardFactoryInstance; static const kernel::pci::Device defaultFilter((kernel::pci::Id(FPGA_PCI_VID_XILINX, FPGA_PCI_PID_VFPGA))); @@ -52,22 +52,24 @@ PCIeCard::List PCIeCardFactory::make(json_t *json, std::shared_ptrinfo("Found config for FPGA card {}", card_name); - json_t *json_ips; - json_t *json_paths = nullptr; - const char *pci_slot = nullptr; - const char *pci_id = nullptr; - int do_reset = 0; - int affinity = 0; + json_t* json_ips = nullptr; + json_t* json_paths = nullptr; + const char* pci_slot = nullptr; + const char* pci_id = nullptr; + int do_reset = 0; + int affinity = 0; + int polling = 0; json_error_t err; - int ret = json_unpack_ex(json_card, &err, 0, "{ s: o, s?: i, s?: b, s?: s, s?: s, s?: o }", - "ips", &json_ips, - "affinity", &affinity, - "do_reset", &do_reset, - "slot", &pci_slot, - "id", &pci_id, - "paths", &json_paths - ); + int ret = json_unpack_ex(json_card, &err, 0, "{ s: o, s?: i, s?: b, s?: s, s?: s, s?: b, s?: o }", + "ips", &json_ips, + "affinity", &affinity, + "do_reset", &do_reset, + "slot", &pci_slot, + "id", &pci_id, + "polling", &polling, + "paths", &json_paths); + if (ret != 0) throw ConfigError(json_card, err, "", "Failed to parse card"); @@ -78,6 +80,7 @@ PCIeCard::List PCIeCardFactory::make(json_t *json, std::shared_ptrvfioContainer = vc; card->affinity = affinity; card->doReset = do_reset != 0; + card->polling = (polling != 0); kernel::pci::Device filter = defaultFilter; diff --git a/fpga/lib/core.cpp b/fpga/lib/core.cpp index 87309b1b3..2ea08d9be 100644 --- a/fpga/lib/core.cpp +++ b/fpga/lib/core.cpp @@ -249,6 +249,9 @@ CoreFactory::make(PCIeCard* card, json_t *json_ips) // IP-specific setup via JSON config CoreFactory->parse(*ip, json_ip); + // Set polling mode + CoreFactory->configurePollingMode(*ip, (card->polling ? PollingMode::POLL : PollingMode::IRQ)); + // IP has been configured now configuredIps.push_back(std::move(ip)); } diff --git a/fpga/lib/ips/dma.cpp b/fpga/lib/ips/dma.cpp index 5888c011f..d159362d1 100644 --- a/fpga/lib/ips/dma.cpp +++ b/fpga/lib/ips/dma.cpp @@ -178,10 +178,15 @@ void Dma::setupScatterGatherRingTx() bool Dma::reset() { + if (xDma.RegBase == 0) { + return true; + } + XAxiDma_IntrDisable(&xDma, XAXIDMA_IRQ_ALL_MASK, XAXIDMA_DMA_TO_DEVICE); XAxiDma_IntrDisable(&xDma, XAXIDMA_IRQ_ALL_MASK, XAXIDMA_DEVICE_TO_DMA); XAxiDma_Reset(&xDma); + // Value taken from libxil implementation int timeout = 500; @@ -641,12 +646,8 @@ void DmaFactory::parse(Core &ip, json_t *cfg) dma.xConfig.AddrWidth = 32; dma.xConfig.SgLengthWidth = 14; - int polling; - json_error_t err; - int ret = json_unpack_ex(cfg, &err, 0, "{ s: b, s: { s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i } }", - "polling", &polling, - + int ret = json_unpack_ex(cfg, &err, 0, "{ s: { s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i, s?: i } }", "parameters", "c_sg_include_stscntrl_strm", &dma.xConfig.HasStsCntrlStrm, "c_include_mm2s", &dma.xConfig.HasMm2S, @@ -665,5 +666,5 @@ void DmaFactory::parse(Core &ip, json_t *cfg) if (ret != 0) throw ConfigError(cfg, err, "", "Failed to parse DMA configuration"); - dma.polling = polling != 0; + dma.configDone = true; }