Index: trunk/src/os2ahci/Makefile
===================================================================
--- trunk/src/os2ahci/Makefile	(revision 208)
+++ trunk/src/os2ahci/Makefile	(revision 209)
@@ -6,4 +6,15 @@
 # Copyright (c) 2013-2016 David Azarewicz
 #
+#define DBG_ALWAYS    0x0000
+#define DBG_FUNCBEG   0x0001
+#define DBG_FUNCEND   0x0002
+#define DBG_ATTACH    0x0004
+#define DBG_DETAILED  0x0008
+#define DBG_INIT      0x0010
+#define DBG_SPECIAL   0x0020
+#define DBG_VERBOSE   0x0100
+#define DBG_ERROR_ALL 0x800000ff
+FDEBUG=0x0000
+
 .ERASE
 .SUFFIXES
@@ -84,5 +95,5 @@
 
 !ifdef DEBUG
-CDEFS=-DDEBUG
+CDEFS=-DDEBUG=$(FDEBUG)
 O=Debug
 !else
Index: trunk/src/os2ahci/ReadMe.txt
===================================================================
--- trunk/src/os2ahci/ReadMe.txt	(revision 208)
+++ trunk/src/os2ahci/ReadMe.txt	(revision 209)
@@ -67,89 +67,85 @@
 Global Options
 
-Option                 Description
-------------------------------------------------------------------------------
-/B:<baud>              Initialize the COM port to the specified baud rate. Allowable
-                       baud values are: 300, 600, 1200, 2400, 4800, 9600, 19200,
-                       38400, 57600, and 115200. /B has no effect if /C is not also
-                       specified. If /B is not specified, the COM port is not
-                       initialized. For example, if you are using the kernel debugger,
-                       the kernel debugger initializes the COM port so you should not
-                       use this switch.
-
-/COM:<n>               Set debug COM port base address. Values for n can be:
-                         1 = COM1
-                         2 = COM2
-                         a hex value (COM port base address) COM1=3f8, COM2=2f8
-                       The default is 0. If set to 0 then no output goes to the COM port.
-
-/D[:n]                 Debug output to COM port/debug buffer. Values for n can be:
-                         1 = requests
-                         2 = detailed
-                         3 = verbose
-                       If :n is not specified the debug level is incremented for
-                       each /D specified.
-
-/W                     Allows the debug buffer to wrap when full.
-
-/V[:n]                 Display informational messages during boot. Values for n can be:
-                         1 = Display sign on banner
-                         2 = Display adapter information
-                       If :n is not specified the verbosity level is incremented for
-                       each /V specified.
-
-/G:<vendor>:<device>   Add generic PCI ID to list of supported AHCI adapters
-                       (e.g. /G:8086:2829)
-
-/T                     Perform thorough PCI ID scan; default = on, can be
-                       turned off with /!T to perform only a PCI class scan
-
-/F                     Force the use of the HW write cache when using NCQ
-                       commands; see "Native Command Queuing" below for
-                       further explanation (default = off)
-
-/R                     Reset ports during initialization (default = on)
-                       Can be turned off with /!R, however, when the
-                       [Intel] AHCI controller was found to be
-                       initialized by the BIOS in SATA mode, ports will
-                       always be reset even when /!R is specified
-
-/A:n                   Set adapter to n for adapter-specific options
-                       (default = -1, all adapters)
-
-/P:n                   Set port to n for port-specific options
-                       (default = -1, all ports)
-
-/I                     Ignore current adapter if no port has been specified.
-                       Otherwise, ignore the current port on the current adapter.
-
-/U                     Check for usable disks and ignore disks that are not
-                       usable. To be usable a disk must be an MBR disk or wiped.
-                       (default = on) Can be turned off with /!U.
+Option                Description
+-----------------------------------------------------------------------------
+/A:n                  Set adapter to n for adapter-specific options
+                      (default = -1, all adapters)
+
+/F                    Force the use of the HW write cache when using NCQ
+                      commands; see "Native Command Queuing" below for
+                      further explanation (default = off)
+
+/G:<vendor>:<device>  Add generic PCI ID to list of supported AHCI adapters
+                      (e.g. /G:8086:2829)
+
+/I                    Ignore current adapter if no port has been specified.
+                      Otherwise, ignore the current port on the current adapter.
+
+/P:n                  Set port to n for port-specific options
+                      (default = -1, all ports)
+
+/R                    Reset ports during initialization (default = on)
+                      Can be turned off with /!R, however, when the
+                      [Intel] AHCI controller was found to be
+                      initialized by the BIOS in SATA mode, ports will
+                      always be reset even when /!R is specified
+
+/T                    Perform thorough PCI ID scan; default = on, can be
+                      turned off with /!T to perform only a PCI class scan
+
+/U                    Check for usable disks and mark disks that are not
+                      usable as unavailable for normal OS/2 operations.
+                      To be usable a disk must be an MBR disk or wiped.
+                      (default = on) Can be turned off with /!U.
+
+/V                    Display informational messages during boot.
+
+Debugging options (may only be available in debug builds)
+
+Option                Description
+-----------------------------------------------------------------------------
+/B:<baud>             Initialize the COM port to the specified baud rate. Allowable
+                      baud values are: 300, 600, 1200, 2400, 4800, 9600, 19200,
+                      38400, 57600, and 115200. /B has no effect if /C is not also
+                      specified. If /B is not specified, the COM port is not
+                      initialized. For example, if you are using the kernel debugger,
+                      the kernel debugger initializes the COM port so you should not
+                      use this switch.
+
+/COM:<n>              Set debug COM port base address. Values for n can be:
+                        1 = COM1
+                        2 = COM2
+                        a hex value (COM port base address) COM1=3f8, COM2=2f8
+                      The default is 0. If set to 0 then no output goes to the COM port.
+
+/DEBUG:<n>            Sets debug mask
+
+/W                    Allows the debug buffer to wrap when full.
 
 Port-specific Options
 
-Option                 Description
-------------------------------------------------------------------------------
-/S                     Enable SCSI emulation for ATAPI units (default = on)
-                       SCSI emulation is required for tools like cdrecord.
-
-/N                     Enable NCQ (Native Command Queuing) for hard disks
-                       (default = off)
-
-/LS                    Set link speed (default = 0):
-                         0 = maximum,
-                         1 = limit to generation 1
-                         2 = limit to generation 2
-                         3 = limit to generation 3
-
-/LP                    Set link power management (default = 0):
-                         0 = full power management,
-                         1 = transitions to "partial slumber state" disabled,
-                         2 = transitions to "slumber state" disabled,
-                         3 = transitions to both partial and slumber states disabled
-
-/4                     Force track size to be 56 sectors regardless of the
-                       reported disk geometry to optimize partition boundaries
-                       for hard disks with 4096 byte sectors.
+Option                Description
+-----------------------------------------------------------------------------
+/S                    Enable SCSI emulation for ATAPI units (default = on)
+                      SCSI emulation is required for tools like cdrecord.
+
+/N                    Enable NCQ (Native Command Queuing) for hard disks
+                      (default = off)
+
+/LS                   Set link speed (default = 0):
+                        0 = maximum,
+                        1 = limit to generation 1
+                        2 = limit to generation 2
+                        3 = limit to generation 3
+
+/LP                   Set link power management (default = 0):
+                        0 = full power management,
+                        1 = transitions to "partial slumber state" disabled,
+                        2 = transitions to "slumber state" disabled,
+                        3 = transitions to both partial and slumber states disabled
+
+/4                    Force track size to be 56 sectors regardless of the
+                      reported disk geometry to optimize partition boundaries
+                      for hard disks with 4096 byte sectors.
 
 Port-specific options depend on the currently active adapter
Index: trunk/src/os2ahci/ahci.c
===================================================================
--- trunk/src/os2ahci/ahci.c	(revision 208)
+++ trunk/src/os2ahci/ahci.c	(revision 209)
@@ -202,5 +202,5 @@
   if ((ai->cap & HOST_CAP_NCQ) && (ai->flags & AHCI_HFLAG_NO_NCQ))
   {
-    DPRINTF(1,"controller can't do NCQ, turning off CAP_NCQ\n");
+    DPRINTF(DBG_INIT, DBG_PREFIX": controller can't do NCQ, turning off CAP_NCQ\n");
     ai->cap &= ~HOST_CAP_NCQ;
   }
@@ -208,5 +208,5 @@
   if (!(ai->cap & HOST_CAP_NCQ) && (ai->flags & AHCI_HFLAG_YES_NCQ))
   {
-    DPRINTF(1,"controller can do NCQ, turning on CAP_NCQ\n");
+    DPRINTF(DBG_INIT, DBG_PREFIX": controller can do NCQ, turning on CAP_NCQ\n");
     ai->cap |= HOST_CAP_NCQ;
   }
