diff options
author | Martin Braun <martin.braun@ettus.com> | 2019-08-13 15:28:13 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-08-16 13:42:02 -0700 |
commit | 3d157e09f642caa7a5d48c71468b444d0566cf8d (patch) | |
tree | b29219cb40d3f887d97a068d4a6e45c5ce2b5a65 /host | |
parent | bbb869ca80fa299f7888b35134218229521dd0c0 (diff) | |
download | uhd-3d157e09f642caa7a5d48c71468b444d0566cf8d.tar.gz uhd-3d157e09f642caa7a5d48c71468b444d0566cf8d.tar.bz2 uhd-3d157e09f642caa7a5d48c71468b444d0566cf8d.zip |
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.
Diffstat (limited to 'host')
-rw-r--r-- | host/lib/usrp/x300/x300_conn_mgr.hpp | 35 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_eth_mgr.hpp | 3 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_impl.cpp | 45 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_impl.hpp | 9 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_pcie_mgr.hpp | 3 |
5 files changed, 64 insertions, 31 deletions
diff --git a/host/lib/usrp/x300/x300_conn_mgr.hpp b/host/lib/usrp/x300/x300_conn_mgr.hpp new file mode 100644 index 000000000..8aca2eb06 --- /dev/null +++ b/host/lib/usrp/x300/x300_conn_mgr.hpp @@ -0,0 +1,35 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_X300_CONN_MGR_HPP +#define INCLUDED_X300_CONN_MGR_HPP + +#include <uhd/transport/if_addrs.hpp> +#include <uhd/types/direction.hpp> +#include <uhd/types/wb_iface.hpp> +#include <uhd/usrp/mboard_eeprom.hpp> +#include <string> + +namespace uhd { namespace usrp { namespace x300 { + +/*! Helper base class to manage the connection to the device + */ +class conn_manager +{ +public: + using sptr = std::shared_ptr<conn_manager>; + virtual ~conn_manager() {} + + /*! Return a reference to a ZPU ctrl interface object + */ + virtual uhd::wb_iface::sptr get_ctrl_iface() = 0; + + virtual size_t get_mtu(uhd::direction_t dir) = 0; +}; + +}}} // namespace uhd::usrp::x300 + +#endif /* INCLUDED_X300_CONN_MGR_HPP */ diff --git a/host/lib/usrp/x300/x300_eth_mgr.hpp b/host/lib/usrp/x300/x300_eth_mgr.hpp index 85b3eabd0..022e14bbd 100644 --- a/host/lib/usrp/x300/x300_eth_mgr.hpp +++ b/host/lib/usrp/x300/x300_eth_mgr.hpp @@ -7,6 +7,7 @@ #ifndef INCLUDED_X300_ETH_MGR_HPP #define INCLUDED_X300_ETH_MGR_HPP +#include "x300_conn_mgr.hpp" #include "x300_device_args.hpp" #include "x300_mboard_type.hpp" #include <uhd/transport/if_addrs.hpp> @@ -22,7 +23,7 @@ namespace uhd { namespace usrp { namespace x300 { /*! Helper class to manage the eth connections */ -class eth_manager +class eth_manager : public conn_manager { public: eth_manager(const x300_device_args_t& args, 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 <uhd/transport/if_addrs.hpp> #include <uhd/types/sid.hpp> #include <uhd/usrp/subdev_spec.hpp> @@ -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<pcie_manager>(new pcie_manager(mb.args, _tree, mb_path)); - mb.zpu_ctrl = mb.pcie_mgr->get_ctrl_iface(); + mb.conn_mgr = std::make_shared<pcie_manager>(mb.args, _tree, mb_path); } else { - mb.eth_mgr = - std::unique_ptr<eth_manager>(new eth_manager(mb.args, _tree, mb_path)); - mb.zpu_ctrl = mb.eth_mgr->get_ctrl_iface(); + mb.conn_mgr = std::make_shared<eth_manager>(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<pcie_manager>(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<eth_manager>(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<pcie_manager>(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<pcie_manager>(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<eth_manager>(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); } /*********************************************************************** diff --git a/host/lib/usrp/x300/x300_impl.hpp b/host/lib/usrp/x300/x300_impl.hpp index 933006eab..2ae586a5d 100644 --- a/host/lib/usrp/x300/x300_impl.hpp +++ b/host/lib/usrp/x300/x300_impl.hpp @@ -10,12 +10,11 @@ #define INCLUDED_X300_IMPL_HPP #include "x300_clock_ctrl.hpp" +#include "x300_conn_mgr.hpp" #include "x300_defaults.hpp" #include "x300_device_args.hpp" -#include "x300_eth_mgr.hpp" #include "x300_fw_common.h" #include "x300_mboard_type.hpp" -#include "x300_pcie_mgr.hpp" #include "x300_radio_ctrl_impl.hpp" #include "x300_regs.hpp" #include <uhd/types/device_addr.hpp> @@ -75,11 +74,7 @@ private: std::vector<uhd::rfnoc::x300_radio_ctrl_impl::sptr> radios; - // Ethernet-specific components: - std::unique_ptr<uhd::usrp::x300::eth_manager> eth_mgr; - - // PCIe-specific components: - std::unique_ptr<uhd::usrp::x300::pcie_manager> pcie_mgr; + uhd::usrp::x300::conn_manager::sptr conn_mgr; }; std::vector<mboard_members_t> _mb; diff --git a/host/lib/usrp/x300/x300_pcie_mgr.hpp b/host/lib/usrp/x300/x300_pcie_mgr.hpp index a9677e9bc..c884c8b5f 100644 --- a/host/lib/usrp/x300/x300_pcie_mgr.hpp +++ b/host/lib/usrp/x300/x300_pcie_mgr.hpp @@ -8,6 +8,7 @@ #define INCLUDED_X300_PCI_MGR_HPP #include "../device3/device3_impl.hpp" +#include "x300_conn_mgr.hpp" #include "x300_device_args.hpp" #include "x300_mboard_type.hpp" #include <uhd/transport/muxed_zero_copy_if.hpp> @@ -18,7 +19,7 @@ namespace uhd { namespace usrp { namespace x300 { /*! Helper class to manage the PCIe connections */ -class pcie_manager +class pcie_manager : public conn_manager { public: pcie_manager(const x300_device_args_t& args, |