From b0cb065111dc3f40b89bdda76e9bd98f3e70b72e Mon Sep 17 00:00:00 2001 From: Samuel O'Brien Date: Fri, 26 Jun 2020 08:26:25 -0500 Subject: rfnoc: Rename chdr_packet to chdr_packet_writer It would be confusing to have two classes named chdr_packet. As it makes more sense to name the new public chdr parser class chdr_packet, the internal uhd::rfnoc::chdr::chdr_packet class is being renamed to chdr_packet_writer to better represent its functionality. Signed-off-by: Samuel O'Brien --- .../include/uhdlib/rfnoc/chdr_ctrl_endpoint.hpp | 2 +- host/lib/include/uhdlib/rfnoc/chdr_ctrl_xport.hpp | 4 +- host/lib/include/uhdlib/rfnoc/chdr_packet.hpp | 320 -------------------- .../include/uhdlib/rfnoc/chdr_packet_writer.hpp | 325 +++++++++++++++++++++ .../include/uhdlib/rfnoc/chdr_rx_data_xport.hpp | 6 +- .../include/uhdlib/rfnoc/chdr_tx_data_xport.hpp | 6 +- .../include/uhdlib/rfnoc/graph_stream_manager.hpp | 2 +- host/lib/include/uhdlib/rfnoc/mgmt_portal.hpp | 2 +- host/lib/rfnoc/CMakeLists.txt | 2 +- host/lib/rfnoc/chdr_ctrl_endpoint.cpp | 2 +- host/lib/rfnoc/chdr_packet.cpp | 222 -------------- host/lib/rfnoc/chdr_packet_writer.cpp | 222 ++++++++++++++ host/lib/rfnoc/chdr_rx_data_xport.cpp | 2 +- host/lib/rfnoc/chdr_tx_data_xport.cpp | 4 +- host/lib/rfnoc/ctrlport_endpoint.cpp | 20 +- host/lib/rfnoc/mgmt_portal.cpp | 2 +- host/lib/usrp/mpmd/mpmd_link_if_ctrl_base.hpp | 2 +- host/lib/usrp/mpmd/mpmd_link_if_mgr.hpp | 2 +- 18 files changed, 574 insertions(+), 573 deletions(-) delete mode 100644 host/lib/include/uhdlib/rfnoc/chdr_packet.hpp create mode 100644 host/lib/include/uhdlib/rfnoc/chdr_packet_writer.hpp delete mode 100644 host/lib/rfnoc/chdr_packet.cpp create mode 100644 host/lib/rfnoc/chdr_packet_writer.cpp (limited to 'host/lib') diff --git a/host/lib/include/uhdlib/rfnoc/chdr_ctrl_endpoint.hpp b/host/lib/include/uhdlib/rfnoc/chdr_ctrl_endpoint.hpp index 6f56fd956..61358fa2f 100644 --- a/host/lib/include/uhdlib/rfnoc/chdr_ctrl_endpoint.hpp +++ b/host/lib/include/uhdlib/rfnoc/chdr_ctrl_endpoint.hpp @@ -7,7 +7,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/host/lib/include/uhdlib/rfnoc/chdr_ctrl_xport.hpp b/host/lib/include/uhdlib/rfnoc/chdr_ctrl_xport.hpp index bf3e03a6b..471a7bc11 100644 --- a/host/lib/include/uhdlib/rfnoc/chdr_ctrl_xport.hpp +++ b/host/lib/include/uhdlib/rfnoc/chdr_ctrl_xport.hpp @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include #include @@ -145,7 +145,7 @@ private: sep_id_t _my_epid; // Packet for received data - chdr::chdr_packet::uptr _recv_packet; + chdr::chdr_packet_writer::uptr _recv_packet; send_io_if::sptr _send_if; recv_io_if::sptr _ctrl_recv_if; diff --git a/host/lib/include/uhdlib/rfnoc/chdr_packet.hpp b/host/lib/include/uhdlib/rfnoc/chdr_packet.hpp deleted file mode 100644 index d56f94d0f..000000000 --- a/host/lib/include/uhdlib/rfnoc/chdr_packet.hpp +++ /dev/null @@ -1,320 +0,0 @@ -// -// Copyright 2019 Ettus Research, a National Instruments Brand -// -// SPDX-License-Identifier: GPL-3.0-or-later -// - -#pragma once - -#include -#include -#include -#include - -namespace uhd { namespace rfnoc { namespace chdr { - -//---------------------------------------------------- -// Generic CHDR Packet Container -//---------------------------------------------------- - -//! A container class that wraps a generic buffer that contains a CHDR packet. The -// container provides a high level API to read and write the header, metadata and payload -// of the packet. The payload can be accessed as a generic buffer using this interface. -// -class chdr_packet -{ -public: - //! A unique pointer to a const chdr_packet. Useful as a read-only interface. - typedef std::unique_ptr cuptr; - //! A unique pointer to a non-const chdr_packet. Useful as a read-write interface. - typedef std::unique_ptr uptr; - - virtual ~chdr_packet() = 0; - - /*! Updates the underlying storage of this packet. This is a const method and is - * only useful for read-only (RX) access. - * - * \param pkt_buff Pointer to a buffer that contains the RX packet - */ - virtual void refresh(const void* pkt_buff) const = 0; - - /*! Updates the underlying storage of this packet, and populates it with the specified - * arguments. This is a non-const method and is useful for read-write (TX) access. - * - * \param pkt_buff Pointer to a buffer that should be populated with the TX packet - * \param header The CHDR header to fill into the TX packet - * \param timestamp The timestamp to fill into the TX packet (if requested) - */ - virtual void refresh(void* pkt_buff, chdr_header& header, uint64_t timestamp = 0) = 0; - - /*! Updates the CHDR header with the written payload size - * - * \param payload_size_bytes The payload size in bytes - */ - virtual void update_payload_size(size_t payload_size_bytes) = 0; - - /*! Returns a class that represents the contents of the CHDR header - * - * \return The CHDR header - */ - virtual chdr_header get_chdr_header() const = 0; - - /*! Returns the timestamp in the packet as an optional value - * - * \return A boost::optional which if initialized has the timestamp - */ - virtual boost::optional get_timestamp() const = 0; - - /*! Returns the endianness of the metadata and payload buffers - * - * \return The byte order as a uhd::endianness_t - */ - virtual endianness_t get_byte_order() const = 0; - - /*! Returns the maximum transfer unit in bytes - * - * \return The maximum transfer unit in bytes - */ - virtual size_t get_mtu_bytes() const = 0; - - /*! Returns the metadata size in bytes - * - * \return The size in bytes - */ - virtual size_t get_mdata_size() const = 0; - - /*! Returns a const void pointer to the metadata section in the packet - * - * \return A pointer to the metadata - */ - virtual const void* get_mdata_const_ptr() const = 0; - - /*! Returns a non-const void pointer to the metadata section in the packet - * - * \return A pointer to the metadata - */ - virtual void* get_mdata_ptr() = 0; - - /*! Returns the payload size in bytes - * - * \return The size in bytes - */ - virtual size_t get_payload_size() const = 0; - - /*! Returns a const void pointer to the payload section in the packet - * - * \return A pointer to the payload - */ - virtual const void* get_payload_const_ptr() const = 0; - - /*! Returns a non-const void pointer to the payload section in the packet - * - * \return A pointer to the payload - */ - virtual void* get_payload_ptr() = 0; - - /*! Return the payload offset in bytes for a given type and num_mdata - * - * \param pkt_type The packet type for calculation - * \param num_mdata The number of metadata words for calculation - * \return The offset of the payload in a packet with the given params - */ - virtual size_t calculate_payload_offset( - const packet_type_t pkt_type, const uint8_t num_mdata = 0) const = 0; - - //! Shortcut to return the const metadata pointer cast as a specific type - template - inline const data_t* get_mdata_const_ptr_as() const - { - return reinterpret_cast(get_mdata_const_ptr()); - } - - //! Shortcut to return the non-const metadata pointer cast as a specific type - template - inline data_t* get_mdata_ptr_as() - { - return reinterpret_cast(get_mdata_ptr()); - } - - //! Shortcut to return the const payload pointer cast as a specific type - template - inline const data_t* get_payload_const_ptr_as() const - { - return reinterpret_cast(get_payload_const_ptr()); - } - - //! Shortcut to return the non-const payload pointer cast as a specific type - template - inline data_t* get_payload_ptr_as() - { - return reinterpret_cast(get_payload_ptr()); - } - - //! Return a function to convert a word of type data_t to host order - template - const std::function conv_to_host() const - { - return (get_byte_order() == uhd::ENDIANNESS_BIG) ? uhd::ntohx - : uhd::wtohx; - } - - //! Return a function to convert a word of type data_t from host order - template - const std::function conv_from_host() const - { - return (get_byte_order() == uhd::ENDIANNESS_BIG) ? uhd::htonx - : uhd::htowx; - } -}; - -//---------------------------------------------------- -// Container for specific CHDR Packets -//---------------------------------------------------- - -//! A container class that wraps a generic buffer that contains a CHDR packet. The -// container provides a high level API to read and write the header, metadata and payload -// of the packet. The payload can be accessed as a specific type that will be serialized -// and deserialized appropriately. -// -template -class chdr_packet_specific -{ -public: - //! A unique pointer to a const chdr_packet. Useful as a read-only interface. - typedef std::unique_ptr> cuptr; - //! A unique pointer to a non-const chdr_packet. Useful as a read-write interface. - typedef std::unique_ptr> uptr; - - chdr_packet_specific(chdr_packet::uptr chdr_pkt) : _chdr_pkt(std::move(chdr_pkt)) {} - ~chdr_packet_specific() = default; - - //! Updates the underlying storage of this packet. This is a const method and is - // only useful for read-only access. - inline void refresh(const void* pkt_buff) const - { - _chdr_pkt->refresh(pkt_buff); - } - - //! Updates the underlying storage of this packet, and populates it with the specified - // arguments. This is a non-const method and is useful for read-write access. - inline void refresh(void* pkt_buff, chdr_header& header, const payload_t& payload) - { - payload.populate_header(header); - _chdr_pkt->refresh(pkt_buff, header); - size_t bytes_copied = payload.serialize(_chdr_pkt->get_payload_ptr_as(), - _chdr_pkt->get_mtu_bytes(), - _chdr_pkt->conv_from_host()); - _chdr_pkt->update_payload_size(bytes_copied); - header = _chdr_pkt->get_chdr_header(); - } - - //! Returns a class that represents the contents of the CHDR header - inline chdr_header get_chdr_header() const - { - return std::move(_chdr_pkt->get_chdr_header()); - } - - //! Returns a class that represents the contents of the CHDR payload - inline payload_t get_payload() const - { - payload_t payload; - payload.deserialize(_chdr_pkt->get_payload_const_ptr_as(), - _chdr_pkt->get_payload_size() / sizeof(uint64_t), - _chdr_pkt->conv_to_host()); - return payload; - } - - //! Fills the CHDR payload into the specified parameter - inline void fill_payload(payload_t& payload) const - { - payload.deserialize(_chdr_pkt->get_payload_const_ptr_as(), - _chdr_pkt->get_payload_size() / sizeof(uint64_t), - _chdr_pkt->conv_to_host()); - } - -private: - chdr_packet::uptr _chdr_pkt; -}; - -//---------------------------------------------------- -// Specific CHDR packet types -//---------------------------------------------------- - -//! CHDR control packet -typedef chdr_packet_specific chdr_ctrl_packet; - -//! CHDR stream status packet -typedef chdr_packet_specific chdr_strs_packet; - -//! CHDR stream command packet -typedef chdr_packet_specific chdr_strc_packet; - -//! CHDR management packet -typedef chdr_packet_specific chdr_mgmt_packet; - -//---------------------------------------------------- -// CHDR packet factory -//---------------------------------------------------- - -//! A copyable and movable factory class that is capable of generating generic and -//! specific CHDR packet containers. -// -class chdr_packet_factory -{ -public: - //! A parametrized ctor that takes in all the info required to generate a CHDR packet - // - // \param chdr_w The CHDR width of the remote device - // \param endianness The endianness of the link being used (e.g., Ethernet - // typically uses big-endian, PCIe typically uses - // little-endian). Note: The host endianness is - // automatically derived. - chdr_packet_factory(chdr_w_t chdr_w, endianness_t endianness); - chdr_packet_factory() = delete; - chdr_packet_factory(const chdr_packet_factory& rhs) = default; - chdr_packet_factory(chdr_packet_factory&& rhs) = default; - - //! Makes a generic CHDR packet and transfers ownership to the client - chdr_packet::uptr make_generic( - size_t mtu_bytes = std::numeric_limits::max()) const; - - //! Makes a CHDR control packet and transfers ownership to the client - chdr_ctrl_packet::uptr make_ctrl( - size_t mtu_bytes = std::numeric_limits::max()) const; - - //! Makes a CHDR stream status packet and transfers ownership to the client - chdr_strs_packet::uptr make_strs( - size_t mtu_bytes = std::numeric_limits::max()) const; - - //! Makes a CHDR stream cmd packet and transfers ownership to the client - chdr_strc_packet::uptr make_strc( - size_t mtu_bytes = std::numeric_limits::max()) const; - - //! Makes a CHDR management packet and transfers ownership to the client - chdr_mgmt_packet::uptr make_mgmt( - size_t mtu_bytes = std::numeric_limits::max()) const; - - //! Get the CHDR width - inline chdr_w_t get_chdr_w() const - { - return _chdr_w; - } - - //! Get the link endianness - inline endianness_t get_endianness() const - { - return _endianness; - } - - //! Get the protocol version for RFNoC and the CHDR format - inline uint16_t get_protover() const - { - return RFNOC_PROTO_VER; - } - -private: - const chdr_w_t _chdr_w; - const endianness_t _endianness; -}; - -}}} // namespace uhd::rfnoc::chdr diff --git a/host/lib/include/uhdlib/rfnoc/chdr_packet_writer.hpp b/host/lib/include/uhdlib/rfnoc/chdr_packet_writer.hpp new file mode 100644 index 000000000..6f1c264dd --- /dev/null +++ b/host/lib/include/uhdlib/rfnoc/chdr_packet_writer.hpp @@ -0,0 +1,325 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#pragma once + +#include +#include +#include +#include + +namespace uhd { namespace rfnoc { namespace chdr { + +//---------------------------------------------------- +// Generic CHDR Packet Container +//---------------------------------------------------- + +//! A container class that wraps a generic buffer that contains a CHDR packet. The +// container provides a high level API to read and write the header, metadata and payload +// of the packet. The payload can be accessed as a generic buffer using this interface. +// +class chdr_packet_writer +{ +public: + //! A unique pointer to a const chdr_packet_writer. Useful as a read-only interface. + typedef std::unique_ptr cuptr; + //! A unique pointer to a non-const chdr_packet_writer. Useful as a read-write + //! interface. + typedef std::unique_ptr uptr; + + virtual ~chdr_packet_writer() = 0; + + /*! Updates the underlying storage of this packet. This is a const method and is + * only useful for read-only (RX) access. + * + * \param pkt_buff Pointer to a buffer that contains the RX packet + */ + virtual void refresh(const void* pkt_buff) const = 0; + + /*! Updates the underlying storage of this packet, and populates it with the specified + * arguments. This is a non-const method and is useful for read-write (TX) access. + * + * \param pkt_buff Pointer to a buffer that should be populated with the TX packet + * \param header The CHDR header to fill into the TX packet + * \param timestamp The timestamp to fill into the TX packet (if requested) + */ + virtual void refresh(void* pkt_buff, chdr_header& header, uint64_t timestamp = 0) = 0; + + /*! Updates the CHDR header with the written payload size + * + * \param payload_size_bytes The payload size in bytes + */ + virtual void update_payload_size(size_t payload_size_bytes) = 0; + + /*! Returns a class that represents the contents of the CHDR header + * + * \return The CHDR header + */ + virtual chdr_header get_chdr_header() const = 0; + + /*! Returns the timestamp in the packet as an optional value + * + * \return A boost::optional which if initialized has the timestamp + */ + virtual boost::optional get_timestamp() const = 0; + + /*! Returns the endianness of the metadata and payload buffers + * + * \return The byte order as a uhd::endianness_t + */ + virtual endianness_t get_byte_order() const = 0; + + /*! Returns the maximum transfer unit in bytes + * + * \return The maximum transfer unit in bytes + */ + virtual size_t get_mtu_bytes() const = 0; + + /*! Returns the metadata size in bytes + * + * \return The size in bytes + */ + virtual size_t get_mdata_size() const = 0; + + /*! Returns a const void pointer to the metadata section in the packet + * + * \return A pointer to the metadata + */ + virtual const void* get_mdata_const_ptr() const = 0; + + /*! Returns a non-const void pointer to the metadata section in the packet + * + * \return A pointer to the metadata + */ + virtual void* get_mdata_ptr() = 0; + + /*! Returns the payload size in bytes + * + * \return The size in bytes + */ + virtual size_t get_payload_size() const = 0; + + /*! Returns a const void pointer to the payload section in the packet + * + * \return A pointer to the payload + */ + virtual const void* get_payload_const_ptr() const = 0; + + /*! Returns a non-const void pointer to the payload section in the packet + * + * \return A pointer to the payload + */ + virtual void* get_payload_ptr() = 0; + + /*! Return the payload offset in bytes for a given type and num_mdata + * + * \param pkt_type The packet type for calculation + * \param num_mdata The number of metadata words for calculation + * \return The offset of the payload in a packet with the given params + */ + virtual size_t calculate_payload_offset( + const packet_type_t pkt_type, const uint8_t num_mdata = 0) const = 0; + + //! Shortcut to return the const metadata pointer cast as a specific type + template + inline const data_t* get_mdata_const_ptr_as() const + { + return reinterpret_cast(get_mdata_const_ptr()); + } + + //! Shortcut to return the non-const metadata pointer cast as a specific type + template + inline data_t* get_mdata_ptr_as() + { + return reinterpret_cast(get_mdata_ptr()); + } + + //! Shortcut to return the const payload pointer cast as a specific type + template + inline const data_t* get_payload_const_ptr_as() const + { + return reinterpret_cast(get_payload_const_ptr()); + } + + //! Shortcut to return the non-const payload pointer cast as a specific type + template + inline data_t* get_payload_ptr_as() + { + return reinterpret_cast(get_payload_ptr()); + } + + //! Return a function to convert a word of type data_t to host order + template + const std::function conv_to_host() const + { + return (get_byte_order() == uhd::ENDIANNESS_BIG) ? uhd::ntohx + : uhd::wtohx; + } + + //! Return a function to convert a word of type data_t from host order + template + const std::function conv_from_host() const + { + return (get_byte_order() == uhd::ENDIANNESS_BIG) ? uhd::htonx + : uhd::htowx; + } +}; + +//---------------------------------------------------- +// Container for specific CHDR Packets +//---------------------------------------------------- + +//! A container class that wraps a generic buffer that contains a CHDR packet. The +// container provides a high level API to read and write the header, metadata and payload +// of the packet. The payload can be accessed as a specific type that will be serialized +// and deserialized appropriately. +// +template +class chdr_packet_writer_specific +{ +public: + //! A unique pointer to a const chdr_packet_writer. Useful as a read-only interface. + typedef std::unique_ptr> cuptr; + //! A unique pointer to a non-const chdr_packet_writer. Useful as a read-write + //! interface. + typedef std::unique_ptr> uptr; + + chdr_packet_writer_specific(chdr_packet_writer::uptr chdr_pkt) + : _chdr_pkt(std::move(chdr_pkt)) + { + } + ~chdr_packet_writer_specific() = default; + + //! Updates the underlying storage of this packet. This is a const method and is + // only useful for read-only access. + inline void refresh(const void* pkt_buff) const + { + _chdr_pkt->refresh(pkt_buff); + } + + //! Updates the underlying storage of this packet, and populates it with the specified + // arguments. This is a non-const method and is useful for read-write access. + inline void refresh(void* pkt_buff, chdr_header& header, const payload_t& payload) + { + payload.populate_header(header); + _chdr_pkt->refresh(pkt_buff, header); + size_t bytes_copied = payload.serialize(_chdr_pkt->get_payload_ptr_as(), + _chdr_pkt->get_mtu_bytes(), + _chdr_pkt->conv_from_host()); + _chdr_pkt->update_payload_size(bytes_copied); + header = _chdr_pkt->get_chdr_header(); + } + + //! Returns a class that represents the contents of the CHDR header + inline chdr_header get_chdr_header() const + { + return std::move(_chdr_pkt->get_chdr_header()); + } + + //! Returns a class that represents the contents of the CHDR payload + inline payload_t get_payload() const + { + payload_t payload; + payload.deserialize(_chdr_pkt->get_payload_const_ptr_as(), + _chdr_pkt->get_payload_size() / sizeof(uint64_t), + _chdr_pkt->conv_to_host()); + return payload; + } + + //! Fills the CHDR payload into the specified parameter + inline void fill_payload(payload_t& payload) const + { + payload.deserialize(_chdr_pkt->get_payload_const_ptr_as(), + _chdr_pkt->get_payload_size() / sizeof(uint64_t), + _chdr_pkt->conv_to_host()); + } + +private: + chdr_packet_writer::uptr _chdr_pkt; +}; + +//---------------------------------------------------- +// Specific CHDR packet types +//---------------------------------------------------- + +//! CHDR control packet +typedef chdr_packet_writer_specific chdr_ctrl_packet; + +//! CHDR stream status packet +typedef chdr_packet_writer_specific chdr_strs_packet; + +//! CHDR stream command packet +typedef chdr_packet_writer_specific chdr_strc_packet; + +//! CHDR management packet +typedef chdr_packet_writer_specific chdr_mgmt_packet; + +//---------------------------------------------------- +// CHDR packet factory +//---------------------------------------------------- + +//! A copyable and movable factory class that is capable of generating generic and +//! specific CHDR packet containers. +// +class chdr_packet_factory +{ +public: + //! A parametrized ctor that takes in all the info required to generate a CHDR packet + // + // \param chdr_w The CHDR width of the remote device + // \param endianness The endianness of the link being used (e.g., Ethernet + // typically uses big-endian, PCIe typically uses + // little-endian). Note: The host endianness is + // automatically derived. + chdr_packet_factory(chdr_w_t chdr_w, endianness_t endianness); + chdr_packet_factory() = delete; + chdr_packet_factory(const chdr_packet_factory& rhs) = default; + chdr_packet_factory(chdr_packet_factory&& rhs) = default; + + //! Makes a generic CHDR packet and transfers ownership to the client + chdr_packet_writer::uptr make_generic( + size_t mtu_bytes = std::numeric_limits::max()) const; + + //! Makes a CHDR control packet and transfers ownership to the client + chdr_ctrl_packet::uptr make_ctrl( + size_t mtu_bytes = std::numeric_limits::max()) const; + + //! Makes a CHDR stream status packet and transfers ownership to the client + chdr_strs_packet::uptr make_strs( + size_t mtu_bytes = std::numeric_limits::max()) const; + + //! Makes a CHDR stream cmd packet and transfers ownership to the client + chdr_strc_packet::uptr make_strc( + size_t mtu_bytes = std::numeric_limits::max()) const; + + //! Makes a CHDR management packet and transfers ownership to the client + chdr_mgmt_packet::uptr make_mgmt( + size_t mtu_bytes = std::numeric_limits::max()) const; + + //! Get the CHDR width + inline chdr_w_t get_chdr_w() const + { + return _chdr_w; + } + + //! Get the link endianness + inline endianness_t get_endianness() const + { + return _endianness; + } + + //! Get the protocol version for RFNoC and the CHDR format + inline uint16_t get_protover() const + { + return RFNOC_PROTO_VER; + } + +private: + const chdr_w_t _chdr_w; + const endianness_t _endianness; +}; + +}}} // namespace uhd::rfnoc::chdr diff --git a/host/lib/include/uhdlib/rfnoc/chdr_rx_data_xport.hpp b/host/lib/include/uhdlib/rfnoc/chdr_rx_data_xport.hpp index caa94bde3..d041f37c6 100644 --- a/host/lib/include/uhdlib/rfnoc/chdr_rx_data_xport.hpp +++ b/host/lib/include/uhdlib/rfnoc/chdr_rx_data_xport.hpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include @@ -391,10 +391,10 @@ private: uint16_t _data_seq_num = 0; // Packet for received data - chdr::chdr_packet::uptr _recv_packet; + chdr::chdr_packet_writer::uptr _recv_packet; // Packet for received data used in callbacks - chdr::chdr_packet::uptr _recv_packet_cb; + chdr::chdr_packet_writer::uptr _recv_packet_cb; // Handles sending of strs flow control response packets detail::rx_flow_ctrl_sender _fc_sender; diff --git a/host/lib/include/uhdlib/rfnoc/chdr_tx_data_xport.hpp b/host/lib/include/uhdlib/rfnoc/chdr_tx_data_xport.hpp index 777066c0a..4394adaea 100644 --- a/host/lib/include/uhdlib/rfnoc/chdr_tx_data_xport.hpp +++ b/host/lib/include/uhdlib/rfnoc/chdr_tx_data_xport.hpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -378,10 +378,10 @@ private: chdr::chdr_header _send_header; // Packet for send data - chdr::chdr_packet::uptr _send_packet; + chdr::chdr_packet_writer::uptr _send_packet; // Packet to receive strs messages - chdr::chdr_packet::uptr _recv_packet; + chdr::chdr_packet_writer::uptr _recv_packet; // Handles sending of strc flow control ack packets detail::tx_flow_ctrl_sender _fc_sender; diff --git a/host/lib/include/uhdlib/rfnoc/graph_stream_manager.hpp b/host/lib/include/uhdlib/rfnoc/graph_stream_manager.hpp index 3e1cdeee5..6cf224feb 100644 --- a/host/lib/include/uhdlib/rfnoc/graph_stream_manager.hpp +++ b/host/lib/include/uhdlib/rfnoc/graph_stream_manager.hpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include diff --git a/host/lib/include/uhdlib/rfnoc/mgmt_portal.hpp b/host/lib/include/uhdlib/rfnoc/mgmt_portal.hpp index 806c9d1ea..223783170 100644 --- a/host/lib/include/uhdlib/rfnoc/mgmt_portal.hpp +++ b/host/lib/include/uhdlib/rfnoc/mgmt_portal.hpp @@ -7,7 +7,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/host/lib/rfnoc/CMakeLists.txt b/host/lib/rfnoc/CMakeLists.txt index 7c54a71f6..7d1334e04 100644 --- a/host/lib/rfnoc/CMakeLists.txt +++ b/host/lib/rfnoc/CMakeLists.txt @@ -16,7 +16,7 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/block_container.cpp ${CMAKE_CURRENT_SOURCE_DIR}/block_id.cpp ${CMAKE_CURRENT_SOURCE_DIR}/chdr_types.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/chdr_packet.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/chdr_packet_writer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/chdr_ctrl_xport.cpp ${CMAKE_CURRENT_SOURCE_DIR}/chdr_rx_data_xport.cpp ${CMAKE_CURRENT_SOURCE_DIR}/chdr_tx_data_xport.cpp diff --git a/host/lib/rfnoc/chdr_ctrl_endpoint.cpp b/host/lib/rfnoc/chdr_ctrl_endpoint.cpp index bba972186..3b2865c73 100644 --- a/host/lib/rfnoc/chdr_ctrl_endpoint.cpp +++ b/host/lib/rfnoc/chdr_ctrl_endpoint.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/host/lib/rfnoc/chdr_packet.cpp b/host/lib/rfnoc/chdr_packet.cpp deleted file mode 100644 index fc6c24838..000000000 --- a/host/lib/rfnoc/chdr_packet.cpp +++ /dev/null @@ -1,222 +0,0 @@ -// -// Copyright 2019 Ettus Research, a National Instruments Brand -// -// SPDX-License-Identifier: GPL-3.0-or-later -// - -#include -#include -#include -#include - -using namespace uhd; -using namespace uhd::rfnoc; -using namespace uhd::rfnoc::chdr; - -chdr_packet::~chdr_packet() = default; - -//------------------------------------------------------------ -// chdr_packet -//------------------------------------------------------------ -// endianness is the link endianness, not the host endianness -template -class chdr_packet_impl : public chdr_packet -{ -public: - chdr_packet_impl() = delete; - chdr_packet_impl(size_t mtu_bytes) : _mtu_bytes(mtu_bytes) {} - ~chdr_packet_impl() = default; - - virtual void refresh(const void* pkt_buff) const - { - assert(pkt_buff); - _pkt_buff = const_cast(reinterpret_cast(pkt_buff)); - _mdata_offset = _compute_mdata_offset(get_chdr_header()); - } - - virtual void refresh(void* pkt_buff, chdr_header& header, uint64_t timestamp = 0) - { - assert(pkt_buff); - _pkt_buff = reinterpret_cast(pkt_buff); - _pkt_buff[0] = u64_from_host(header); - if (_has_timestamp(header)) { - _pkt_buff[1] = u64_from_host(timestamp); - } - _mdata_offset = _compute_mdata_offset(get_chdr_header()); - } - - virtual void update_payload_size(size_t payload_size_bytes) - { - chdr_header header = get_chdr_header(); - header.set_length(((_mdata_offset + header.get_num_mdata()) * chdr_w_bytes) - + payload_size_bytes); - _pkt_buff[0] = u64_from_host(header); - } - - virtual endianness_t get_byte_order() const - { - return endianness; - } - - virtual size_t get_mtu_bytes() const - { - return _mtu_bytes; - } - - virtual chdr_header get_chdr_header() const - { - assert(_pkt_buff); - return std::move(chdr_header(u64_to_host(_pkt_buff[0]))); - } - - virtual boost::optional get_timestamp() const - { - if (_has_timestamp(get_chdr_header())) { - // In a unit64_t buffer, the timestamp is always immediately after the header - // regardless of chdr_w. - return u64_to_host(_pkt_buff[1]); - } else { - return boost::none; - } - } - - virtual size_t get_mdata_size() const - { - return get_chdr_header().get_num_mdata() * chdr_w_bytes; - } - - virtual const void* get_mdata_const_ptr() const - { - return const_cast( - const_cast*>(this)->get_mdata_ptr()); - } - - virtual void* get_mdata_ptr() - { - return reinterpret_cast(_pkt_buff + (chdr_w_stride * _mdata_offset)); - } - - virtual size_t get_payload_size() const - { - return get_chdr_header().get_length() - get_mdata_size() - - (chdr_w_bytes * _mdata_offset); - } - - virtual const void* get_payload_const_ptr() const - { - return const_cast( - const_cast*>(this)->get_payload_ptr()); - } - - virtual void* get_payload_ptr() - { - return reinterpret_cast( - _pkt_buff - + (chdr_w_stride * (_mdata_offset + get_chdr_header().get_num_mdata()))); - } - - virtual size_t calculate_payload_offset( - const packet_type_t pkt_type, const uint8_t num_mdata = 0) const - { - chdr_header header; - header.set_pkt_type(pkt_type); - return (_compute_mdata_offset(header) + num_mdata) * chdr_w_bytes; - } - -private: - inline bool _has_timestamp(const chdr_header& header) const - { - return (header.get_pkt_type() == PKT_TYPE_DATA_WITH_TS); - } - - inline size_t _compute_mdata_offset(const chdr_header& header) const - { - // The metadata offset depends on the chdr_w and whether we have a timestamp - if (chdr_w == 64) { - return _has_timestamp(header) ? 2 : 1; - } else { - return 1; - } - } - - inline static uint64_t u64_to_host(uint64_t word) - { - return (endianness == ENDIANNESS_BIG) ? uhd::ntohx(word) - : uhd::wtohx(word); - } - - inline static uint64_t u64_from_host(uint64_t word) - { - return (endianness == ENDIANNESS_BIG) ? uhd::htonx(word) - : uhd::htowx(word); - } - - static const size_t chdr_w_bytes = (chdr_w / 8); - static const size_t chdr_w_stride = (chdr_w / 64); - - // Packet state - const size_t _mtu_bytes = 0; - mutable uint64_t* _pkt_buff = nullptr; - mutable size_t _mdata_offset = 0; -}; - -chdr_packet_factory::chdr_packet_factory(chdr_w_t chdr_w, endianness_t endianness) - : _chdr_w(chdr_w), _endianness(endianness) -{ -} - -chdr_packet::uptr chdr_packet_factory::make_generic(size_t mtu_bytes) const -{ - if (_endianness == ENDIANNESS_BIG) { - switch (_chdr_w) { - case CHDR_W_512: - return std::make_unique>(mtu_bytes); - case CHDR_W_256: - return std::make_unique>(mtu_bytes); - case CHDR_W_128: - return std::make_unique>(mtu_bytes); - case CHDR_W_64: - return std::make_unique>(mtu_bytes); - default: - assert(0); - } - } else { - switch (_chdr_w) { - case CHDR_W_512: - return std::make_unique>( - mtu_bytes); - case CHDR_W_256: - return std::make_unique>( - mtu_bytes); - case CHDR_W_128: - return std::make_unique>( - mtu_bytes); - case CHDR_W_64: - return std::make_unique>( - mtu_bytes); - default: - assert(0); - } - } - return chdr_packet::uptr(); -} - -chdr_ctrl_packet::uptr chdr_packet_factory::make_ctrl(size_t mtu_bytes) const -{ - return std::make_unique(make_generic(mtu_bytes)); -} - -chdr_strs_packet::uptr chdr_packet_factory::make_strs(size_t mtu_bytes) const -{ - return std::make_unique(make_generic(mtu_bytes)); -} - -chdr_strc_packet::uptr chdr_packet_factory::make_strc(size_t mtu_bytes) const -{ - return std::make_unique(make_generic(mtu_bytes)); -} - -chdr_mgmt_packet::uptr chdr_packet_factory::make_mgmt(size_t mtu_bytes) const -{ - return std::make_unique(make_generic(mtu_bytes)); -} diff --git a/host/lib/rfnoc/chdr_packet_writer.cpp b/host/lib/rfnoc/chdr_packet_writer.cpp new file mode 100644 index 000000000..c58ffd932 --- /dev/null +++ b/host/lib/rfnoc/chdr_packet_writer.cpp @@ -0,0 +1,222 @@ +// +// Copyright 2019 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include +#include +#include +#include + +using namespace uhd; +using namespace uhd::rfnoc; +using namespace uhd::rfnoc::chdr; + +chdr_packet_writer::~chdr_packet_writer() = default; + +//------------------------------------------------------------ +// chdr_packet +//------------------------------------------------------------ +// endianness is the link endianness, not the host endianness +template +class chdr_packet_impl : public chdr_packet_writer +{ +public: + chdr_packet_impl() = delete; + chdr_packet_impl(size_t mtu_bytes) : _mtu_bytes(mtu_bytes) {} + ~chdr_packet_impl() = default; + + virtual void refresh(const void* pkt_buff) const + { + assert(pkt_buff); + _pkt_buff = const_cast(reinterpret_cast(pkt_buff)); + _mdata_offset = _compute_mdata_offset(get_chdr_header()); + } + + virtual void refresh(void* pkt_buff, chdr_header& header, uint64_t timestamp = 0) + { + assert(pkt_buff); + _pkt_buff = reinterpret_cast(pkt_buff); + _pkt_buff[0] = u64_from_host(header); + if (_has_timestamp(header)) { + _pkt_buff[1] = u64_from_host(timestamp); + } + _mdata_offset = _compute_mdata_offset(get_chdr_header()); + } + + virtual void update_payload_size(size_t payload_size_bytes) + { + chdr_header header = get_chdr_header(); + header.set_length(((_mdata_offset + header.get_num_mdata()) * chdr_w_bytes) + + payload_size_bytes); + _pkt_buff[0] = u64_from_host(header); + } + + virtual endianness_t get_byte_order() const + { + return endianness; + } + + virtual size_t get_mtu_bytes() const + { + return _mtu_bytes; + } + + virtual chdr_header get_chdr_header() const + { + assert(_pkt_buff); + return std::move(chdr_header(u64_to_host(_pkt_buff[0]))); + } + + virtual boost::optional get_timestamp() const + { + if (_has_timestamp(get_chdr_header())) { + // In a unit64_t buffer, the timestamp is always immediately after the header + // regardless of chdr_w. + return u64_to_host(_pkt_buff[1]); + } else { + return boost::none; + } + } + + virtual size_t get_mdata_size() const + { + return get_chdr_header().get_num_mdata() * chdr_w_bytes; + } + + virtual const void* get_mdata_const_ptr() const + { + return const_cast( + const_cast*>(this)->get_mdata_ptr()); + } + + virtual void* get_mdata_ptr() + { + return reinterpret_cast(_pkt_buff + (chdr_w_stride * _mdata_offset)); + } + + virtual size_t get_payload_size() const + { + return get_chdr_header().get_length() - get_mdata_size() + - (chdr_w_bytes * _mdata_offset); + } + + virtual const void* get_payload_const_ptr() const + { + return const_cast( + const_cast*>(this)->get_payload_ptr()); + } + + virtual void* get_payload_ptr() + { + return reinterpret_cast( + _pkt_buff + + (chdr_w_stride * (_mdata_offset + get_chdr_header().get_num_mdata()))); + } + + virtual size_t calculate_payload_offset( + const packet_type_t pkt_type, const uint8_t num_mdata = 0) const + { + chdr_header header; + header.set_pkt_type(pkt_type); + return (_compute_mdata_offset(header) + num_mdata) * chdr_w_bytes; + } + +private: + inline bool _has_timestamp(const chdr_header& header) const + { + return (header.get_pkt_type() == PKT_TYPE_DATA_WITH_TS); + } + + inline size_t _compute_mdata_offset(const chdr_header& header) const + { + // The metadata offset depends on the chdr_w and whether we have a timestamp + if (chdr_w == 64) { + return _has_timestamp(header) ? 2 : 1; + } else { + return 1; + } + } + + inline static uint64_t u64_to_host(uint64_t word) + { + return (endianness == ENDIANNESS_BIG) ? uhd::ntohx(word) + : uhd::wtohx(word); + } + + inline static uint64_t u64_from_host(uint64_t word) + { + return (endianness == ENDIANNESS_BIG) ? uhd::htonx(word) + : uhd::htowx(word); + } + + static const size_t chdr_w_bytes = (chdr_w / 8); + static const size_t chdr_w_stride = (chdr_w / 64); + + // Packet state + const size_t _mtu_bytes = 0; + mutable uint64_t* _pkt_buff = nullptr; + mutable size_t _mdata_offset = 0; +}; + +chdr_packet_factory::chdr_packet_factory(chdr_w_t chdr_w, endianness_t endianness) + : _chdr_w(chdr_w), _endianness(endianness) +{ +} + +chdr_packet_writer::uptr chdr_packet_factory::make_generic(size_t mtu_bytes) const +{ + if (_endianness == ENDIANNESS_BIG) { + switch (_chdr_w) { + case CHDR_W_512: + return std::make_unique>(mtu_bytes); + case CHDR_W_256: + return std::make_unique>(mtu_bytes); + case CHDR_W_128: + return std::make_unique>(mtu_bytes); + case CHDR_W_64: + return std::make_unique>(mtu_bytes); + default: + assert(0); + } + } else { + switch (_chdr_w) { + case CHDR_W_512: + return std::make_unique>( + mtu_bytes); + case CHDR_W_256: + return std::make_unique>( + mtu_bytes); + case CHDR_W_128: + return std::make_unique>( + mtu_bytes); + case CHDR_W_64: + return std::make_unique>( + mtu_bytes); + default: + assert(0); + } + } + return chdr_packet_writer::uptr(); +} + +chdr_ctrl_packet::uptr chdr_packet_factory::make_ctrl(size_t mtu_bytes) const +{ + return std::make_unique(make_generic(mtu_bytes)); +} + +chdr_strs_packet::uptr chdr_packet_factory::make_strs(size_t mtu_bytes) const +{ + return std::make_unique(make_generic(mtu_bytes)); +} + +chdr_strc_packet::uptr chdr_packet_factory::make_strc(size_t mtu_bytes) const +{ + return std::make_unique(make_generic(mtu_bytes)); +} + +chdr_mgmt_packet::uptr chdr_packet_factory::make_mgmt(size_t mtu_bytes) const +{ + return std::make_unique(make_generic(mtu_bytes)); +} diff --git a/host/lib/rfnoc/chdr_rx_data_xport.cpp b/host/lib/rfnoc/chdr_rx_data_xport.cpp index df7162a73..ebfcda2b8 100644 --- a/host/lib/rfnoc/chdr_rx_data_xport.cpp +++ b/host/lib/rfnoc/chdr_rx_data_xport.cpp @@ -106,7 +106,7 @@ chdr_rx_data_xport::fc_params_t chdr_rx_data_xport::configure_sep(io_service::sp const sep_id_t local_epid = epids.second; rx_flow_ctrl_sender fc_sender(pkt_factory, epids); - chdr::chdr_packet::uptr pkt = pkt_factory.make_generic(); + chdr::chdr_packet_writer::uptr pkt = pkt_factory.make_generic(); fc_sender.set_capacity(recv_capacity); chdr::strc_payload strc; diff --git a/host/lib/rfnoc/chdr_tx_data_xport.cpp b/host/lib/rfnoc/chdr_tx_data_xport.cpp index 321b6ea85..a51835a07 100644 --- a/host/lib/rfnoc/chdr_tx_data_xport.cpp +++ b/host/lib/rfnoc/chdr_tx_data_xport.cpp @@ -96,8 +96,8 @@ static chdr_tx_data_xport::fc_params_t configure_flow_ctrl(io_service::sptr io_s const double fc_freq_ratio, const double fc_headroom_ratio) { - chdr::chdr_strc_packet::uptr strc_packet = pkt_factory.make_strc(); - chdr::chdr_packet::uptr recv_packet = pkt_factory.make_generic(); + chdr::chdr_strc_packet::uptr strc_packet = pkt_factory.make_strc(); + chdr::chdr_packet_writer::uptr recv_packet = pkt_factory.make_generic(); // No flow control at initialization, just release all send buffs auto send_cb = [](frame_buff::uptr buff, send_link_if* send_link) { diff --git a/host/lib/rfnoc/ctrlport_endpoint.cpp b/host/lib/rfnoc/ctrlport_endpoint.cpp index 5cff24443..5afb3919e 100644 --- a/host/lib/rfnoc/ctrlport_endpoint.cpp +++ b/host/lib/rfnoc/ctrlport_endpoint.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include @@ -121,9 +121,8 @@ public: { // Compute transaction expiration time, use MASSIVE_TIMEOUT if a timed // command is in the queue - auto timeout_time = start_timeout( - check_timed_in_queue() ? MASSIVE_TIMEOUT : _policy.timeout - ); + auto timeout_time = + start_timeout(check_timed_in_queue() ? MASSIVE_TIMEOUT : _policy.timeout); // Send request auto request = @@ -174,9 +173,8 @@ public: // Compute transaction expiration time, use MASSIVE_TIMEOUT if a timed // command is in the queue - auto timeout_time = start_timeout( - check_timed_in_queue() ? MASSIVE_TIMEOUT : _policy.timeout - ); + auto timeout_time = + start_timeout(check_timed_in_queue() ? MASSIVE_TIMEOUT : _policy.timeout); // Send request auto request = send_request_packet(OP_POLL, @@ -192,12 +190,10 @@ public: virtual void sleep(uhd::time_spec_t duration, bool ack = false) { - // Compute transaction expiration time, use MASSIVE_TIMEOUT if a timed // command is in the queue - auto timeout_time = start_timeout( - check_timed_in_queue() ? MASSIVE_TIMEOUT : _policy.timeout - ); + auto timeout_time = + start_timeout(check_timed_in_queue() ? MASSIVE_TIMEOUT : _policy.timeout); // Send request auto request = send_request_packet(OP_SLEEP, @@ -421,7 +417,7 @@ private: // If we can fit the current request in the queue then we can proceed return (_buff_occupied + pyld_size) <= (_buff_capacity - - (ASYNC_MESSAGE_SIZE * _max_outstanding_async_msgs)); + - (ASYNC_MESSAGE_SIZE * _max_outstanding_async_msgs)); }; if (!buff_not_full()) { // If we're sending a timed command or if we have a timed command in the diff --git a/host/lib/rfnoc/mgmt_portal.cpp b/host/lib/rfnoc/mgmt_portal.cpp index 971c9837a..a54efaaf7 100644 --- a/host/lib/rfnoc/mgmt_portal.cpp +++ b/host/lib/rfnoc/mgmt_portal.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/host/lib/usrp/mpmd/mpmd_link_if_ctrl_base.hpp b/host/lib/usrp/mpmd/mpmd_link_if_ctrl_base.hpp index a9cb456e5..fd1ef8818 100644 --- a/host/lib/usrp/mpmd/mpmd_link_if_ctrl_base.hpp +++ b/host/lib/usrp/mpmd/mpmd_link_if_ctrl_base.hpp @@ -10,7 +10,7 @@ #include "mpmd_link_if_mgr.hpp" #include -#include +#include #include #include diff --git a/host/lib/usrp/mpmd/mpmd_link_if_mgr.hpp b/host/lib/usrp/mpmd/mpmd_link_if_mgr.hpp index b8e7454cb..4bf893dd4 100644 --- a/host/lib/usrp/mpmd/mpmd_link_if_mgr.hpp +++ b/host/lib/usrp/mpmd/mpmd_link_if_mgr.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include -- cgit v1.2.3