@@ -214,5 +214,5 @@
   if ((ai->cap & HOST_CAP_PMP) && (ai->flags & AHCI_HFLAG_NO_PMP))
   {
-    DPRINTF(1,"controller can't do PMP, turning off CAP_PMP\n");
+    DPRINTF(DBG_INIT, DBG_PREFIX": controller can't do PMP, turning off CAP_PMP\n");
     ai->cap |= HOST_CAP_PMP;
   }
@@ -220,5 +220,5 @@
   if ((ai->cap & HOST_CAP_SNTF) && (ai->flags & AHCI_HFLAG_NO_SNTF))
   {
-    DPRINTF(1,"controller can't do SNTF, turning off CAP_SNTF\n");
+    DPRINTF(DBG_INIT, DBG_PREFIX": controller can't do SNTF, turning off CAP_SNTF\n");
     ai->cap &= ~HOST_CAP_SNTF;
   }
@@ -226,5 +226,5 @@
   if (ai->pci_vendor == PCI_VENDOR_ID_JMICRON && ai->pci_device == 0x2361 && ai->port_map != 1)
   {
-    DPRINTF(1,"JMB361 has only one port, port_map 0x%x -> 0x%x\n", ai->port_map, 1);
+    DPRINTF(DBG_INIT, DBG_PREFIX": JMB361 has only one port, port_map 0x%x -> 0x%x\n", ai->port_map, 1);
     ai->port_map = 1;
     ai->hw_ports = 1;
@@ -249,5 +249,5 @@
     /* more ports in port_map than in HOST_CAP & 0x1f */
     ports = ai->hw_ports;
-    DPRINTF(0,"implemented port map (0x%x) contains more ports than hw_ports (%d), using hw_ports\n", ai->port_map, ports);
+    DPRINTF(DBG_INIT, DBG_PREFIX": implemented port map (0x%x) contains more ports than hw_ports (%d), using hw_ports\n", ai->port_map, ports);
     ai->port_map = (1UL << ports) - 1UL;
   }
@@ -274,5 +274,5 @@
   }
 
-  DPRINTF(3,__func__": BIOS AHCI mode is %d\n", ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN);
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": BIOS AHCI mode is %d\n", ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN);
 
   if ((ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN) == 0 && ai->pci_vendor == PCI_VENDOR_ID_INTEL)
@@ -284,5 +284,5 @@
   }
 
-  DUMP_HOST_REGS(6,ai,1);
+  DUMP_HOST_REGS(DBG_DETAILED, ai, 1);
 
   return(0);
@@ -296,5 +296,5 @@
 int ahci_restore_bios_config(AD_INFO *ai)
 {
-  DPRINTF(3,__func__": restoring AHCI BIOS configuration on adapter %d\n", ad_no(ai));
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": restoring AHCI BIOS configuration on adapter %d\n", ad_no(ai));
 
   /* Restore saved BIOS configuration; please note that HOST_CTL is restored
@@ -354,5 +354,5 @@
 int ahci_restore_initial_config(AD_INFO *ai)
 {
-  DPRINTF(3,__func__": restoring initial configuration on adapter %d\n", ad_no(ai));
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": restoring initial configuration on adapter %d\n", ad_no(ai));
 
   /* restore saved BIOS configuration */
@@ -379,5 +379,5 @@
     TIMER Timer;
 
-    DPRINTF(2,"controller reset starting on adapter %d\n", ad_no(ai));
+    DPRINTF(DBG_ATTACH, DBG_PREFIX": controller reset starting on adapter %d\n", ad_no(ai));
 
     /* we must be in AHCI mode, before using anything AHCI-specific, such as HOST_RESET. */
@@ -414,9 +414,9 @@
       u32 tmp16 = 0;
 
-      DPRINTF(1,"ahci_reset_controller: intel detected\n");
+      DPRINTF(DBG_ATTACH, DBG_PREFIX": ahci_reset_controller: intel detected\n");
       /* configure PCS */
       PciReadConfig(ai->bus, ai->dev_func, 0x92, sizeof(u16), &tmp16);
       if ((tmp16 & ai->port_map) != ai->port_map) {
-        DPRINTF(3,"ahci_reset_controller: updating PCS %x/%x\n", tmp16, ai->port_map);
+        DPRINTF(DBG_ATTACH, DBG_PREFIX": ahci_reset_controller: updating PCS %x/%x\n", tmp16, ai->port_map);
         tmp16 |= ai->port_map;
         PciWriteConfig(ai->bus, ai->dev_func, 0x92, sizeof(u16), tmp16);
@@ -535,5 +535,5 @@
   int i;
 
-  DPRINTF(2,__func__": completing initialization of adapter #%d\n", ad_no(ai));
+  DPRINTF(DBG_INIT, DBG_PREFIX": completing initialization of adapter #%d\n", ad_no(ai));
 
   if (!ai->int_set)
@@ -559,5 +559,5 @@
       if (i >= MAX_IRQ_HANDLERS) return -1; /* no more handlers available */
 
-      DPRINTF(2,"registering interrupt %d pin=%d\n", ai->irq, ai->irq_pin);
+      DPRINTF(DBG_INIT, DBG_PREFIX": registering interrupt %d pin=%d\n", ai->irq, ai->irq_pin);
 
       rc = Dev32Help_SetIRQ(ahci_intr, ai->irq, p, ai->irq);
@@ -592,10 +592,10 @@
       if (init_reset)
       {
-        DPRINTF(3,__func__": resetting port %d\n", p);
+        DPRINTF(DBG_INIT, DBG_PREFIX": resetting port %d\n", p);
         ahci_reset_port(ai, p, 1);
       }
       else
       {
-        DPRINTF(3,__func__": restarting port #%d\n", p);
+        DPRINTF(DBG_INIT, DBG_PREFIX": restarting port #%d\n", p);
         ahci_stop_port(ai, p);
         ahci_start_port(ai, p, 1);
@@ -615,5 +615,5 @@
   /* pci_enable_int(ai->bus, ai->dev_func); */
 
-  DPRINTF(2,__func__": done\n");
+  DPRINTF(DBG_INIT|DBG_FUNCEND, DBG_PREFIX": END\n");
   return(0);
 }
@@ -644,5 +644,5 @@
          AP_END)) break;
 
-    DHEXDUMP(5, pSector0, 512, "Sector0:\n");
+    DHEXDUMP(DBG_DETAILED, pSector0, 512, "Sector0:\n");
 
     /* check for wiped disk */
@@ -722,5 +722,5 @@
   }
 
