+/**
+ * Build debugging infra unconditionally. Debug components controlled via
+ * debug configuration. Comes with some overhead so it's not recommended for
+ * production/performance scenarios. Takes priority over TCP_DEBUG_ENABLE.
+ */
+#define TCP_DEBUG_ALWAYS (0)
+/**
+ * Build debugging infra only if enabled. Debug components controlled via
+ * macros that follow.
+ */
+#define TCP_DEBUG_ENABLE (0)
+
+#define TCP_DEBUG_SM (0)
+#define TCP_DEBUG_CC (0)
+#define TCP_DEBUG_CS (0)
+#define TCP_DEBUG_LC (0 || TCP_DEBUG_SM || TCP_DEBUG_CC || TCP_DEBUG_CS)
+
+#define TCP_DEBUG (TCP_DEBUG_ALWAYS || TCP_DEBUG_ENABLE)
+#define TCP_DEBUG_BUF_ALLOC (0)
+
+#if TCP_DEBUG > 0
+#define TRANSPORT_DEBUG (1)
+#endif
+
+#define TCP_CONCAT_HELPER(_a, _b) _a##_b
+#define TCP_CC(_a, _b) TCP_CONCAT_HELPER(_a, _b)
+
+#define tcp_evt_lvl(_evt) TCP_CC(_evt, _LVL)
+#define tcp_evt_grp(_evt) TCP_CC(_evt, _GRP)
+#define tcp_evt_handler(_evt, _args...) TCP_CC(_evt, _HANDLER) (_args)
+#define tcp_evt_grp_dbg_lvl(_evt) tcp_dbg_main.grp_dbg_lvl[tcp_evt_grp (_evt)]
+
+#define foreach_tcp_evt_grp \
+ _(LC, "life cycle") \
+ _(SM, "state machine") \
+ _(CC, "congestion control") \
+ _(CS, "cc stats") \
+
+typedef enum tcp_evt_grp_
+{
+#define _(sym, str) TCP_EVT_GRP_ ## sym,
+ foreach_tcp_evt_grp
+#undef _
+ TCP_EVT_N_GRP
+} tcp_evt_grp_e;
+
+typedef struct tcp_dbg_main_
+{
+ u8 grp_dbg_lvl[TCP_EVT_N_GRP];
+ u32 *free_track_indices;
+} tcp_dbg_main_t;
+
+extern tcp_dbg_main_t tcp_dbg_main;
+
+#define foreach_tcp_dbg_evt \
+ _(INIT, LC, 1, "init") \
+ _(DEALLOC, LC, 1, "dealloc") \
+ _(OPEN, LC, 1, "open") \
+ _(CLOSE, LC, 1, "close") \
+ _(BIND, LC, 1, "bind") \
+ _(UNBIND, LC, 1, "unbind") \
+ _(DELETE, LC, 1, "delete") \
+ _(SYN_RCVD, LC, 1, "SYN rcvd") \
+ _(STATE_CHANGE, LC, 1, "state change") \
+ _(SYN_SENT, SM, 1, "SYN sent") \
+ _(SYN_RXT, SM, 1, "SYN retransmit") \
+ _(SYNACK_SENT, SM, 1, "SYNACK sent") \
+ _(SYNACK_RCVD, SM, 1, "SYNACK rcvd") \
+ _(FIN_SENT, SM, 1, "FIN sent") \
+ _(FIN_RCVD, SM, 1, "FIN rcvd") \
+ _(RST_SENT, SM, 1, "RST sent") \
+ _(RST_RCVD, SM, 1, "RST rcvd") \
+ _(TIMER_POP, SM, 1, "timer pop") \
+ _(SEG_INVALID, SM, 2, "invalid segment") \
+ _(PAWS_FAIL, SM, 2, "failed paws check") \
+ _(ACK_RCV_ERR, SM, 2, "invalid ack") \
+ _(RCV_WND_SHRUNK, SM, 2, "shrunk rcv_wnd") \
+ _(ACK_SENT, SM, 3, "ACK sent") \
+ _(ACK_RCVD, SM, 3, "ACK rcvd") \
+ _(PKTIZE, SM, 3, "packetize") \
+ _(INPUT, SM, 3, "in") \
+ _(OUTPUT, SM, 4, "output") \
+ _(SND_WND, SM, 4, "snd_wnd update") \
+ _(CC_EVT, CC, 1, "cc event") \
+ _(CC_RTX, CC, 2, "retransmit") \
+ _(CC_PACK, CC, 2, "cc partial ack") \
+ _(DUPACK_SENT, CC, 2, "DUPACK sent") \
+ _(DUPACK_RCVD, CC, 2, "DUPACK rcvd") \
+ _(CC_SCOREBOARD, CC, 2, "scoreboard stats") \
+ _(CC_SACKS, CC, 2, "snd sacks stats") \
+ _(CC_INPUT, CC, 2, "ooo data delivered") \
+ _(CC_STAT, CS, 1, "cc stats") \
+ _(CC_RTO_STAT, CS, 1, "cc rto stats") \
+
+typedef enum tcp_evt_types_
+{
+#define _(sym, grp, lvl, str) TCP_EVT_##sym,
+ foreach_tcp_dbg_evt
+#undef _
+} tcp_evt_types_e;
+
+typedef enum tcp_evt_lvl_