USRP Hardware Driver and USRP Manual  Version: 4.4.0.HEAD-0-g5fac246b
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 
10 #include <uhd/types/endianness.hpp>
11 #include <uhd/utils/byteswap.hpp>
12 #include <boost/format.hpp>
13 #include <boost/optional.hpp>
14 #include <deque>
15 #include <list>
16 #include <memory>
17 #include <vector>
18 
19 namespace uhd { namespace rfnoc { namespace chdr {
20 
22  PKT_TYPE_MGMT = 0x0,
23  PKT_TYPE_STRS = 0x1,
24  PKT_TYPE_STRC = 0x2,
25  PKT_TYPE_CTRL = 0x4,
28 };
29 
30 //----------------------------------------------------
31 // CHDR Header
32 //----------------------------------------------------
33 
35 {
36 public: // 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 
81  inline packet_type_t get_pkt_type() const
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 
192 private:
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,
244  CMD_CMDERR = 0x1,
245  CMD_TSERR = 0x2,
246  CMD_WARNING = 0x3,
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 {
267 public: // 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 
291 public: // 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 
321  void deserialize(const uint64_t* buff,
322  size_t buff_size,
323  const std::function<uint64_t(uint64_t)>& conv_byte_order);
324 
328  template <endianness_t endianness>
329  void deserialize(const uint64_t* buff, size_t buff_size)
330  {
331  auto conv_byte_order = [](uint64_t x) -> uint64_t {
332  return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx<uint64_t>(x)
333  : uhd::wtohx<uint64_t>(x);
334  };
335  deserialize(buff, buff_size, conv_byte_order);
336  }
337 
339  size_t get_length() const;
340 
341  // Return whether or not we have a valid timestamp
342  bool has_timestamp() const
343  {
344  return bool(timestamp);
345  }
346 
348  bool operator==(const ctrl_payload& rhs) const;
349 
351  inline bool operator!=(const ctrl_payload& rhs) const
352  {
353  return !(*this == rhs);
354  }
355 
357  const std::string to_string() const;
358 
359 private:
360  static constexpr size_t DST_PORT_WIDTH = 10;
361  static constexpr size_t SRC_PORT_WIDTH = 10;
362  static constexpr size_t NUM_DATA_WIDTH = 4;
363  static constexpr size_t SEQ_NUM_WIDTH = 6;
364  static constexpr size_t HAS_TIME_WIDTH = 1;
365  static constexpr size_t IS_ACK_WIDTH = 1;
366  static constexpr size_t SRC_EPID_WIDTH = 16;
367  static constexpr size_t ADDRESS_WIDTH = 20;
368  static constexpr size_t BYTE_ENABLE_WIDTH = 4;
369  static constexpr size_t OPCODE_WIDTH = 4;
370  static constexpr size_t STATUS_WIDTH = 2;
371 
372  // Offsets assume 64-bit alignment
373  static constexpr size_t DST_PORT_OFFSET = 0;
374  static constexpr size_t SRC_PORT_OFFSET = 10;
375  static constexpr size_t NUM_DATA_OFFSET = 20;
376  static constexpr size_t SEQ_NUM_OFFSET = 24;
377  static constexpr size_t HAS_TIME_OFFSET = 30;
378  static constexpr size_t IS_ACK_OFFSET = 31;
379  static constexpr size_t SRC_EPID_OFFSET = 32;
380  static constexpr size_t ADDRESS_OFFSET = 0;
381  static constexpr size_t BYTE_ENABLE_OFFSET = 20;
382  static constexpr size_t OPCODE_OFFSET = 24;
383  static constexpr size_t STATUS_OFFSET = 30;
384  static constexpr size_t LO_DATA_OFFSET = 0;
385  static constexpr size_t HI_DATA_OFFSET = 32;
386 };
387 
388 //----------------------------------------------------
389 // CHDR Stream Status Packet Payload
390 //----------------------------------------------------
391 
393  STRS_OKAY = 0x0,
394  STRS_CMDERR = 0x1,
395  STRS_SEQERR = 0x2,
396  STRS_DATAERR = 0x3,
397  STRS_RTERR = 0x4,
398 };
399 
401 {
402 public: // Members
404  uint16_t src_epid = 0;
408  uint64_t capacity_bytes = 0;
410  uint32_t capacity_pkts = 0;
412  uint64_t xfer_count_bytes = 0;
414  uint64_t xfer_count_pkts = 0;
416  uint16_t buff_info = 0;
418  uint64_t status_info = 0;
419 
420 public: // Functions
421  strs_payload() = default;
422  strs_payload(const strs_payload& rhs) = default;
423  strs_payload(strs_payload&& rhs) = default;
424 
425  strs_payload& operator=(const strs_payload& rhs) = default;
426 
428  void populate_header(chdr_header& header) const;
429 
431  size_t serialize(uint64_t* buff,
432  size_t max_size_bytes,
433  const std::function<uint64_t(uint64_t)>& conv_byte_order) const;
434 
436  template <endianness_t endianness>
437  size_t serialize(uint64_t* buff, size_t max_size_bytes) const
438  {
439  auto conv_byte_order = [](uint64_t x) -> uint64_t {
440  return (endianness == uhd::ENDIANNESS_BIG) ? uhd::htonx<uint64_t>(x)
441  : uhd::htowx<uint64_t>(x);
442  };
443  return serialize(buff, max_size_bytes, conv_byte_order);
444  }
445 
450  void deserialize(const uint64_t* buff,
451  size_t buff_size,
452  const std::function<uint64_t(uint64_t)>& conv_byte_order);
453 
457  template <endianness_t endianness>
458  void deserialize(const uint64_t* buff, size_t buff_size)
459  {
460  auto conv_byte_order = [](uint64_t x) -> uint64_t {
461  return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx<uint64_t>(x)
462  : uhd::wtohx<uint64_t>(x);
463  };
464  deserialize(buff, buff_size, conv_byte_order);
465  }
466 
468  size_t get_length() const;
469 
471  bool operator==(const strs_payload& rhs) const;
472 
474  inline bool operator!=(const strs_payload& rhs) const
475  {
476  return !(*this == rhs);
477  }
478 
480  const std::string to_string() const;
481 
482 private:
483  static constexpr size_t SRC_EPID_WIDTH = 16;
484  static constexpr size_t STATUS_WIDTH = 4;
485  static constexpr size_t CAPACITY_BYTES_WIDTH = 40;
486  static constexpr size_t CAPACITY_PKTS_WIDTH = 24;
487  static constexpr size_t XFER_COUNT_PKTS_WIDTH = 40;
488  static constexpr size_t BUFF_INFO_WIDTH = 16;
489  static constexpr size_t STATUS_INFO_WIDTH = 48;
490 
491  // Offsets assume 64-bit alignment
492  static constexpr size_t SRC_EPID_OFFSET = 0;
493  static constexpr size_t STATUS_OFFSET = 16;
494  static constexpr size_t CAPACITY_BYTES_OFFSET = 24;
495  static constexpr size_t CAPACITY_PKTS_OFFSET = 0;
496  static constexpr size_t XFER_COUNT_PKTS_OFFSET = 24;
497  static constexpr size_t BUFF_INFO_OFFSET = 0;
498  static constexpr size_t STATUS_INFO_OFFSET = 16;
499 };
500 
501 //----------------------------------------------------
502 // CHDR Stream Command Packet Payload
503 //----------------------------------------------------
504 
506  STRC_INIT = 0x0,
507  STRC_PING = 0x1,
508  STRC_RESYNC = 0x2,
509 };
510 
512 {
513 public: // Members
515  uint16_t src_epid = 0;
519  uint8_t op_data = 0;
521  uint64_t num_pkts = 0;
523  uint64_t num_bytes = 0;
525  static constexpr size_t MAX_PACKET_SIZE = 128;
526 
527 public: // Functions
528  strc_payload() = default;
529  strc_payload(const strc_payload& rhs) = default;
530  strc_payload(strc_payload&& rhs) = default;
531 
532  strc_payload& operator=(const strc_payload& rhs) = default;
533 
535  void populate_header(chdr_header& header) const;
536 
538  size_t serialize(uint64_t* buff,
539  size_t max_size_bytes,
540  const std::function<uint64_t(uint64_t)>& conv_byte_order) const;
541 
543  template <endianness_t endianness>
544  size_t serialize(uint64_t* buff, size_t max_size_bytes) const
545  {
546  auto conv_byte_order = [](uint64_t x) -> uint64_t {
547  return (endianness == uhd::ENDIANNESS_BIG) ? uhd::htonx<uint64_t>(x)
548  : uhd::htowx<uint64_t>(x);
549  };
550  return serialize(buff, max_size_bytes, conv_byte_order);
551  }
552 
557  void deserialize(const uint64_t* buff,
558  size_t buff_size,
559  const std::function<uint64_t(uint64_t)>& conv_byte_order);
560 
564  template <endianness_t endianness>
565  void deserialize(const uint64_t* buff, size_t buff_size)
566  {
567  auto conv_byte_order = [](uint64_t x) -> uint64_t {
568  return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx<uint64_t>(x)
569  : uhd::wtohx<uint64_t>(x);
570  };
571  deserialize(buff, buff_size, conv_byte_order);
572  }
573 
575  size_t get_length() const;
576 
578  bool operator==(const strc_payload& rhs) const;
579 
581  inline bool operator!=(const strc_payload& rhs) const
582  {
583  return !(*this == rhs);
584  }
585 
587  const std::string to_string() const;
588 
589 private:
590  static constexpr size_t SRC_EPID_WIDTH = 16;
591  static constexpr size_t OP_CODE_WIDTH = 4;
592  static constexpr size_t OP_DATA_WIDTH = 4;
593  static constexpr size_t NUM_PKTS_WIDTH = 40;
594 
595  // Offsets assume 64-bit alignment
596  static constexpr size_t SRC_EPID_OFFSET = 0;
597  static constexpr size_t OP_CODE_OFFSET = 16;
598  static constexpr size_t OP_DATA_OFFSET = 20;
599  static constexpr size_t NUM_PKTS_OFFSET = 24;
600 };
601 
602 //----------------------------------------------------
603 // CHDR Management Packet Payload
604 //----------------------------------------------------
605 
607 // An operation consists of an operation code and some
608 // payload associated with that operation.
610 {
611 public:
612  // Operation code
613  // Note that a management packet has 8 bits available for op codes. The
614  // values for these enums are used to construct the packets, so these values
615  // must match the values in rfnoc_chdr_internal_utils.vh.
616  enum op_code_t {
618  MGMT_OP_NOP = 0,
620  MGMT_OP_ADVERTISE = 1,
622  MGMT_OP_SEL_DEST = 2,
624  MGMT_OP_RETURN = 3,
626  MGMT_OP_INFO_REQ = 4,
628  MGMT_OP_INFO_RESP = 5,
630  MGMT_OP_CFG_WR_REQ = 6,
632  MGMT_OP_CFG_RD_REQ = 7,
634  MGMT_OP_CFG_RD_RESP = 8
635  };
636 
638  using payload_t = uint64_t;
639 
642  {
643  const uint16_t dest;
644 
645  sel_dest_payload(uint16_t dest_) : dest(dest_) {}
646  sel_dest_payload(payload_t payload_) : dest(static_cast<uint16_t>(payload_)) {}
647  operator payload_t() const
648  {
649  return static_cast<payload_t>(dest);
650  }
651  };
652 
655  struct cfg_payload
656  {
657  const uint16_t addr;
658  const uint32_t data;
659 
660  cfg_payload(uint16_t addr_, uint32_t data_ = 0) : addr(addr_), data(data_) {}
662  : addr(static_cast<uint16_t>(payload_ >> 0))
663  , data(static_cast<uint32_t>(payload_ >> 16))
664  {
665  }
666  operator payload_t() const
667  {
668  return ((static_cast<payload_t>(data) << 16) | static_cast<payload_t>(addr));
669  }
670  };
671 
674  {
675  const uint16_t device_id;
676  const uint8_t node_type;
677  const uint16_t node_inst;
678  const uint32_t ext_info;
679 
680  node_info_payload(uint16_t device_id_,
681  uint8_t node_type_,
682  uint16_t node_inst_,
683  uint32_t ext_info_)
684  : device_id(device_id_)
685  , node_type(node_type_)
686  , node_inst(node_inst_)
687  , ext_info(ext_info_)
688  {
689  }
691  : device_id(static_cast<uint16_t>(payload_ >> 0))
692  , node_type(static_cast<uint8_t>((payload_ >> 16) & 0xF))
693  , node_inst(static_cast<uint16_t>((payload_ >> 20) & 0x3FF))
694  , ext_info(static_cast<uint32_t>((payload_ >> 30) & 0x3FFFF))
695  {
696  }
697  operator payload_t() const
698  {
699  return ((static_cast<payload_t>(device_id) << 0)
700  | (static_cast<payload_t>(node_type & 0xF) << 16)
701  | (static_cast<payload_t>(node_inst & 0x3FF) << 20)
702  | (static_cast<payload_t>(ext_info & 0x3FFFF) << 30));
703  }
704  };
705 
706  mgmt_op_t(const op_code_t op_code, const payload_t op_payload = 0,
707  const uint8_t ops_pending = 0)
708  : _op_code(op_code), _op_payload(op_payload), _ops_pending(ops_pending)
709  {
710  }
711  mgmt_op_t(const mgmt_op_t& rhs) = default;
712 
714  // Note that ops_pending is not used by UHD, since it can infer this value
715  // from the ops vector in mgmt_hop_t. It is needed only by the CHDR
716  // dissector.
717  inline uint8_t get_ops_pending() const
718  {
719  return _ops_pending;
720  }
721 
723  inline op_code_t get_op_code() const
724  {
725  return _op_code;
726  }
727 
729  inline uint64_t get_op_payload() const
730  {
731  return _op_payload;
732  }
733 
735  inline bool operator==(const mgmt_op_t& rhs) const
736  {
737  return (_op_code == rhs._op_code) && (_op_payload == rhs._op_payload);
738  }
739 
741  const std::string to_string() const;
742 
743 private:
744  op_code_t _op_code;
745  payload_t _op_payload;
746  uint8_t _ops_pending;
747 };
748 
750 // A hop is a collection for management transactions for
751 // a single node.
753 {
754 public:
755  mgmt_hop_t() = default;
756  mgmt_hop_t(const mgmt_hop_t& rhs) = default;
757 
759  // Operations are added to the hop in FIFO order and executed in FIFO order.
760  inline void add_op(const mgmt_op_t& op)
761  {
762  _ops.push_back(op);
763  }
764 
766  inline size_t get_num_ops() const
767  {
768  return _ops.size();
769  }
770 
772  inline const mgmt_op_t& get_op(size_t i) const
773  {
774  return _ops.at(i);
775  }
776 
778  // The RFNoC Specification section 2.2.6 specifies that for chdr widths
779  // greater than 64, all MSBs are 0, so we pad out the hop based on the width
780  size_t serialize(std::vector<uint64_t>& target,
781  const std::function<uint64_t(uint64_t)>& conv_byte_order,
782  const size_t padding_size) const;
783 
785  // The RFNoC Specification section 2.2.6 specifies that for chdr widths
786  // greater than 64, all MSBs are 0, so we remove padding based on the width
787  void deserialize(std::list<uint64_t>& src,
788  const std::function<uint64_t(uint64_t)>& conv_byte_order,
789  const size_t padding_size);
790 
792  inline bool operator==(const mgmt_hop_t& rhs) const
793  {
794  return _ops == rhs._ops;
795  }
796 
798  const std::string to_string() const;
799 
800 private:
801  std::vector<mgmt_op_t> _ops;
802 };
803 
805 // A transaction is a collection of hops, where each hop is a collection
806 // of management transactions.
808 {
809 public:
810  mgmt_payload() = default;
811  mgmt_payload(const mgmt_payload& rhs) = default;
812  mgmt_payload(mgmt_payload&& rhs) = default;
813 
814  mgmt_payload& operator=(const mgmt_payload& rhs) = default;
815 
816  inline void set_header(sep_id_t src_epid, uint16_t protover, chdr_w_t chdr_w)
817  {
818  set_src_epid(src_epid);
819  set_chdr_w(chdr_w);
820  set_proto_ver(protover);
821  }
822 
824  // Hops are added to the hop in FIFO order and executed in FIFO order.
825  inline void add_hop(const mgmt_hop_t& hop)
826  {
827  _hops.push_back(hop);
828  }
829 
831  inline size_t get_num_hops() const
832  {
833  return _hops.size();
834  }
835 
837  inline const mgmt_hop_t& get_hop(size_t i) const
838  {
839  return _hops.at(i);
840  }
841 
844  {
845  auto hop = _hops.front();
846  _hops.pop_front();
847  return hop;
848  }
849 
850  inline size_t get_size_bytes() const
851  {
852  size_t num_lines = 1; /* header */
853  for (const auto& hop : _hops) {
854  num_lines += hop.get_num_ops();
855  }
856  return num_lines * (chdr_w_to_bits(_chdr_w) / 8);
857  }
858 
860  void populate_header(chdr_header& header) const;
861 
863  size_t serialize(uint64_t* buff,
864  size_t max_size_bytes,
865  const std::function<uint64_t(uint64_t)>& conv_byte_order) const;
866 
868  template <endianness_t endianness>
869  size_t serialize(uint64_t* buff, size_t max_size_bytes) const
870  {
871  auto conv_byte_order = [](uint64_t x) -> uint64_t {
872  return (endianness == uhd::ENDIANNESS_BIG) ? uhd::htonx<uint64_t>(x)
873  : uhd::htowx<uint64_t>(x);
874  };
875  return serialize(buff, max_size_bytes, conv_byte_order);
876  }
877 
882  void deserialize(const uint64_t* buff,
883  size_t buff_size,
884  const std::function<uint64_t(uint64_t)>& conv_byte_order);
885 
889  template <endianness_t endianness>
890  void deserialize(const uint64_t* buff, size_t buff_size)
891  {
892  auto conv_byte_order = [](uint64_t x) -> uint64_t {
893  return (endianness == uhd::ENDIANNESS_BIG) ? uhd::ntohx<uint64_t>(x)
894  : uhd::wtohx<uint64_t>(x);
895  };
896  deserialize(buff, buff_size, conv_byte_order);
897  }
898 
900  size_t get_length() const;
901 
903  const std::string to_string() const;
904 
906  const std::string hops_to_string() const;
907 
909  inline sep_id_t get_src_epid() const
910  {
911  return _src_epid;
912  }
913 
915  inline void set_src_epid(sep_id_t src_epid)
916  {
917  _src_epid = src_epid;
918  }
919 
921  bool operator==(const mgmt_payload& rhs) const;
922 
924  inline chdr_w_t get_chdr_w() const
925  {
926  return _chdr_w;
927  }
928 
930  inline void set_chdr_w(chdr_w_t chdr_w)
931  {
932  _chdr_w = chdr_w;
933  _padding_size = (chdr_w_to_bits(_chdr_w) / 64) - 1;
934  }
935 
937  inline uint16_t get_proto_ver() const
938  {
939  return _protover;
940  }
941 
943  inline void set_proto_ver(uint16_t proto_ver)
944  {
945  _protover = proto_ver;
946  }
947 
948 private:
949  sep_id_t _src_epid = 0;
950  uint16_t _protover = 0;
951  chdr_w_t _chdr_w = CHDR_W_64;
952  size_t _padding_size = 0;
953  std::deque<mgmt_hop_t> _hops;
954 };
955 
957 template <typename payload_t>
959 
960 template <>
962 {
963  return PKT_TYPE_CTRL;
964 }
965 
966 template <>
968 {
969  return PKT_TYPE_MGMT;
970 }
971 
972 template <>
974 {
975  return PKT_TYPE_STRC;
976 }
977 
978 template <>
980 {
981  return PKT_TYPE_STRS;
982 }
983 
984 }}} // namespace uhd::rfnoc::chdr
uhd::rfnoc::chdr::chdr_header::pack
uint64_t pack() const
Pack the header into a uint64_t.
Definition: chdr_types.hpp:141
uhd::rfnoc::chdr::CMD_TSERR
@ CMD_TSERR
Slave asserted a command error.
Definition: chdr_types.hpp:245
uhd::rfnoc::chdr::OP_USER4
@ OP_USER4
Definition: chdr_types.hpp:260
uhd::rfnoc::chdr::OP_SLEEP
@ OP_SLEEP
Definition: chdr_types.hpp:250
uhd::rfnoc::chdr::chdr_header::set_vc
void set_vc(uint8_t vc)
Set the virtual channel field (6 bits)
Definition: chdr_types.hpp:51
uhd::rfnoc::chdr::OP_READ_WRITE
@ OP_READ_WRITE
Definition: chdr_types.hpp:253
uhd::rfnoc::chdr::strs_payload
Definition: chdr_types.hpp:400
uhd::rfnoc::chdr::mgmt_op_t::node_info_payload::node_type
const uint8_t node_type
Definition: chdr_types.hpp:676
uhd::rfnoc::chdr::mgmt_hop_t::get_num_ops
size_t get_num_ops() const
Get the number of management operations in this hop.
Definition: chdr_types.hpp:766
uhd::rfnoc::chdr::payload_to_packet_type< strc_payload >
constexpr packet_type_t payload_to_packet_type< strc_payload >()
Definition: chdr_types.hpp:973
uhd::rfnoc::chdr::STRC_RESYNC
@ STRC_RESYNC
Trigger a stream status response.
Definition: chdr_types.hpp:508
uhd::rfnoc::chdr::chdr_header::set_eob
void set_eob(bool eob)
Set the end-of-burst flag (1 bit)
Definition: chdr_types.hpp:63
uhd::rfnoc::chdr::mgmt_op_t
A class that represents a single management operation.
Definition: chdr_types.hpp:609
uhd::rfnoc::chdr::ctrl_payload::serialize
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
uhd::rfnoc::chdr::chdr_header::operator=
const chdr_header & operator=(const uint64_t &rhs)
Assignment operator (=) from a uint64_t.
Definition: chdr_types.hpp:172
uhd::rfnoc::chdr::ctrl_payload::deserialize
void deserialize(const uint64_t *buff, size_t buff_size)
Definition: chdr_types.hpp:329
uhd::rfnoc::chdr::mgmt_payload::serialize
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:869
uhd::rfnoc::chdr::PKT_TYPE_CTRL
@ PKT_TYPE_CTRL
Stream Command.
Definition: chdr_types.hpp:25
uhd::rfnoc::chdr::chdr_header::to_string
const std::string to_string() const
Return a string representation of this object.
Definition: chdr_types.hpp:179
uhd::rfnoc::chdr::mgmt_op_t::cfg_payload::data
const uint32_t data
Definition: chdr_types.hpp:658
byteswap.hpp
uhd::rfnoc::chdr::ctrl_payload
Definition: chdr_types.hpp:265
uhd::rfnoc::chdr::mgmt_op_t::cfg_payload::cfg_payload
cfg_payload(payload_t payload_)
Definition: chdr_types.hpp:661
uhd::rfnoc::chdr::mgmt_payload::get_num_hops
size_t get_num_hops() const
Get the number of management hops in this hop.
Definition: chdr_types.hpp:831
uhd::rfnoc::chdr::OP_USER2
@ OP_USER2
Definition: chdr_types.hpp:258
uhd::rfnoc::chdr::STRC_PING
@ STRC_PING
Initialize stream.
Definition: chdr_types.hpp:507
uhd::rfnoc::chdr_w_to_bits
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
uhd::rfnoc::chdr::mgmt_op_t::cfg_payload::addr
const uint16_t addr
Definition: chdr_types.hpp:657
uhd::rfnoc::CHDR_W_64
@ CHDR_W_64
Definition: rfnoc_types.hpp:19
uhd::rfnoc::chdr::chdr_header::set_dst_epid
void set_dst_epid(uint16_t dst_epid)
Set the destination EPID field (16 bits)
Definition: chdr_types.hpp:135
endianness.hpp
uhd::rfnoc::chdr::chdr_header::set_pkt_type
void set_pkt_type(packet_type_t pkt_type)
Set the packet type field (3 bits)
Definition: chdr_types.hpp:87
uhd::rfnoc::chdr::mgmt_op_t::node_info_payload::device_id
const uint16_t device_id
Definition: chdr_types.hpp:675
uhd::rfnoc::chdr::mgmt_hop_t::operator==
bool operator==(const mgmt_hop_t &rhs) const
Comparison operator (==)
Definition: chdr_types.hpp:792
uhd::rfnoc::chdr::OP_USER3
@ OP_USER3
Definition: chdr_types.hpp:259
uhd::rfnoc::chdr::STRS_RTERR
@ STRS_RTERR
Data integrity check failed.
Definition: chdr_types.hpp:397
uhd::rfnoc::chdr::ctrl_payload::has_timestamp
bool has_timestamp() const
Definition: chdr_types.hpp:342
uhd::rfnoc::chdr::mgmt_payload::set_src_epid
void set_src_epid(sep_id_t src_epid)
Set the source EPID for this transaction.
Definition: chdr_types.hpp:915
uhd::rfnoc::chdr::mgmt_op_t::node_info_payload::ext_info
const uint32_t ext_info
Definition: chdr_types.hpp:678
uhd::rfnoc::chdr::chdr_header::set_eov
void set_eov(bool eov)
Set the end-of-vector flag (1 bit)
Definition: chdr_types.hpp:75
uhd::rfnoc::chdr::mgmt_op_t::op_code_t
op_code_t
Definition: chdr_types.hpp:616
uhd::rfnoc::chdr::chdr_header::set_length
void set_length(uint16_t length)
Set the packet length field (16 bits)
Definition: chdr_types.hpp:123
uhd::rfnoc::chdr::mgmt_payload::set_proto_ver
void set_proto_ver(uint16_t proto_ver)
Set the protocol version for this transaction.
Definition: chdr_types.hpp:943
uhd::rfnoc::chdr::chdr_header::get_eov
bool get_eov() const
Get the end-of-vector flag (1 bit)
Definition: chdr_types.hpp:69
uhd::ENDIANNESS_BIG
@ ENDIANNESS_BIG
Definition: endianness.hpp:34
uhd::rfnoc::chdr::mgmt_op_t::sel_dest_payload::dest
const uint16_t dest
Definition: chdr_types.hpp:643
uhd::rfnoc::chdr::chdr_header::set_num_mdata
void set_num_mdata(uint8_t num_mdata)
Set number of metadata words field (5 bits)
Definition: chdr_types.hpp:99
uhd::rfnoc::chdr::mgmt_hop_t::add_op
void add_op(const mgmt_op_t &op)
Add a management operation to this hop.
Definition: chdr_types.hpp:760
uhd::operator==
UHD_API bool operator==(const time_spec_t &, const time_spec_t &)
Implement equality_comparable interface.
uhd::rfnoc::chdr::mgmt_payload::add_hop
void add_hop(const mgmt_hop_t &hop)
Add a management hop to this transaction.
Definition: chdr_types.hpp:825
UHD_API
#define UHD_API
Definition: config.h:87
uhd::rfnoc::chdr::STRS_OKAY
@ STRS_OKAY
Definition: chdr_types.hpp:393
uhd::rfnoc::chdr::mgmt_op_t::node_info_payload::node_inst
const uint16_t node_inst
Definition: chdr_types.hpp:677
uhd::rfnoc::chdr::mgmt_op_t::operator==
bool operator==(const mgmt_op_t &rhs) const
Comparison operator (==)
Definition: chdr_types.hpp:735
uhd::rfnoc::chdr::chdr_header::operator!=
bool operator!=(const chdr_header &rhs) const
Comparison operator (!=)
Definition: chdr_types.hpp:159
uhd::rfnoc::chdr::mgmt_op_t::mgmt_op_t
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:706
uhd::rfnoc::chdr::strc_payload::deserialize
void deserialize(const uint64_t *buff, size_t buff_size)
Definition: chdr_types.hpp:565
uhd::rfnoc::chdr::chdr_header::get_num_mdata
uint8_t get_num_mdata() const
Get number of metadata words field (5 bits)
Definition: chdr_types.hpp:93
uhd::rfnoc::chdr::strc_payload::serialize
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:544
uhd::rfnoc::chdr::strs_payload::deserialize
void deserialize(const uint64_t *buff, size_t buff_size)
Definition: chdr_types.hpp:458
uhd::rfnoc::sep_id_t
uint16_t sep_id_t
Stream Endpoint ID Type.
Definition: rfnoc_types.hpp:73
uhd::rfnoc::chdr::CMD_WARNING
@ CMD_WARNING
Slave asserted a time stamp error.
Definition: chdr_types.hpp:246
uhd::rfnoc::chdr::mgmt_op_t::get_op_payload
uint64_t get_op_payload() const
Get the payload for this transaction.
Definition: chdr_types.hpp:729
uhd::rfnoc::chdr::strc_op_code_t
strc_op_code_t
Definition: chdr_types.hpp:505
uhd::rfnoc::chdr::PKT_TYPE_MGMT
@ PKT_TYPE_MGMT
Definition: chdr_types.hpp:22
uhd::rfnoc::chdr::mgmt_op_t::sel_dest_payload::sel_dest_payload
sel_dest_payload(payload_t payload_)
Definition: chdr_types.hpp:646
uhd::rfnoc::chdr::STRS_CMDERR
@ STRS_CMDERR
No error.
Definition: chdr_types.hpp:394
uhd::rfnoc::chdr::strc_payload
Definition: chdr_types.hpp:511
uhd::rfnoc::chdr::payload_to_packet_type
constexpr packet_type_t payload_to_packet_type()
Conversion from payload_t to pkt_type.
uhd::rfnoc::chdr::chdr_header::get_pkt_type
packet_type_t get_pkt_type() const
Get the packet type field (3 bits)
Definition: chdr_types.hpp:81
uhd::rfnoc::chdr::OP_BLOCK_WRITE
@ OP_BLOCK_WRITE
Definition: chdr_types.hpp:254
uhd::rfnoc::chdr::OP_POLL
@ OP_POLL
Definition: chdr_types.hpp:256
uhd::rfnoc::chdr::payload_to_packet_type< ctrl_payload >
constexpr packet_type_t payload_to_packet_type< ctrl_payload >()
Definition: chdr_types.hpp:961
uhd::rfnoc::chdr::OP_WRITE
@ OP_WRITE
Definition: chdr_types.hpp:251
uhd::rfnoc::chdr::strs_status_t
strs_status_t
Definition: chdr_types.hpp:392
uhd::rfnoc::chdr::chdr_header::operator=
const chdr_header & operator=(const chdr_header &rhs)
Assignment operator (=) from a chdr_header.
Definition: chdr_types.hpp:165
uhd::rfnoc::chdr::PKT_TYPE_DATA_WITH_TS
@ PKT_TYPE_DATA_WITH_TS
Data Packet without TimeStamp.
Definition: chdr_types.hpp:27
uhd::rfnoc::chdr::chdr_header::get_seq_num
uint16_t get_seq_num() const
Get the sequence number field (16 bits)
Definition: chdr_types.hpp:105
uhd::rfnoc::chdr::STRS_DATAERR
@ STRS_DATAERR
Packet out of sequence (sequence error)
Definition: chdr_types.hpp:396
uhd::rfnoc::chdr::ctrl_opcode_t
ctrl_opcode_t
Definition: chdr_types.hpp:249
uhd
Definition: build_info.hpp:12
uhd::rfnoc::chdr::CMD_CMDERR
@ CMD_CMDERR
Transaction successful.
Definition: chdr_types.hpp:244
uhd::rfnoc::chdr::mgmt_op_t::node_info_payload
An interpretation class for the payload for MGMT_OP_INFO_RESP.
Definition: chdr_types.hpp:673
uhd::rfnoc::chdr::payload_to_packet_type< mgmt_payload >
constexpr packet_type_t payload_to_packet_type< mgmt_payload >()
Definition: chdr_types.hpp:967
uhd::rfnoc::chdr::packet_type_t
packet_type_t
Definition: chdr_types.hpp:21
uhd::rfnoc::chdr::mgmt_op_t::payload_t
uint64_t payload_t
The payload for an operation is 48 bits wide.
Definition: chdr_types.hpp:638
uhd::rfnoc::chdr::mgmt_op_t::get_op_code
op_code_t get_op_code() const
Get the op-code for this transaction.
Definition: chdr_types.hpp:723
uhd::rfnoc::chdr::mgmt_hop_t
A class that represents a single management hop.
Definition: chdr_types.hpp:752
uhd::rfnoc::chdr::mgmt_op_t::cfg_payload
Definition: chdr_types.hpp:655
uhd::rfnoc::chdr::strs_payload::operator!=
bool operator!=(const strs_payload &rhs) const
Comparison operator (!=)
Definition: chdr_types.hpp:474
uhd::rfnoc::chdr::mgmt_payload::set_header
void set_header(sep_id_t src_epid, uint16_t protover, chdr_w_t chdr_w)
Definition: chdr_types.hpp:816
uhd::rfnoc::chdr::chdr_header::chdr_header
chdr_header()=default
uhd::rfnoc::chdr::STRC_INIT
@ STRC_INIT
Definition: chdr_types.hpp:506
uhd::rfnoc::chdr::PKT_TYPE_STRC
@ PKT_TYPE_STRC
Stream status.
Definition: chdr_types.hpp:24
uhd::rfnoc::chdr::ctrl_payload::operator!=
bool operator!=(const ctrl_payload &rhs) const
Comparison operator (!=)
Definition: chdr_types.hpp:351
rfnoc_types.hpp
uhd::rfnoc::chdr::OP_USER1
@ OP_USER1
Definition: chdr_types.hpp:257
uhd::rfnoc::chdr::chdr_header::operator==
bool operator==(const chdr_header &rhs) const
Comparison operator (==)
Definition: chdr_types.hpp:153
uhd::rfnoc::chdr::mgmt_payload::get_chdr_w
chdr_w_t get_chdr_w() const
Return the CHDR_W for this transaction.
Definition: chdr_types.hpp:924
uhd::rfnoc::chdr::STRS_SEQERR
@ STRS_SEQERR
A stream command signalled an error.
Definition: chdr_types.hpp:395
uhd::rfnoc::chdr::mgmt_payload::get_proto_ver
uint16_t get_proto_ver() const
Return the protocol version for this transaction.
Definition: chdr_types.hpp:937
uhd::rfnoc::chdr::mgmt_payload::set_chdr_w
void set_chdr_w(chdr_w_t chdr_w)
Set the CHDR_W for this transaction.
Definition: chdr_types.hpp:930
uhd::rfnoc::chdr::chdr_header
Definition: chdr_types.hpp:34
uhd::rfnoc::chdr::PKT_TYPE_DATA_NO_TS
@ PKT_TYPE_DATA_NO_TS
Control Transaction.
Definition: chdr_types.hpp:26
uhd::rfnoc::chdr::OP_USER6
@ OP_USER6
Definition: chdr_types.hpp:262
uhd::rfnoc::chdr::strs_payload::serialize
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:437
uhd::rfnoc::chdr::strc_payload::operator!=
bool operator!=(const strc_payload &rhs) const
Comparison operator (!=)
Definition: chdr_types.hpp:581
uhd::rfnoc::chdr::chdr_header::get_dst_epid
uint16_t get_dst_epid() const
Get the destination EPID field (16 bits)
Definition: chdr_types.hpp:129
uhd::rfnoc::chdr::ctrl_status_t
ctrl_status_t
Definition: chdr_types.hpp:242
uhd::rfnoc::chdr::mgmt_op_t::sel_dest_payload::sel_dest_payload
sel_dest_payload(uint16_t dest_)
Definition: chdr_types.hpp:645
uhd::rfnoc::chdr::OP_USER5
@ OP_USER5
Definition: chdr_types.hpp:261
uhd::rfnoc::chdr::mgmt_payload::get_hop
const mgmt_hop_t & get_hop(size_t i) const
Get the n'th hop in the transaction.
Definition: chdr_types.hpp:837
uhd::rfnoc::chdr::OP_READ
@ OP_READ
Definition: chdr_types.hpp:252
uhd::rfnoc::chdr::chdr_header::get_length
uint16_t get_length() const
Get the packet length field (16 bits)
Definition: chdr_types.hpp:117
uhd::rfnoc::chdr::chdr_header::set_seq_num
void set_seq_num(uint16_t seq_num)
Set the sequence number field (16 bits)
Definition: chdr_types.hpp:111
uhd::rfnoc::chdr::mgmt_op_t::node_info_payload::node_info_payload
node_info_payload(payload_t payload_)
Definition: chdr_types.hpp:690
uhd::rfnoc::chdr::mgmt_payload
A class that represents a complete multi-hop management transaction.
Definition: chdr_types.hpp:807
uhd::rfnoc::chdr::mgmt_payload::get_size_bytes
size_t get_size_bytes() const
Definition: chdr_types.hpp:850
uhd::rfnoc::chdr::mgmt_op_t::node_info_payload::node_info_payload
node_info_payload(uint16_t device_id_, uint8_t node_type_, uint16_t node_inst_, uint32_t ext_info_)
Definition: chdr_types.hpp:680
uhd::rfnoc::chdr::PKT_TYPE_STRS
@ PKT_TYPE_STRS
Management packet.
Definition: chdr_types.hpp:23
uhd::rfnoc::chdr::mgmt_payload::deserialize
void deserialize(const uint64_t *buff, size_t buff_size)
Definition: chdr_types.hpp:890
uhd::rfnoc::chdr::chdr_header::get_vc
uint8_t get_vc() const
Get the virtual channel field (6 bits)
Definition: chdr_types.hpp:45
uhd::soft_reg_field::width
UHD_INLINE size_t width(const soft_reg_field_t field)
Definition: soft_register.hpp:75
uhd::rfnoc::chdr::CMD_OKAY
@ CMD_OKAY
Definition: chdr_types.hpp:243
uhd::rfnoc::chdr::mgmt_op_t::get_ops_pending
uint8_t get_ops_pending() const
Get the ops pending for this transaction.
Definition: chdr_types.hpp:717
uhd::rfnoc::chdr::chdr_header::chdr_header
chdr_header(uint64_t flat_hdr)
Unpack the header from a uint64_t.
Definition: chdr_types.hpp:42
uhd::rfnoc::chdr::mgmt_hop_t::get_op
const mgmt_op_t & get_op(size_t i) const
Get the n'th operation in the hop.
Definition: chdr_types.hpp:772
uhd::rfnoc::chdr::OP_BLOCK_READ
@ OP_BLOCK_READ
Definition: chdr_types.hpp:255
uhd::rfnoc::chdr::mgmt_payload::pop_hop
mgmt_hop_t pop_hop()
Pop the first hop of the transaction and return it.
Definition: chdr_types.hpp:843
uhd::rfnoc::chdr::payload_to_packet_type< strs_payload >
constexpr packet_type_t payload_to_packet_type< strs_payload >()
Definition: chdr_types.hpp:979
uhd::rfnoc::chdr::chdr_header::get_eob
bool get_eob() const
Get the end-of-burst flag (1 bit)
Definition: chdr_types.hpp:57
uhd::rfnoc::chdr::mgmt_op_t::sel_dest_payload
An interpretation class for the payload for MGMT_OP_SEL_DEST.
Definition: chdr_types.hpp:641
uhd::rfnoc::chdr::mgmt_op_t::cfg_payload::cfg_payload
cfg_payload(uint16_t addr_, uint32_t data_=0)
Definition: chdr_types.hpp:660
uhd::rfnoc::chdr_w_t
chdr_w_t
Type that indicates the CHDR Width in bits.
Definition: rfnoc_types.hpp:19
uhd::rfnoc::chdr::mgmt_payload::get_src_epid
sep_id_t get_src_epid() const
Return the source EPID for this transaction.
Definition: chdr_types.hpp:909