-  DPRINTF(2,"found device %d.%d.%d: removable=%d dev_type=%d atapi=%d ncq_max=%d\n",
+  DPRINTF(DBG_ATTACH, DBG_PREFIX": found device %d.%d.%d: removable=%d dev_type=%d atapi=%d ncq_max=%d\n",
           ad_no(ai), p, d,
           ai->ports[p].devs[d].removable,
@@ -804,5 +804,5 @@
 
   /* perform port scan */
-  DPRINTF(1,__func__": scanning ports on adapter %d\n", ad_no(ai));
+  DPRINTF(DBG_ATTACH, DBG_PREFIX": scanning ports on adapter %d\n", ad_no(ai));
   for (p = 0; p < AHCI_MAX_PORTS; p++)
   {
@@ -812,5 +812,5 @@
     // DAZ allocate port structure here
 
-    DPRINTF(3,__func__": Wait till not busy on port %d\n", p);
+    DPRINTF(DBG_ATTACH, DBG_PREFIX": Wait till not busy on port %d\n", p);
     /* wait until all active commands have completed on this port */
     TimerInit(&Timer, 250);
@@ -832,5 +832,5 @@
     else
     {
-      DPRINTF(3,__func__": (re)starting port %d\n", p);
+      DPRINTF(DBG_ATTACH, DBG_PREFIX": (re)starting port %d\n", p);
       ahci_stop_port(ai, p);
       rc = ahci_start_port(ai, p, 0);
@@ -840,5 +840,5 @@
     {
       /* this port seems to have a device attached and ready for commands */
-      DPRINTF(2,__func__": port %d seems to be attached to a device; probing...\n", p);
+      DPRINTF(DBG_ATTACH, DBG_PREFIX": port %d seems to be attached to a device; probing...\n", p);
 
       #ifdef DAZ_NEW_CODE
@@ -871,5 +871,5 @@
     {
       /* we have a valid IDENTIFY or IDENTIFY_PACKET response */
-      DHEXDUMP(5,id_buf, ATA_ID_WORDS * sizeof(u16), "ATA_IDENTIFY%s results:\n", (is_ata) ? "" : "_PACKET");
+      DHEXDUMP(DBG_DETAILED,id_buf, ATA_ID_WORDS * sizeof(u16), "ATA_IDENTIFY%s results:\n", (is_ata) ? "" : "_PACKET");
       ahci_setup_device(ai, p, 0, id_buf);
       if (!IsUsableDisk(ai, p, 0)) ai->ports[p].devs[0].ignored = 1;
@@ -915,6 +915,6 @@
   TIMER Timer;
 
-  DPRINTF(3,__func__": resetting port %d.%d\n", ad_no(ai), p);
-  DUMP_PORT_REGS(3,ai,p);
+  DPRINTF(DBG_ATTACH, DBG_PREFIX": resetting port %d.%d\n", ad_no(ai), p);
+  DUMP_PORT_REGS(DBG_DETAILED,ai,p);
 
   /* stop port engines (we don't care whether there is an error doing so) */
@@ -932,5 +932,5 @@
 
   /* set link speed and power management options */
-  DPRINTF(3,__func__": setting link speed and power management options\n");
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": setting link speed and power management options\n");
   tmp = readl(port_mmio + PORT_SCR_CTL) & ~0x00000fffUL;
   tmp |= (link_speed[ad_no(ai)][p] & 0x0f) << 4;
@@ -939,5 +939,5 @@
 
   /* issue COMRESET on the port */
-  DPRINTF(3,__func__": issuing COMRESET on port %d\n", p);
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": issuing COMRESET on port %d\n", p);
   writel(port_mmio + PORT_SCR_CTL, tmp | 1);
   readl(port_mmio + PORT_SCR_CTL);  /* flush */
@@ -950,5 +950,5 @@
 
   /* wait for communication to be re-established after port reset */
-  DPRINTF(3,"Wait for communication...\n");
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": Wait for communication...\n");
   TimerInit(&Timer, 500);
   while (((tmp = readl(port_mmio + PORT_SCR_STAT)) & 3) != 3)
@@ -956,5 +956,5 @@
     if (TimerCheckAndBlock(&Timer))
     {
-      DPRINTF(2,"no device present after resetting port #%d (PORT_SCR_STAT = 0x%x)\n", p, tmp);
+      DPRINTF(DBG_ATTACH, DBG_PREFIX": no device present after resetting port #%d (PORT_SCR_STAT = 0x%x)\n", p, tmp);
       return(-1);
     }
@@ -966,5 +966,5 @@
 
   /* start port so we can receive the COMRESET FIS */
-  DPRINTF(3,__func__": starting port %d again\n", p);
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": starting port %d again\n", p);
   ahci_start_port(ai, p, ei);
 
@@ -975,10 +975,10 @@
     if (TimerCheckAndBlock(&Timer))
     {
-      DPRINTF(0,"device not ready on port #%d (PORT_TFDATA = 0x%x)\n", p, tmp);
+      DPRINTF(0, DBG_PREFIX": device not ready on port #%d (PORT_TFDATA = 0x%x)\n", p, tmp);
       ahci_stop_port(ai, p);
       return(-1);
     }
   }
-  DPRINTF(3,__func__": PORT_TFDATA = 0x%x\n", readl(port_mmio + PORT_TFDATA));
+  DPRINTF(DBG_ATTACH|DBG_FUNCEND, DBG_PREFIX": END PORT_TFDATA = 0x%x\n", readl(port_mmio + PORT_TFDATA));
 
   return(0);
@@ -993,14 +993,14 @@
   u32 status;
 
-  DPRINTF(3,__func__": %d.%d\n", ad_no(ai), p);
+  DPRINTF(DBG_ATTACH, DBG_PREFIX": %d.%d\n", ad_no(ai), p);
   /* check whether device presence is detected and link established */
 
   status = readl(port_mmio + PORT_SCR_STAT);
-  DPRINTF(3,__func__": PORT_SCR_STAT = 0x%x\n", status);
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": PORT_SCR_STAT = 0x%x\n", status);
   if ((status & 0xf) != 3) return(-1);
 
   /* clear SError, if any */
   status = readl(port_mmio + PORT_SCR_ERR);
-  DPRINTF(3,__func__": PORT_SCR_ERR  = 0x%x\n", status);
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": PORT_SCR_ERR  = 0x%x\n", status);
   writel(port_mmio + PORT_SCR_ERR, status);
 
@@ -1090,5 +1090,5 @@
   int rc;
 
-  DPRINTF(3,__func__": %d.%d\n", ad_no(ai), p);
+  DPRINTF(DBG_ATTACH, DBG_PREFIX": %d.%d\n", ad_no(ai), p);
 
   /* disable port interrupts */
@@ -1233,5 +1233,5 @@
   }
 
-  DPRINTF(7,"---------- "__func__": iorb=%x\n", vIorb);
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": ---------- iorb=%x\n", vIorb);
 
   /* Enable AHCI mode; apparently, the AHCI mode may end up becoming
@@ -1259,5 +1259,5 @@
       cmd_max = ai->cmd_max;
     }
-    DPRINTF(8,__func__": NCQ command; cmd_max = %d->%d\n", ai->cmd_max, cmd_max);
+    DPRINTF(DBG_DETAILED, DBG_PREFIX": NCQ command; cmd_max = %d->%d\n", ai->cmd_max, cmd_max);
   }
 
@@ -1312,5 +1312,5 @@
         aws->cmd_slot = port->cmd_slot;
 
-        DPRINTF(7,__func__": Issuing command Slot=%d cmds=%x\n", port->cmd_slot, *cmds);
+        DPRINTF(DBG_DETAILED, DBG_PREFIX": Issuing command Slot=%d cmds=%x\n", port->cmd_slot, *cmds);
         if (aws->is_ncq)
         {
@@ -1405,5 +1405,5 @@
   {
     /* successfully prepared cmd; issue cmd and wait for completion */
-    DPRINTF(3,"---------- "__func__" executing polled cmd on slot 0...");
+    DPRINTF(DBG_DETAILED, DBG_PREFIX": ---------- executing polled cmd on slot 0...");
     writel(port_mmio + PORT_CMD_ISSUE, 1);
     TimerInit(&Timer, timeout);
@@ -1417,10 +1417,10 @@
     if (rc)
     {
-      DPRINTF(3," timeout for IORB %x port=%x", vIorb, p);
+      DPRINTF(DBG_DETAILED, " timeout for IORB %x port=%x", vIorb, p);
       iorb_seterr(pIorb, IOERR_ADAPTER_TIMEOUT);
     }
     else if (readl(port_mmio + PORT_SCR_ERR) != 0 || readl(port_mmio + PORT_TFDATA) & 0x89)
     {
-      DPRINTF(3," polled cmd error for IORB %x", vIorb);
+      DPRINTF(DBG_DETAILED, " polled cmd error for IORB %x", vIorb);
       iorb_seterr(pIorb, IOERR_DEVICE_NONSPECIFIC);
       ahci_reset_port(ai, iorb_unit_port(pIorb), 0);
@@ -1438,5 +1438,5 @@
       }
     }
-    DPRINTF(3,"\n");
+    DPRINTF(DBG_DETAILED, "\n");
   }
 
@@ -1476,5 +1476,5 @@
   if (readl(port_mmio + PORT_CMD_ISSUE) & 1)
   {
-    DPRINTF(3,__func__": port %d slot 0 is not idle; not executing polled cmd\n", p);
+    DPRINTF(0, DBG_PREFIX": port %d slot 0 is not idle; not executing polled cmd\n", p);
     return(-1);
   }
@@ -1485,5 +1485,5 @@
 
   /* start command execution for slot 0 */
-  DPRINTF(3,"---------- "__func__" executing polled cmd...");
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": ---------- executing polled cmd...");
   writel(port_mmio + PORT_CMD_ISSUE, 1);
 
@@ -1496,5 +1496,5 @@
     if (rc)
     {
-      DPRINTF(2," Timeout");
+      DPRINTF(DBG_DETAILED, " Timeout");
       break;
     }
@@ -1504,5 +1504,5 @@
   if (tmp & PORT_ERR_FAIL_BITS)
   {
-    DPRINTF(2," SERR = 0x%08lx", tmp);
+    DPRINTF(DBG_DETAILED, " SERR = 0x%08lx", tmp);
     rc = 1;
   }
@@ -1510,5 +1510,5 @@
   if (((tmp = readl(port_mmio + PORT_TFDATA)) & 0x89) != 0)
   {
-    DPRINTF(2," TFDATA = 0x%08lx", tmp);
+    DPRINTF(DBG_DETAILED, " TFDATA = 0x%08lx", tmp);
     rc = 1;
   }
@@ -1516,9 +1516,9 @@
   if (rc)
   {
-    DPRINTF(3,"failed\n");
+    DPRINTF(DBG_DETAILED, "failed\n");
     ahci_reset_port(ai, p, 0);
     return(-1);
   }
-  DPRINTF(3,"success\n");
+  DPRINTF(DBG_DETAILED, "success\n");
   return(0);
 }
