Index: trunk/src/os2ahci/Makefile
===================================================================
--- trunk/src/os2ahci/Makefile	(revision 173)
+++ trunk/src/os2ahci/Makefile	(revision 174)
@@ -30,5 +30,5 @@
 # Define default build version if not specified in environment
 BLD_MAJOR=1
-BLD_MINOR=31 # must be 2 digits
+BLD_MINOR=32 # must be 2 digits
 BLD_REV=0 # not used at this time
 FIXPACK=
@@ -58,16 +58,6 @@
 !endif
 
-CC_INCLUDE = -I..\include &
-             -I$(DDK)\base\h &
-             -I$(DDK)\base\ibmh &
-             -I$(DDK)\base\src\dev\dasd\diskh &
-             -I$(DDK)\base\src\dev\thinkpad\dockii\apmcalls &
-
-AS_INCLUDE = -I=$(DDK)\base\inc &
-             -I=$(DDK)\base\src\dev\dasd\diskinc
-
-LIB_DIRS   = $(DDK)\base\lib\ &
-             $(DDK)\base\src\dev\dasd\devhlp\ &
-             $(DDK)\base\src\dev\thinkpad\dockii\apmcalls\
+AS_INCLUDE = -I=$(DDK)\base\inc
+LIB_DIRS = $(DDK)\base\lib\
 
 ###############################################################################
@@ -79,8 +69,9 @@
 #
 
-%PATH=..\..\tools;$(WATCOM)\BINP;$(WATCOM)\BINW;
-AS     = wasm
-CC     = wcc
-MAPSYM = $(DDK)\base\tools\mapsym.exe
+%INCLUDE=..\include;$(DDK)\base\h;
+%PATH=..\..\tools;$(WATCOM)\BINP;$(WATCOM)\BINW;$(DDK)\base\tools;
+AS=wasm
+CC=wcc
+MAPSYM=mapsym.exe
 
 !ifdef __LOADDLL__
@@ -160,5 +151,5 @@
 
 .c.obj: .autodepend
