USRP Hardware Driver and USRP Manual Version: 4.1.0.1
UHD and USRP Manual
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
12#include <boost/format.hpp>
13#include <boost/optional.hpp>
14#include <deque>
15#include <list>
16#include <memory>
17#include <vector>
18
19namespace uhd { namespace rfnoc { namespace chdr {
20
28};
29
30//----------------------------------------------------
31// CHDR Header
32//----------------------------------------------------
33
35{
36public: // Functions
37 chdr_header() = default;
38 chdr_header(const chdr_header& rhs) = default;
39 chdr_header(chdr_header&& rhs) = default;
40
42 chdr_header(uint64_t flat_hdr) : _flat_hdr(flat_hdr) {}
43
45 inline uint8_t get_vc() const
46 {
47 return get_field<uint8_t>(_flat_hdr, VC_OFFSET, VC_WIDTH);
48 }
49
51 inline void set_vc(uint8_t vc)
52 {
53 _flat_hdr = set_field(_flat_hdr, vc, VC_OFFSET, VC_WIDTH);
54 }
55
57 inline bool get_eob() const
58 {
59 return get_field<bool>(_flat_hdr, EOB_OFFSET, EOB_WIDTH);
60 }
61
63 inline void set_eob(bool eob)
64 {
65 _flat_hdr = set_field(_flat_hdr, eob, EOB_OFFSET, EOB_WIDTH);
66 }
67
69 inline bool get_eov() const
70 {
71 return get_field<bool>(_flat_hdr, EOV_OFFSET, EOV_WIDTH);
72 }
73
75 inline void set_eov(bool eov)
76 {
77 _flat_hdr = set_field(_flat_hdr, eov, EOV_OFFSET, EOV_WIDTH);
78 }
79
82 {
83 return get_field<packet_type_t>(_flat_hdr, PKT_TYPE_OFFSET, PKT_TYPE_WIDTH);
84 }
85
87 inline void set_pkt_type(packet_type_t pkt_type)
88 {
89 _flat_hdr = set_field(_flat_hdr, pkt_type, PKT_TYPE_OFFSET, PKT_TYPE_WIDTH);
90 }
91
93 inline uint8_t get_num_mdata() const
94 {
95 return get_field<uint8_t>(_flat_hdr, NUM_MDATA_OFFSET, NUM_MDATA_WIDTH);
96 }
97
99 inline void set_num_mdata(uint8_t num_mdata)
100 {
101 _flat_hdr = set_field(_flat_hdr, num_mdata, NUM_MDATA_OFFSET, NUM_MDATA_WIDTH);
102 }
103
105 inline uint16_t get_seq_num() const
106 {
107 return get_field<uint16_t>(_flat_hdr, SEQ_NUM_OFFSET, SEQ_NUM_WIDTH);
108 }
109
111 inline void set_seq_num(uint16_t seq_num)
112 {
113 _flat_hdr = set_field(_flat_hdr, seq_num, SEQ_NUM_OFFSET, SEQ_NUM_WIDTH);
114 }
115
117 inline uint16_t get_length() const
118 {
119 return get_field<uint16_t>(_flat_hdr, LENGTH_OFFSET, LENGTH_WIDTH);
120 }
121
123 inline void set_length(uint16_t length)
124 {
125 _flat_hdr = set_field(_flat_hdr, length, LENGTH_OFFSET, LENGTH_WIDTH);
126 }
127
129 inline uint16_t get_dst_epid() const
130 {
131 return get_field<uint16_t>(_flat_hdr, DST_EPID_OFFSET, DST_EPID_WIDTH);
132 }
133
135 inline void set_dst_epid(uint16_t dst_epid)
136 {
137 _flat_hdr = set_field(_flat_hdr, dst_epid, DST_EPID_OFFSET, DST_EPID_WIDTH);
138 }
139
141 inline uint64_t pack() const
142 {
143 return _flat_hdr;
144 }
145
147 inline operator uint64_t() const
148 {
149 return pack();
150 }
151
153 inline bool operator==(const chdr_header& rhs) const
154 {
155 return _flat_hdr == rhs._flat_hdr;
156 }
157
159 inline bool operator!=(const chdr_header& rhs) const
160 {
161 return _flat_hdr != rhs._flat_hdr;
162 }
163
165 inline const chdr_header& operator=(const chdr_header& rhs)
166 {
167 _flat_hdr = rhs._flat_hdr;
168 return *this;
169 }
170
172 inline const chdr_header& operator=(const uint64_t& rhs)
173 {
174 _flat_hdr = rhs;
175 return *this;
176 }
177
179 inline const std::string to_string() const
180 {
181 // The static_casts are because vc and num_mdata are uint8_t -> unsigned char
182 // For some reason, despite the %u meaning unsigned int, boost still formats them
183 // as chars
184 return str(boost::format("chdr_header{vc:%u, eob:%c, eov:%c, pkt_type:%u, "
185 "num_mdata:%u, seq_num:%u, length:%u, dst_epid:%u}\n")
186 % static_cast<uint16_t>(get_vc()) % (get_eob() ? 'Y' : 'N')
187 % (get_eov() ? 'Y' : 'N') % get_pkt_type()
188 % static_cast<uint16_t>(get_num_mdata()) % get_seq_num() % get_length()
189 % get_dst_epid());
190 }
191
192private:
193 // The flattened representation of the header stored in host order
194 uint64_t _flat_hdr = 0;
195
196 static constexpr size_t VC_WIDTH = 6;
197 static constexpr size_t EOB_WIDTH = 1;
198 static constexpr size_t EOV_WIDTH = 1;
199 static constexpr size_t PKT_TYPE_WIDTH = 3;
200 static constexpr size_t NUM_MDATA_WIDTH = 5;
201 static constexpr size_t SEQ_NUM_WIDTH = 16;
202 static constexpr size_t LENGTH_WIDTH = 16;
203 static constexpr size_t DST_EPID_WIDTH = 16;
204
205 static constexpr size_t VC_OFFSET = 58;
206 static constexpr size_t EOB_OFFSET = 57;
207 static constexpr size_t EOV_OFFSET = 56;
208 static constexpr size_t PKT_TYPE_OFFSET = 53;
209 static constexpr size_t NUM_MDATA_OFFSET = 48;
210 static constexpr size_t SEQ_NUM_OFFSET = 32;
211 static constexpr size_t LENGTH_OFFSET = 16;
212 static constexpr size_t DST_EPID_OFFSET = 0;
213
214 static inline uint64_t mask(const size_t width)
215 {
216 return ((uint64_t(1) << width) - 1);
217 }
218
219 template <typename field_t>
220 static inline field_t get_field(
221 const uint64_t flat_hdr, const size_t offset, const size_t width)
222 {
223 return static_cast<field_t>((flat_hdr >> offset) & mask(width));
224 }
225
226 template <typename field_t>
227 static inline uint64_t set_field(const uint64_t old_val,
228 const field_t field,
229 const size_t offset,
230 const size_t width)
231 {
232 return (old_val & ~(mask(width) << offset))
233 | ((static_cast<uint64_t>(field) & mask(width)) << offset);
234 }
235};
236
237
238//----------------------------------------------------
239// CHDR Control Packet Payload
240//----------------------------------------------------
241
243 CMD_OKAY = 0x0,
245 CMD_TSERR = 0x2,
247};
248
250 OP_SLEEP = 0x0,
251 OP_WRITE = 0x1,
252 OP_READ = 0x2,
256 OP_POLL = 0x6,
257 OP_USER1 = 0xA,
258 OP_USER2 = 0xB,
259 OP_USER3 = 0xC,
260 OP_USER4 = 0xD,
261 OP_USER5 = 0xE,
262 OP_USER6 = 0xF,
263};
264
266{
267public: // Members
269 uint16_t dst_port = 0;
271 uint16_t src_port = 0;
273 uint8_t seq_num = 0;
275 boost::optional<uint64_t> timestamp = boost::none;
277 bool is_ack = false;
279 uint16_t src_epid = 0;
281 uint32_t address = 0;
283 std::vector<uint32_t> data_vtr = {0};
285 uint8_t byte_enable = 0xF;
290
291public: // Functions
292 ctrl_payload() = default;
293 ctrl_payload(const ctrl_payload& rhs) = default;
294 ctrl_payload(ctrl_payload&& rhs) = default;
295
296 ctrl_payload& operator=(const ctrl_payload& rhs) = default;
297
299 void populate_header(chdr_header& header) const;
300
302 size_t serialize(uint64_t* buff,
303 size_t max_size_bytes,
304 const std::function<uint64_t(uint64_t)>& conv_byte_order) const;
305
307 template <endianness_t endianness>
308 size_t serialize(uint64_t* buff, size_t max_size_bytes) const
309 {
310 auto conv_byte_order = [](uint64_t x) -> uint64_t {
311 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::htonx<uint64_t>(x)
312 : uhd::htowx<uint64_t>(x);
313 };
314 return serialize(buff, max_size_bytes, conv_byte_order);
315 }
316
318 void deserialize(const uint64_t* buff,
319 size_t num_elems,
320 const std::function<uint64_t(uint64_t)>& conv_byte_order);
321
323 template <endianness_t endianness>
324 void deserialize(const uint64_t* buff, size_t num_elems)
325 {
326 auto conv_byte_order = [](uint64_t x) -> uint64_t {
327 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx<uint64_t>(x)
328 : uhd::wtohx<uint64_t>(x);
329 };
330 deserialize(buff, num_elems, conv_byte_order);
331 }
332
334 size_t get_length() const;
335
336 // Return whether or not we have a valid timestamp
337 bool has_timestamp() const
338 {
339 return bool(timestamp);
340 }
341
343 bool operator==(const ctrl_payload& rhs) const;
344
346 inline bool operator!=(const ctrl_payload& rhs) const
347 {
348 return !(*this == rhs);
349 }
350
352 const std::string to_string() const;
353
354private:
355 static constexpr size_t DST_PORT_WIDTH = 10;
356 static constexpr size_t SRC_PORT_WIDTH = 10;
357 static constexpr size_t NUM_DATA_WIDTH = 4;
358 static constexpr size_t SEQ_NUM_WIDTH = 6;
359 static constexpr size_t HAS_TIME_WIDTH = 1;
360 static constexpr size_t IS_ACK_WIDTH = 1;
361 static constexpr size_t SRC_EPID_WIDTH = 16;
362 static constexpr size_t ADDRESS_WIDTH = 20;
363 static constexpr size_t BYTE_ENABLE_WIDTH = 4;
364 static constexpr size_t OPCODE_WIDTH = 4;
365 static constexpr size_t STATUS_WIDTH = 2;
366
367 // Offsets assume 64-bit alignment
368 static constexpr size_t DST_PORT_OFFSET = 0;
369 static constexpr size_t SRC_PORT_OFFSET = 10;
370 static constexpr size_t NUM_DATA_OFFSET = 20;
371 static constexpr size_t SEQ_NUM_OFFSET = 24;
372 static constexpr size_t HAS_TIME_OFFSET = 30;
373 static constexpr size_t IS_ACK_OFFSET = 31;
374 static constexpr size_t SRC_EPID_OFFSET = 32;
375 static constexpr size_t ADDRESS_OFFSET = 0;
376 static constexpr size_t BYTE_ENABLE_OFFSET = 20;
377 static constexpr size_t OPCODE_OFFSET = 24;
378 static constexpr size_t STATUS_OFFSET = 30;
379 static constexpr size_t LO_DATA_OFFSET = 0;
380 static constexpr size_t HI_DATA_OFFSET = 32;
381};
382
383//----------------------------------------------------
384// CHDR Stream Status Packet Payload
385//----------------------------------------------------
386
388 STRS_OKAY = 0x0,
393};
394
396{
397public: // Members
399 uint16_t src_epid = 0;
403 uint64_t capacity_bytes = 0;
405 uint32_t capacity_pkts = 0;
407 uint64_t xfer_count_bytes = 0;
409 uint64_t xfer_count_pkts = 0;
411 uint16_t buff_info = 0;
413 uint64_t status_info = 0;
414
415public: // Functions
416 strs_payload() = default;
417 strs_payload(const strs_payload& rhs) = default;
418 strs_payload(strs_payload&& rhs) = default;
419
420 strs_payload& operator=(const strs_payload& rhs) = default;
421
423 void populate_header(chdr_header& header) const;
424
426 size_t serialize(uint64_t* buff,
427 size_t max_size_bytes,
428 const std::function<uint64_t(uint64_t)>& conv_byte_order) const;
429
431 template <endianness_t endianness>
432 size_t serialize(uint64_t* buff, size_t max_size_bytes) const
433 {
434 auto conv_byte_order = [](uint64_t x) -> uint64_t {
435 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::htonx<uint64_t>(x)
436 : uhd::htowx<uint64_t>(x);
437 };
438 return serialize(buff, max_size_bytes, conv_byte_order);
439 }
440
442 void deserialize(const uint64_t* buff,
443 size_t num_elems,
444 const std::function<uint64_t(uint64_t)>& conv_byte_order);
445
447 template <endianness_t endianness>
448 void deserialize(const uint64_t* buff, size_t num_elems)
449 {
450 auto conv_byte_order = [](uint64_t x) -> uint64_t {
451 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx<uint64_t>(x)
452 : uhd::wtohx<uint64_t>(x);
453 };
454 deserialize(buff, num_elems, conv_byte_order);
455 }
456
458 size_t get_length() const;
459
461 bool operator==(const strs_payload& rhs) const;
462
464 inline bool operator!=(const strs_payload& rhs) const
465 {
466 return !(*this == rhs);
467 }
468
470 const std::string to_string() const;
471
472private:
473 static constexpr size_t SRC_EPID_WIDTH = 16;
474 static constexpr size_t STATUS_WIDTH = 4;
475 static constexpr size_t CAPACITY_BYTES_WIDTH = 40;
476 static constexpr size_t CAPACITY_PKTS_WIDTH = 24;
477 static constexpr size_t XFER_COUNT_PKTS_WIDTH = 40;
478 static constexpr size_t BUFF_INFO_WIDTH = 16;
479 static constexpr size_t STATUS_INFO_WIDTH = 48;
480
481 // Offsets assume 64-bit alignment
482 static constexpr size_t SRC_EPID_OFFSET = 0;
483 static constexpr size_t STATUS_OFFSET = 16;
484 static constexpr size_t CAPACITY_BYTES_OFFSET = 24;
485 static constexpr size_t CAPACITY_PKTS_OFFSET = 0;
486 static constexpr size_t XFER_COUNT_PKTS_OFFSET = 24;
487 static constexpr size_t BUFF_INFO_OFFSET = 0;
488 static constexpr size_t STATUS_INFO_OFFSET = 16;
489};
490
491//----------------------------------------------------
492// CHDR Stream Command Packet Payload
493//----------------------------------------------------
494
496 STRC_INIT = 0x0,
497 STRC_PING = 0x1,
499};
500
502{
503public: // Members
505 uint16_t src_epid = 0;
509 uint8_t op_data = 0;
511 uint64_t num_pkts = 0;
513 uint64_t num_bytes = 0;
515 static constexpr size_t MAX_PACKET_SIZE = 128;
516
517public: // Functions
518 strc_payload() = default;
519 strc_payload(const strc_payload& rhs) = default;
520 strc_payload(strc_payload&& rhs) = default;
521
522 strc_payload& operator=(const strc_payload& rhs) = default;
523
525 void populate_header(chdr_header& header) const;
526
528 size_t serialize(uint64_t* buff,
529 size_t max_size_bytes,
530 const std::function<uint64_t(uint64_t)>& conv_byte_order) const;
531
533 template <endianness_t endianness>
534 size_t serialize(uint64_t* buff, size_t max_size_bytes) const
535 {
536 auto conv_byte_order = [](uint64_t x) -> uint64_t {
537 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::htonx<uint64_t>(x)
538 : uhd::htowx<uint64_t>(x);
539 };
540 return serialize(buff, max_size_bytes, conv_byte_order);
541 }
542
544 void deserialize(const uint64_t* buff,
545 size_t num_elems,
546 const std::function<uint64_t(uint64_t)>& conv_byte_order);
547
549 template <endianness_t endianness>
550 void deserialize(const uint64_t* buff, size_t num_elems)
551 {
552 auto conv_byte_order = [](uint64_t x) -> uint64_t {
553 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx<uint64_t>(x)
554 : uhd::wtohx<uint64_t>(x);
555 };
556 deserialize(buff, num_elems, conv_byte_order);
557 }
558
560 size_t get_length() const;
561
563 bool operator==(const strc_payload& rhs) const;
564
566 inline bool operator!=(const strc_payload& rhs) const
567 {
568 return !(*this == rhs);
569 }
570
572 const std::string to_string() const;
573
574private:
575 static constexpr size_t SRC_EPID_WIDTH = 16;
576 static constexpr size_t OP_CODE_WIDTH = 4;
577 static constexpr size_t OP_DATA_WIDTH = 4;
578 static constexpr size_t NUM_PKTS_WIDTH = 40;
579
580 // Offsets assume 64-bit alignment
581 static constexpr size_t SRC_EPID_OFFSET = 0;
582 static constexpr size_t OP_CODE_OFFSET = 16;
583 static constexpr size_t OP_DATA_OFFSET = 20;
584 static constexpr size_t NUM_PKTS_OFFSET = 24;
585};
586
587//----------------------------------------------------
588// CHDR Management Packet Payload
589//----------------------------------------------------
590
592// An operation consists of an operation code and some
593// payload associated with that operation.
595{
596public:
597 // Operation code
600 MGMT_OP_NOP = 0,
602 MGMT_OP_ADVERTISE = 1,
604 MGMT_OP_SEL_DEST = 2,
606 MGMT_OP_RETURN = 3,
608 MGMT_OP_INFO_REQ = 4,
610 MGMT_OP_INFO_RESP = 5,
612 MGMT_OP_CFG_WR_REQ = 6,
614 MGMT_OP_CFG_RD_REQ = 7,
616 MGMT_OP_CFG_RD_RESP = 8
617 };
618
620 using payload_t = uint64_t;
621
624 {
625 const uint16_t dest;
626
627 sel_dest_payload(uint16_t dest_) : dest(dest_) {}
628 sel_dest_payload(payload_t payload_) : dest(static_cast<uint16_t>(payload_)) {}
629 operator payload_t() const
630 {
631 return static_cast<payload_t>(dest);
632 }
633 };
634
638 {
639 const uint16_t addr;
640 const uint32_t data;
641
642 cfg_payload(uint16_t addr_, uint32_t data_ = 0) : addr(addr_), data(data_) {}
644 : addr(static_cast<uint16_t>(payload_ >> 0))
645 , data(static_cast<uint32_t>(payload_ >> 16))
646 {
647 }
648 operator payload_t() const
649 {
650 return ((static_cast<payload_t>(data) << 16) | static_cast<payload_t>(addr));
651 }
652 };
653
656 {
657 const uint16_t device_id;
658 const uint8_t node_type;
659 const uint16_t node_inst;
660 const uint32_t ext_info;
661
662 node_info_payload(uint16_t device_id_,
663 uint8_t node_type_,
664 uint16_t node_inst_,
665 uint32_t ext_info_)
666 : device_id(device_id_)
667 , node_type(node_type_)
668 , node_inst(node_inst_)
669 , ext_info(ext_info_)
670 {
671 }
673 : device_id(static_cast<uint16_t>(payload_ >> 0))
674 , node_type(static_cast<uint8_t>((payload_ >> 16) & 0xF))
675 , node_inst(static_cast<uint16_t>((payload_ >> 20) & 0x3FF))
676 , ext_info(static_cast<uint32_t>((payload_ >> 30) & 0x3FFFF))
677 {
678 }
679 operator payload_t() const
680 {
681 return ((static_cast<payload_t>(device_id) << 0)
682 | (static_cast<payload_t>(node_type & 0xF) << 16)
683 | (static_cast<payload_t>(node_inst & 0x3FF) << 20)
684 | (static_cast<payload_t>(ext_info & 0x3FFFF) << 30));
685 }
686 };
687
688 mgmt_op_t(const op_code_t op_code, const payload_t op_payload = 0)
689 : _op_code(op_code), _op_payload(op_payload)
690 {
691 }
692 mgmt_op_t(const mgmt_op_t& rhs) = default;
693
695 inline op_code_t get_op_code() const
696 {
697 return _op_code;
698 }
699
701 inline uint64_t get_op_payload() const
702 {
703 return _op_payload;
704 }
705
707 inline bool operator==(const mgmt_op_t& rhs) const
708 {
709 return (_op_code == rhs._op_code) && (_op_payload == rhs._op_payload);
710 }
711
713 const std::string to_string() const;
714
715private:
716 op_code_t _op_code;
717 payload_t _op_payload;
718};
719
721// A hop is a collection for management transactions for
722// a single node.
724{
725public:
726 mgmt_hop_t() = default;
727 mgmt_hop_t(const mgmt_hop_t& rhs) = default;
728
730 // Operations are added to the hop in FIFO order and executed in FIFO order.
731 inline void add_op(const mgmt_op_t& op)
732 {
733 _ops.push_back(op);
734 }
735
737 inline size_t get_num_ops() const
738 {
739 return _ops.size();
740 }
741
743 inline const mgmt_op_t& get_op(size_t i) const
744 {
745 return _ops.at(i);
746 }
747
749 // The RFNoC Specification section 2.2.6 specifies that for chdr widths
750 // greater than 64, all MSBs are 0, so we pad out the hop based on the width
751 size_t serialize(std::vector<uint64_t>& target,
752 const std::function<uint64_t(uint64_t)>& conv_byte_order,
753 const size_t padding_size) const;
754
756 // The RFNoC Specification section 2.2.6 specifies that for chdr widths
757 // greater than 64, all MSBs are 0, so we remove padding based on the width
758 void deserialize(std::list<uint64_t>& src,
759 const std::function<uint64_t(uint64_t)>& conv_byte_order,
760 const size_t padding_size);
761
763 inline bool operator==(const mgmt_hop_t& rhs) const
764 {
765 return _ops == rhs._ops;
766 }
767
769 const std::string to_string() const;
770
771private:
772 std::vector<mgmt_op_t> _ops;
773};
774
776// A transaction is a collection of hops, where each hop is a collection
777// of management transactions.
779{
780public:
781 mgmt_payload() = default;
782 mgmt_payload(const mgmt_payload& rhs) = default;
783 mgmt_payload(mgmt_payload&& rhs) = default;
784
785 mgmt_payload& operator=(const mgmt_payload& rhs) = default;
786
787 inline void set_header(sep_id_t src_epid, uint16_t protover, chdr_w_t chdr_w)
788 {
789 set_src_epid(src_epid);
790 set_chdr_w(chdr_w);
791 set_proto_ver(protover);
792 }
793
795 // Hops are added to the hop in FIFO order and executed in FIFO order.
796 inline void add_hop(const mgmt_hop_t& hop)
797 {
798 _hops.push_back(hop);
799 }
800
802 inline size_t get_num_hops() const
803 {
804 return _hops.size();
805 }
806
808 inline const mgmt_hop_t& get_hop(size_t i) const
809 {
810 return _hops.at(i);
811 }
812
815 {
816 auto hop = _hops.front();
817 _hops.pop_front();
818 return hop;
819 }
820
821 inline size_t get_size_bytes() const
822 {
823 size_t num_lines = 1; /* header */
824 for (const auto& hop : _hops) {
825 num_lines += hop.get_num_ops();
826 }
827 return num_lines * (chdr_w_to_bits(_chdr_w) / 8);
828 }
829
831 void populate_header(chdr_header& header) const;
832
834 size_t serialize(uint64_t* buff,
835 size_t max_size_bytes,
836 const std::function<uint64_t(uint64_t)>& conv_byte_order) const;
837
839 template <endianness_t endianness>
840 size_t serialize(uint64_t* buff, size_t max_size_bytes) const
841 {
842 auto conv_byte_order = [](uint64_t x) -> uint64_t {
843 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::htonx<uint64_t>(x)
844 : uhd::htowx<uint64_t>(x);
845 };
846 return serialize(buff, max_size_bytes, conv_byte_order);
847 }
848
850 void deserialize(const uint64_t* buff,
851 size_t num_elems,
852 const std::function<uint64_t(uint64_t)>& conv_byte_order);
853
855 template <endianness_t endianness>
856 void deserialize(const uint64_t* buff, size_t num_elems)
857 {
858 auto conv_byte_order = [](uint64_t x) -> uint64_t {
859 return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx<uint64_t>(x)
860 : uhd::wtohx<uint64_t>(x);
861 };
862 deserialize(buff, num_elems, conv_byte_order);
863 }
864
866 size_t get_length() const;
867
869 const std::string to_string() const;
870
872 const std::string hops_to_string() const;
873
875 inline sep_id_t get_src_epid() const
876 {
877 return _src_epid;
878 }
879
881 inline void set_src_epid(sep_id_t src_epid)
882 {
883 _src_epid = src_epid;
884 }
885
887 bool operator==(const mgmt_payload& rhs) const;
888
890 inline chdr_w_t get_chdr_w() const
891 {
892 return _chdr_w;
893 }
894
896 inline void set_chdr_w(chdr_w_t chdr_w)
897 {
898 _chdr_w = chdr_w;
899 _padding_size = (chdr_w_to_bits(_chdr_w) / 64) - 1;
900 }
901
903 inline uint16_t get_proto_ver() const
904 {
905 return _protover;
906 }
907
909 inline void set_proto_ver(uint16_t proto_ver)
910 {
911 _protover = proto_ver;
912 }
913
914private:
915 sep_id_t _src_epid = 0;
916 uint16_t _protover = 0;
917 chdr_w_t _chdr_w = CHDR_W_64;
918 size_t _padding_size = 0;
919 std::deque<mgmt_hop_t> _hops;
920};
921
923template <typename payload_t>
925
926template <>
928{
929 return PKT_TYPE_CTRL;
930}
931
932template <>
934{
935 return PKT_TYPE_MGMT;
936}
937
938template <>
940{
941 return PKT_TYPE_STRC;
942}
943
944template <>
946{
947 return PKT_TYPE_STRS;
948}
949
950}}} // namespace uhd::rfnoc::chdr
Definition: chdr_types.hpp:35
void set_vc(uint8_t vc)
Set the virtual channel field (6 bits)
Definition: chdr_types.hpp:51
void set_eob(bool eob)
Set the end-of-burst flag (1 bit)
Definition: chdr_types.hpp:63
uint8_t get_vc() const
Get the virtual channel field (6 bits)
Definition: chdr_types.hpp:45
void set_pkt_type(packet_type_t pkt_type)
Set the packet type field (3 bits)
Definition: chdr_types.hpp:87
const std::string to_string() const
Return a string representation of this object.
Definition: chdr_types.hpp:179
chdr_header(const chdr_header &rhs)=default
chdr_header(uint64_t flat_hdr)
Unpack the header from a uint64_t.
Definition: chdr_types.hpp:42
void set_length(uint16_t length)
Set the packet length field (16 bits)
Definition: chdr_types.hpp:123
bool operator!=(const chdr_header &rhs) const
Comparison operator (!=)
Definition: chdr_types.hpp:159
uint64_t pack() const
Pack the header into a uint64_t.
Definition: chdr_types.hpp:141
uint16_t get_seq_num() const
Get the sequence number field (16 bits)
Definition: chdr_types.hpp:105
void set_dst_epid(uint16_t dst_epid)
Set the destination EPID field (16 bits)
Definition: chdr_types.hpp:135
uint16_t get_length() const
Get the packet length field (16 bits)
Definition: chdr_types.hpp:117
chdr_header(chdr_header &&rhs)=default
bool get_eov() const
Get the end-of-vector flag (1 bit)
Definition: chdr_types.hpp:69
packet_type_t get_pkt_type() const
Get the packet type field (3 bits)
Definition: chdr_types.hpp:81
bool get_eob() const
Get the end-of-burst flag (1 bit)
Definition: chdr_types.hpp:57
uint8_t get_num_mdata() const
Get number of metadata words field (5 bits)
Definition: chdr_types.hpp:93
void set_eov(bool eov)
Set the end-of-vector flag (1 bit)
Definition: chdr_types.hpp:75
uint16_t get_dst_epid() const
Get the destination EPID field (16 bits)
Definition: chdr_types.hpp:129
void set_num_mdata(uint8_t num_mdata)
Set number of metadata words field (5 bits)
Definition: chdr_types.hpp:99
void set_seq_num(uint16_t seq_num)
Set the sequence number field (16 bits)
Definition: chdr_types.hpp:111
const chdr_header & operator=(const chdr_header &rhs)
Assignment operator (=) from a chdr_header.
Definition: chdr_types.hpp:165
const chdr_header & operator=(const uint64_t &rhs)
Assignment operator (=) from a uint64_t.
Definition: chdr_types.hpp:172
bool operator==(const chdr_header &rhs) const
Comparison operator (==)
Definition: chdr_types.hpp:153
Definition: chdr_types.hpp:266
ctrl_payload & operator=(const ctrl_payload &rhs)=default
bool has_timestamp() const
Definition: chdr_types.hpp:337
size_t get_length() const
Get the serialized size of this payload in 64 bit words.
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.
const std::string to_string() const
Return a string representation of this object.
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:308
ctrl_payload(const ctrl_payload &rhs)=default
bool operator==(const ctrl_payload &rhs) const
Comparison operator (==)
bool operator!=(const ctrl_payload &rhs) const
Comparison operator (!=)
Definition: chdr_types.hpp:346
void populate_header(chdr_header &header) const
Populate the header for this type of packet.
ctrl_payload(ctrl_payload &&rhs)=default
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:324
void deserialize(const uint64_t *buff, size_t num_elems, const std::function< uint64_t(uint64_t)> &conv_byte_order)
Deserialize the payload from a uint64_t buffer.
A class that represents a single management hop.
Definition: chdr_types.hpp:724
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:763
const mgmt_op_t & get_op(size_t i) const
Get the n'th operation in the hop.
Definition: chdr_types.hpp:743
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:731
const 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:737
A class that represents a single management operation.
Definition: chdr_types.hpp:595
mgmt_op_t(const mgmt_op_t &rhs)=default
op_code_t
Definition: chdr_types.hpp:598
op_code_t get_op_code() const
Get the op-code for this transaction.
Definition: chdr_types.hpp:695
mgmt_op_t(const op_code_t op_code, const payload_t op_payload=0)
Definition: chdr_types.hpp:688
uint64_t get_op_payload() const
Get the payload for this transaction.
Definition: chdr_types.hpp:701
uint64_t payload_t
The payload for an operation is 48 bits wide.
Definition: chdr_types.hpp:620
bool operator==(const mgmt_op_t &rhs) const
Comparison operator (==)
Definition: chdr_types.hpp:707
const std::string to_string() const
Return a string representation of this object.
A class that represents a complete multi-hop management transaction.
Definition: chdr_types.hpp:779
size_t get_num_hops() const
Get the number of management hops in this hop.
Definition: chdr_types.hpp:802
void set_proto_ver(uint16_t proto_ver)
Set the protocol version for this transaction.
Definition: chdr_types.hpp:909
chdr_w_t get_chdr_w() const
Return the CHDR_W for this transaction.
Definition: chdr_types.hpp:890
void set_src_epid(sep_id_t src_epid)
Set the source EPID for this transaction.
Definition: chdr_types.hpp:881
void set_chdr_w(chdr_w_t chdr_w)
Set the CHDR_W for this transaction.
Definition: chdr_types.hpp:896
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:787
size_t get_length() const
Get the serialized size of this payload in 64 bit words.
void deserialize(const uint64_t *buff, size_t num_elems, const std::function< uint64_t(uint64_t)> &conv_byte_order)
Deserialize the payload from a uint64_t buffer.
mgmt_hop_t pop_hop()
Pop the first hop of the transaction and return it.
Definition: chdr_types.hpp:814
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:796
void populate_header(chdr_header &header) const
Populate the header for this type of packet.
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:856
size_t get_size_bytes() const
Definition: chdr_types.hpp:821
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:840
sep_id_t get_src_epid() const
Return the source EPID for this transaction.
Definition: chdr_types.hpp:875
uint16_t get_proto_ver() const
Return the protocol version for this transaction.
Definition: chdr_types.hpp:903
const std::string to_string() const
Return a string representation of this object.
const std::string hops_to_string() const
Return a string representaiton of the hops contained by 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:808
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 (==)
Definition: chdr_types.hpp:502
const std::string to_string() const
Return a string representation of this object.
bool operator==(const strc_payload &rhs) const
Comparison operator (==)
strc_payload(const strc_payload &rhs)=default
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:534
size_t get_length() const
Get the serialized size of this payload in 64 bit words.
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:550
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.
bool operator!=(const strc_payload &rhs) const
Comparison operator (!=)
Definition: chdr_types.hpp:566
strc_payload & operator=(const strc_payload &rhs)=default
void deserialize(const uint64_t *buff, size_t num_elems, const std::function< uint64_t(uint64_t)> &conv_byte_order)
Deserialize the payload from a uint64_t buffer.
Definition: chdr_types.hpp:396
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:464
bool operator==(const strs_payload &rhs) const
Comparison operator (==)
void deserialize(const uint64_t *buff, size_t num_elems, const std::function< uint64_t(uint64_t)> &conv_byte_order)
Deserialize the payload from a uint64_t buffer.
strs_payload & operator=(const strs_payload &rhs)=default
const std::string to_string() const
Return a string representation of this object.
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:432
strs_payload(strs_payload &&rhs)=default
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:448
strs_payload(const strs_payload &rhs)=default
size_t get_length() const
Get the serialized size of this payload in 64 bit words.
void populate_header(chdr_header &header) const
Populate the header for this type of packet.
#define UHD_API
Definition: config.h:70
strs_status_t
Definition: chdr_types.hpp:387
@ STRS_CMDERR
No error.
Definition: chdr_types.hpp:389
@ STRS_OKAY
Definition: chdr_types.hpp:388
@ STRS_DATAERR
Packet out of sequence (sequence error)
Definition: chdr_types.hpp:391
@ STRS_RTERR
Data integrity check failed.
Definition: chdr_types.hpp:392
@ STRS_SEQERR
A stream command signalled an error.
Definition: chdr_types.hpp:390
constexpr packet_type_t payload_to_packet_type< mgmt_payload >()
Definition: chdr_types.hpp:933
constexpr packet_type_t payload_to_packet_type< strs_payload >()
Definition: chdr_types.hpp:945
strc_op_code_t
Definition: chdr_types.hpp:495
@ STRC_RESYNC
Trigger a stream status response.
Definition: chdr_types.hpp:498
@ STRC_INIT
Definition: chdr_types.hpp:496
@ STRC_PING
Initialize stream.
Definition: chdr_types.hpp:497
constexpr packet_type_t payload_to_packet_type< strc_payload >()
Definition: chdr_types.hpp:939
ctrl_opcode_t
Definition: chdr_types.hpp:249
@ OP_WRITE
Definition: chdr_types.hpp:251
@ OP_SLEEP
Definition: chdr_types.hpp:250
@ OP_USER1
Definition: chdr_types.hpp:257
@ OP_POLL
Definition: chdr_types.hpp:256
@ OP_USER2
Definition: chdr_types.hpp:258
@ OP_BLOCK_WRITE
Definition: chdr_types.hpp:254
@ OP_USER6
Definition: chdr_types.hpp:262
@ OP_READ
Definition: chdr_types.hpp:252
@ OP_READ_WRITE
Definition: chdr_types.hpp:253
@ OP_BLOCK_READ
Definition: chdr_types.hpp:255
@ OP_USER3
Definition: chdr_types.hpp:259
@ OP_USER4
Definition: chdr_types.hpp:260
@ OP_USER5
Definition: chdr_types.hpp:261
ctrl_status_t
Definition: chdr_types.hpp:242
@ CMD_TSERR
Slave asserted a command error.
Definition: chdr_types.hpp:245
@ CMD_OKAY
Definition: chdr_types.hpp:243
@ CMD_CMDERR
Transaction successful.
Definition: chdr_types.hpp:244
@ CMD_WARNING
Slave asserted a time stamp error.
Definition: chdr_types.hpp:246
constexpr packet_type_t payload_to_packet_type< ctrl_payload >()
Definition: chdr_types.hpp:927
constexpr packet_type_t payload_to_packet_type()
Conversion from payload_t to pkt_type.
packet_type_t
Definition: chdr_types.hpp:21
@ PKT_TYPE_DATA_WITH_TS
Data Packet without TimeStamp.
Definition: chdr_types.hpp:27
@ PKT_TYPE_DATA_NO_TS
Control Transaction.
Definition: chdr_types.hpp:26
@ PKT_TYPE_MGMT
Definition: chdr_types.hpp:22
@ PKT_TYPE_STRS
Management packet.
Definition: chdr_types.hpp:23
@ PKT_TYPE_CTRL
Stream Command.
Definition: chdr_types.hpp:25
@ PKT_TYPE_STRC
Stream status.
Definition: chdr_types.hpp:24
uint16_t sep_id_t
Stream Endpoint ID Type.
Definition: rfnoc_types.hpp:38
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:21
UHD_INLINE size_t width(const soft_reg_field_t field)
Definition: soft_register.hpp:76
Definition: build_info.hpp:12
@ ENDIANNESS_BIG
Definition: endianness.hpp:30
Definition: chdr_types.hpp:638
cfg_payload(payload_t payload_)
Definition: chdr_types.hpp:643
const uint32_t data
Definition: chdr_types.hpp:640
cfg_payload(uint16_t addr_, uint32_t data_=0)
Definition: chdr_types.hpp:642
const uint16_t addr
Definition: chdr_types.hpp:639
An interpretation class for the payload for MGMT_OP_INFO_RESP.
Definition: chdr_types.hpp:656
const uint16_t node_inst
Definition: chdr_types.hpp:659
node_info_payload(payload_t payload_)
Definition: chdr_types.hpp:672
const uint8_t node_type
Definition: chdr_types.hpp:658
const uint32_t ext_info
Definition: chdr_types.hpp:660
const uint16_t device_id
Definition: chdr_types.hpp:657
node_info_payload(uint16_t device_id_, uint8_t node_type_, uint16_t node_inst_, uint32_t ext_info_)
Definition: chdr_types.hpp:662
An interpretation class for the payload for MGMT_OP_SEL_DEST.
Definition: chdr_types.hpp:624
sel_dest_payload(uint16_t dest_)
Definition: chdr_types.hpp:627
const uint16_t dest
Definition: chdr_types.hpp:625
sel_dest_payload(payload_t payload_)
Definition: chdr_types.hpp:628