USRP Hardware Driver and Device Manual Version: 4.11.0.0-0-unknown
UHD and USRP Manual
Loading...
Searching...
No Matches
chdr_types.hpp
Go to the documentation of this file.
1//
2// Copyright 2019 Ettus Research, a National Instruments Brand
3//
4// SPDX-License-Identifier: GPL-3.0-or-later
5//
6
7#pragma once
8
10#include <uhd/types/endianness.hpp>
12#include <cstdint>
13#include <deque>
14#include <functional>
15#include <list>
16#include <memory>
17#include <optional>
18#include <string>
19#include <vector>
20
21namespace uhd { namespace rfnoc { namespace chdr {
22
31
32//----------------------------------------------------
33// CHDR Header
34//----------------------------------------------------
35
37{
38public: // Functions
39 chdr_header() = default;
40 chdr_header(const chdr_header& rhs) = default;
41 chdr_header(chdr_header&& rhs) = default;
42
44 chdr_header(uint64_t flat_hdr) : _flat_hdr(flat_hdr) {}
45
47 inline uint8_t get_vc() const
48 {
49 return get_field<uint8_t>(_flat_hdr, VC_OFFSET, VC_WIDTH);
50 }
51
53 inline void set_vc(uint8_t vc)
54 {
55 _flat_hdr = set_field(_flat_hdr, vc, VC_OFFSET, VC_WIDTH);
56 }
57
59 inline bool get_eob() const
60 {
61 return get_field<bool>(_flat_hdr, EOB_OFFSET, EOB_WIDTH);
62 }
63
65 inline void set_eob(bool eob)
66 {
67 _flat_hdr = set_field(_flat_hdr, eob, EOB_OFFSET, EOB_WIDTH);
68 }
69
71 inline bool get_eov() const
72 {
73 return get_field<bool>(_flat_hdr, EOV_OFFSET, EOV_WIDTH);
74 }
75
77 inline void set_eov(bool eov)
78 {
79 _flat_hdr = set_field(_flat_hdr, eov, EOV_OFFSET, EOV_WIDTH);
80 }
81
84 {
85 return get_field<packet_type_t>(_flat_hdr, PKT_TYPE_OFFSET, PKT_TYPE_WIDTH);
86 }
87
89 inline void set_pkt_type(packet_type_t pkt_type)
90 {
91 _flat_hdr = set_field(_flat_hdr, pkt_type, PKT_TYPE_OFFSET, PKT_TYPE_WIDTH);
92 }
93
95 inline uint8_t get_num_mdata() const
96 {
97 return get_field<uint8_t>(_flat_hdr, NUM_MDATA_OFFSET, NUM_MDATA_WIDTH);
98 }
99
101 inline void set_num_mdata(uint8_t num_mdata)
102 {
103 _flat_hdr = set_field(_flat_hdr, num_mdata, NUM_MDATA_OFFSET, NUM_MDATA_WIDTH);
104 }
105
107 inline uint16_t get_seq_num() const
108 {
109 return get_field<uint16_t>(_flat_hdr, SEQ_NUM_OFFSET, SEQ_NUM_WIDTH);
110 }
111
113 inline void set_seq_num(uint16_t seq_num)
114 {
115 _flat_hdr = set_field(_flat_hdr, seq_num, SEQ_NUM_OFFSET, SEQ_NUM_WIDTH);
116 }
117
119 inline uint16_t get_length() const
120 {
121 return get_field<uint16_t>(_flat_hdr, LENGTH_OFFSET, LENGTH_WIDTH);
122 }
123
125 inline void set_length(uint16_t length)
126 {
127 _flat_hdr = set_field(_flat_hdr, length, LENGTH_OFFSET, LENGTH_WIDTH);
128 }
129
131 inline uint16_t get_dst_epid() const
132 {
133 return get_field<uint16_t>(_flat_hdr, DST_EPID_OFFSET, DST_EPID_WIDTH);
134 }
135
137 inline void set_dst_epid(uint16_t dst_epid)
138 {
139 _flat_hdr = set_field(_flat_hdr, dst_epid, DST_EPID_OFFSET, DST_EPID_WIDTH);
140 }
141
143 inline uint64_t pack() const
144 {
145 return _flat_hdr;
146 }
147
149 inline operator uint64_t() const
150 {
151 return pack();
152 }
153
155 inline bool operator==(const chdr_header& rhs) const
156 {
157 return _flat_hdr == rhs._flat_hdr;
158 }
159
161 inline bool operator!=(const chdr_header& rhs) const
162 {
163 return _flat_hdr != rhs._flat_hdr;
164 }
165
167 inline const chdr_header& operator=(const chdr_header& rhs)
168 {
169 _flat_hdr = rhs._flat_hdr;
170 return *this;
171 }
172
174 inline const chdr_header& operator=(const uint64_t& rhs)
175 {
176 _flat_hdr = rhs;
177 return *this;
178 }
179
181 const std::string to_string() const;
182
183private:
184 // The flattened representation of the header stored in host order
185 uint64_t _flat_hdr = 0;
186
187 static constexpr size_t VC_WIDTH = 6;
188 static constexpr size_t EOB_WIDTH = 1;
189 static constexpr size_t EOV_WIDTH = 1;
190 static constexpr size_t PKT_TYPE_WIDTH = 3;
191 static constexpr size_t NUM_MDATA_WIDTH = 5;
192 static constexpr size_t SEQ_NUM_WIDTH = 16;
193 static constexpr size_t LENGTH_WIDTH = 16;
194 static constexpr size_t DST_EPID_WIDTH = 16;
195
196 static constexpr size_t VC_OFFSET = 58;
197 static constexpr size_t EOB_OFFSET = 57;
198 static constexpr size_t EOV_OFFSET = 56;
199 static constexpr size_t PKT_TYPE_OFFSET = 53;
200 static constexpr size_t NUM_MDATA_OFFSET = 48;
201 static constexpr size_t SEQ_NUM_OFFSET = 32;
202 static constexpr size_t LENGTH_OFFSET = 16;
203 static constexpr size_t DST_EPID_OFFSET = 0;
204
205 static inline uint64_t mask(const size_t width)
206 {
207 return ((uint64_t(1) << width) - 1);
208 }
209
210 template <typename field_t>
211 static inline field_t get_field(
212 const uint64_t flat_hdr, const size_t offset, const size_t width)
213 {
214 return static_cast<field_t>((flat_hdr >> offset) & mask(width));
215 }
216
217 template <typename field_t>
218 static inline uint64_t set_field(const uint64_t old_val,
219 const field_t field,
220 const size_t offset,
221 const size_t width)
222 {
223 return (old_val & ~(mask(width) << offset))
224 | ((static_cast<uint64_t>(field) & mask(width)) << offset);
225 }
226};
227
228
229//----------------------------------------------------
230// CHDR Control Packet Payload
231//----------------------------------------------------
232
239
255
257{
258public: // Members
260 uint16_t dst_port = 0;
262 uint16_t src_port = 0;
264 uint8_t seq_num = 0;
266 std::optional<uint64_t> timestamp{};
268 bool is_ack = false;
270 uint16_t src_epid = 0;
272 uint32_t address = 0;
274 std::vector<uint32_t> data_vtr = {0};
276 size_t num_data = 1;
278 size_t req_size = 0;
280 uint8_t byte_enable = 0xF;
285
286public: // Functions
287 ctrl_payload() = default;
288 ctrl_payload(const ctrl_payload& rhs) = default;
289 ctrl_payload(ctrl_payload&& rhs) = default;
290
291 ctrl_payload& operator=(const ctrl_payload& rhs) = default;
292
294 void populate_header(chdr_header& header) const;
295
297 size_t serialize(uint32_t* buff,
298 size_t max_size_bytes,
299 const std::function<uint32_t(uint32_t)>& conv_byte_order) const;
300
302 template <endianness_t endianness>
303 size_t serialize(uint32_t* buff, size_t max_size_bytes) const
304 {
305 auto conv_byte_order = [](uint32_t x) -> uint32_t {
306 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::htonx<uint32_t>(x)
308 };
309 return serialize(buff, max_size_bytes, conv_byte_order);
310 }
311
318 void deserialize(const uint32_t* buff,
319 size_t buff_size,
320 const std::function<uint32_t(uint32_t)>& conv_byte_order);
321
327 template <endianness_t endianness>
328 void deserialize(const uint32_t* buff, size_t buff_size)
329 {
330 auto conv_byte_order = [](uint32_t x) -> uint32_t {
331 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx<uint32_t>(x)
333 };
334 deserialize(buff, buff_size, conv_byte_order);
335 }
336
338 size_t get_length() const;
339
340 // Return whether or not we have a valid timestamp
341 bool has_timestamp() const
342 {
343 return bool(timestamp);
344 }
345
350 bool is_read_request() const
351 {
352 return !is_ack && (op_code == OP_READ || op_code == OP_BLOCK_READ);
353 }
354
358 bool is_write_response() const
359 {
360 return is_ack
362 || op_code == OP_SLEEP);
363 }
364
367 bool is_read_response() const
368 {
369 return is_ack && (op_code == OP_READ || op_code == OP_BLOCK_READ);
370 }
371
373 bool operator==(const ctrl_payload& rhs) const;
374
376 inline bool operator!=(const ctrl_payload& rhs) const
377 {
378 return !(*this == rhs);
379 }
380
382 std::string to_string() const;
383
384private:
385 static constexpr size_t DST_PORT_WIDTH = 10;
386 static constexpr size_t SRC_PORT_WIDTH = 10;
387 static constexpr size_t NUM_DATA_WIDTH = 4;
388 static constexpr size_t REQ_SIZE_WIDTH = 4;
389 static constexpr size_t SEQ_NUM_WIDTH = 8;
390 static constexpr size_t HAS_TIME_WIDTH = 1;
391 static constexpr size_t IS_ACK_WIDTH = 1;
392 static constexpr size_t SRC_EPID_WIDTH = 16;
393 static constexpr size_t ADDRESS_WIDTH = 20;
394 static constexpr size_t BYTE_ENABLE_WIDTH = 4;
395 static constexpr size_t OPCODE_WIDTH = 4;
396 static constexpr size_t STATUS_WIDTH = 2;
397
398 // Bit offsets within each 32-bit wire word
399 // Ctrl header word 0
400 static constexpr size_t DST_PORT_OFFSET = 0;
401 static constexpr size_t NUM_DATA_OFFSET = 10;
402 static constexpr size_t HAS_TIME_OFFSET = 14;
403 static constexpr size_t IS_ACK_OFFSET = 15;
404 static constexpr size_t SRC_EPID_OFFSET = 16;
405 // Ctrl header word 1
406 static constexpr size_t SRC_PORT_OFFSET = 0;
407 static constexpr size_t SEQ_NUM_OFFSET = 20;
408 static constexpr size_t REQ_SIZE_OFFSET = 28;
409 // Op-word
410 static constexpr size_t ADDRESS_OFFSET = 0;
411 static constexpr size_t BYTE_ENABLE_OFFSET = 20;
412 static constexpr size_t OPCODE_OFFSET = 24;
413 static constexpr size_t STATUS_OFFSET = 30;
414
415public: // Constants (depend on private members, so must be declared here)
417 static constexpr size_t MAX_DATA_WORDS = (size_t(1) << NUM_DATA_WIDTH) - 1;
418};
419
420//----------------------------------------------------
421// CHDR Stream Status Packet Payload
422//----------------------------------------------------
423
431
433{
434public: // Members
436 uint16_t src_epid = 0;
440 uint64_t capacity_bytes = 0;
442 uint32_t capacity_pkts = 0;
444 uint64_t xfer_count_bytes = 0;
446 uint64_t xfer_count_pkts = 0;
448 uint16_t buff_info = 0;
450 union {
451 uint64_t info = 0;
452 struct
453 {
454 uint16_t last_control_seq_num : 16;
455 uint16_t expected_seq_num : 16;
456 uint16_t reserved_1 : 12;
458 bool seq_error_occoured : 1;
459 bool reserved_2 : 1;
460 bool flow_control_due : 1;
461 } status;
462 struct
463 {
464 uint16_t current_seq_num : 16;
465 uint16_t expected_seq_num : 16;
466 uint8_t chdr_packet_type : 3;
467 uint16_t reserved_1 : 9;
469 bool seq_error_occoured : 1;
470 bool reserved_2 : 1;
471 bool reserved_3 : 1;
473 struct
474 {
475 uint16_t dest_epid : 16;
476 uint16_t this_epid : 16;
477 uint32_t reserved_1 : 32;
479 } status_info;
480
481public: // Functions
482 strs_payload() = default;
483 strs_payload(const strs_payload& rhs) = default;
484 strs_payload(strs_payload&& rhs) = default;
485
486 strs_payload& operator=(const strs_payload& rhs) = default;
487
489 void populate_header(chdr_header& header) const;
490
492 size_t serialize(uint64_t* buff,
493 size_t max_size_bytes,
494 const std::function<uint64_t(uint64_t)>& conv_byte_order) const;
495
497 template <endianness_t endianness>
498 size_t serialize(uint64_t* buff, size_t max_size_bytes) const
499 {
500 auto conv_byte_order = [](uint64_t x) -> uint64_t {
501 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::htonx<uint64_t>(x)
503 };
504 return serialize(buff, max_size_bytes, conv_byte_order);
505 }
506
513 void deserialize(const uint64_t* buff,
514 size_t buff_size,
515 const std::function<uint64_t(uint64_t)>& conv_byte_order);
516
522 template <endianness_t endianness>
523 void deserialize(const uint64_t* buff, size_t buff_size)
524 {
525 auto conv_byte_order = [](uint64_t x) -> uint64_t {
526 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx<uint64_t>(x)
528 };
529 deserialize(buff, buff_size, conv_byte_order);
530 }
531
533 size_t get_length() const;
534
536 bool operator==(const strs_payload& rhs) const;
537
539 inline bool operator!=(const strs_payload& rhs) const
540 {
541 return !(*this == rhs);
542 }
543
545 std::string to_string() const;
546
547private:
548 static constexpr size_t SRC_EPID_WIDTH = 16;
549 static constexpr size_t STATUS_WIDTH = 4;
550 static constexpr size_t CAPACITY_BYTES_WIDTH = 40;
551 static constexpr size_t CAPACITY_PKTS_WIDTH = 24;
552 static constexpr size_t XFER_COUNT_PKTS_WIDTH = 40;
553 static constexpr size_t BUFF_INFO_WIDTH = 16;
554 static constexpr size_t STATUS_INFO_WIDTH = 48;
555
556 // Offsets assume 64-bit alignment
557 static constexpr size_t SRC_EPID_OFFSET = 0;
558 static constexpr size_t STATUS_OFFSET = 16;
559 static constexpr size_t CAPACITY_BYTES_OFFSET = 24;
560 static constexpr size_t CAPACITY_PKTS_OFFSET = 0;
561 static constexpr size_t XFER_COUNT_PKTS_OFFSET = 24;
562 static constexpr size_t BUFF_INFO_OFFSET = 0;
563 static constexpr size_t STATUS_INFO_OFFSET = 16;
564};
565
566//----------------------------------------------------
567// CHDR Stream Command Packet Payload
568//----------------------------------------------------
569
575
577{
578public: // Members
580 uint16_t src_epid = 0;
584 uint8_t op_data = 0;
586 uint64_t num_pkts = 0;
588 uint64_t num_bytes = 0;
590 static constexpr size_t MAX_PACKET_SIZE = 128;
591
592public: // Functions
593 strc_payload() = default;
594 strc_payload(const strc_payload& rhs) = default;
595 strc_payload(strc_payload&& rhs) = default;
596
597 strc_payload& operator=(const strc_payload& rhs) = default;
598
600 void populate_header(chdr_header& header) const;
601
603 size_t serialize(uint64_t* buff,
604 size_t max_size_bytes,
605 const std::function<uint64_t(uint64_t)>& conv_byte_order) const;
606
608 template <endianness_t endianness>
609 size_t serialize(uint64_t* buff, size_t max_size_bytes) const
610 {
611 auto conv_byte_order = [](uint64_t x) -> uint64_t {
612 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::htonx<uint64_t>(x)
614 };
615 return serialize(buff, max_size_bytes, conv_byte_order);
616 }
617
624 void deserialize(const uint64_t* buff,
625 size_t buff_size,
626 const std::function<uint64_t(uint64_t)>& conv_byte_order);
627
633 template <endianness_t endianness>
634 void deserialize(const uint64_t* buff, size_t buff_size)
635 {
636 auto conv_byte_order = [](uint64_t x) -> uint64_t {
637 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx<uint64_t>(x)
639 };
640 deserialize(buff, buff_size, conv_byte_order);
641 }
642
644 size_t get_length() const;
645
647 bool operator==(const strc_payload& rhs) const;
648
650 inline bool operator!=(const strc_payload& rhs) const
651 {
652 return !(*this == rhs);
653 }
654
656 std::string to_string() const;
657
658private:
659 static constexpr size_t SRC_EPID_WIDTH = 16;
660 static constexpr size_t OP_CODE_WIDTH = 4;
661 static constexpr size_t OP_DATA_WIDTH = 4;
662 static constexpr size_t NUM_PKTS_WIDTH = 40;
663
664 // Offsets assume 64-bit alignment
665 static constexpr size_t SRC_EPID_OFFSET = 0;
666 static constexpr size_t OP_CODE_OFFSET = 16;
667 static constexpr size_t OP_DATA_OFFSET = 20;
668 static constexpr size_t NUM_PKTS_OFFSET = 24;
669};
670
671//----------------------------------------------------
672// CHDR Management Packet Payload
673//----------------------------------------------------
674
680{
681public:
708
710 using payload_t = uint64_t;
711
714 {
715 const uint16_t dest;
716
717 sel_dest_payload(uint16_t dest_) : dest(dest_) {}
718 sel_dest_payload(payload_t payload_) : dest(static_cast<uint16_t>(payload_)) {}
719 operator payload_t() const
720 {
721 return static_cast<payload_t>(dest);
722 }
723 };
724
729 {
730 const uint16_t addr;
731 const uint32_t data;
732
733 cfg_payload(uint16_t addr_, uint32_t data_ = 0) : addr(addr_), data(data_) {}
735 : addr(static_cast<uint16_t>(payload_ >> 0))
736 , data(static_cast<uint32_t>(payload_ >> 16))
737 {
738 }
739 operator payload_t() const
740 {
741 return ((static_cast<payload_t>(data) << 16) | static_cast<payload_t>(addr));
742 }
743 };
744
747 {
748 const uint16_t device_id;
749 const uint8_t node_type;
750 const uint16_t node_inst;
751 const uint32_t ext_info;
752
753 node_info_payload(uint16_t device_id_,
754 uint8_t node_type_,
755 uint16_t node_inst_,
756 uint32_t ext_info_)
757 : device_id(device_id_)
758 , node_type(node_type_)
759 , node_inst(node_inst_)
760 , ext_info(ext_info_)
761 {
762 }
764 : device_id(static_cast<uint16_t>(payload_ >> 0))
765 , node_type(static_cast<uint8_t>((payload_ >> 16) & 0xF))
766 , node_inst(static_cast<uint16_t>((payload_ >> 20) & 0x3FF))
767 , ext_info(static_cast<uint32_t>((payload_ >> 30) & 0x3FFFF))
768 {
769 }
770 operator payload_t() const
771 {
772 return ((static_cast<payload_t>(device_id) << 0)
773 | (static_cast<payload_t>(node_type & 0xF) << 16)
774 | (static_cast<payload_t>(node_inst & 0x3FF) << 20)
775 | (static_cast<payload_t>(ext_info & 0x3FFFF) << 30));
776 }
777 };
778
779 mgmt_op_t(const op_code_t op_code,
780 const payload_t op_payload = 0,
781 const uint8_t ops_pending = 0)
782 : _op_code(op_code), _op_payload(op_payload), _ops_pending(ops_pending)
783 {
784 }
785
786 mgmt_op_t(const mgmt_op_t& rhs) = default;
787 mgmt_op_t& operator=(const mgmt_op_t& rhs) = default;
788
789
796 inline uint8_t get_ops_pending() const
797 {
798 return _ops_pending;
799 }
800
802 inline op_code_t get_op_code() const
803 {
804 return _op_code;
805 }
806
808 inline uint64_t get_op_payload() const
809 {
810 return _op_payload;
811 }
812
814 inline bool operator==(const mgmt_op_t& rhs) const
815 {
816 return (_op_code == rhs._op_code) && (_op_payload == rhs._op_payload);
817 }
818
820 std::string to_string() const;
821
822private:
823 op_code_t _op_code;
824 payload_t _op_payload;
825 uint8_t _ops_pending;
826};
827
834{
835public:
836 mgmt_hop_t() = default;
837 mgmt_hop_t(const mgmt_hop_t& rhs) = default;
838
843 inline void add_op(const mgmt_op_t& op)
844 {
845 _ops.push_back(op);
846 }
847
849 inline size_t get_num_ops() const
850 {
851 return _ops.size();
852 }
853
855 inline const mgmt_op_t& get_op(size_t i) const
856 {
857 return _ops.at(i);
858 }
859
865 size_t serialize(std::vector<uint64_t>& target,
866 const std::function<uint64_t(uint64_t)>& conv_byte_order,
867 const size_t padding_size) const;
868
874 void deserialize(std::list<uint64_t>& src,
875 const std::function<uint64_t(uint64_t)>& conv_byte_order,
876 const size_t padding_size);
877
879 inline bool operator==(const mgmt_hop_t& rhs) const
880 {
881 return _ops == rhs._ops;
882 }
883
885 std::string to_string() const;
886
887private:
888 std::vector<mgmt_op_t> _ops;
889};
890
897{
898public:
899 mgmt_payload() = default;
900 mgmt_payload(const mgmt_payload& rhs) = default;
901 mgmt_payload(mgmt_payload&& rhs) = default;
902
903 mgmt_payload& operator=(const mgmt_payload& rhs) = default;
904
905 inline void set_header(sep_id_t src_epid, uint16_t protover, chdr_w_t chdr_w)
906 {
907 set_src_epid(src_epid);
908 set_chdr_w(chdr_w);
909 set_proto_ver(protover);
910 }
911
916 inline void add_hop(const mgmt_hop_t& hop)
917 {
918 _hops.push_back(hop);
919 }
920
922 inline size_t get_num_hops() const
923 {
924 return _hops.size();
925 }
926
928 inline const mgmt_hop_t& get_hop(size_t i) const
929 {
930 return _hops.at(i);
931 }
932
935 {
936 auto hop = _hops.front();
937 _hops.pop_front();
938 return hop;
939 }
940
941 inline size_t get_size_bytes() const
942 {
943 size_t num_lines = 1; /* header */
944 for (const auto& hop : _hops) {
945 num_lines += hop.get_num_ops();
946 }
947 return num_lines * (chdr_w_to_bits(_chdr_w) / 8);
948 }
949
951 void populate_header(chdr_header& header) const;
952
954 size_t serialize(uint64_t* buff,
955 size_t max_size_bytes,
956 const std::function<uint64_t(uint64_t)>& conv_byte_order) const;
957
959 template <endianness_t endianness>
960 size_t serialize(uint64_t* buff, size_t max_size_bytes) const
961 {
962 auto conv_byte_order = [](uint64_t x) -> uint64_t {
963 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::htonx<uint64_t>(x)
965 };
966 return serialize(buff, max_size_bytes, conv_byte_order);
967 }
968
975 void deserialize(const uint64_t* buff,
976 size_t buff_size,
977 const std::function<uint64_t(uint64_t)>& conv_byte_order);
978
984 template <endianness_t endianness>
985 void deserialize(const uint64_t* buff, size_t buff_size)
986 {
987 auto conv_byte_order = [](uint64_t x) -> uint64_t {
988 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx<uint64_t>(x)
990 };
991 deserialize(buff, buff_size, conv_byte_order);
992 }
993
995 size_t get_length() const;
996
998 std::string to_string() const;
999
1001 std::string hops_to_string() const;
1002
1004 inline sep_id_t get_src_epid() const
1005 {
1006 return _src_epid;
1007 }
1008
1010 inline void set_src_epid(sep_id_t src_epid)
1011 {
1012 _src_epid = src_epid;
1013 }
1014
1016 bool operator==(const mgmt_payload& rhs) const;
1017
1019 inline chdr_w_t get_chdr_w() const
1020 {
1021 return _chdr_w;
1022 }
1023
1025 inline void set_chdr_w(chdr_w_t chdr_w)
1026 {
1027 _chdr_w = chdr_w;
1028 _padding_size = (chdr_w_to_bits(_chdr_w) / 64) - 1;
1029 }
1030
1032 inline uint16_t get_proto_ver() const
1033 {
1034 return _protover;
1035 }
1036
1038 inline void set_proto_ver(uint16_t proto_ver)
1039 {
1040 _protover = proto_ver;
1041 }
1042
1043private:
1044 sep_id_t _src_epid = 0;
1045 uint16_t _protover = 0;
1046 chdr_w_t _chdr_w = CHDR_W_64;
1047 size_t _padding_size = 0;
1048 std::deque<mgmt_hop_t> _hops;
1049};
1050
1052template <typename payload_t>
1054
1055template <>
1060
1061template <>
1066
1067template <>
1072
1073template <>
1078
1079}}} // namespace uhd::rfnoc::chdr
Definition chdr_types.hpp:37
void set_vc(uint8_t vc)
Set the virtual channel field (6 bits).
Definition chdr_types.hpp:53
void set_eob(bool eob)
Set the end-of-burst flag (1 bit).
Definition chdr_types.hpp:65
uint8_t get_vc() const
Get the virtual channel field (6 bits).
Definition chdr_types.hpp:47
void set_pkt_type(packet_type_t pkt_type)
Set the packet type field (3 bits).
Definition chdr_types.hpp:89
const std::string to_string() const
Return a string representation of this object.
chdr_header(const chdr_header &rhs)=default
chdr_header(uint64_t flat_hdr)
Unpack the header from a uint64_t.
Definition chdr_types.hpp:44
void set_length(uint16_t length)
Set the packet length field (16 bits).
Definition chdr_types.hpp:125
bool operator!=(const chdr_header &rhs) const
Comparison operator (!=).
Definition chdr_types.hpp:161
uint64_t pack() const
Pack the header into a uint64_t.
Definition chdr_types.hpp:143
uint16_t get_seq_num() const
Get the sequence number field (16 bits).
Definition chdr_types.hpp:107
void set_dst_epid(uint16_t dst_epid)
Set the destination EPID field (16 bits).
Definition chdr_types.hpp:137
uint16_t get_length() const
Get the packet length field (16 bits).
Definition chdr_types.hpp:119
chdr_header(chdr_header &&rhs)=default
bool get_eov() const
Get the end-of-vector flag (1 bit).
Definition chdr_types.hpp:71
packet_type_t get_pkt_type() const
Get the packet type field (3 bits).
Definition chdr_types.hpp:83
bool get_eob() const
Get the end-of-burst flag (1 bit).
Definition chdr_types.hpp:59
uint8_t get_num_mdata() const
Get number of metadata words field (5 bits).
Definition chdr_types.hpp:95
void set_eov(bool eov)
Set the end-of-vector flag (1 bit).
Definition chdr_types.hpp:77
uint16_t get_dst_epid() const
Get the destination EPID field (16 bits).
Definition chdr_types.hpp:131
void set_num_mdata(uint8_t num_mdata)
Set number of metadata words field (5 bits).
Definition chdr_types.hpp:101
void set_seq_num(uint16_t seq_num)
Set the sequence number field (16 bits).
Definition chdr_types.hpp:113
const chdr_header & operator=(const chdr_header &rhs)
Assignment operator (=) from a chdr_header.
Definition chdr_types.hpp:167
const chdr_header & operator=(const uint64_t &rhs)
Assignment operator (=) from a uint64_t.
Definition chdr_types.hpp:174
bool operator==(const chdr_header &rhs) const
Comparison operator (==).
Definition chdr_types.hpp:155
ctrl_payload & operator=(const ctrl_payload &rhs)=default
bool has_timestamp() const
Definition chdr_types.hpp:341
size_t get_length() const
Get the serialized size of this payload in bytes.
bool is_ack
Is Acknowledgment Flag (1 bit).
Definition chdr_types.hpp:268
void deserialize(const uint32_t *buff, size_t buff_size)
Deserialize the payload from a uint32_t buffer (no conversion function).
Definition chdr_types.hpp:328
bool is_read_response() const
Definition chdr_types.hpp:367
std::string to_string() const
Return a string representation of this object.
bool is_write_response() const
Definition chdr_types.hpp:358
uint16_t src_port
Source port for transaction (10 bits).
Definition chdr_types.hpp:262
bool is_read_request() const
Definition chdr_types.hpp:350
size_t serialize(uint32_t *buff, size_t max_size_bytes) const
Serialize the payload to a uint32_t buffer (no conversion function).
Definition chdr_types.hpp:303
uint16_t src_epid
Source endpoint ID of transaction (16 bits).
Definition chdr_types.hpp:270
ctrl_payload(const ctrl_payload &rhs)=default
std::optional< uint64_t > timestamp
Has Time Flag (1 bit) and timestamp (64 bits).
Definition chdr_types.hpp:266
size_t req_size
Number of 32-bit data words requested (4 bits).
Definition chdr_types.hpp:278
ctrl_status_t status
Transaction status (4 bits).
Definition chdr_types.hpp:284
bool operator==(const ctrl_payload &rhs) const
Comparison operator (==).
size_t serialize(uint32_t *buff, size_t max_size_bytes, const std::function< uint32_t(uint32_t)> &conv_byte_order) const
Serialize the payload to a uint32_t buffer.
uint32_t address
Address for transaction (20 bits).
Definition chdr_types.hpp:272
uint8_t seq_num
Sequence number (8 bits).
Definition chdr_types.hpp:264
void deserialize(const uint32_t *buff, size_t buff_size, const std::function< uint32_t(uint32_t)> &conv_byte_order)
Deserialize the payload from a uint32_t buffer.
bool operator!=(const ctrl_payload &rhs) const
Comparison operator (!=).
Definition chdr_types.hpp:376
ctrl_opcode_t op_code
Operation code (4 bits).
Definition chdr_types.hpp:282
uint16_t dst_port
Destination port for transaction (10 bits).
Definition chdr_types.hpp:260
void populate_header(chdr_header &header) const
Populate the header for this type of packet.
static constexpr size_t MAX_DATA_WORDS
Maximum number of 32-bit data words in a CTRL payload.
Definition chdr_types.hpp:417
std::vector< uint32_t > data_vtr
Data for transaction (vector of 32 bits).
Definition chdr_types.hpp:274
ctrl_payload(ctrl_payload &&rhs)=default
size_t num_data
Number of 32-bit data words present in the packet (4 bits).
Definition chdr_types.hpp:276
uint8_t byte_enable
Byte-enable mask for transaction (4 bits).
Definition chdr_types.hpp:280
A class that represents a single management hop.
Definition chdr_types.hpp:834
void deserialize(std::list< uint64_t > &src, const std::function< uint64_t(uint64_t)> &conv_byte_order, const size_t padding_size)
Deserialize the payload from a uint64_t buffer.
bool operator==(const mgmt_hop_t &rhs) const
Comparison operator (==).
Definition chdr_types.hpp:879
const mgmt_op_t & get_op(size_t i) const
Get the n'th operation in the hop.
Definition chdr_types.hpp:855
size_t serialize(std::vector< uint64_t > &target, const std::function< uint64_t(uint64_t)> &conv_byte_order, const size_t padding_size) const
Serialize the payload to a uint64_t buffer.
void add_op(const mgmt_op_t &op)
Add a management operation to this hop.
Definition chdr_types.hpp:843
std::string to_string() const
Return a string representation of this object.
mgmt_hop_t(const mgmt_hop_t &rhs)=default
size_t get_num_ops() const
Get the number of management operations in this hop.
Definition chdr_types.hpp:849
Definition chdr_types.hpp:680
mgmt_op_t(const op_code_t op_code, const payload_t op_payload=0, const uint8_t ops_pending=0)
Definition chdr_types.hpp:779
mgmt_op_t(const mgmt_op_t &rhs)=default
op_code_t
Operation code.
Definition chdr_types.hpp:688
@ MGMT_OP_INFO_RESP
A response to an information request.
Definition chdr_types.hpp:700
@ MGMT_OP_NOP
Do nothing.
Definition chdr_types.hpp:690
@ MGMT_OP_CFG_WR_REQ
Perform a configuration write on the node.
Definition chdr_types.hpp:702
@ MGMT_OP_RETURN
Return the management packet back to its source.
Definition chdr_types.hpp:696
@ MGMT_OP_ADVERTISE
Advertise this operation to the outside logic.
Definition chdr_types.hpp:692
@ MGMT_OP_CFG_RD_RESP
A response to a configuration read.
Definition chdr_types.hpp:706
@ MGMT_OP_INFO_REQ
Request information about the current node.
Definition chdr_types.hpp:698
@ MGMT_OP_SEL_DEST
Select the next destination for routing.
Definition chdr_types.hpp:694
@ MGMT_OP_CFG_RD_REQ
Perform a configuration read on the node.
Definition chdr_types.hpp:704
std::string to_string() const
Return a string representation of this object.
op_code_t get_op_code() const
Get the op-code for this transaction.
Definition chdr_types.hpp:802
mgmt_op_t & operator=(const mgmt_op_t &rhs)=default
uint8_t get_ops_pending() const
Get the ops pending for this transaction.
Definition chdr_types.hpp:796
uint64_t get_op_payload() const
Get the payload for this transaction.
Definition chdr_types.hpp:808
uint64_t payload_t
The payload for an operation is 48 bits wide.
Definition chdr_types.hpp:710
bool operator==(const mgmt_op_t &rhs) const
Comparison operator (==).
Definition chdr_types.hpp:814
size_t get_num_hops() const
Get the number of management hops in this hop.
Definition chdr_types.hpp:922
void set_proto_ver(uint16_t proto_ver)
Set the protocol version for this transaction.
Definition chdr_types.hpp:1038
chdr_w_t get_chdr_w() const
Return the CHDR_W for this transaction.
Definition chdr_types.hpp:1019
void deserialize(const uint64_t *buff, size_t buff_size, const std::function< uint64_t(uint64_t)> &conv_byte_order)
Deserialize the payload from a uint64_t buffer.
void set_src_epid(sep_id_t src_epid)
Set the source EPID for this transaction.
Definition chdr_types.hpp:1010
void set_chdr_w(chdr_w_t chdr_w)
Set the CHDR_W for this transaction.
Definition chdr_types.hpp:1025
mgmt_payload(const mgmt_payload &rhs)=default
void set_header(sep_id_t src_epid, uint16_t protover, chdr_w_t chdr_w)
Definition chdr_types.hpp:905
size_t get_length() const
Get the serialized size of this payload in 64 bit words.
mgmt_hop_t pop_hop()
Pop the first hop of the transaction and return it.
Definition chdr_types.hpp:934
mgmt_payload & operator=(const mgmt_payload &rhs)=default
void add_hop(const mgmt_hop_t &hop)
Add a management hop to this transaction.
Definition chdr_types.hpp:916
void populate_header(chdr_header &header) const
Populate the header for this type of packet.
void deserialize(const uint64_t *buff, size_t buff_size)
Deserialize the payload from a uint64_t buffer (no conversion function).
Definition chdr_types.hpp:985
std::string hops_to_string() const
Return a string representaiton of the hops contained by this object.
size_t get_size_bytes() const
Definition chdr_types.hpp:941
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:960
sep_id_t get_src_epid() const
Return the source EPID for this transaction.
Definition chdr_types.hpp:1004
uint16_t get_proto_ver() const
Return the protocol version for this transaction.
Definition chdr_types.hpp:1032
std::string to_string() const
Return a string representation of this object.
mgmt_payload(mgmt_payload &&rhs)=default
const mgmt_hop_t & get_hop(size_t i) const
Get the n'th hop in the transaction.
Definition chdr_types.hpp:928
size_t serialize(uint64_t *buff, size_t max_size_bytes, const std::function< uint64_t(uint64_t)> &conv_byte_order) const
Serialize the payload to a uint64_t buffer.
bool operator==(const mgmt_payload &rhs) const
Comparison operator (==).
uint16_t src_epid
The source EPID for the stream (16 bits).
Definition chdr_types.hpp:580
bool operator==(const strc_payload &rhs) const
Comparison operator (==).
void deserialize(const uint64_t *buff, size_t buff_size, const std::function< uint64_t(uint64_t)> &conv_byte_order)
Deserialize the payload from a uint64_t buffer.
strc_payload(const strc_payload &rhs)=default
static constexpr size_t MAX_PACKET_SIZE
Worst-case size of a strc packet (including header).
Definition chdr_types.hpp:590
strc_op_code_t op_code
Operation code for the command (4 bits).
Definition chdr_types.hpp:582
strc_payload(strc_payload &&rhs)=default
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:609
std::string to_string() const
Return a string representation of this object.
size_t get_length() const
Get the serialized size of this payload in 64 bit words.
uint64_t num_bytes
Number of bytes to use for operation (64 bits).
Definition chdr_types.hpp:588
uint64_t num_pkts
Number of packets to use for operation (40 bits).
Definition chdr_types.hpp:586
size_t serialize(uint64_t *buff, size_t max_size_bytes, const std::function< uint64_t(uint64_t)> &conv_byte_order) const
Serialize the payload to a uint64_t buffer.
void populate_header(chdr_header &header) const
Populate the header for this type of packet.
uint8_t op_data
Data associated with the operation (4 bits).
Definition chdr_types.hpp:584
void deserialize(const uint64_t *buff, size_t buff_size)
Deserialize the payload from a uint64_t buffer (no conversion function).
Definition chdr_types.hpp:634
bool operator!=(const strc_payload &rhs) const
Comparison operator (!=).
Definition chdr_types.hpp:650
strc_payload & operator=(const strc_payload &rhs)=default
uint64_t capacity_bytes
Buffer capacity in bytes (40 bits).
Definition chdr_types.hpp:440
uint16_t src_epid
The source EPID for the stream (16 bits).
Definition chdr_types.hpp:436
size_t serialize(uint64_t *buff, size_t max_size_bytes, const std::function< uint64_t(uint64_t)> &conv_byte_order) const
Serialize the payload to a uint64_t buffer.
bool operator!=(const strs_payload &rhs) const
Comparison operator (!=).
Definition chdr_types.hpp:539
bool operator==(const strs_payload &rhs) const
Comparison operator (==).
void deserialize(const uint64_t *buff, size_t buff_size)
Deserialize the payload from a uint64_t buffer (no conversion function).
Definition chdr_types.hpp:523
std::string to_string() const
Return a string representation of this object.
uint16_t buff_info
Buffer info (16 bits).
Definition chdr_types.hpp:448
strs_payload & operator=(const strs_payload &rhs)=default
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:498
strs_payload(strs_payload &&rhs)=default
void deserialize(const uint64_t *buff, size_t buff_size, const std::function< uint64_t(uint64_t)> &conv_byte_order)
Deserialize the payload from a uint64_t buffer.
uint64_t xfer_count_bytes
Transfer count in bytes (64 bits).
Definition chdr_types.hpp:444
strs_payload(const strs_payload &rhs)=default
size_t get_length() const
Get the serialized size of this payload in 64 bit words.
uint32_t capacity_pkts
Buffer capacity in packets (24 bits).
Definition chdr_types.hpp:442
strs_status_t status
The status of the stream (4 bits).
Definition chdr_types.hpp:438
uint64_t xfer_count_pkts
Transfer count in packets (40 bits).
Definition chdr_types.hpp:446
void populate_header(chdr_header &header) const
Populate the header for this type of packet.
#define UHD_API
Definition config.h:87
Definition chdr_types.hpp:21
strs_status_t
Definition chdr_types.hpp:424
@ STRS_CMDERR
No error.
Definition chdr_types.hpp:426
@ STRS_OKAY
Definition chdr_types.hpp:425
@ STRS_DATAERR
Packet out of sequence (sequence error).
Definition chdr_types.hpp:428
@ STRS_RTERR
Data integrity check failed.
Definition chdr_types.hpp:429
@ STRS_SEQERR
A stream command signalled an error.
Definition chdr_types.hpp:427
strc_op_code_t
Definition chdr_types.hpp:570
@ STRC_RESYNC
Trigger a stream status response.
Definition chdr_types.hpp:573
@ STRC_INIT
Definition chdr_types.hpp:571
@ STRC_PING
Initialize stream.
Definition chdr_types.hpp:572
ctrl_opcode_t
Definition chdr_types.hpp:240
@ OP_WRITE
Definition chdr_types.hpp:242
@ OP_SLEEP
Definition chdr_types.hpp:241
@ OP_USER1
Definition chdr_types.hpp:248
@ OP_POLL
Definition chdr_types.hpp:247
@ OP_USER2
Definition chdr_types.hpp:249
@ OP_BLOCK_WRITE
Definition chdr_types.hpp:245
@ OP_USER6
Definition chdr_types.hpp:253
@ OP_READ
Definition chdr_types.hpp:243
@ OP_READ_WRITE
Definition chdr_types.hpp:244
@ OP_BLOCK_READ
Definition chdr_types.hpp:246
@ OP_USER3
Definition chdr_types.hpp:250
@ OP_USER4
Definition chdr_types.hpp:251
@ OP_USER5
Definition chdr_types.hpp:252
ctrl_status_t
Definition chdr_types.hpp:233
@ CMD_TSERR
Slave asserted a command error.
Definition chdr_types.hpp:236
@ CMD_OKAY
Definition chdr_types.hpp:234
@ CMD_CMDERR
Transaction successful.
Definition chdr_types.hpp:235
@ CMD_WARNING
Slave asserted a time stamp error.
Definition chdr_types.hpp:237
constexpr packet_type_t payload_to_packet_type()
Conversion from payload_t to pkt_type.
packet_type_t
Definition chdr_types.hpp:23
@ PKT_TYPE_DATA_WITH_TS
Data Packet without TimeStamp.
Definition chdr_types.hpp:29
@ PKT_TYPE_DATA_NO_TS
Control Transaction.
Definition chdr_types.hpp:28
@ PKT_TYPE_MGMT
Definition chdr_types.hpp:24
@ PKT_TYPE_STRS
Management packet.
Definition chdr_types.hpp:25
@ PKT_TYPE_CTRL
Stream Command.
Definition chdr_types.hpp:27
@ PKT_TYPE_STRC
Stream status.
Definition chdr_types.hpp:26
Definition actions.hpp:25
uint16_t sep_id_t
Stream Endpoint ID Type.
Definition rfnoc_types.hpp:75
chdr_w_t
Type that indicates the CHDR Width in bits.
Definition rfnoc_types.hpp:19
@ CHDR_W_64
Definition rfnoc_types.hpp:19
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:22
Definition build_info.hpp:12
T ntohx(T)
network to host: short, long, or long-long
Definition byteswap.ipp:111
T htowx(T)
host to worknet: short, long, or long-long.
Definition byteswap.ipp:141
T wtohx(T)
worknet to host: short, long, or long-long.
Definition byteswap.ipp:131
T htonx(T)
host to network: short, long, or long-long
Definition byteswap.ipp:121
cfg_payload(payload_t payload_)
Definition chdr_types.hpp:734
const uint32_t data
Definition chdr_types.hpp:731
cfg_payload(uint16_t addr_, uint32_t data_=0)
Definition chdr_types.hpp:733
const uint16_t addr
Definition chdr_types.hpp:730
const uint16_t node_inst
Definition chdr_types.hpp:750
node_info_payload(payload_t payload_)
Definition chdr_types.hpp:763
const uint8_t node_type
Definition chdr_types.hpp:749
const uint32_t ext_info
Definition chdr_types.hpp:751
const uint16_t device_id
Definition chdr_types.hpp:748
node_info_payload(uint16_t device_id_, uint8_t node_type_, uint16_t node_inst_, uint32_t ext_info_)
Definition chdr_types.hpp:753
sel_dest_payload(uint16_t dest_)
Definition chdr_types.hpp:717
const uint16_t dest
Definition chdr_types.hpp:715
sel_dest_payload(payload_t payload_)
Definition chdr_types.hpp:718
struct uhd::rfnoc::chdr::strs_payload::@134025066271002252156312116055072335245246223075::@200370270273044100307226111231362352172047104305 sequence_error
struct uhd::rfnoc::chdr::strs_payload::@134025066271002252156312116055072335245246223075::@315200334066242126067152201266055270274312375345 routing_error
struct uhd::rfnoc::chdr::strs_payload::@134025066271002252156312116055072335245246223075::@237127230026216160036247045277037205320242340130 status