All of lore.kernel.org
 help / color / mirror / Atom feed
From: Don Porter <porter@cs.unc.edu>
To: qemu-devel@nongnu.org
Cc: Austin Clements <aclements@csail.mit.edu>,
	Geoffrey Thomas <geofft@ldpreload.com>,
	Don Porter <porter@cs.unc.edu>
Subject: [PATCH 1/1] e1000: Get debug flags from an environment variable
Date: Fri, 29 Mar 2024 11:04:50 -0400	[thread overview]
Message-ID: <20240329150450.2843758-2-porter@cs.unc.edu> (raw)
In-Reply-To: <20240329150450.2843758-1-porter@cs.unc.edu>

From: Austin Clements <aclements@csail.mit.edu>

The E1000 debug messages are very useful for developing drivers, so
this introduces an E1000_DEBUG environment variable that lets the
debug flags be set without recompiling QEMU.

Signed-off-by: Austin Clements <aclements@csail.mit.edu>
[geofft@ldpreload.com: Rebased on top of 2.9.0]
Signed-off-by: Geoffrey Thomas <geofft@ldpreload.com>
Signed-off-by: Don Porter <porter@cs.unc.edu>
---
 hw/net/e1000.c | 65 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 59 insertions(+), 6 deletions(-)

diff --git a/hw/net/e1000.c b/hw/net/e1000.c
index 43f3a4a701..8d46225944 100644
--- a/hw/net/e1000.c
+++ b/hw/net/e1000.c
@@ -30,11 +30,14 @@
 #include "hw/pci/pci_device.h"
 #include "hw/qdev-properties.h"
 #include "migration/vmstate.h"
+#include "monitor/monitor.h"
 #include "net/eth.h"
 #include "net/net.h"
 #include "net/checksum.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/dma.h"
+#include "qapi/qmp/qerror.h"
+#include "qemu/error-report.h"
 #include "qemu/iov.h"
 #include "qemu/module.h"
 #include "qemu/range.h"
@@ -44,15 +47,19 @@
 #include "trace.h"
 #include "qom/object.h"
 
-/* #define E1000_DEBUG */
-
-#ifdef E1000_DEBUG
 enum {
     DEBUG_GENERAL,      DEBUG_IO,       DEBUG_MMIO,     DEBUG_INTERRUPT,
     DEBUG_RX,           DEBUG_TX,       DEBUG_MDIC,     DEBUG_EEPROM,
     DEBUG_UNKNOWN,      DEBUG_TXSUM,    DEBUG_TXERR,    DEBUG_RXERR,
     DEBUG_RXFILTER,     DEBUG_PHY,      DEBUG_NOTYET,
 };
+
+static const char *debugnames[] = {
+    "GENERAL",      "IO",       "MMIO",     "INTERRUPT",
+    "RX",           "TX",       "MDIC",     "EEPROM",
+    "UNKNOWN",      "TXSUM",    "TXERR",    "RXERR",
+    "RXFILTER",     "PHY",      "NOTYET",   NULL
+};
 #define DBGBIT(x)    (1<<DEBUG_##x)
 static int debugflags = DBGBIT(TXERR) | DBGBIT(GENERAL);
 
@@ -60,9 +67,6 @@ static int debugflags = DBGBIT(TXERR) | DBGBIT(GENERAL);
     if (debugflags & DBGBIT(what)) \
         fprintf(stderr, "e1000: " fmt, ## __VA_ARGS__); \
     } while (0)
-#else
-#define DBGOUT(what, fmt, ...) do {} while (0)
-#endif
 
 #define IOPORT_SIZE       0x40
 #define PNPMMIO_SIZE      0x20000
@@ -1779,3 +1783,52 @@ static void e1000_register_types(void)
 }
 
 type_init(e1000_register_types)
+
+static void e1000_init_debug(void)
+{
+    const char *e1000_debug;
+    const char *p, *p1;
+    const char **debugname;
+    int i;
+
+    e1000_debug = getenv("E1000_DEBUG");
+    if (!e1000_debug || !*e1000_debug) {
+        return;
+    }
+
+    if (strcmp(e1000_debug, "?") == 0) {
+        error_printf("E1000_DEBUG flags:\n");
+        for (debugname = debugnames; *debugname; debugname++) {
+            error_printf("%s\n", *debugname);
+        }
+        exit(0);
+    }
+
+    p = e1000_debug;
+    debugflags = 0;
+    for (p = e1000_debug; ; p = p1 + 1) {
+        p1 = strchr(p, ',');
+        if (!p1) {
+            p1 = p + strlen(p);
+        }
+        for (i = 0, debugname = debugnames; *debugname; i++, debugname++) {
+            if (strlen(*debugname) == p1 - p &&
+                strncasecmp(p, *debugname, p1 - p) == 0) {
+                debugflags |= 1 << i;
+                break;
+            }
+        }
+        if (!*debugname) {
+            error_report(QERR_INVALID_PARAMETER_VALUE, "E1000_DEBUG",
+                         "a comma-separated list of E1000 debug flags");
+            error_printf_unless_qmp(
+                "Try with argument '?' for a list.\n");
+            exit(1);
+        }
+        if (*p1 != ',') {
+            break;
+        }
+    }
+}
+
+type_init(e1000_init_debug)
-- 
2.25.1



  reply	other threads:[~2024-03-29 16:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-29 15:04 [PATCH 0/1] Upstreaming Course Debugging Changes Don Porter
2024-03-29 15:04 ` Don Porter [this message]
2024-03-29 17:46   ` [PATCH 1/1] e1000: Get debug flags from an environment variable Richard Henderson
2024-04-03 13:45     ` [PATCH v2] e1000: Convert debug macros into tracepoints Don Porter
2024-04-03 17:51       ` Richard Henderson
2024-04-03 18:44       ` Austin Clements
2024-04-08 21:11         ` Don Porter
2024-04-08 21:15         ` [PATCH v3] " Don Porter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240329150450.2843758-2-porter@cs.unc.edu \
    --to=porter@cs.unc.edu \
    --cc=aclements@csail.mit.edu \
    --cc=geofft@ldpreload.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.