@@ -1537,5 +1537,5 @@
   if (!ai->ports[p].devs[d].atapi)
   {
-    DPRINTF(2,__func__": flushing cache on %d.%d.%d\n", ad_no(ai), p, d);
+    DPRINTF(DBG_INIT, DBG_PREFIX": flushing cache on %d.%d.%d\n", ad_no(ai), p, d);
     return(ahci_exec_polled_cmd(ai, p, d, 30000,
            ai->ports[p].devs[d].lba48 ? ATA_CMD_FLUSH_EXT : ATA_CMD_FLUSH, AP_END));
@@ -1554,5 +1554,5 @@
 int ahci_set_dev_idle(AD_INFO *ai, int p, int d, int idle)
 {
-  DPRINTF(3,__func__": sending IDLE=%d command to port %d\n", idle, p);
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": sending IDLE=%d command to port %d\n", idle, p);
   return ahci_exec_polled_cmd(ai, p, d, 500, ATA_CMD_IDLE, AP_COUNT, idle ? 1 : 0, AP_END);
 }
@@ -1612,5 +1612,5 @@
     if ((u32)&irq_stat < 0xf000)
     {
-      DPRINTF(0,__func__": IRQ stack running low; arming engine context hook\n");
+      DPRINTF(DBG_DETAILED, DBG_PREFIX": IRQ stack running low; arming engine context hook\n");
       /* Rousseau:
        * A context hook cannot be re-armed before it has completed.
@@ -1689,5 +1689,5 @@
     active_cmds = readl(port_mmio + PORT_SCR_ACT);
     done_mask = ai->ports[p].ncq_cmds ^ active_cmds;
-    DPRINTF(7,"[ncq_cmds]: active_cmds=0x%08x done_mask=0x%08x\n", active_cmds, done_mask);
+    DPRINTF(DBG_DETAILED, DBG_PREFIX": [ncq_cmds]: active_cmds=0x%08x done_mask=0x%08x\n", active_cmds, done_mask);
   }
   else
@@ -1695,5 +1695,5 @@
     active_cmds = readl(port_mmio + PORT_CMD_ISSUE);
     done_mask = ai->ports[p].reg_cmds ^ active_cmds;
-    DPRINTF(7,"[reg_cmds]: active_cmds=0x%08x  done_mask=0x%08x\n", active_cmds, done_mask);
+    DPRINTF(DBG_DETAILED, DBG_PREFIX": [reg_cmds]: active_cmds=0x%08x  done_mask=0x%08x\n", active_cmds, done_mask);
   }
 
@@ -1775,5 +1775,5 @@
     #ifdef DEBUG
     u32 *unk = (u32 *) (port_dma_base(ai, p)->rx_fis + RX_FIS_UNK);
-    DPRINTF(0,"warning: unknown FIS %08lx %08lx %08lx %08lx\n", unk[0], unk[1], unk[2], unk[3]);
+    dprintf(0,"warning: unknown FIS %08lx %08lx %08lx %08lx\n", unk[0], unk[1], unk[2], unk[3]);
     #endif
     reset_port = 1;
@@ -1803,5 +1803,5 @@
   dprintf(0,"port #%d interrupt error status: 0x%08x; restarting port\n", p, irq_stat);
   #else
-  if (!ai->ports[p].devs[0].atapi || D32g_DbgLevel)
+  if (!ai->ports[p].devs[0].atapi)
   {
     dprintf(0,"port #%d interrupt error status: 0x%08x; restarting port\n", p, irq_stat);
@@ -1823,5 +1823,5 @@
 void ahci_get_geometry(IORBH FAR16DATA *vIorb, IORBH *pIorb)
 {
-  DPRINTF(7,"ahci_get_geometry(%d.%d.%d)\n", iorb_unit_adapter(pIorb),
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": ahci_get_geometry(%d.%d.%d)\n", iorb_unit_adapter(pIorb),
           iorb_unit_port(pIorb), iorb_unit_device(pIorb));
 
@@ -1834,5 +1834,5 @@
 void ahci_unit_ready(IORBH FAR16DATA *vIorb, IORBH *pIorb)
 {
-  DPRINTF(7,"ahci_unit_ready(%d.%d.%d)\n", iorb_unit_adapter(pIorb),
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": ahci_unit_ready(%d.%d.%d)\n", iorb_unit_adapter(pIorb),
           iorb_unit_port(pIorb), iorb_unit_device(pIorb));
 
@@ -1845,5 +1845,5 @@
 void ahci_read(IORBH FAR16DATA *vIorb, IORBH *pIorb)
 {
-  DPRINTF(7,"ahci_read(%d.%d.%d, %d, %d)\n", iorb_unit_adapter(vIorb),
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": ahci_read(%d.%d.%d, %d, %d)\n", iorb_unit_adapter(vIorb),
           iorb_unit_port(pIorb), iorb_unit_device(pIorb),
           ((IORB_EXECUTEIO *) pIorb)->RBA,
@@ -1858,5 +1858,5 @@
 void ahci_verify(IORBH FAR16DATA *vIorb, IORBH *pIorb)
 {
-  DPRINTF(7,"ahci_verify(%d.%d.%d, %d, %d)\n", iorb_unit_adapter(pIorb),
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": ahci_verify(%d.%d.%d, %d, %d)\n", iorb_unit_adapter(pIorb),
           iorb_unit_port(pIorb), iorb_unit_device(pIorb),
           ((IORB_EXECUTEIO *)pIorb)->RBA,
@@ -1871,5 +1871,5 @@
 void ahci_write(IORBH FAR16DATA *vIorb, IORBH *pIorb)
 {
-  DPRINTF(7,"ahci_write(%d.%d.%d, %d, %d)\n", iorb_unit_adapter(pIorb),
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": ahci_write(%d.%d.%d, %d, %d)\n", iorb_unit_adapter(pIorb),
           iorb_unit_port(pIorb), iorb_unit_device(pIorb),
           ((IORB_EXECUTEIO *)pIorb)->RBA,
@@ -1888,5 +1888,5 @@
   int d = iorb_unit_device(pIorb);
 
-  DHEXDUMP(5,Far16ToFlat(((IORB_ADAPTER_PASSTHRU *)pIorb)->f16ControllerCmd),
+  DHEXDUMP(DBG_DETAILED ,Far16ToFlat(((IORB_ADAPTER_PASSTHRU *)pIorb)->f16ControllerCmd),
         ((IORB_ADAPTER_PASSTHRU *)pIorb)->ControllerCmdLen,
         "ahci_execute_cdb(%d.%d.%d): ", a, p, d);
@@ -1914,5 +1914,5 @@
   int d = iorb_unit_device(pIorb);
 
-  DHEXDUMP(5,Far16ToFlat(((IORB_ADAPTER_PASSTHRU *)pIorb)->f16ControllerCmd),
+  DHEXDUMP(DBG_DETAILED, Far16ToFlat(((IORB_ADAPTER_PASSTHRU *)pIorb)->f16ControllerCmd),
         ((IORB_ADAPTER_PASSTHRU *)pIorb)->ControllerCmdLen,
         "ahci_execute_ata(%d.%d.%d): ", a, p, d);
Index: trunk/src/os2ahci/apm.c
===================================================================
--- trunk/src/os2ahci/apm.c	(revision 208)
+++ trunk/src/os2ahci/apm.c	(revision 209)
@@ -45,5 +45,5 @@
   /* connect to APM driver */
   if ((rc = APMAttach()) != 0) {
-    DPRINTF(2,"couldn't connect to APM driver (rc = %d)\n", rc);
+    DPRINTF(0, DBG_PREFIX": couldn't connect to APM driver (rc = %d)\n", rc);
     return;
   }
@@ -53,5 +53,5 @@
                                    APM_NOTIFYNORMRESUME |
                                    APM_NOTIFYCRITRESUME, 0)) != 0) {
-    DPRINTF(2,"couldn't register for power event notificatins (rc = %d)\n", rc);
+    DPRINTF(0, DBG_PREFIX": couldn't register for power event notificatins (rc = %d)\n", rc);
     return;
   }
@@ -65,5 +65,5 @@
   USHORT msg = (USHORT) evt->ulParm1;
 
-  DPRINTF(2,"received APM event: 0x%x/0x%x\n");
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": received APM event: 0x%x/0x%x\n");
 
   switch (msg) {
@@ -83,5 +83,5 @@
 
   default:
-    DPRINTF(2,"unknown APM event; ignoring...\n");
+    DPRINTF(0, DBG_PREFIX": unknown APM event; ignoring...\n");
     break;
   }
@@ -103,5 +103,5 @@
 
   if (suspended) return;
-  DPRINTF(2,"suspend()\n");
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": suspend()\n");
 
   /* restart all ports with interrupts disabled */
@@ -144,5 +144,5 @@
 
   suspended = 1;
-  DPRINTF(2,"suspend() finished\n");
+  DPRINTF(DBG_FUNCEND, DBG_PREFIX": suspend() finished\n");
 }
 