-    $(CC) $(CFLAGS) $(CC_INCLUDE) $[@
+    $(CC) $(CFLAGS) $[@
     #wdis -l $^@
 
Index: trunk/src/os2ahci/README
===================================================================
--- trunk/src/os2ahci/README	(revision 173)
+++ trunk/src/os2ahci/README	(revision 174)
@@ -8,6 +8,6 @@
 
 OS2AHCI is an AHCI driver for eComStation. It supports both ATA and
-ATAPI devices in a single driver, thus there's no need for an
-ATAPI/CDROM filter driver.
+ATAPI devices in a single driver. An ATAPI/CDROM filter driver is
+only required if you want to read/write CD-DA (audio) format CDs.
 
 
@@ -43,5 +43,5 @@
 =========================
 
-The *binary* delivery of OS2AHCI.ADD as obtained from ecomstation.nl,
+The *binary* delivery of OS2AHCI.ADD as obtained from the BetaZone,
 or as part of packaged eComStation releases, is licensed to run with
 eComStation only.
@@ -53,6 +53,6 @@
 
 Please note that builds other than the official binary delivered as
-part of eComStation releases or downloaded from ecomstation.nl are
-not officially supported by Mensys.
+part of eComStation releases or downloaded from the BetaZone are
+not officially supported.
 
 
@@ -62,12 +62,6 @@
 The toolchain required for compilation consists of:
 
- - IBM OS/2 DDK version 9.23 or later (see ddk\base\h\version.mak)
-   and that has been updated for SMP systems. (Used for include files)
- - Open Watcom C/C++ package
-   (available from: http://www.openwatcom.org/index.php/Downloads)
- - WCC 16-bit C Compiler (part of the Open Watcom package)
- - WASM Assembler (part of the Open Watcom package)
- - WLINK Linker (part of the Open Watcom package)
- - MAPSYM (part of the DDK)
+ - The MiniDDK or an updated DDK
+ - Open Watcom version 1.9 or later
 
 Define DDK and WATCOM in the environment.
@@ -358,7 +352,7 @@
 the character device named "IBMS506$", they will not work with OS2AHCI unless
 modified to open the OS2AHCI$ device. Previous versions of OS2AHCI used to
-register a duplicate device with the IBMS506$ name, however since
-that caused so many unacceptable problems, that is no longer done. You must
-have a SMART utility that opens the OS2AHCI$ device to access the AHCI driver.
+register a duplicate device with the IBMS506$ name, however since that caused
+so many unacceptable problems, that is no longer done. You must have a SMART
+utility that opens the OS2AHCI$ device to access the AHCI driver.
 
 A patched version of the smartctl.exe program is included in the OS2AHCI
@@ -393,4 +387,9 @@
 Change Log
 ==========
+
+v.1.32 09-Nov-2013 - David Azarewicz
+  Fix for some hardware that reports incorrect status
+  Report real device in addition to fake SCSI device when SCSI emulation
+    is enabled.
 
 v.1.31 21-Aug-2013 - David Azarewicz
Index: trunk/src/os2ahci/ahci.c
===================================================================
--- trunk/src/os2ahci/ahci.c	(revision 173)
+++ trunk/src/os2ahci/ahci.c	(revision 174)
@@ -315,7 +315,5 @@
     /* more ports in port_map than in HOST_CAP & 0x1f */
     ports = ai->hw_ports;
-    dprintf("implemented port map (0x%lx) contains more "
-            "ports than nr_ports (%d), using nr_ports\n",
-            ai->port_map, ports);
+    dprintf("implemented port map (0x%lx) contains more ports than nr_ports (%d), using nr_ports\n", ai->port_map, ports);
     ai->port_map = (1UL << ports) - 1UL;
   }
@@ -347,6 +345,5 @@
   readl(ai->mmio + HOST_CTL);
 
-  if ((ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN) == 0 &&
-      ai->pci_vendor == PCI_VENDOR_ID_INTEL) {
+  if ((ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN) == 0 && ai->pci_vendor == PCI_VENDOR_ID_INTEL) {
 
     /* This BIOS apparently accesses the controller via SATA registers and
@@ -410,4 +407,5 @@
 }
 
+#ifdef NOT_USED
 int ahci_reset_controller(AD_INFO *ai)
 {
@@ -416,7 +414,6 @@
 
     dprintf("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.
-     */
+
+    /* we must be in AHCI mode, before using anything AHCI-specific, such as HOST_RESET. */
     ahci_enable_ahci(ai);
 
@@ -445,7 +442,5 @@
     ahci_enable_ahci(ai);
 
-    /* Some registers might be cleared on reset.  Restore
-     * initial values.
-     */
+    /* Some registers might be cleared on reset.  Restore initial values. */
     ahci_restore_initial_config(ai);
 
@@ -465,4 +460,5 @@
     return 0;
 }
+#endif
 
 /******************************************************************************
@@ -769,8 +765,9 @@
   writel(port_mmio + PORT_SCR_ERR, tmp);
 
-  /* power up and spin up the drive if necessary */
-  if (((tmp = readl(port_mmio + PORT_CMD)) & (PORT_CMD_SPIN_UP|PORT_CMD_POWER_ON)) != (PORT_CMD_SPIN_UP|PORT_CMD_POWER_ON)) {
-    writel(port_mmio + PORT_CMD, tmp | PORT_CMD_SPIN_UP | PORT_CMD_POWER_ON);
-  }
+  /* Some hardware reports incorrect status so just set these bits unconditionally */
+  tmp = readl(port_mmio + PORT_CMD);
+  tmp &= ~PORT_CMD_ALPE; /* turn off agressive power management */
+  tmp |= (PORT_CMD_SPIN_UP | PORT_CMD_POWER_ON); /* power up and spin up the drive */
+  writel(port_mmio + PORT_CMD, tmp);
 
   /* set link speed and power management options */
@@ -1309,10 +1306,11 @@
     rc = timer_check_and_block(&Timer);
     if (rc) {
-      dprintf(" Timeout", tmp);
+      dprintf(" Timeout");
       break;
     }
   }
 
-  if ((tmp = readl(port_mmio + PORT_SCR_ERR)) != 0) {
+  tmp = readl(port_mmio + PORT_SCR_ERR);
+  if (tmp & PORT_ERR_FAIL_BITS) {
     dprintf(" SERR = 0x%08lx", tmp);
     rc = 1;
Index: trunk/src/os2ahci/ahci.h
===================================================================
--- trunk/src/os2ahci/ahci.h	(revision 173)
+++ trunk/src/os2ahci/ahci.h	(revision 174)
@@ -182,4 +182,25 @@
                                  PORT_IRQ_PIOS_FIS | PORT_IRQ_D2H_REG_FIS)
 
+#define PORT_ERR_X              (1UL << 26) /* Exchanged */
+#define PORT_ERR_FIS            (1UL << 25) /* Unknown FIS type */
+#define PORT_ERR_TP             (1UL << 24) /* Transport State Transition Error */
+#define PORT_ERR_S              (1UL << 23) /* Link Sequence Error */
+#define PORT_ERR_H              (1UL << 22) /* Handshake Error */
+#define PORT_ERR_CRC            (1UL << 21) /* CRC Error */
+#define PORT_ERR_D              (1UL << 20) /* Disparity Error */
+#define PORT_ERR_B              (1UL << 19) /* 10B to 8B Decode Error */
+#define PORT_ERR_W              (1UL << 18) /* Comm Wake */
+#define PORT_ERR_PI             (1UL << 17) /* Phy Internal Error */
+#define PORT_ERR_N              (1UL << 16) /* PhyRdy Change */
+#define PORT_ERR_IE             (1UL << 11) /* Internal Error */
+#define PORT_ERR_P              (1UL << 10) /* Protocol Error */
+#define PORT_ERR_C              (1UL << 9)  /* Persistent Communication or Data Integrity Error */
+#define PORT_ERR_TD             (1UL << 8)  /* Transient Data Integrity Error */
+#define PORT_ERR_M              (1UL << 1)  /* Recovered Communications Error */
+#define PORT_ERR_DI             (1UL << 0)  /* Recoverred Data Integrity Error */
+#define PORT_ERR_FAIL_BITS      (PORT_ERR_X | PORT_ERR_FIS | PORT_ERR_TP | PORT_ERR_S | PORT_ERR_H | PORT_ERR_CRC | \
+                                 PORT_ERR_D | PORT_ERR_B | PORT_ERR_W | PORT_ERR_PI | PORT_ERR_IE | PORT_ERR_P | \
+                                 PORT_ERR_C | PORT_ERR_TD)
+
 /* PORT_CMD bits */
 #define PORT_CMD_ASP            (1UL << 27) /* Aggressive Slumber/Partial */
Index: trunk/src/os2ahci/os2ahci.c
===================================================================
--- trunk/src/os2ahci/os2ahci.c	(revision 173)
+++ trunk/src/os2ahci/os2ahci.c	(revision 174)
@@ -1072,7 +1072,7 @@
           if (ad_info->ports[p].devs[d].present) {
             if (ad_info->ports[p].devs[d].atapi && emulate_scsi[dta][p]) {
-              /* only report this unit as SCSI unit */
+              /* report this unit as SCSI unit */
               scsi_units++;
-              continue;
+              //continue;
             }
             if (add_unit_info(iorb_conf, dta, dta, p, d, 0)) {
@@ -1101,7 +1101,5 @@
         for (p = 0; p <= ad_info->port_max; p++) {
           for (d = 0; d <= ad_info->ports[p].dev_max; d++) {
-            if (ad_info->ports[p].devs[d].present &&
-                ad_info->ports[p].devs[d].atapi &&
-                emulate_scsi[a][p]) {
+            if (ad_info->ports[p].devs[d].present && ad_info->ports[p].devs[d].atapi && emulate_scsi[a][p]) {
               if (add_unit_info(iorb_conf, dta, a, p, d, scsi_id++)) {
                 goto iocm_device_table_done;
@@ -1446,6 +1444,5 @@
  * separate function which is invoked via a context hook.
  */
-void _cdecl _far timeout_callback(ULONG timer_handle, ULONG p1,
-                                  ULONG p2)
+void _cdecl _far timeout_callback(ULONG timer_handle, ULONG p1, ULONG p2)
 {
   IORBH _far *iorb = (IORBH _far *) p1;
@@ -1502,6 +1499,5 @@
  * problems during the early boot phase.
  */
-void _cdecl _far reset_watchdog(ULONG timer_handle, ULONG p1,
-                                ULONG p2)
+void _cdecl _far reset_watchdog(ULONG timer_handle, ULONG p1, ULONG p2)
 {
   /* reset watchdog timer */
Index: trunk/src/os2ahci/pci.c
===================================================================
--- trunk/src/os2ahci/pci.c	(revision 173)
+++ trunk/src/os2ahci/pci.c	(revision 174)
@@ -931,6 +931,6 @@
   }
 
-  dddphex(parm, sizeof(*parm), "oemhlp_parm: ");
-  dddphex(data, sizeof(*data), "oemhlp_data: ");
+  //dddphex(parm, sizeof(*parm), "oemhlp_parm: ");
+  //dddphex(data, sizeof(*data), "oemhlp_data: ");
 
   if (ioctl.rph.Status & STERR) {
