git: 76d0a25be397 - main - aq(4): add a runtime dev.aq.N.debug trace control

From: Adrian Chadd <adrian_at_FreeBSD.org>
Date: Sat, 20 Jun 2026 19:10:42 UTC
The branch main has been updated by adrian:

URL: https://cgit.FreeBSD.org/src/commit/?id=76d0a25be3976634631bab975f4c2ddbc98f72a2

commit 76d0a25be3976634631bab975f4c2ddbc98f72a2
Author:     Nick Price <nick@spun.io>
AuthorDate: 2026-06-20 19:03:28 +0000
Commit:     Adrian Chadd <adrian@FreeBSD.org>
CommitDate: 2026-06-20 19:10:16 +0000

    aq(4): add a runtime dev.aq.N.debug trace control
    
    The trace_* family (trace/trace_error/trace_warn/trace_detail, used in the
    F/W and init/config paths) was gated behind the compile-time
    AQ_CFG_DEBUG_LVL, which is 0, so the dbg_level_/dbg_categories_ runtime
    variables were dead and tracing could only be enabled by recompiling.
    
    Decouple trace_base_ from AQ_CFG_DEBUG_LVL so it is always compiled and
    gated purely at runtime on dbg_level_/dbg_categories_, make those two
    variables writable (no longer const, default level 0 = off), and expose
    them as dev.aq.N.debug (verbosity) and dev.aq.N.debug_categories
    (subsystem mask) sysctls.
    
    The datapath-heavy AQ_DBG_ENTER/PRINT/DUMP macros and the trace_aq_*_descr
    descriptor dumps stay behind AQ_CFG_DEBUG_LVL (still 0), so the per-packet
    paths are untouched -- trace_* is only used off the datapath.  The two
    variables are global (the trace macros reference them directly), so the
    per-device sysctls share one backing store, which is fine for a debug
    knob.
    
    Validated on AQC107: dev.aq.0.debug defaults to 0 with no trace output;
    setting it to 6 emits the F/W init/reset/capabilities traces on the next
    F/W operation; setting it back to 0 silences them; traffic unaffected at
    line rate, rx_err=0.
    
    Reviewed by:    adrian
    Differential Revision:  https://reviews.freebsd.org/D57440
---
 sys/dev/aq/aq_dbg.c  |  4 ++--
 sys/dev/aq/aq_dbg.h  | 10 +++-------
 sys/dev/aq/aq_main.c |  8 ++++++++
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/sys/dev/aq/aq_dbg.c b/sys/dev/aq/aq_dbg.c
index ec3954185749..86e8fb9cc82a 100644
--- a/sys/dev/aq/aq_dbg.c
+++ b/sys/dev/aq/aq_dbg.c
@@ -45,8 +45,8 @@ __FBSDID("$FreeBSD$");
 #include "aq_dbg.h"
 
 
-const enum aq_debug_level dbg_level_ = lvl_detail;
-const uint32_t dbg_categories_ = dbg_init | dbg_config | dbg_fw;
+int dbg_level_ = 0;
+uint32_t dbg_categories_ = dbg_init | dbg_config | dbg_tx | dbg_rx | dbg_intr | dbg_fw;
 
 
 
diff --git a/sys/dev/aq/aq_dbg.h b/sys/dev/aq/aq_dbg.h
index 280572e7d5da..7b546d4f3d78 100644
--- a/sys/dev/aq/aq_dbg.h
+++ b/sys/dev/aq/aq_dbg.h
@@ -109,16 +109,12 @@ enum aq_debug_category
 
 #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
 
-extern const enum aq_debug_level dbg_level_;
-extern const uint32_t dbg_categories_;
+extern int dbg_level_;
+extern uint32_t dbg_categories_;
 
 #define log_base_(_lvl, _fmt, args...) printf( "atlantic: " _fmt "\n", ##args)
 
-#if AQ_CFG_DEBUG_LVL > 0
-#define trace_base_(_lvl, _cat, _fmt, args...) do { if (dbg_level_ >= _lvl && (_cat & dbg_categories_)) { printf( "atlantic: " _fmt " @%s,%d\n", ##args, __FILENAME__, __LINE__); }} while (0)
-#else
-#define trace_base_(_lvl, _cat, _fmt, ...) do {} while (0)
-#endif // AQ_CFG_DEBUG_LVL > 0
+#define trace_base_(_lvl, _cat, _fmt, args...) do { if (dbg_level_ >= (_lvl) && ((_cat) & dbg_categories_)) { printf( "atlantic: " _fmt " @%s,%d\n", ##args, __FILENAME__, __LINE__); }} while (0)
 
 #define aq_log_warn(_fmt, args...)     log_base_(lvl_warn, "/!\\ " _fmt, ##args)
 #define aq_log(_fmt, args...)          log_base_(lvl_trace, _fmt, ##args)
diff --git a/sys/dev/aq/aq_main.c b/sys/dev/aq/aq_main.c
index ecb7e66e5b15..e1b294012b27 100644
--- a/sys/dev/aq/aq_main.c
+++ b/sys/dev/aq/aq_main.c
@@ -1311,6 +1311,14 @@ aq_add_stats_sysctls(struct aq_dev *softc)
 	    CTLTYPE_STRING | CTLFLAG_RD, softc, 0,
 	    aq_sysctl_print_rss_config, "A", "Prints RSS Configuration");
 
+	/* Runtime trace controls (global) */
+	SYSCTL_ADD_INT(ctx, child, OID_AUTO, "debug",
+	    CTLFLAG_RW, &dbg_level_, 0,
+	    "Trace verbosity: 0=off, 3=err, 4=+warn, 5=+trace, 6=+detail");
+	SYSCTL_ADD_U32(ctx, child, OID_AUTO, "debug_categories",
+	    CTLFLAG_RW, &dbg_categories_, 0,
+	    "Trace category mask: init=1 config=2 tx=4 rx=8 intr=16 fw=32");
+
 	/* Driver Statistics */
 	for (int i = 0; i < softc->tx_rings_count; i++) {
 		struct aq_ring *ring = softc->tx_rings[i];