@@ -156,5 +156,5 @@
 
   if (!suspended) return;
-  DPRINTF(2,"resume()\n");
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": resume()\n");
 
   for (a = 0; a < ad_info_cnt; a++) {
@@ -192,5 +192,5 @@
   KernArmHook(engine_ctxhook_h, 0, 0);
 
-  DPRINTF(2,"resume() finished\n");
+  DPRINTF(DBG_FUNCEND, DBG_PREFIX": resume() finished\n");
 }
 
@@ -209,5 +209,5 @@
   //int d;
 
-  DPRINTF(1,"shutdown_driver() enter\n");
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": shutdown_driver() enter\n");
 
   for (a = 0; a < ad_info_cnt; a++)
@@ -255,5 +255,5 @@
   }
 
-  DPRINTF(1,"shutdown_driver() finished\n");
-}
-
+  DPRINTF(DBG_FUNCEND, DBG_PREFIX": shutdown_driver() finished\n");
+}
+
Index: trunk/src/os2ahci/ata.c
===================================================================
--- trunk/src/os2ahci/ata.c	(revision 208)
+++ trunk/src/os2ahci/ata.c	(revision 209)
@@ -263,5 +263,5 @@
       if ((sg_addr & 1) || (chunk & 1))
       {
-        DPRINTF(0,"warning: ata_cmd() called with unaligned S/G element(s)\n");
+        DPRINTF(0, DBG_PREFIX": warning: ata_cmd() called with unaligned S/G element(s)\n");
         return(ATA_CMD_UNALIGNED_ADDR);
       }
@@ -277,18 +277,15 @@
   cmd_hdr->options |= n << 16;
 
-  #ifdef DEBUG
-  if ((D32g_DbgLevel >= 5) /*|| (atapi_cmd != NULL)*/)
-  {
-    DPRINTF(0,"ATA command for %d.%d.%d, slot %d:\n", ad_no(ai), p, d, slot);
-    dHexDump(0,cmd_hdr, offsetof(AHCI_CMD_HDR, reserved), "cmd_hdr: ");
-    dHexDump(0,&ata_cmd, sizeof(ata_cmd), "ata_cmd: ");
-    if (atapi_cmd != NULL)
-    {
-      dHexDump(0,atapi_cmd, atapi_cmd_len, "atapi_cmd: ");
-    }
-    if (n > 0)
-    {
-      dHexDump(0,cmd_tbl->sg_list, sizeof(*cmd_tbl->sg_list) * n, "sg_list: ");
-    }
+  #if DEBUG & DBG_DETAILED
+  dprintf(0,"ATA command for %d.%d.%d, slot %d:\n", ad_no(ai), p, d, slot);
+  dHexDump(0,cmd_hdr, offsetof(AHCI_CMD_HDR, reserved), "cmd_hdr: ");
+  dHexDump(0,&ata_cmd, sizeof(ata_cmd), "ata_cmd: ");
+  if (atapi_cmd != NULL)
+  {
+    dHexDump(0,atapi_cmd, atapi_cmd_len, "atapi_cmd: ");
+  }
+  if (n > 0)
+  {
+    dHexDump(0,cmd_tbl->sg_list, sizeof(*cmd_tbl->sg_list) * n, "sg_list: ");
   }
   #endif
@@ -447,9 +444,9 @@
   if (rc) return 0;
 
-  DHEXDUMP(5,pDLA, sizeof(DLA_Table_Sector), "DLA sector %d:\n", sector-1);
+  DHEXDUMP(DBG_DETAILED, pDLA, sizeof(DLA_Table_Sector), "DLA sector %d:\n", sector-1);
 
   if ((pDLA->DLA_Signature1 == DLA_TABLE_SIGNATURE1) && (pDLA->DLA_Signature2 == DLA_TABLE_SIGNATURE2))
   {
-    DPRINTF(3,__func__": DLA found at sector %d\n", sector-1);
+    DPRINTF(DBG_ATTACH, DBG_PREFIX": DLA found at sector %d\n", sector-1);
     geometry->TotalCylinders = pDLA->Cylinders;
     geometry->NumHeads = pDLA->Heads_Per_Cylinder;
@@ -482,5 +479,5 @@
   int p = iorb_unit_port(pIorb);
   int d = iorb_unit_device(pIorb);
-  DPRINTF(3,__func__" (%d.%d.%d)\n", ad_no(ai), p, d);
+  dprintf(DBG_DETAILED, DBG_PREFIX": (%d.%d.%d)\n", ad_no(ai), p, d);
   #endif
 
@@ -607,5 +604,5 @@
   }
 
-  DPRINTF(2,"Physical geometry: %d cylinders, %d heads, %d sectors per track (%dMB) (%s)\n",
+  DPRINTF(DBG_ATTACH, DBG_PREFIX": Physical geometry: %d cylinders, %d heads, %d sectors per track (%dMB) (%s)\n",
       geometry->TotalCylinders, geometry->NumHeads, geometry->SectorsPerTrack,
       (ULONG)(ullTotalSectors / 2048), Method);
@@ -616,12 +613,12 @@
   else ullTotalSectors = geometry->TotalSectors;
 
-  ad_infos[a].ports[p].devs[0].dev_info.Cylinders = geometry->TotalCylinders;
-  ad_infos[a].ports[p].devs[0].dev_info.HeadsPerCylinder = geometry->NumHeads;
-  ad_infos[a].ports[p].devs[0].dev_info.SectorsPerTrack = geometry->SectorsPerTrack;
-  ad_infos[a].ports[p].devs[0].dev_info.TotalSectors = ullTotalSectors;
-  ad_infos[a].ports[p].devs[0].dev_info.Method = Method;
+  ad_infos[a].ports[p].devs[0].dev_info.ulCylinders = geometry->TotalCylinders;
+  ad_infos[a].ports[p].devs[0].dev_info.usHeadsPerCylinder = geometry->NumHeads;
+  ad_infos[a].ports[p].devs[0].dev_info.usSectorsPerTrack = geometry->SectorsPerTrack;
+  ad_infos[a].ports[p].devs[0].dev_info.ullTotalSectors = ullTotalSectors;
+  ad_infos[a].ports[p].devs[0].dev_info.pMethod = Method;
 
   //DAZ DPRINTF(2,"Reported geometry: %d cylinders, %d heads, %d sectors per track (%dMB) (%s)\n",
-  DPRINTF(0,"Reported geometry: %d cylinders, %d heads, %d sectors per track (%dMB) (%s)\n",
+  DPRINTF(DBG_ATTACH, DBG_PREFIX": Reported geometry: %d cylinders, %d heads, %d sectors per track (%dMB) (%s)\n",
       geometry->TotalCylinders, geometry->NumHeads, geometry->SectorsPerTrack,
       (ULONG)(ullTotalSectors / 2048), Method);
@@ -799,5 +796,5 @@
   }
 
-  DPRINTF(7,"ata_read_unaligned(%d.%d.%d, %lld)\n", ad_no(ai), p, d, ullLba);
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": ata_read_unaligned(%d.%d.%d, %lld)\n", ad_no(ai), p, d, ullLba);
   ai->ports[p].unaligned_read_count++;
 
@@ -848,5 +845,5 @@
 
   io->BlocksXferred += add_workspace(pIorb)->blocks;
-  DPRINTF(7,__func__": blocks transferred = %d\n", io->BlocksXferred);
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": blocks transferred = %d\n", io->BlocksXferred);
 
   if (io->BlocksXferred >= io->BlockCount)
@@ -1059,5 +1056,5 @@
   }
 
-  DPRINTF(7,"ata_write_unaligned(%d.%d.%d, %lld)\n", ad_no(ai), p, d, ullLba);
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": ata_write_unaligned(%d.%d.%d, %lld)\n", ad_no(ai), p, d, ullLba);
 
   /* allocate transfer buffer */
@@ -1106,5 +1103,5 @@
 
   io->BlocksXferred += add_workspace(pIorb)->blocks;
-  DPRINTF(7,"ata_write_pp(): blocks transferred = %d\n", io->BlocksXferred);
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": ata_write_pp(): blocks transferred = %d\n", io->BlocksXferred);
 
   if (io->BlocksXferred >= io->BlockCount)
