Index: trunk/src/os2ahci/Makefile
===================================================================
--- trunk/src/os2ahci/Makefile	(revision 170)
+++ trunk/src/os2ahci/Makefile	(revision 171)
@@ -153,5 +153,5 @@
     @AddToFile $^@,$#define BLD_MONTH,DATEMONTH
     @AddToFile $^@,$#define BLD_DAY,DATEDAY
-    @AddToFile $^@,$#define BLDLEVEL,BLDLEVEL2,$(VENDOR),$(BLD_MAJOR).$(BLD_MINOR),AHCI Driver (c) Mensys BV 2013,$(FIXPACK)
+    @AddToFile $^@,$#define BLDLEVEL,BLDLEVEL2,$(VENDOR),$(BLD_MAJOR).$(BLD_MINOR),AHCI Driver (c) 2013 $(VENDOR),$(FIXPACK)
 
 .asm.obj: .autodepend
Index: trunk/src/os2ahci/README
===================================================================
--- trunk/src/os2ahci/README	(revision 170)
+++ trunk/src/os2ahci/README	(revision 171)
@@ -17,5 +17,5 @@
 Copyright (c) 2011 thi.guten Software Development
 Copyright (c) 2011-2013 Mensys B.V.
-Portions copyright (c) 2013 David Azarewicz
+Copyright (c) 2013 David Azarewicz
 
 Authors: Christian Mueller, Markus Thielen
@@ -394,7 +394,8 @@
 ==========
 
-v.1.31 04-Aug-2013 - David Azarewicz
+v.1.31 21-Aug-2013 - David Azarewicz
   Enhanced debug output.
   Added code to check for bad geometries reported by the BIOS and fix them.
+  Fixed a PCI ID coding error that has been there since version 1.01.
 
 v.1.30 29-Jun-2013 - David Azarewicz
Index: trunk/src/os2ahci/ahci.c
===================================================================
--- trunk/src/os2ahci/ahci.c	(revision 170)
+++ trunk/src/os2ahci/ahci.c	(revision 171)
@@ -4,5 +4,5 @@
  * Copyright (c) 2011 thi.guten Software Development
  * Copyright (c) 2011 Mensys B.V.
- * Portions copyright (c) 2013 David Azarewicz
+ * Copyright (c) 2013 David Azarewicz
  *
  * Authors: Christian Mueller, Markus Thielen
@@ -234,10 +234,6 @@
   }
 
