12 #include <boost/format.hpp> 13 #include <boost/optional.hpp> 19 namespace uhd {
namespace rfnoc {
namespace chdr {
47 return get_field<uint8_t>(_flat_hdr, VC_OFFSET, VC_WIDTH);
53 _flat_hdr = set_field(_flat_hdr, vc, VC_OFFSET, VC_WIDTH);
59 return get_field<bool>(_flat_hdr, EOB_OFFSET, EOB_WIDTH);
65 _flat_hdr = set_field(_flat_hdr, eob, EOB_OFFSET, EOB_WIDTH);
71 return get_field<bool>(_flat_hdr, EOV_OFFSET, EOV_WIDTH);
77 _flat_hdr = set_field(_flat_hdr, eov, EOV_OFFSET, EOV_WIDTH);
83 return get_field<packet_type_t>(_flat_hdr, PKT_TYPE_OFFSET, PKT_TYPE_WIDTH);
89 _flat_hdr = set_field(_flat_hdr, pkt_type, PKT_TYPE_OFFSET, PKT_TYPE_WIDTH);
95 return get_field<uint8_t>(_flat_hdr, NUM_MDATA_OFFSET, NUM_MDATA_WIDTH);
101 _flat_hdr = set_field(_flat_hdr, num_mdata, NUM_MDATA_OFFSET, NUM_MDATA_WIDTH);
107 return get_field<uint16_t>(_flat_hdr, SEQ_NUM_OFFSET, SEQ_NUM_WIDTH);
113 _flat_hdr = set_field(_flat_hdr, seq_num, SEQ_NUM_OFFSET, SEQ_NUM_WIDTH);
119 return get_field<uint16_t>(_flat_hdr, LENGTH_OFFSET, LENGTH_WIDTH);
125 _flat_hdr = set_field(_flat_hdr, length, LENGTH_OFFSET, LENGTH_WIDTH);
131 return get_field<uint16_t>(_flat_hdr, DST_EPID_OFFSET, DST_EPID_WIDTH);
137 _flat_hdr = set_field(_flat_hdr, dst_epid, DST_EPID_OFFSET, DST_EPID_WIDTH);
147 inline operator uint64_t()
const 155 return _flat_hdr == rhs._flat_hdr;
161 return _flat_hdr != rhs._flat_hdr;
167 _flat_hdr = rhs._flat_hdr;
184 return str(boost::format(
"chdr_header{vc:%u, eob:%b, eov:%b, pkt_type:%u, " 185 "num_mdata:%u, seq_num:%u, length:%u, dst_epid:%u}\n")
193 uint64_t _flat_hdr = 0;
195 static constexpr
size_t VC_WIDTH = 6;
196 static constexpr
size_t EOB_WIDTH = 1;
197 static constexpr
size_t EOV_WIDTH = 1;
198 static constexpr
size_t PKT_TYPE_WIDTH = 3;
199 static constexpr
size_t NUM_MDATA_WIDTH = 5;
200 static constexpr
size_t SEQ_NUM_WIDTH = 16;
201 static constexpr
size_t LENGTH_WIDTH = 16;
202 static constexpr
size_t DST_EPID_WIDTH = 16;
204 static constexpr
size_t VC_OFFSET = 58;
205 static constexpr
size_t EOB_OFFSET = 57;
206 static constexpr
size_t EOV_OFFSET = 56;
207 static constexpr
size_t PKT_TYPE_OFFSET = 53;
208 static constexpr
size_t NUM_MDATA_OFFSET = 48;
209 static constexpr
size_t SEQ_NUM_OFFSET = 32;
210 static constexpr
size_t LENGTH_OFFSET = 16;
211 static constexpr
size_t DST_EPID_OFFSET = 0;
213 static inline uint64_t mask(
const size_t width)
215 return ((uint64_t(1) <<
width) - 1);
218 template <
typename field_t>
219 static inline field_t get_field(
220 const uint64_t flat_hdr,
const size_t offset,
const size_t width)
222 return static_cast<field_t
>((flat_hdr >> offset) & mask(
width));
225 template <
typename field_t>
226 static inline uint64_t set_field(
const uint64_t old_val,
231 return (old_val & ~(mask(
width) << offset))
232 | ((
static_cast<uint64_t
>(field) & mask(
width)) << offset);
268 uint16_t dst_port = 0;
270 uint16_t src_port = 0;
274 boost::optional<uint64_t> timestamp = boost::none;
278 uint16_t src_epid = 0;
280 uint32_t address = 0;
282 std::vector<uint32_t> data_vtr = {0};
284 uint8_t byte_enable = 0xF;
301 size_t serialize(uint64_t* buff,
302 size_t max_size_bytes,
303 const std::function<uint64_t(uint64_t)>& conv_byte_order)
const;
306 template <endianness_t endianness>
307 size_t serialize(uint64_t* buff,
size_t max_size_bytes)
const 309 auto conv_byte_order = [](uint64_t x) -> uint64_t {
311 : uhd::htowx<uint64_t>(x);
313 return serialize(buff, max_size_bytes, conv_byte_order);
317 void deserialize(
const uint64_t* buff,
319 const std::function<uint64_t(uint64_t)>& conv_byte_order);
322 template <endianness_t endianness>
325 auto conv_byte_order = [](uint64_t x) -> uint64_t {
327 : uhd::wtohx<uint64_t>(x);
329 deserialize(buff, num_elems, conv_byte_order);
333 size_t get_length()
const;
338 return bool(timestamp);
347 return !(*
this == rhs);
351 const std::string to_string()
const;
354 static constexpr
size_t DST_PORT_WIDTH = 10;
355 static constexpr
size_t SRC_PORT_WIDTH = 10;
356 static constexpr
size_t NUM_DATA_WIDTH = 4;
357 static constexpr
size_t SEQ_NUM_WIDTH = 6;
358 static constexpr
size_t HAS_TIME_WIDTH = 1;
359 static constexpr
size_t IS_ACK_WIDTH = 1;
360 static constexpr
size_t SRC_EPID_WIDTH = 16;
361 static constexpr
size_t ADDRESS_WIDTH = 20;
362 static constexpr
size_t BYTE_ENABLE_WIDTH = 4;
363 static constexpr
size_t OPCODE_WIDTH = 4;
364 static constexpr
size_t STATUS_WIDTH = 2;
367 static constexpr
size_t DST_PORT_OFFSET = 0;
368 static constexpr
size_t SRC_PORT_OFFSET = 10;
369 static constexpr
size_t NUM_DATA_OFFSET = 20;
370 static constexpr
size_t SEQ_NUM_OFFSET = 24;
371 static constexpr
size_t HAS_TIME_OFFSET = 30;
372 static constexpr
size_t IS_ACK_OFFSET = 31;
373 static constexpr
size_t SRC_EPID_OFFSET = 32;
374 static constexpr
size_t ADDRESS_OFFSET = 0;
375 static constexpr
size_t BYTE_ENABLE_OFFSET = 20;
376 static constexpr
size_t OPCODE_OFFSET = 24;
377 static constexpr
size_t STATUS_OFFSET = 30;
378 static constexpr
size_t LO_DATA_OFFSET = 0;
379 static constexpr
size_t HI_DATA_OFFSET = 32;
398 uint16_t src_epid = 0;
402 uint64_t capacity_bytes = 0;
404 uint32_t capacity_pkts = 0;
406 uint64_t xfer_count_bytes = 0;
408 uint64_t xfer_count_pkts = 0;
410 uint16_t buff_info = 0;
412 uint64_t status_info = 0;
425 size_t serialize(uint64_t* buff,
426 size_t max_size_bytes,
427 const std::function<uint64_t(uint64_t)>& conv_byte_order)
const;
430 template <endianness_t endianness>
431 size_t serialize(uint64_t* buff,
size_t max_size_bytes)
const 433 auto conv_byte_order = [](uint64_t x) -> uint64_t {
435 : uhd::htowx<uint64_t>(x);
437 return serialize(buff, max_size_bytes, conv_byte_order);
441 void deserialize(
const uint64_t* buff,
443 const std::function<uint64_t(uint64_t)>& conv_byte_order);
446 template <endianness_t endianness>
449 auto conv_byte_order = [](uint64_t x) -> uint64_t {
451 : uhd::wtohx<uint64_t>(x);
453 deserialize(buff, num_elems, conv_byte_order);
457 size_t get_length()
const;
465 return !(*
this == rhs);
469 const std::string to_string()
const;
472 static constexpr
size_t SRC_EPID_WIDTH = 16;
473 static constexpr
size_t STATUS_WIDTH = 4;
474 static constexpr
size_t CAPACITY_BYTES_WIDTH = 40;
475 static constexpr
size_t CAPACITY_PKTS_WIDTH = 24;
476 static constexpr
size_t XFER_COUNT_PKTS_WIDTH = 40;
477 static constexpr
size_t BUFF_INFO_WIDTH = 16;
478 static constexpr
size_t STATUS_INFO_WIDTH = 48;
481 static constexpr
size_t SRC_EPID_OFFSET = 0;
482 static constexpr
size_t STATUS_OFFSET = 16;
483 static constexpr
size_t CAPACITY_BYTES_OFFSET = 24;
484 static constexpr
size_t CAPACITY_PKTS_OFFSET = 0;
485 static constexpr
size_t XFER_COUNT_PKTS_OFFSET = 24;
486 static constexpr
size_t BUFF_INFO_OFFSET = 0;
487 static constexpr
size_t STATUS_INFO_OFFSET = 16;
504 uint16_t src_epid = 0;
510 uint64_t num_pkts = 0;
512 uint64_t num_bytes = 0;
514 static constexpr
size_t MAX_PACKET_SIZE = 128;
527 size_t serialize(uint64_t* buff,
528 size_t max_size_bytes,
529 const std::function<uint64_t(uint64_t)>& conv_byte_order)
const;
532 template <endianness_t endianness>
533 size_t serialize(uint64_t* buff,
size_t max_size_bytes)
const 535 auto conv_byte_order = [](uint64_t x) -> uint64_t {
537 : uhd::htowx<uint64_t>(x);
539 return serialize(buff, max_size_bytes, conv_byte_order);
543 void deserialize(
const uint64_t* buff,
545 const std::function<uint64_t(uint64_t)>& conv_byte_order);
548 template <endianness_t endianness>
551 auto conv_byte_order = [](uint64_t x) -> uint64_t {
553 : uhd::wtohx<uint64_t>(x);
555 deserialize(buff, num_elems, conv_byte_order);
559 size_t get_length()
const;
567 return !(*
this == rhs);
571 const std::string to_string()
const;
574 static constexpr
size_t SRC_EPID_WIDTH = 16;
575 static constexpr
size_t OP_CODE_WIDTH = 4;
576 static constexpr
size_t OP_DATA_WIDTH = 4;
577 static constexpr
size_t NUM_PKTS_WIDTH = 40;
580 static constexpr
size_t SRC_EPID_OFFSET = 0;
581 static constexpr
size_t OP_CODE_OFFSET = 16;
582 static constexpr
size_t OP_DATA_OFFSET = 20;
583 static constexpr
size_t NUM_PKTS_OFFSET = 24;
601 MGMT_OP_ADVERTISE = 1,
603 MGMT_OP_SEL_DEST = 2,
607 MGMT_OP_INFO_REQ = 4,
609 MGMT_OP_INFO_RESP = 5,
611 MGMT_OP_CFG_WR_REQ = 6,
613 MGMT_OP_CFG_RD_REQ = 7,
615 MGMT_OP_CFG_RD_RESP = 8
641 cfg_payload(uint16_t addr_, uint32_t data_ = 0) : addr(addr_), data(data_) {}
643 : addr(static_cast<uint16_t>(payload_ >> 0))
644 , data(static_cast<uint32_t>(payload_ >> 16))
649 return ((static_cast<payload_t>(data) << 16) | static_cast<payload_t>(addr));
665 : device_id(device_id_)
666 , node_type(node_type_)
667 , node_inst(node_inst_)
668 , ext_info(ext_info_)
672 : device_id(static_cast<uint16_t>(payload_ >> 0))
673 , node_type(static_cast<uint8_t>((payload_ >> 16) & 0xF))
674 , node_inst(static_cast<uint16_t>((payload_ >> 20) & 0x3FF))
675 , ext_info(static_cast<uint32_t>((payload_ >> 30) & 0x3FFFF))
680 return ((static_cast<payload_t>(device_id) << 0)
681 | (static_cast<payload_t>(node_type & 0xF) << 16)
682 | (static_cast<payload_t>(node_inst & 0x3FF) << 20)
683 | (static_cast<payload_t>(ext_info & 0x3FFFF) << 30));
688 : _op_code(op_code), _op_payload(op_payload)
708 return (_op_code == rhs._op_code) && (_op_payload == rhs._op_payload);
712 const std::string to_string()
const;
716 payload_t _op_payload;
750 size_t serialize(std::vector<uint64_t>& target,
751 const std::function<uint64_t(uint64_t)>& conv_byte_order,
752 const size_t padding_size)
const;
757 void deserialize(std::list<uint64_t>& src,
758 const std::function<uint64_t(uint64_t)>& conv_byte_order,
759 const size_t padding_size);
764 return _ops == rhs._ops;
768 const std::string to_string()
const;
771 std::vector<mgmt_op_t> _ops;
788 set_src_epid(src_epid);
790 set_proto_ver(protover);
797 _hops.push_back(hop);
815 auto hop = _hops.front();
822 size_t num_lines = 1;
823 for (
const auto& hop : _hops) {
824 num_lines += hop.get_num_ops();
833 size_t serialize(uint64_t* buff,
834 size_t max_size_bytes,
835 const std::function<uint64_t(uint64_t)>& conv_byte_order)
const;
838 template <endianness_t endianness>
839 size_t serialize(uint64_t* buff,
size_t max_size_bytes)
const 841 auto conv_byte_order = [](uint64_t x) -> uint64_t {
843 : uhd::htowx<uint64_t>(x);
845 return serialize(buff, max_size_bytes, conv_byte_order);
849 void deserialize(
const uint64_t* buff,
851 const std::function<uint64_t(uint64_t)>& conv_byte_order);
854 template <endianness_t endianness>
857 auto conv_byte_order = [](uint64_t x) -> uint64_t {
859 : uhd::wtohx<uint64_t>(x);
861 deserialize(buff, num_elems, conv_byte_order);
865 size_t get_length()
const;
868 const std::string to_string()
const;
871 const std::string hops_to_string()
const;
882 _src_epid = src_epid;
910 _protover = proto_ver;
915 uint16_t _protover = 0;
917 size_t _padding_size = 0;
918 std::deque<mgmt_hop_t> _hops;
922 template <
typename payload_t>
Definition: chdr_types.hpp:250
Definition: chdr_types.hpp:255
Packet out of sequence (sequence error)
Definition: chdr_types.hpp:390
cfg_payload(uint16_t addr_, uint32_t data_=0)
Definition: chdr_types.hpp:641
Transaction successful.
Definition: chdr_types.hpp:243
constexpr size_t chdr_w_to_bits(chdr_w_t chdr_w)
Conversion from chdr_w_t to a number of bits.
Definition: rfnoc_types.hpp:21
chdr_w_t get_chdr_w() const
Return the CHDR_W for this transaction.
Definition: chdr_types.hpp:889
Definition: chdr_types.hpp:394
void deserialize(const uint64_t *buff, size_t num_elems)
Deserialize the payload from a uint64_t buffer (no conversion function)
Definition: chdr_types.hpp:447
void set_proto_ver(uint16_t proto_ver)
Set the protocol version for this transaction.
Definition: chdr_types.hpp:908
size_t get_num_ops() const
Get the number of management operations in this hop.
Definition: chdr_types.hpp:736
uint16_t sep_id_t
Stream Endpoint ID Type.
Definition: rfnoc_types.hpp:38
cfg_payload(payload_t payload_)
Definition: chdr_types.hpp:642
packet_type_t
Definition: chdr_types.hpp:21
sep_id_t get_src_epid() const
Return the source EPID for this transaction.
Definition: chdr_types.hpp:874
void set_header(sep_id_t src_epid, uint16_t protover, chdr_w_t chdr_w)
Definition: chdr_types.hpp:786
ctrl_opcode_t
Definition: chdr_types.hpp:248
Definition: chdr_types.hpp:254
Data integrity check failed.
Definition: chdr_types.hpp:391
Stream Command.
Definition: chdr_types.hpp:25
bool operator!=(const strc_payload &rhs) const
Comparison operator (!=)
Definition: chdr_types.hpp:565
const uint16_t dest
Definition: chdr_types.hpp:624
Control Transaction.
Definition: chdr_types.hpp:26
const uint32_t ext_info
Definition: chdr_types.hpp:659
Data Packet without TimeStamp.
Definition: chdr_types.hpp:27
Definition: rfnoc_types.hpp:19
Definition: chdr_types.hpp:261
Initialize stream.
Definition: chdr_types.hpp:496
const uint16_t device_id
Definition: chdr_types.hpp:656
sel_dest_payload(payload_t payload_)
Definition: chdr_types.hpp:627
mgmt_hop_t pop_hop()
Pop the first hop of the transaction and return it.
Definition: chdr_types.hpp:813
Slave asserted a time stamp error.
Definition: chdr_types.hpp:245
const mgmt_hop_t & get_hop(size_t i) const
Get the n'th hop in the transaction.
Definition: chdr_types.hpp:807
Definition: chdr_types.hpp:257
const uint32_t data
Definition: chdr_types.hpp:639
constexpr packet_type_t payload_to_packet_type< mgmt_payload >()
Definition: chdr_types.hpp:932
void add_hop(const mgmt_hop_t &hop)
Add a management hop to this transaction.
Definition: chdr_types.hpp:795
UHD_INLINE size_t width(const soft_reg_field_t field)
Definition: soft_register.hpp:76
strs_status_t
Definition: chdr_types.hpp:386
size_t serialize(uint64_t *buff, size_t max_size_bytes) const
Serialize the payload to a uint64_t buffer (no conversion function)
Definition: chdr_types.hpp:839
A class that represents a single management operation.
Definition: chdr_types.hpp:593
bool operator!=(const ctrl_payload &rhs) const
Comparison operator (!=)
Definition: chdr_types.hpp:345
uint64_t get_op_payload() const
Get the payload for this transaction.
Definition: chdr_types.hpp:700
Definition: chdr_types.hpp:242
constexpr packet_type_t payload_to_packet_type< strc_payload >()
Definition: chdr_types.hpp:938
Definition: build_info.hpp:12
op_code_t
Definition: chdr_types.hpp:597
node_info_payload(payload_t payload_)
Definition: chdr_types.hpp:671
uint64_t payload_t
The payload for an operation is 48 bits wide.
Definition: chdr_types.hpp:619
size_t get_size_bytes() const
Definition: chdr_types.hpp:820
Definition: chdr_types.hpp:249
const uint16_t addr
Definition: chdr_types.hpp:638
bool operator==(const mgmt_hop_t &rhs) const
Comparison operator (==)
Definition: chdr_types.hpp:762
bool operator!=(const strs_payload &rhs) const
Comparison operator (!=)
Definition: chdr_types.hpp:463
Definition: chdr_types.hpp:500
op_code_t get_op_code() const
Get the op-code for this transaction.
Definition: chdr_types.hpp:694
bool operator==(const mgmt_op_t &rhs) const
Comparison operator (==)
Definition: chdr_types.hpp:706
Trigger a stream status response.
Definition: chdr_types.hpp:497
uint16_t get_proto_ver() const
Return the protocol version for this transaction.
Definition: chdr_types.hpp:902
An interpretation class for the payload for MGMT_OP_SEL_DEST.
Definition: chdr_types.hpp:622
void add_op(const mgmt_op_t &op)
Add a management operation to this hop.
Definition: chdr_types.hpp:730
size_t get_num_hops() const
Get the number of management hops in this hop.
Definition: chdr_types.hpp:801
Stream status.
Definition: chdr_types.hpp:24
A stream command signalled an error.
Definition: chdr_types.hpp:389
void deserialize(const uint64_t *buff, size_t num_elems)
Deserialize the payload from a uint64_t buffer (no conversion function)
Definition: chdr_types.hpp:855
constexpr packet_type_t payload_to_packet_type()
Conversion from payload_t to pkt_type.
void set_src_epid(sep_id_t src_epid)
Set the source EPID for this transaction.
Definition: chdr_types.hpp:880
Definition: chdr_types.hpp:264
size_t serialize(uint64_t *buff, size_t max_size_bytes) const
Serialize the payload to a uint64_t buffer (no conversion function)
Definition: chdr_types.hpp:533
Definition: chdr_types.hpp:636
An interpretation class for the payload for MGMT_OP_INFO_RESP.
Definition: chdr_types.hpp:654
#define UHD_API
Definition: config.h:67
const mgmt_op_t & get_op(size_t i) const
Get the n'th operation in the hop.
Definition: chdr_types.hpp:742
void deserialize(const uint64_t *buff, size_t num_elems)
Deserialize the payload from a uint64_t buffer (no conversion function)
Definition: chdr_types.hpp:323
void set_chdr_w(chdr_w_t chdr_w)
Set the CHDR_W for this transaction.
Definition: chdr_types.hpp:895
Definition: chdr_types.hpp:256
A class that represents a complete multi-hop management transaction.
Definition: chdr_types.hpp:777
Slave asserted a command error.
Definition: chdr_types.hpp:244
Definition: chdr_types.hpp:259
size_t serialize(uint64_t *buff, size_t max_size_bytes) const
Serialize the payload to a uint64_t buffer (no conversion function)
Definition: chdr_types.hpp:307
Management packet.
Definition: chdr_types.hpp:23
Definition: chdr_types.hpp:22
size_t serialize(uint64_t *buff, size_t max_size_bytes) const
Serialize the payload to a uint64_t buffer (no conversion function)
Definition: chdr_types.hpp:431
No error.
Definition: chdr_types.hpp:388
A class that represents a single management hop.
Definition: chdr_types.hpp:722
Definition: chdr_types.hpp:260
Definition: chdr_types.hpp:251
UHD_API bool operator==(const time_spec_t &, const time_spec_t &)
Implement equality_comparable interface.
chdr_w_t
Type that indicates the CHDR Width in bits.
Definition: rfnoc_types.hpp:19
constexpr packet_type_t payload_to_packet_type< strs_payload >()
Definition: chdr_types.hpp:944
Definition: endianness.hpp:30
ctrl_status_t
Definition: chdr_types.hpp:241
strc_op_code_t
Definition: chdr_types.hpp:494
node_info_payload(uint16_t device_id_, uint8_t node_type_, uint16_t node_inst_, uint32_t ext_info_)
Definition: chdr_types.hpp:661
Definition: chdr_types.hpp:252
constexpr packet_type_t payload_to_packet_type< ctrl_payload >()
Definition: chdr_types.hpp:926
sel_dest_payload(uint16_t dest_)
Definition: chdr_types.hpp:626
Definition: chdr_types.hpp:258
bool has_timestamp() const
Definition: chdr_types.hpp:336
void deserialize(const uint64_t *buff, size_t num_elems)
Deserialize the payload from a uint64_t buffer (no conversion function)
Definition: chdr_types.hpp:549
Definition: chdr_types.hpp:495
Definition: chdr_types.hpp:253
const uint16_t node_inst
Definition: chdr_types.hpp:658
mgmt_op_t(const op_code_t op_code, const payload_t op_payload=0)
Definition: chdr_types.hpp:687
const uint8_t node_type
Definition: chdr_types.hpp:657
Definition: chdr_types.hpp:387