Index: /trunk/src/os2ahci/ahci.c
===================================================================
--- /trunk/src/os2ahci/ahci.c	(revision 70)
+++ /trunk/src/os2ahci/ahci.c	(revision 71)
@@ -553,5 +553,5 @@
 
   /* enable interrupts on PCI-level (PCI 2.3 added a feature to disable ints) */
-  pci_enable_int(ai->bus, ai->dev_func);
+  /* pci_enable_int(ai->bus, ai->dev_func); */
 
   return(0);
@@ -1103,9 +1103,11 @@
 int ahci_flush_cache(AD_INFO *ai, int p, int d)
 {
-  dprintf("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));
+  if (!ai->ports[p].devs[d].atapi) {
+    dprintf("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));
+  }
 }
 
@@ -1397,8 +1399,4 @@
   int d = iorb_unit_device(iorb);
 
-  dphex(((IORB_ADAPTER_PASSTHRU _far *) iorb)->pControllerCmd,
-        ((IORB_ADAPTER_PASSTHRU _far *) iorb)->ControllerCmdLen,
-        "ahci_execute_cdb(%d.%d.%d)", a, p, d);
-
   if (ad_infos[a].ports[p].devs[d].atapi) {
     ahci_exec_iorb(iorb, 0, atapi_execute_cdb);
@@ -1471,5 +1469,5 @@
       dprintf("NCQ off for a:%d p:%d\n", (int) ad_no(ai), p);
     } else {
-      ai->ports[p].devs[d].ncq_max = id_buf[ATA_ID_QUEUE_DEPTH] & 0x001fU;
+      ai->ports[p].devs[d].ncq_max = max(1, id_buf[ATA_ID_QUEUE_DEPTH] & 0x001fU);
       dprintf("NCQ max=%d for a:%d p:%d\n", ai->ports[p].devs[d].ncq_max, (int) ad_no(ai), p);
     }
@@ -1518,5 +1516,5 @@
   if (ai == ad_infos && p == 7 &&
       ai->pci->vendor == 0x8086 && ai->pci->device == 0x2829 &&
-      !memcmp(ds.DevDescriptName, "VBOX HARDDISK", 13)) {
+      !memcmp(ata_dev_name(id_buf), "VBOX HARDDISK", 13)) {
     /* running inside virtualbox */
     pci_hack_virtualbox();
Index: /trunk/src/os2ahci/ata.c
===================================================================
--- /trunk/src/os2ahci/ata.c	(revision 70)
+++ /trunk/src/os2ahci/ata.c	(revision 71)
@@ -624,5 +624,5 @@
 
   io->BlocksXferred += add_workspace(iorb)->blocks;
-  ddprintf("ata(pi)_read_pp(): blocks transferred = %d\n", (int) io->BlocksXferred);
+  dprintf("ata_read_pp(): blocks transferred = %d\n", (int) io->BlocksXferred);
 
   if (io->BlocksXferred >= io->BlockCount) {
@@ -756,5 +756,5 @@
 
   io->BlocksXferred += add_workspace(iorb)->blocks;
-  ddprintf("ata_write_pp(): blocks transferred = %d\n", (int) io->BlocksXferred);
+  dprintf("ata_write_pp(): blocks transferred = %d\n", (int) io->BlocksXferred);
 
   if (io->BlocksXferred >= io->BlockCount) {
Index: /trunk/src/os2ahci/atapi.c
===================================================================
--- /trunk/src/os2ahci/atapi.c	(revision 70)
+++ /trunk/src/os2ahci/atapi.c	(revision 71)
@@ -53,5 +53,5 @@
 int atapi_unit_ready(IORBH _far *iorb, int slot)
 {
-  dprintf("atapi_unit_ready called\n");
+  ddprintf("atapi_unit_ready called\n");
   iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
   return(-1);
@@ -123,5 +123,5 @@
 int atapi_verify(IORBH _far *iorb, int slot)
 {
-  dprintf("atapi_verify called\n");
+  ddprintf("atapi_verify called\n");
   iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
   return(-1);
@@ -133,5 +133,5 @@
 int atapi_write(IORBH _far *iorb, int slot)
 {
-  dprintf("atapi_write called\n");
+  ddprintf("atapi_write called\n");
   iorb_seterr(iorb, IOERR_CMD_NOT_SUPPORTED);
   return(-1);
@@ -241,5 +241,5 @@
   ATAPI_SENSE_DATA *psd = (ATAPI_SENSE_DATA *) aws->buf;
 
-  ddphex(psd, sizeof(psd), "sense buffer:\n");
+  dphex(psd, sizeof(psd), "sense buffer:\n");
 
   /* map sense data to some IOERR_ value */
Index: /trunk/src/os2ahci/libc.c
===================================================================
--- /trunk/src/os2ahci/libc.c	(revision 70)
+++ /trunk/src/os2ahci/libc.c	(revision 71)
@@ -73,5 +73,5 @@
   int reg;
   u8  data;
-} com1_init_sequence[] = {
+} com_init_sequence[] = {
   3, 0x80,   /* overlay divisor latch register at 0x3f8 and 0x3f9 */
   0, 0x01,   /* set low byte of divisor to 1 (115200 baud) */
@@ -107,9 +107,9 @@
   int i;
 
-  DevHelp_CreateSpinLock(&com_lock);
-
-  for (i = 0; com1_init_sequence[i].reg != -1; i++) {
-    u16 port = com_base + com1_init_sequence[i].reg;
-    u8  data = com1_init_sequence[i].data;
+  spin_lock(com_lock);
+
+  for (i = 0; com_init_sequence[i].reg != -1; i++) {
+    u16 port = com_base + com_init_sequence[i].reg;
+    u8  data = com_init_sequence[i].data;
     _asm {
       mov  dx, port;
@@ -118,4 +118,6 @@
     }
   }
+
+  spin_unlock(com_lock);
 }
 
Index: /trunk/src/os2ahci/os2ahci.c
===================================================================
--- /trunk/src/os2ahci/os2ahci.c	(revision 70)
+++ /trunk/src/os2ahci/os2ahci.c	(revision 71)
@@ -964,6 +964,6 @@
   }
 
-  dprintf("IORB queued:  %d/%d (queue = %Fp, IORB = %Fp)\n",
-          iorb->CommandCode, iorb->CommandModifier, queue, iorb);
+  ddprintf("IORB queued:  %d/%d (queue = %Fp, IORB = %Fp)\n",
+           iorb->CommandCode, iorb->CommandModifier, queue, iorb);
 }
 
@@ -995,7 +995,7 @@
 
   if (found) {
-    dprintf("IORB removed: %d/%d (queue = %Fp, IORB = %Fp) - %04x/%04x\n",
-            iorb->CommandCode, iorb->CommandModifier, queue, iorb,
-            iorb->Status, iorb->ErrorCode);
+    ddprintf("IORB removed: %d/%d (queue = %Fp, IORB = %Fp) - %04x/%04x\n",
+             iorb->CommandCode, iorb->CommandModifier, queue, iorb,
+             iorb->Status, iorb->ErrorCode);
   } else {
     dprintf("IORB %Fp not found in queue %Fp\n", iorb, queue);
Index: /trunk/src/os2ahci/os2ahci.def
===================================================================
--- /trunk/src/os2ahci/os2ahci.def	(revision 70)
+++ /trunk/src/os2ahci/os2ahci.def	(revision 71)
@@ -1,4 +1,4 @@
 library os2ahci
-Description '$@#thi.guten (www.thiguten.de):1.00.20110107#@OS/2 AHCI Adapter Device Driver'
+Description '$@#thi.guten (www.thiguten.de):1.00.20110215#@OS/2 AHCI Adapter Device Driver'
 protmode
 
Index: /trunk/src/os2ahci/os2ahci.h
===================================================================
--- /trunk/src/os2ahci/os2ahci.h	(revision 70)
+++ /trunk/src/os2ahci/os2ahci.h	(revision 71)
@@ -79,6 +79,6 @@
 
 /* max/min macros */
-#define max(a, b)  a > b ? a : b
-#define min(a, b)  a < b ? a : b
+#define max(a, b)  (a) > (b) ? (a) : (b)
+#define min(a, b)  (a) < (b) ? (a) : (b)
 
 /* debug output macros */