-#if 0
-  /* init_reset is set by default. This code is commented out to allow
-   * unsetting init_reset by a command line switch
-   */
   if ((ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN) == 0 &&
-      ai->pci->vendor == PCI_VENDOR_ID_INTEL) {
+      ai->pci_vendor == PCI_VENDOR_ID_INTEL) {
     /* Adapter is not in AHCI mode and the spec says a COMRESET is
      * required when switching from SATA to AHCI mode and vice versa.
@@ -245,5 +241,4 @@
     init_reset = 1;
   }
-#endif
 
   #ifdef DEBUG
@@ -295,6 +290,6 @@
   }
 
-  if (ai->pci->vendor == PCI_VENDOR_ID_JMICRON &&
-      ai->pci->device == 0x2361 && ai->port_map != 1) {
+  if (ai->pci_vendor == PCI_VENDOR_ID_JMICRON &&
+      ai->pci_device == 0x2361 && ai->port_map != 1) {
     dprintf("JMB361 has only one port, port_map 0x%lx -> 0x%lx\n", ai->port_map, 1);
     ai->port_map = 1;
@@ -353,5 +348,5 @@
 
   if ((ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN) == 0 &&
-      ai->pci->vendor == PCI_VENDOR_ID_INTEL) {
+      ai->pci_vendor == PCI_VENDOR_ID_INTEL) {
 
     /* This BIOS apparently accesses the controller via SATA registers and
@@ -455,5 +450,5 @@
     ahci_restore_initial_config(ai);
 
-    if (ai->pci->vendor == PCI_VENDOR_ID_INTEL) {
+    if (ai->pci_vendor == PCI_VENDOR_ID_INTEL) {
       u32 tmp16 = 0;
 
@@ -1243,9 +1238,9 @@
     }
 
+    /* 0x89 = BSY(0x80) | DRQ(0x08) | ERR(0x01) */
     if (rc) {
       dprintf(" timeout for IORB %Fp", iorb);
       iorb_seterr(iorb, IOERR_ADAPTER_TIMEOUT);
-    } else if (readl(port_mmio + PORT_SCR_ERR) != 0 ||
-               readl(port_mmio + PORT_TFDATA) & 0x89) {
+    } else if (readl(port_mmio + PORT_SCR_ERR) != 0 || readl(port_mmio + PORT_TFDATA) & 0x89) {
       dprintf(" polled cmd error for IORB %Fp", iorb);
       iorb_seterr(iorb, IOERR_DEVICE_NONSPECIFIC);
@@ -1313,12 +1308,15 @@
   while (readl(port_mmio + PORT_CMD_ISSUE) & 1) {
     rc = timer_check_and_block(&Timer);
-    if (rc) break;
-  }
-
-  /* check error condition */
+    if (rc) {
+      dprintf(" Timeout", tmp);
+      break;
+    }
+  }
+
   if ((tmp = readl(port_mmio + PORT_SCR_ERR)) != 0) {
     dprintf(" SERR = 0x%08lx", tmp);
     rc = 1;
   }
+  /* 0x89 = BSY(0x80) | DRQ(0x08) | ERR(0x01) */
   if (((tmp = readl(port_mmio + PORT_TFDATA)) & 0x89) != 0) {
     dprintf(" TFDATA = 0x%08lx", tmp);
@@ -1819,5 +1817,5 @@
 
   /* try to detect virtualbox environment to enable a hack for IRQ routing */
-  if (ai == ad_infos && ai->pci->vendor == 0x8086 && ai->pci->device == 0x2829 &&
+  if (ai == ad_infos && ai->pci_vendor == 0x8086 && ai->pci_device == 0x2829 &&
       !memcmp(ata_dev_name(id_buf), "VBOX HARDDISK", 13)) {
     /* running inside virtualbox */
Index: trunk/src/os2ahci/init.asm
===================================================================
--- trunk/src/os2ahci/init.asm	(revision 170)
+++ trunk/src/os2ahci/init.asm	(revision 171)
@@ -37,5 +37,5 @@
 DEVHDR          SEGMENT WORD PUBLIC 'DATA'
 _dev_hdr        dd      -1                      ; next device header
-                dw      DEVLEV_3 + DEV_CHAR_DEV + DEV_IDC ; flags for ADD drivers
+                dw      DEVLEV_3 + DEV_CHAR_DEV + DEV_IDC + DEV_30; flags for ADD drivers
                 dw      OFFSET _asm_strat       ; strategy routine
                 dw      OFFSET _asm_idc_entry   ; IDC entry point
Index: trunk/src/os2ahci/os2ahci.c
===================================================================
--- trunk/src/os2ahci/os2ahci.c	(revision 170)
+++ trunk/src/os2ahci/os2ahci.c	(revision 171)
@@ -4,5 +4,5 @@
  * Copyright (c) 2011 thi.guten Software Development
  * Copyright (c) 2011 Mensys B.V.
- * Portions copyright (c) 2013 David Azarewicz
+ * Copyright (c) 2013 David Azarewicz
  *
  * Authors: Christian Mueller, Markus Thielen
@@ -153,7 +153,5 @@
 
 /******************************************************************************
- * OS/2 device driver main strategy function. This function is only used
- * for initialization purposes; all other calls go directly to the adapter
- * device driver's strategy function.
+ * OS/2 device driver main strategy function.
  *
  * NOTE: this is also used as the IDC entry point. We expect an IOCTL request
@@ -178,4 +176,9 @@
     break;
 
+  case CMDOpen:
+    build_user_info(1);
+    rc = STDON;
+    break;
+
   case CMDINPUT:
     rc = char_dev_input((RP_RWV _far *) req);
@@ -184,4 +187,11 @@
   case CMDSaveRestore:
     rc = sr_drv(((RPSAVERESTORE _far *) req)->FuncCode);
+    break;
+
+  case CMDClose:
+  case CMDInputS:
+  case CMDInputF:
+    /* noop */
+    rc = STDON;
     break;
 
@@ -831,5 +841,5 @@
       #endif
 
-      build_user_info();
+      build_user_info(0);
     }
     iorb_done(iorb);
Index: trunk/src/os2ahci/os2ahci.h
===================================================================
--- trunk/src/os2ahci/os2ahci.h	(revision 170)
+++ trunk/src/os2ahci/os2ahci.h	(revision 171)
@@ -4,4 +4,5 @@
  * Copyright (c) 2011 thi.guten Software Development
  * Copyright (c) 2011 Mensys B.V.
+ * Copyright (c) 2013 David Azarewicz
  *
  * Authors: Christian Mueller, Markus Thielen
@@ -376,4 +377,6 @@
 
   u32           port_map;              /* bitmap of active ports */
+  u16           pci_vendor;
+  u16           pci_device;
 
   /* initial adapter configuration from BIOS */
@@ -572,5 +575,5 @@
 extern u16         trace_read    (u8 _far *buf, u16 cb_buf);
 extern u16         trace_char_dev(RP_RWV _far *rwrb);
-extern void        build_user_info(void);
+extern void        build_user_info(int check);
 
 /* pci.c */
Index: trunk/src/os2ahci/pci.c
===================================================================
--- trunk/src/os2ahci/pci.c	(revision 170)
+++ trunk/src/os2ahci/pci.c	(revision 171)
@@ -4,4 +4,5 @@
  * Copyright (c) 2011 thi.guten Software Development
  * Copyright (c) 2011 Mensys B.V.
+ * Copyright (c) 2013 David Azarewicz
  *
  * Authors: Christian Mueller, Markus Thielen
@@ -712,8 +713,10 @@
    * itself with the OS/2 resource manager
    */
-  ad_info->pci      = pci_ids + i;
-  ad_info->bus      = bus;
+  ad_info->pci = pci_id;
+  ad_info->pci_vendor = vendor;
+  ad_info->pci_device = device;
+  ad_info->bus = bus;
   ad_info->dev_func = dev_func;
-  ad_info->irq      = irq;
+  ad_info->irq = irq;
 
   /* allocate memory for port-specific DMA scratch buffers */
Index: trunk/src/os2ahci/trace.c
===================================================================
--- trunk/src/os2ahci/trace.c	(revision 170)
+++ trunk/src/os2ahci/trace.c	(revision 171)
@@ -4,5 +4,5 @@
  * Copyright (c) 2011 thi.guten Software Development
  * Copyright (c) 2011 Mensys B.V.
- * Portions copyright (c) 2013 David Azarewicz
+ * Copyright (c) 2013 David Azarewicz
  *
  * Authors: Christian Mueller, Markus Thielen
@@ -210,5 +210,5 @@
  * Create adapter/port/device list for user output.
  */
-void build_user_info(void)
+void build_user_info(int check)
 {
   int a;
@@ -216,10 +216,12 @@
   int d;
 
+  if ( check && (ahci_trace_buf.readp != ahci_trace_buf.writep)) return;
+
   for (a = 0; a < ad_info_cnt; a++) {
     AD_INFO *ai = ad_infos + a;
 
-    ntprintf("Adapter %d: PCI=%d:%d:%d ID=%04x:%04x irq=%d addr=0x%lx version=%lx\n", a,
+    ntprintf("Adapter %d: PCI=%d:%d:%d ID=%04x:%04x %s %s irq=%d addr=0x%lx version=%lx\n", a,
       ai->bus, ai->dev_func>>3, ai->dev_func&7,
-      ai->pci->vendor, ai->pci->device,
+      ai->pci_vendor, ai->pci_device, vendor_from_id(ai->pci_vendor), ai->pci->chipname,
       ai->irq, ai->mmio_phys,
       ai->bios_config[HOST_VERSION / sizeof(u32)]);
