From 3d157e09f642caa7a5d48c71468b444d0566cf8d Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Tue, 13 Aug 2019 15:28:13 -0700 Subject: x300: Introduce conn_manager This is a superclass to eth_manager and pcie_manager, since they usually do the same thing. This saves storing and passing multiple pointers. Also, x300_impl now stores a shared_ptr of the conn_manager, because we'll need to pass it around in the future. --- host/lib/usrp/x300/x300_impl.cpp | 45 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'host/lib/usrp/x300/x300_impl.cpp') diff --git a/host/lib/usrp/x300/x300_impl.cpp b/host/lib/usrp/x300/x300_impl.cpp index 59ba1153b..0283cf659 100644 --- a/host/lib/usrp/x300/x300_impl.cpp +++ b/host/lib/usrp/x300/x300_impl.cpp @@ -8,9 +8,11 @@ #include "x300_impl.hpp" #include "x300_claim.hpp" +#include "x300_eth_mgr.hpp" #include "x300_mb_eeprom.hpp" #include "x300_mb_eeprom_iface.hpp" #include "x300_mboard_type.hpp" +#include "x300_pcie_mgr.hpp" #include #include #include @@ -216,14 +218,11 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t& dev_addr) UHD_LOGGER_DEBUG("X300") << "Setting up basic communication..."; if (mb.xport_path == xport_path_t::NIRIO) { - mb.pcie_mgr = - std::unique_ptr(new pcie_manager(mb.args, _tree, mb_path)); - mb.zpu_ctrl = mb.pcie_mgr->get_ctrl_iface(); + mb.conn_mgr = std::make_shared(mb.args, _tree, mb_path); } else { - mb.eth_mgr = - std::unique_ptr(new eth_manager(mb.args, _tree, mb_path)); - mb.zpu_ctrl = mb.eth_mgr->get_ctrl_iface(); + mb.conn_mgr = std::make_shared(mb.args, _tree, mb_path); } + mb.zpu_ctrl = mb.conn_mgr->get_ctrl_iface(); // Claim device if (not try_to_claim(mb.zpu_ctrl)) { @@ -330,9 +329,10 @@ void x300_impl::setup_mb(const size_t mb_i, const uhd::device_addr_t& dev_addr) // discover interfaces, frame sizes, and link rates //////////////////////////////////////////////////////////////////// if (mb.xport_path == xport_path_t::NIRIO) { - mb.pcie_mgr->init_link(); + std::dynamic_pointer_cast(mb.conn_mgr)->init_link(); } else if (mb.xport_path == xport_path_t::ETH) { - mb.eth_mgr->init_link(mb_eeprom, mb.loaded_fpga_image); + std::dynamic_pointer_cast(mb.conn_mgr) + ->init_link(mb_eeprom, mb.loaded_fpga_image); } //////////////////////////////////////////////////////////////////// @@ -537,7 +537,8 @@ x300_impl::~x300_impl(void) // kill the claimer task and unclaim the device mb.claimer_task.reset(); if (mb.xport_path == xport_path_t::NIRIO) { - mb.pcie_mgr->release_ctrl_iface([&mb]() { release(mb.zpu_ctrl); }); + std::dynamic_pointer_cast(mb.conn_mgr) + ->release_ctrl_iface([&mb]() { release(mb.zpu_ctrl); }); } else { release(mb.zpu_ctrl); } @@ -565,16 +566,19 @@ uhd::both_xports_t x300_impl::make_transport(const uhd::sid_t& address, xports.send_sid = this->allocate_sid(mb, address, x300::SRC_ADDR0, x300::XB_DST_PCI); xports.recv_sid = xports.send_sid.reversed(); - return mb.pcie_mgr->make_transport(xports, xport_type, args, send_mtu, recv_mtu); + std::dynamic_pointer_cast(mb.conn_mgr) + ->make_transport(xports, xport_type, args, send_mtu, recv_mtu); } else if (mb.xport_path == xport_path_t::ETH) { - xports = mb.eth_mgr->make_transport(xports, - xport_type, - args, - send_mtu, - recv_mtu, - [this, &mb, address](const uint32_t src_addr, const uint32_t src_dst) { - return this->allocate_sid(mb, address, src_addr, src_dst); - }); + xports = std::dynamic_pointer_cast(mb.conn_mgr) + ->make_transport(xports, + xport_type, + args, + send_mtu, + recv_mtu, + [this, &mb, address]( + const uint32_t src_addr, const uint32_t src_dst) { + return this->allocate_sid(mb, address, src_addr, src_dst); + }); // reprogram the ethernet dispatcher's udp port (should be safe to always set) UHD_LOGGER_TRACE("X300") @@ -818,10 +822,7 @@ bool x300_impl::is_pps_present(mboard_members_t& mb) size_t x300_impl::get_mtu(const size_t mb_index, const uhd::direction_t dir) { auto& mb = _mb.at(mb_index); - if (mb.xport_path == xport_path_t::NIRIO) { - return mb.pcie_mgr->get_mtu(dir); - } - return mb.eth_mgr->get_mtu(dir); + return mb.conn_mgr->get_mtu(dir); } /*********************************************************************** -- cgit v1.2.3