@@ -1176,5 +1173,5 @@
   {
     /* this is not a D2H FIS - give up silently */
-    DPRINTF(3,"ata_execute_ata_pp(): D2H FIS type incorrect: %d\n", fis[0]);
+    DPRINTF(DBG_DETAILED, DBG_PREFIX": ata_execute_ata_pp(): D2H FIS type incorrect: %d\n", fis[0]);
     add_workspace(pIorb)->complete = 1;
     return;
@@ -1197,5 +1194,5 @@
                 | ((u16) fis[13] << 8);
 
-  DHEXDUMP(5,cmd, sizeof(*cmd), "ahci_execute_ata_pp(): cmd after completion:\n");
+  DHEXDUMP(DBG_DETAILED, cmd, sizeof(*cmd), "ahci_execute_ata_pp(): cmd after completion:\n");
 
   /* signal completion to interrupt handler */
Index: trunk/src/os2ahci/atapi.c
===================================================================
--- trunk/src/os2ahci/atapi.c	(revision 208)
+++ trunk/src/os2ahci/atapi.c	(revision 209)
@@ -41,5 +41,5 @@
 int atapi_get_geometry(IORBH FAR16DATA *vIorb, IORBH *pIorb, int slot)
 {
-  DPRINTF(4,"atapi_get_geometry called\n");
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": atapi_get_geometry called\n");
   iorb_seterr(pIorb, IOERR_CMD_NOT_SUPPORTED);
   return(-1);
@@ -51,5 +51,5 @@
 int atapi_unit_ready(IORBH FAR16DATA *vIorb, IORBH *pIorb, int slot)
 {
-  DPRINTF(4,"atapi_unit_ready called\n");
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": atapi_unit_ready called\n");
   iorb_seterr(pIorb, IOERR_CMD_NOT_SUPPORTED);
   return(-1);
@@ -92,5 +92,5 @@
   SET_CDB_32(cdb.lba, io->RBA + io->BlocksXferred);
 
-  DPRINTF(4, "atapi_read\n");
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": atapi_read\n");
 
   do {
@@ -166,5 +166,5 @@
 
   ai->ports[p].unaligned_read_count++;
-  DPRINTF(4, "atapi_read_unaligned\n");
+  DPRINTF(DBG_DETAILED, DBG_PREFIX": atapi_read_unaligned\n");
 
   /* allocate transfer buffer */
@@ -207,5 +207,5 @@
 int atapi_verify(IORBH FAR16DATA *vIorb, IORBH *pIorb, int slot)
 {
-  DPRINTF(4,"atapi_verify called\n");
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": atapi_verify called\n");
   iorb_seterr(pIorb, IOERR_CMD_NOT_SUPPORTED);
   return(-1);
@@ -217,5 +217,5 @@
 int atapi_write(IORBH FAR16DATA *vIorb, IORBH *pIorb, int slot)
 {
-  DPRINTF(4,"atapi_write called\n");
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": atapi_write called\n");
   iorb_seterr(pIorb, IOERR_CMD_NOT_SUPPORTED);
   return(-1);
@@ -287,5 +287,5 @@
   size_t sense_buf_len = ATAPI_SENSE_LEN;
 
-  DPRINTF(4,"atapi_req_sense\n");
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": atapi_req_sense\n");
 
   if ((pIorb->RequestControl & IORB_REQ_STATUSBLOCK) &&
@@ -363,5 +363,5 @@
   ATAPI_SENSE_DATA *psd = (ATAPI_SENSE_DATA *) aws->buf;
 
-  DHEXDUMP(5,psd, sizeof(*psd), "sense buffer:\n");
+  DHEXDUMP(DBG_DETAILED, psd, sizeof(*psd), "sense buffer:\n");
 
   if ((pIorb->RequestControl & IORB_REQ_STATUSBLOCK) &&
Index: trunk/src/os2ahci/ctxhook.c
===================================================================
--- trunk/src/os2ahci/ctxhook.c	(revision 208)
+++ trunk/src/os2ahci/ctxhook.c	(revision 209)
@@ -97,5 +97,5 @@
   rearm_ctx_hook = 0;
 
-  DPRINTF(8,"restart_ctxhook() started\n");
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": restart_ctxhook() started\n");
   memset(&done_queue, 0x00, sizeof(done_queue));
 
@@ -124,9 +124,9 @@
         need_reset = 0;
 
-        DPRINTF(8,"port %d, TF_DATA: 0x%x\n", p, readl(port_mmio + PORT_TFDATA));
+        DPRINTF(DBG_DETAILED, DBG_PREFIX": port %d, TF_DATA: 0x%x\n", p, readl(port_mmio + PORT_TFDATA));
 
         /* get "current command slot"; only valid if there are no NCQ cmds */
         ccs = (int) ((readl(port_mmio + PORT_CMD) >> 8) & 0x1f);
-        DPRINTF(8," PORT_CMD      = 0x%x\n", ccs);
+        DPRINTF(DBG_DETAILED, DBG_PREFIX": PORT_CMD      = 0x%x\n", ccs);
 
         for (vIorb = ai->ports[p].iorb_queue.vRoot; vIorb != FAR16NULL; vIorb = vNext)
@@ -152,5 +152,5 @@
               {
                 /* this is the non-NCQ command that failed */
-                DPRINTF(0,"failing IORB: %x\n", vIorb);
+                DPRINTF(0, DBG_PREFIX": failing IORB: %x\n", vIorb);
                 vProblemIorb = vIorb;
               }
@@ -179,5 +179,5 @@
         if (ai->ports[p].ncq_cmds != 0 || ai->ports[p].reg_cmds != 0)
         {
-          DPRINTF(0,"warning: commands issued not 0 (%08lx/%08lx); resetting...\n",
+          DPRINTF(0, DBG_PREFIX": warning: commands issued not 0 (%08lx/%08lx); resetting...\n",
                   ai->ports[p].ncq_cmds, ai->ports[p].reg_cmds);
           need_reset = 1;
@@ -278,5 +278,5 @@
   spin_unlock(drv_lock);
 
-  DPRINTF(8,"restart_ctxhook() completed\n");
+  DPRINTF(DBG_FUNCEND, DBG_PREFIX": restart_ctxhook() completed\n");
 
   /* Check whether we have to rearm ourselves because some adapters were busy
@@ -332,5 +332,5 @@
   rearm_ctx_hook = 0;
 
-  DPRINTF(8,"reset_ctxhook() started\n");
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": reset_ctxhook() started\n");
   memset(&done_queue, 0x00, sizeof(done_queue));
 
@@ -457,5 +457,5 @@
   spin_unlock(drv_lock);
 
-  DPRINTF(8,"reset_ctxhook() completed\n");
+  DPRINTF(DBG_FUNCEND, DBG_PREFIX": reset_ctxhook() completed\n");
 
   /* Check whether we have to rearm ourselves because some adapters were busy
@@ -489,5 +489,5 @@
   D32ThunkStackTo32();
 
-  DPRINTF(8,"engine_ctxhook() started\n");
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": engine_ctxhook() started\n");
   if (resume_sleep_flag)
   {
@@ -503,5 +503,5 @@
   spin_unlock(drv_lock);
 
-  DPRINTF(8,"engine_ctxhook() completed\n");
+  DPRINTF(DBG_FUNCEND, DBG_PREFIX": engine_ctxhook() completed\n");
 
   if (iorbs_sent != 0)
Index: trunk/src/os2ahci/os2ahci.c
===================================================================
--- trunk/src/os2ahci/os2ahci.c	(revision 208)
+++ trunk/src/os2ahci/os2ahci.c	(revision 209)
@@ -59,5 +59,5 @@
 int init_reset = 1;    /* if != 0, reset ports during init */
 int force_write_cache; /* if != 0, force write cache */
-int verbosity = 0;     /* default is quiet. 1=show sign on banner, >1=show adapter info during boot */
+int iVerbose = 0;     /* default is quiet. 1=show sign on banner, >1=show adapter info during boot */
 int use_mbr_test = 1;
 
@@ -182,5 +182,7 @@
     return(RPDONE | ((init_drv_failed) ? RPERR_INITFAIL : 0));
   }
-  D32g_DbgLevel = 0;
+  #ifdef DEBUG
+  D32g_DbgLevel = 0x80000000 | DEBUG;
+  #endif
   init_drv_called = 1;
   suspended = 0;
@@ -203,5 +205,5 @@
   if ((rmrc = RMCreateDriver(&rm_drvinfo, &rm_drvh)) != RMRC_SUCCESS)
   {
-    iprintf("%s: failed to register driver with resource manager (rc = %d)", drv_name, rmrc);
+    iprintf("OS2AHCI.ADD: failed to register driver with resource manager (rc = %d)", rmrc);
     goto init_fail;
   }
@@ -236,15 +238,12 @@
     }
 
-    if (ArgCmp(pszCmdLine, "D"))
-    {
-      pszCmdLine++;
-      if (*pszCmdLine == ':')
-      {
-        pszCmdLine++;
-        D32g_DbgLevel = strtol(pszCmdLine, &pszCmdLine, 0);
-      }
-      else D32g_DbgLevel++; /* increase debug level */
-      continue;
-    }
+    #ifdef DEBUG
+    if (ArgCmp(pszCmdLine, "DEBUG:"))
+    {
+      pszCmdLine += 6;
+      D32g_DbgLevel = strtol(pszCmdLine, &pszCmdLine, 0);
+      continue;
+    }
+    #endif
 
     if (ArgCmp(pszCmdLine, "G:"))
@@ -261,5 +260,5 @@
       if (add_pci_id(usVendor, usDevice))
       {
-        iprintf("%s: failed to add PCI ID %04x:%04x", drv_name, usVendor, usDevice);
+        iprintf("OS2AHCI.ADD: failed to add PCI ID %04x:%04x", usVendor, usDevice);
         iStatus = 1;
       }
@@ -299,5 +298,5 @@
       if (adapter_index < 0 || adapter_index >= MAX_AD)
       {
-        iprintf("%s: invalid adapter index (%d)", drv_name, adapter_index);
+        iprintf("OS2AHCI.ADD: invalid adapter index (%d)", adapter_index);
         iStatus = 1;
       }
@@ -312,5 +311,5 @@
       if (port_index < 0 || port_index >= AHCI_MAX_PORTS)
       {
-        iprintf("%s: invalid port index (%d)", drv_name, port_index);
+        iprintf("OS2AHCI.ADD: invalid port index (%d)", port_index);
         iStatus = 1;
       }
@@ -393,10 +392,5 @@
     {
       pszCmdLine++;
-      if (*pszCmdLine == ':')
-      {
-        pszCmdLine++;
-        verbosity = strtol(pszCmdLine, &pszCmdLine, 0);
-      }
-      else verbosity++; /* increase verbosity level */
+      iVerbose = 1;
       continue;
     }
@@ -410,5 +404,5 @@
     }
 
