@@ -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)