-    iprintf("Unrecognized switch: %s", pszCmdLine-1);
+    iprintf("OS2AHCI.ADD: Unrecognized switch: %s", pszCmdLine-1);
     iStatus = 1; /* unrecognized argument */
   }
@@ -427,5 +421,5 @@
 
   /* print initialization message */
-  ciprintf("%s driver version %d.%02d", drv_name, DMAJOR, DMINOR);
+  if (iVerbose) iprintf("OS2AHCI.ADD: driver version %d.%02d", DMAJOR, DMINOR);
 
   #ifdef TESTVER
@@ -442,5 +436,5 @@
     if (Dev32Help_RegisterDeviceClass(drv_name, add_entry, 0, 1, &add_handle))
     {
-      iprintf("%s: couldn't register device class", drv_name);
+      iprintf("OS2AHCI.ADD: couldn't register device class");
       goto init_fail;
     }
@@ -461,5 +455,5 @@
   {
     /* no adapters found */
-    ciprintf("%s: No adapters found.", drv_name);
+    if (iVerbose) iprintf("OS2AHCI.ADD: No adapters found.");
   }
 
@@ -474,5 +468,5 @@
   }
 
-  ciprintf("%s driver *not* installed", drv_name);
+  if (iVerbose) iprintf("OS2AHCI.ADD: driver *not* installed");
   return(RPDONE | RPERR_INITFAIL);
 }
@@ -486,5 +480,5 @@
 USHORT gen_ioctl(REQPACKET *ioctl)
 {
-  DPRINTF(2,"IOCTL 0x%x/0x%x\n", ioctl->ioctl.bCategory, ioctl->ioctl.bFunction);
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": IOCTL 0x%x/0x%x\n", ioctl->ioctl.bCategory, ioctl->ioctl.bFunction);
   AhciStats.ulTestCount2++;
 
@@ -544,5 +538,5 @@
 USHORT exit_drv(int func)
 {
-  DPRINTF(2,"exit_drv(%d) called\n", func);
+  DPRINTF(DBG_FUNCBEG|DBG_INIT, DBG_PREFIX": exit_drv(%d) called\n", func);
 
   if (func == 0)
@@ -562,5 +556,5 @@
 USHORT sr_drv(int func)
 {
-  DPRINTF(2,"sr_drv(%d) called\n", func);
+  DPRINTF(DBG_FUNCBEG|DBG_INIT, DBG_PREFIX": sr_drv(%d) called\n", func);
 
   if (func) resume();
@@ -859,5 +853,5 @@
     if (!init_complete)
     {
-      DPRINTF(1,"leaving initialization mode\n");
+      DPRINTF(DBG_INIT, DBG_PREFIX": leaving initialization mode\n");
       for (a = 0; a < ad_info_cnt; a++)
       {
@@ -872,5 +866,5 @@
         unlock_adapter(ad_infos + a);
       }
-      DPRINTF(1,"leaving initialization mode 2\n");
+      DPRINTF(DBG_INIT, DBG_PREFIX": leaving initialization mode 2\n");
 
       #ifdef LEGACY_APM
@@ -1308,5 +1302,4 @@
 
   #ifdef DEBUG
-  if (D32g_DbgLevel)
   {
     /* determine queue type (local, driver, abort or port) and minimum debug
@@ -1314,5 +1307,5 @@
      */
     char *queue_type;
-    int min_debug = 7;
+    int min_debug = DBG_DETAILED;
 
     if ((u32)queue >> 16 == (u32)&queue >> 16) /* DAZ this is bogus */
@@ -1320,5 +1313,5 @@
       /* this queue is on the stack */
       queue_type = "local";
-      min_debug = 8;
+      min_debug = DBG_DETAILED;
     }
     else if (queue == &driver_queue)
@@ -1329,5 +1322,5 @@
     {
       queue_type = "abort";
-      min_debug = 8;
+      min_debug = DBG_DETAILED;
     }
     else
@@ -1336,5 +1329,5 @@
     }
 
-    DPRINTF(min_debug,"IORB %x queued (cmd=%d/%d queue=%x [%s], timeout=%d)\n",
+    dprintf(min_debug, DBG_PREFIX": IORB %x queued (cmd=%d/%d queue=%x [%s], timeout=%d)\n",
            vIorb, pIorb->CommandCode, pIorb->CommandModifier, queue, queue_type,
            pIorb->Timeout);
@@ -1381,9 +1374,9 @@
   if (found)
   {
-    DPRINTF(8,"IORB %x removed (queue = %x)\n", vIorb, queue);
+    DPRINTF(DBG_DETAILED, DBG_PREFIX": IORB %x removed (queue = %x)\n", vIorb, queue);
   }
   else
   {
-    DPRINTF(2,"IORB %x not found in queue %x\n", vIorb, queue);
+    DPRINTF(0, DBG_PREFIX": IORB %x not found in queue %x\n", vIorb, queue);
   }
   #endif
@@ -1454,5 +1447,5 @@
   pIorb->Status |= IORB_DONE;
 
-  DPRINTF(7,"IORB %x complete status=0x%04x error=0x%04x\n",
+  DPRINTF(DBG_FUNCBEG, DBG_PREFIX": IORB %x complete status=0x%04x error=0x%04x\n",
           vIorb, pIorb->Status, pIorb->ErrorCode);
 
Index: trunk/src/os2ahci/os2ahci.h
===================================================================
--- trunk/src/os2ahci/os2ahci.h	(revision 208)
+++ trunk/src/os2ahci/os2ahci.h	(revision 209)
@@ -64,10 +64,22 @@
 #define MAX_RETRIES 3
 
+#define DBG_ALWAYS    0x0000
+#define DBG_FUNCBEG   0x0001
+#define DBG_FUNCEND   0x0002
+#define DBG_ATTACH    0x0004
+#define DBG_DETAILED  0x0008
+#define DBG_INIT      0x0010
+#define DBG_SPECIAL   0x0020
+#define DBG_VERBOSE   0x0100
+#define DBG_ERROR_ALL 0x800000ff
+
+#define DBG_PREFIX "AHCI: "__func__
+
 /* debug output macros */
 #ifdef DEBUG
 #define DPRINTF(a,b,...) dprintf(a, b, ##__VA_ARGS__)
 #define DHEXDUMP(a,b,c,d,...) dHexDump(a, b, c, d, ##__VA_ARGS__)
-#define DUMP_HOST_REGS(l,a,b) {if (D32g_DbgLevel>=l) ahci_dump_host_regs(a,b);}
-#define DUMP_PORT_REGS(l,a,b) {if (D32g_DbgLevel>=l) ahci_dump_port_regs(a,b);}
+#define DUMP_HOST_REGS(l,a,b) {if (D32g_DbgLevel&l) ahci_dump_host_regs(a,b);}
+#define DUMP_PORT_REGS(l,a,b) {if (D32g_DbgLevel&l) ahci_dump_port_regs(a,b);}
 #else
 #define DPRINTF(a,b,...)
@@ -76,11 +88,4 @@
 #define DUMP_PORT_REGS(l,a,b)
 #endif
-
-/* verbosity console print macros
- * (we use 'i' in ciprintf here to avoid name clash
- * with vprintf-like funcs)
- */
-#define ciprintf(a,...)  {if (verbosity > 0) iprintf(a, ##__VA_ARGS__);}
-#define ciiprintf(a,...) {if (verbosity > 1) iprintf(a, ##__VA_ARGS__);}
 
 /* adapter number from AD_INFO pointer; mainly for dprintf() purposes */
@@ -230,9 +235,9 @@
 
 typedef struct {
-    ULONG Cylinders;
-    USHORT HeadsPerCylinder;
-    USHORT SectorsPerTrack;
-    ULONGLONG  TotalSectors;
-    char *Method;
+    ULONG ulCylinders;
+    USHORT usHeadsPerCylinder;
+    USHORT usSectorsPerTrack;
+    ULONGLONG  ullTotalSectors;
+    char *pMethod;
 } DEV_INFO;
 
@@ -479,5 +484,5 @@
 extern int init_reset; /* if != 0, reset ports during init */
 extern int force_write_cache; /* if != 0, force write cache */
-extern int verbosity; /* if != 0, show some info during boot */
+extern int iVerbose; /* if != 0, show some info during boot */
 extern int use_mbr_test;
 
Index: trunk/src/os2ahci/pci.c
===================================================================
--- trunk/src/os2ahci/pci.c	(revision 208)
+++ trunk/src/os2ahci/pci.c	(revision 209)
@@ -271,5 +271,5 @@
   USHORT BusDevFunc;
 
-  DPRINTF(3,"scanning PCI bus...\n");
+  DPRINTF(DBG_INIT|DBG_FUNCBEG, DBG_PREFIX": scanning PCI bus...\n");
 
   /* Go through the list of PCI IDs and search for each device
@@ -374,5 +374,5 @@
   {
     /* set IRQ for first device/func to 11 */
-    DPRINTF(1,"hacking virtualbox PIIX3 PCI to ISA bridge IRQ mapping\n");
+    DPRINTF(DBG_INIT, DBG_PREFIX": hacking virtualbox PIIX3 PCI to ISA bridge IRQ mapping\n");
     irq = ad_infos[0].irq;
     PciWriteConfig(0x0008, 0x60, sizeof(irq), irq);
@@ -467,23 +467,8 @@
   pin = (int) ((val >> 8) & 0xff);
 
-  #if 0
-  i = 1;
-  if (irq==0 || irq==255) i = 0;
-
-  if (verbosity > i)
-  {
-    iprintf("%s AHCI device %s %s (%d:%d:%d %04x:%04x) class:0x%06x", i?"Found":"Ignoring",
-     vendor_from_id(vendor), device_from_id(device),
-     PCI_BUS_FROM_BDF(BusDevFunc), PCI_DEV_FROM_BDF(BusDevFunc), PCI_FUNC_FROM_BDF(BusDevFunc),
-     vendor, device, class);
-    if (i==0) iprintf("Invalid interrupt (IRQ=%d).", irq);
-  }
-  if (i==0) return;
-  #endif
-
   /* make sure we got room in the adapter information array */
   if (ad_info_cnt >= MAX_AD - 1)
   {
-    iprintf("%s: too many AHCI devices", drv_name);
+    iprintf("OS2AHCI.ADD: too many AHCI devices");
     return;
   }
@@ -511,7 +496,10 @@
    */
 
-  ciprintf("Adapter %d PCI=%d:%d:%d ID=%04x:%04x\n", ad_info_cnt, PCI_BUS_FROM_BDF(BusDevFunc),
-    PCI_DEV_FROM_BDF(BusDevFunc), PCI_FUNC_FROM_BDF(BusDevFunc), vendor, device);
-  DPRINTF(1,"Adapter %d PCI=%d:%d:%d ID=%04x:%04x\n", ad_info_cnt, PCI_BUS_FROM_BDF(BusDevFunc),
+  if (iVerbose)
+  {
+    iprintf("OS2AHCI.ADD: Adapter %d PCI=%d:%d:%d ID=%04x:%04x", ad_info_cnt, PCI_BUS_FROM_BDF(BusDevFunc),
+      PCI_DEV_FROM_BDF(BusDevFunc), PCI_FUNC_FROM_BDF(BusDevFunc), vendor, device);
+  }
+  DPRINTF(DBG_INIT, DBG_PREFIX": Adapter %d PCI=%d:%d:%d ID=%04x:%04x\n", ad_info_cnt, PCI_BUS_FROM_BDF(BusDevFunc),
     PCI_DEV_FROM_BDF(BusDevFunc), PCI_FUNC_FROM_BDF(BusDevFunc), vendor, device);
 
@@ -535,5 +523,5 @@
       if (resource.ResourceType != RS_TYPE_MEM)
       {
-        iprintf("%s: BAR #5 must be an MMIO region", drv_name);
+        iprintf("OS2AHCI.ADD: BAR #5 must be an MMIO region");
         goto add_pci_fail;
       }
@@ -549,9 +537,9 @@
       if (ret == RMRC_RES_ALREADY_CLAIMED)
       {
-        ciiprintf("Device already claimed.");
+        if (iVerbose) iprintf("OS2AHCI.ADD: Device already claimed.");
       }
       else
       {
-        iprintf("%s: couldn't register [MM]IO region (rc = %s)", drv_name, rmerr(ret));
+        iprintf("OS2AHCI.ADD: couldn't register [MM]IO region (rc = %s)", rmerr(ret));
       }
       goto add_pci_fail;
@@ -562,5 +550,5 @@
   if (ad_info->mmio_phys == 0)
   {
-    iprintf("%s: couldn't determine MMIO base address", drv_name);
+    iprintf("OS2AHCI.ADD: couldn't determine MMIO base address");
     goto add_pci_fail;
   }
@@ -602,5 +590,5 @@
   if (ret != RMRC_SUCCESS)
   {
-    iprintf("%s: couldn't register adapter (rc = %s)", drv_name, rmerr(ret));
+    iprintf("OS2AHCI.ADD: couldn't register adapter (rc = %s)", rmerr(ret));
     goto add_pci_fail;
   }
@@ -666,5 +654,5 @@
       PciWriteConfig(BusDevFunc, PCI_BAR(i), sizeof(u32), bar_addr) )
   {
-    iprintf("%s: couldn't determine [MM]IO size", drv_name);
+    iprintf("OS2AHCI.ADD: couldn't determine [MM]IO size");
     if (bar_addr != 0)
     {
@@ -703,7 +691,6 @@
   }
 
-  DPRINTF(3,"BAR #%d: type = %s, addr = 0x%08lx, size = %d\n", i,
-           (resource->ResourceType == RS_TYPE_IO) ? "I/O" : "MEM",
-           bar_addr, bar_size);
+  DPRINTF(DBG_INIT, DBG_PREFIX": BAR #%d: type = %s, addr = 0x%08lx, size = %d\n", i,
+           (resource->ResourceType == RS_TYPE_IO) ? "I/O" : "MEM", bar_addr, bar_size);
 
   return((long) bar_size);
Index: trunk/src/os2ahci/trace.c
===================================================================
--- trunk/src/os2ahci/trace.c	(revision 208)
+++ trunk/src/os2ahci/trace.c	(revision 209)
@@ -42,9 +42,10 @@
           if (pi->devs[d].atapi) dprintf(0," atapi");
           if (pi->devs[d].removable) dprintf(0," removable");
-          if (pi->devs[d].dev_info.Method != NULL)
+          if (pi->devs[d].dev_info.pMethod != NULL)
           {
             dprintf(0," %d cylinders, %d heads, %d sectors per track (%dMB) (%s)",
-              pi->devs[d].dev_info.Cylinders, pi->devs[d].dev_info.HeadsPerCylinder, pi->devs[d].dev_info.SectorsPerTrack,
-              (ULONG)(pi->devs[d].dev_info.TotalSectors/2048), pi->devs[d].dev_info.Method);
+              pi->devs[d].dev_info.ulCylinders, pi->devs[d].dev_info.usHeadsPerCylinder,
+              pi->devs[d].dev_info.usSectorsPerTrack,
+              (ULONG)(pi->devs[d].dev_info.ullTotalSectors/2048), pi->devs[d].dev_info.pMethod);
           }
           if (pi->devs[d].ignored) dprintf(0," Unusable");
@@ -52,5 +53,5 @@
           dprintf(0,"          Model: %s\n", pi->devs[d].dev_name);
         }
-        else if (verbosity > 0)
+        else if (iVerbose > 0)
         {
           if (iFlag) dprintf(0,"  Port %d: No drive present\n", p);
@@ -64,5 +65,5 @@
 void DumpIorb(IORBH *pIorb)
 {
-  if (D32g_DbgLevel < 2) return;
+  if (!(D32g_DbgLevel & DBG_DETAILED)) return;
   if (!ad_infos[iorb_unit_adapter(pIorb)].ports[iorb_unit_port(pIorb)].devs[iorb_unit_device(pIorb)].atapi) return;
 
