win-pvdrivers

changeset 1025:aa2e51f67f7c

Fix hibernate under Win8. Change debugprints.
author James Harper <james.harper@bendigoit.com.au>
date Tue Feb 19 15:14:53 2013 +1100 (2013-02-19)
parents 53d89db72d24
children d9a2a6de2ab4
files xenvbd_common/common_miniport.h xenvbd_common/common_xen.h xenvbd_filter/xenvbd_filter.c xenvbd_scsiport/common.h xenvbd_scsiport/xenvbd.c xenvbd_storport/xenvbd.c xenvbd_storport/xenvbd.h
line diff
     1.1 --- a/xenvbd_common/common_miniport.h	Tue Feb 19 15:13:22 2013 +1100
     1.2 +++ b/xenvbd_common/common_miniport.h	Tue Feb 19 15:14:53 2013 +1100
     1.3 @@ -40,10 +40,9 @@ ULONGLONG parse_numeric_string(PCHAR str
     1.4  
     1.5  /* called with StartIoLock held */
     1.6  static blkif_shadow_t *
     1.7 -get_shadow_from_freelist(PXENVBD_DEVICE_DATA xvdd)
     1.8 -{
     1.9 +get_shadow_from_freelist(PXENVBD_DEVICE_DATA xvdd) {
    1.10    if (xvdd->shadow_free == 0) {
    1.11 -    KdPrint((__DRIVER_NAME "     No more shadow entries\n"));
    1.12 +    FUNCTION_MSG("No more shadow entries\n");
    1.13      return NULL;
    1.14    }
    1.15    xvdd->shadow_free--;
    1.16 @@ -118,7 +117,7 @@ decode_cdb_sector(PSCSI_REQUEST_BLOCK sr
    1.17             | ((ULONGLONG)(UCHAR)srb->Cdb[4] << 40) | ((ULONGLONG)(UCHAR)srb->Cdb[5] << 32)
    1.18             | ((ULONGLONG)(UCHAR)srb->Cdb[6] << 24) | ((ULONGLONG)(UCHAR)srb->Cdb[7] << 16)
    1.19             | ((ULONGLONG)(UCHAR)srb->Cdb[8] << 8) | ((ULONGLONG)(UCHAR)srb->Cdb[9]);
    1.20 -    //KdPrint((__DRIVER_NAME "     sector_number = %d (high) %d (low)\n", (ULONG)(sector >> 32), (ULONG)sector));
    1.21 +    //FUNCTION_MSG("sector_number = %d (high) %d (low)\n", (ULONG)(sector >> 32), (ULONG)sector);
    1.22      break;
    1.23    default:
    1.24      sector = 0;
    1.25 @@ -182,8 +181,11 @@ XenVbd_HandleEvent(PXENVBD_DEVICE_DATA x
    1.26    blkif_shadow_t *shadow;
    1.27    srb_list_entry_t *srb_entry;
    1.28  
    1.29 -  //if (dump_mode)
    1.30 -  //FUNCTION_ENTER();
    1.31 +  if (xvdd->device_state != DEVICE_STATE_ACTIVE && xvdd->device_state != DEVICE_STATE_DISCONNECTING) {
    1.32 +    /* if we aren't active (eg just restored from hibernate) then we still want to process non-scsi srb's */
    1.33 +    XenVbd_ProcessSrbList(xvdd);
    1.34 +    return;
    1.35 +  }
    1.36  
    1.37    while (more_to_do) {
    1.38      rp = xvdd->ring.sring->rsp_prod;
    1.39 @@ -202,22 +204,22 @@ XenVbd_HandleEvent(PXENVBD_DEVICE_DATA x
    1.40          FUNCTION_MSG("discarding stale (non-dump-mode) shadow\n");
    1.41        } else {
    1.42          srb = shadow->srb;
    1.43 -        NT_ASSERT(srb);
    1.44 +        XN_ASSERT(srb);
    1.45          srb_entry = srb->SrbExtension;
    1.46 -        NT_ASSERT(srb_entry);
    1.47 +        XN_ASSERT(srb_entry);
    1.48          /* a few errors occur in dump mode because Xen refuses to allow us to map pages we are using for other stuff. Just ignore them */
    1.49          if (rep->status == BLKIF_RSP_OKAY || (dump_mode &&  dump_mode_errors++ < DUMP_MODE_ERROR_LIMIT)) {
    1.50            srb->SrbStatus = SRB_STATUS_SUCCESS;
    1.51          } else {
    1.52 -          KdPrint((__DRIVER_NAME "     Xen Operation returned error\n"));
    1.53 +          FUNCTION_MSG("Xen Operation returned error\n");
    1.54            if (decode_cdb_is_read(srb))
    1.55 -            KdPrint((__DRIVER_NAME "     Operation = Read\n"));
    1.56 +            FUNCTION_MSG("Operation = Read\n");
    1.57            else
    1.58 -            KdPrint((__DRIVER_NAME "     Operation = Write\n"));
    1.59 +            FUNCTION_MSG("Operation = Write\n");
    1.60            srb_entry->error = TRUE;
    1.61          }
    1.62          if (shadow->aligned_buffer_in_use) {
    1.63 -          NT_ASSERT(xvdd->aligned_buffer_in_use);
    1.64 +          XN_ASSERT(xvdd->aligned_buffer_in_use);
    1.65            xvdd->aligned_buffer_in_use = FALSE;
    1.66            if (srb->SrbStatus == SRB_STATUS_SUCCESS && decode_cdb_is_read(srb))
    1.67              memcpy((PUCHAR)shadow->system_address, xvdd->aligned_buffer, shadow->length);
    1.68 @@ -259,7 +261,7 @@ XenVbd_HandleEvent(PXENVBD_DEVICE_DATA x
    1.69      }
    1.70    }
    1.71  
    1.72 -  if (xvdd->device_state != DEVICE_STATE_ACTIVE && xvdd->device_state != DEVICE_STATE_INACTIVE && xvdd->shadow_free == SHADOW_ENTRIES) {
    1.73 +  if (xvdd->device_state == DEVICE_STATE_DISCONNECTING && xvdd->shadow_free == SHADOW_ENTRIES) {
    1.74      FUNCTION_MSG("ring now empty - completing disconnect\n");
    1.75      XenVbd_CompleteDisconnect(xvdd);
    1.76    }
    1.77 @@ -282,23 +284,25 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
    1.78    PVOID system_address;
    1.79  
    1.80    //if (dump_mode) FUNCTION_ENTER();
    1.81 -  //FUNCTION_MSG("Srb = %p\n", srb);
    1.82  
    1.83    //FUNCTION_MSG("aligned_buffer_in_use = %d\n", xvdd->aligned_buffer_in_use);
    1.84    //FUNCTION_MSG("shadow_free = %d\n", xvdd->shadow_free);
    1.85    
    1.86 -  NT_ASSERT(srb);
    1.87 +  XN_ASSERT(srb);
    1.88 +  
    1.89 +  if (xvdd->device_state != DEVICE_STATE_ACTIVE) {
    1.90 +    InsertHeadList(&xvdd->srb_list, (PLIST_ENTRY)srb->SrbExtension);
    1.91 +    return FALSE;
    1.92 +  }
    1.93  
    1.94    if (!dump_mode) {
    1.95      if (SxxxPortGetSystemAddress(xvdd, srb, &system_address) != STATUS_SUCCESS) {
    1.96        FUNCTION_MSG("Failed to map DataBuffer\n");
    1.97        InsertHeadList(&xvdd->srb_list, (PLIST_ENTRY)srb->SrbExtension);
    1.98 -      //if (dump_mode) FUNCTION_EXIT();
    1.99        return FALSE;
   1.100      }
   1.101      system_address = (PUCHAR)system_address + srb_entry->offset;
   1.102    } else {
   1.103 -    //FUNCTION_MSG("DataBuffer = %p\n", srb->DataBuffer);
   1.104      system_address = (PUCHAR)srb->DataBuffer + srb_entry->offset;
   1.105    }
   1.106    block_count = decode_cdb_length(srb);
   1.107 @@ -306,12 +310,12 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
   1.108    block_count *= xvdd->bytes_per_sector / 512;
   1.109    sector_number *= xvdd->bytes_per_sector / 512;
   1.110  
   1.111 -  NT_ASSERT(block_count * 512 == srb->DataTransferLength);
   1.112 +  XN_ASSERT(block_count * 512 == srb->DataTransferLength);
   1.113    
   1.114    sector_number += srb_entry->offset / 512;
   1.115    block_count -= srb_entry->offset / 512;
   1.116  
   1.117 -  NT_ASSERT(block_count > 0);
   1.118 +  XN_ASSERT(block_count > 0);
   1.119  
   1.120    /* look for pending writes that overlap this one */
   1.121    /* we get warnings from drbd if we don't */
   1.122 @@ -336,14 +340,13 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
   1.123        if (sector_number2 < sector_number && sector_number2 + block_count2 <= sector_number)
   1.124          continue;
   1.125  
   1.126 -      KdPrint((__DRIVER_NAME "     Concurrent outstanding write detected (%I64d, %d) (%I64d, %d)\n",
   1.127 -        sector_number, block_count, sector_number2, block_count2));
   1.128 +      FUNCTION_MSG("Concurrent outstanding write detected (%I64d, %d) (%I64d, %d)\n",
   1.129 +        sector_number, block_count, sector_number2, block_count2);
   1.130        break;
   1.131      }
   1.132      if (i != MAX_SHADOW_ENTRIES) {
   1.133        /* put the srb back at the start of the queue */
   1.134        InsertHeadList(&xvdd->srb_list, (PLIST_ENTRY)srb->SrbExtension);
   1.135 -      //if (dump_mode) FUNCTION_EXIT();
   1.136        return FALSE;
   1.137      }
   1.138    }
   1.139 @@ -355,8 +358,8 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
   1.140      //if (dump_mode) FUNCTION_EXIT();
   1.141      return FALSE;
   1.142    }
   1.143 -  NT_ASSERT(!shadow->aligned_buffer_in_use);
   1.144 -  NT_ASSERT(!shadow->srb);
   1.145 +  XN_ASSERT(!shadow->aligned_buffer_in_use);
   1.146 +  XN_ASSERT(!shadow->srb);
   1.147    shadow->req.sector_number = sector_number;
   1.148    shadow->req.handle = 0;
   1.149    shadow->req.operation = decode_cdb_is_read(srb)?BLKIF_OP_READ:BLKIF_OP_WRITE;
   1.150 @@ -380,7 +383,7 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
   1.151        shadow->aligned_buffer_in_use = FALSE;
   1.152      }
   1.153    } else {
   1.154 -    NT_ASSERT(!((ULONG_PTR)shadow->system_address & 511));
   1.155 +    XN_ASSERT(!((ULONG_PTR)shadow->system_address & 511));
   1.156      ptr = shadow->system_address;
   1.157      shadow->aligned_buffer_in_use = FALSE;
   1.158    }
   1.159 @@ -392,11 +395,10 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
   1.160      if (!dump_mode) {
   1.161        physical_address = MmGetPhysicalAddress(ptr);
   1.162      } else {
   1.163 -#if 0
   1.164 -      ULONG length;       
   1.165 -      physical_address = StorPortGetPhysicalAddress(xvdd, srb, ptr, &length);
   1.166 -#endif
   1.167 -      physical_address = MmGetPhysicalAddress(ptr);
   1.168 +      ULONG length;
   1.169 +      physical_address = SxxxPortGetPhysicalAddress(xvdd, srb, ptr, &length);
   1.170 +      //FUNCTION_MSG("physical_address = %08I64x\n", physical_address.QuadPart);
   1.171 +      
   1.172      }
   1.173      gref = XnGrantAccess(xvdd->handle,
   1.174             (ULONG)(physical_address.QuadPart >> PAGE_SHIFT), FALSE, INVALID_GRANT_REF, xvdd->grant_tag);
   1.175 @@ -413,15 +415,15 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
   1.176        /* put the srb back at the start of the queue */
   1.177        InsertHeadList(&xvdd->srb_list, (PLIST_ENTRY)srb_entry);
   1.178        put_shadow_on_freelist(xvdd, shadow);
   1.179 -      KdPrint((__DRIVER_NAME "     Out of gref's. Deferring\n"));
   1.180 +      FUNCTION_MSG("Out of gref's. Deferring\n");
   1.181        /* TODO: what if there are no requests currently in progress to kick the queue again?? timer? */
   1.182        return FALSE;
   1.183      }
   1.184      offset = physical_address.LowPart & (PAGE_SIZE - 1);
   1.185      length = min(PAGE_SIZE - offset, remaining);
   1.186 -    NT_ASSERT((offset & 511) == 0);
   1.187 -    NT_ASSERT((length & 511) == 0);
   1.188 -    NT_ASSERT(offset + length <= PAGE_SIZE);
   1.189 +    XN_ASSERT((offset & 511) == 0);
   1.190 +    XN_ASSERT((length & 511) == 0);
   1.191 +    XN_ASSERT(offset + length <= PAGE_SIZE);
   1.192      shadow->req.seg[shadow->req.nr_segments].gref = gref;
   1.193      shadow->req.seg[shadow->req.nr_segments].first_sect = (UCHAR)(offset / 512);
   1.194      shadow->req.seg[shadow->req.nr_segments].last_sect = (UCHAR)(((offset + length) / 512) - 1);
   1.195 @@ -462,8 +464,6 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   1.196    RtlZeroMemory(buffer, ARRAY_SIZE(buffer));
   1.197    offset = 0;
   1.198  
   1.199 -  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   1.200 -  
   1.201    switch (srb->Cdb[0]) {
   1.202    case SCSIOP_MODE_SENSE:
   1.203      cdb_llbaa = FALSE;
   1.204 @@ -474,7 +474,7 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   1.205      parameter_header->MediumType = 0;
   1.206      parameter_header->DeviceSpecificParameter = 0;
   1.207      if (xvdd->device_mode == XENVBD_DEVICEMODE_READ) {
   1.208 -      KdPrint((__DRIVER_NAME " Mode sense to a read only disk.\n"));
   1.209 +      FUNCTION_MSG(" Mode sense to a read only disk.\n");
   1.210        parameter_header->DeviceSpecificParameter |= MODE_DSP_WRITE_PROTECT; 
   1.211      }
   1.212      offset += sizeof(MODE_PARAMETER_HEADER);
   1.213 @@ -487,15 +487,14 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   1.214      parameter_header10 = (PMODE_PARAMETER_HEADER10)&buffer[offset];
   1.215      parameter_header10->MediumType = 0;
   1.216      parameter_header10->DeviceSpecificParameter = 0;
   1.217 -    if (xvdd->device_mode == XENVBD_DEVICEMODE_READ)
   1.218 -    {
   1.219 -      KdPrint((__DRIVER_NAME " Mode sense to a read only disk.\n"));
   1.220 +    if (xvdd->device_mode == XENVBD_DEVICEMODE_READ) {
   1.221 +      FUNCTION_MSG(" Mode sense to a read only disk.\n");
   1.222        parameter_header10->DeviceSpecificParameter |= MODE_DSP_WRITE_PROTECT; 
   1.223      }
   1.224      offset += sizeof(MODE_PARAMETER_HEADER10);
   1.225      break;
   1.226    default:
   1.227 -    KdPrint((__DRIVER_NAME "     SCSIOP_MODE_SENSE_WTF (%02x)\n", (ULONG)srb->Cdb[0]));
   1.228 +    FUNCTION_MSG("SCSIOP_MODE_SENSE_WTF (%02x)\n", (ULONG)srb->Cdb[0]);
   1.229      return FALSE;
   1.230    }  
   1.231    
   1.232 @@ -600,7 +599,6 @@ XenVbd_ResetBus(PXENVBD_DEVICE_DATA xvdd
   1.233    /* need to make sure that each SRB is only reset once */
   1.234    LIST_ENTRY srb_reset_list;
   1.235    PLIST_ENTRY list_entry;
   1.236 -  //STOR_LOCK_HANDLE lock_handle;
   1.237  
   1.238    UNREFERENCED_PARAMETER(PathId);
   1.239  
   1.240 @@ -676,18 +674,13 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.241    #endif
   1.242    PCDB cdb;
   1.243    ULONG data_transfer_length;
   1.244 -  UCHAR srb_status = SRB_STATUS_PENDING;
   1.245 +  UCHAR srb_status;
   1.246    ULONG notify = FALSE;
   1.247    PSCSI_REQUEST_BLOCK srb;
   1.248    srb_list_entry_t *srb_entry;
   1.249    PSRB_IO_CONTROL sic;
   1.250    ULONG prev_offset;
   1.251  
   1.252 -  if (xvdd->device_state != DEVICE_STATE_ACTIVE) {
   1.253 -    FUNCTION_MSG("Not yet active - state = %d\n", xvdd->device_state);
   1.254 -    return;
   1.255 -  }
   1.256 -
   1.257    while(!xvdd->aligned_buffer_in_use && xvdd->shadow_free && (srb_entry = (srb_list_entry_t *)RemoveHeadList(&xvdd->srb_list)) != (srb_list_entry_t *)&xvdd->srb_list) {
   1.258      srb = srb_entry->srb;
   1.259      prev_offset = srb_entry->offset;
   1.260 @@ -700,23 +693,28 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.261      }
   1.262  
   1.263      data_transfer_length = srb->DataTransferLength;
   1.264 +    srb_status = SRB_STATUS_PENDING;
   1.265      
   1.266      switch (srb->Function) {
   1.267      case SRB_FUNCTION_EXECUTE_SCSI:
   1.268 +      if (xvdd->device_state != DEVICE_STATE_ACTIVE) {
   1.269 +        FUNCTION_MSG("Not yet active - state = %d\n", xvdd->device_state);
   1.270 +        InsertHeadList(&xvdd->srb_list, (PLIST_ENTRY)srb->SrbExtension);
   1.271 +        break;
   1.272 +      }
   1.273        cdb = (PCDB)srb->Cdb;
   1.274 -
   1.275        switch(cdb->CDB6GENERIC.OperationCode) {
   1.276        case SCSIOP_TEST_UNIT_READY:
   1.277          if (dump_mode)
   1.278 -          KdPrint((__DRIVER_NAME "     Command = TEST_UNIT_READY\n"));
   1.279 +          FUNCTION_MSG("Command = TEST_UNIT_READY\n");
   1.280          srb_status = SRB_STATUS_SUCCESS;
   1.281          srb->ScsiStatus = 0;
   1.282          break;
   1.283        case SCSIOP_INQUIRY:
   1.284 -        if (dump_mode)
   1.285 -          KdPrint((__DRIVER_NAME "     Command = INQUIRY\n"));
   1.286 -  //      KdPrint((__DRIVER_NAME "     (LUN = %d, EVPD = %d, Page Code = %02X)\n", srb->Cdb[1] >> 5, srb->Cdb[1] & 1, srb->Cdb[2]));
   1.287 -  //      KdPrint((__DRIVER_NAME "     (Length = %d)\n", srb->DataTransferLength));
   1.288 +//        if (dump_mode)
   1.289 +          FUNCTION_MSG("Command = INQUIRY\n");
   1.290 +  //      FUNCTION_MSG("(LUN = %d, EVPD = %d, Page Code = %02X)\n", srb->Cdb[1] >> 5, srb->Cdb[1] & 1, srb->Cdb[2]);
   1.291 +  //      FUNCTION_MSG("(Length = %d)\n", srb->DataTransferLength);
   1.292          
   1.293          data_buffer = srb->DataBuffer;
   1.294          RtlZeroMemory(data_buffer, srb->DataTransferLength);
   1.295 @@ -760,22 +758,31 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.296                data_buffer[0] = DIRECT_ACCESS_DEVICE;
   1.297                data_buffer[1] = VPD_SERIAL_NUMBER;
   1.298                data_buffer[2] = 0x00;
   1.299 -              data_buffer[3] = 8;
   1.300 -              memset(&data_buffer[4], ' ', 8);
   1.301 -              data_transfer_length = 12;
   1.302 +              data_buffer[3] = (UCHAR)strlen(xvdd->serial_number);
   1.303 +              if (data_transfer_length > 4) {
   1.304 +                memcpy(&data_buffer[4], xvdd->serial_number, min(data_transfer_length - 4, strlen(xvdd->serial_number)));
   1.305 +              }
   1.306 +              data_transfer_length = 4 + (UCHAR)strlen(xvdd->serial_number);
   1.307                break;
   1.308              case VPD_DEVICE_IDENTIFIERS: /* identification - we don't support any so just return zero */
   1.309                FUNCTION_MSG("VPD_DEVICE_IDENTIFIERS\n");
   1.310                data_buffer[0] = DIRECT_ACCESS_DEVICE;
   1.311                data_buffer[1] = VPD_DEVICE_IDENTIFIERS;
   1.312                data_buffer[2] = 0x00;
   1.313 -              //data_buffer[3] = 4 + (UCHAR)strlen(xvdd->vectors.path); /* length */
   1.314 -              data_buffer[4] = 2; /* ASCII */
   1.315 -              data_buffer[5] = 1; /* VendorId */
   1.316 -              data_buffer[6] = 0;
   1.317 -              //data_buffer[7] = (UCHAR)strlen(xvdd->vectors.path);
   1.318 -              //memcpy(&data_buffer[8], xvdd->vectors.path, strlen(xvdd->vectors.path));
   1.319 -              //data_transfer_length = (ULONG)(8 + strlen(xvdd->vectors.path));
   1.320 +              data_buffer[3] = 2 * (4 + (UCHAR)strlen(xvdd->serial_number));
   1.321 +              if (data_transfer_length >= 4 + 2 * (4 + (ULONG)strlen(xvdd->serial_number))) {
   1.322 +                data_buffer[4] = 2; /* ASCII */
   1.323 +                data_buffer[5] = 0; /* VendorId */
   1.324 +                data_buffer[6] = 0; /* reserved */
   1.325 +                data_buffer[7] = (UCHAR)strlen(xvdd->serial_number);
   1.326 +                memcpy(&data_buffer[8], xvdd->serial_number, (UCHAR)strlen(xvdd->serial_number));
   1.327 +                data_buffer[8 + (UCHAR)strlen(xvdd->serial_number) + 0] = 2; /* ASCII */
   1.328 +                data_buffer[8 + (UCHAR)strlen(xvdd->serial_number) + 1] = 1; /* T10 VendorId */
   1.329 +                data_buffer[8 + (UCHAR)strlen(xvdd->serial_number) + 2] = 0; /* Reserved */
   1.330 +                data_buffer[8 + (UCHAR)strlen(xvdd->serial_number) + 3] = (UCHAR)strlen(xvdd->serial_number);
   1.331 +                memcpy(&data_buffer[8 + (UCHAR)strlen(xvdd->serial_number) + 4], xvdd->serial_number, (UCHAR)strlen(xvdd->serial_number));
   1.332 +              }
   1.333 +              data_transfer_length = 4 + 2 * (4 + (ULONG)strlen(xvdd->serial_number));
   1.334                break;
   1.335              case VPD_BLOCK_LIMITS: /* to indicate support for UNMAP (TRIM/DISCARD) */
   1.336                FUNCTION_MSG("VPD_BLOCK_LIMITS\n");
   1.337 @@ -836,36 +843,33 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.338                data_transfer_length = 12;
   1.339                break;
   1.340              default:
   1.341 -              //KdPrint((__DRIVER_NAME "     Unknown Page %02x requested\n", srb->Cdb[2]));
   1.342 +              FUNCTION_MSG("Unknown Page %02x requested\n", srb->Cdb[2]);
   1.343                srb_status = SRB_STATUS_ERROR;
   1.344                break;
   1.345              }
   1.346            }
   1.347            break;
   1.348          default:
   1.349 -          //KdPrint((__DRIVER_NAME "     Unknown DeviceType %02x requested\n", xvdd->device_type));
   1.350 +          FUNCTION_MSG("Unknown DeviceType %02x requested\n", xvdd->device_type);
   1.351            srb_status = SRB_STATUS_ERROR;
   1.352            break;
   1.353          }
   1.354          break;
   1.355        case SCSIOP_READ_CAPACITY:
   1.356          //if (dump_mode)
   1.357 -        //  KdPrint((__DRIVER_NAME "     Command = READ_CAPACITY\n"));
   1.358 -        //KdPrint((__DRIVER_NAME "       LUN = %d, RelAdr = %d\n", srb->Cdb[1] >> 4, srb->Cdb[1] & 1));
   1.359 -        //KdPrint((__DRIVER_NAME "       LBA = %02x%02x%02x%02x\n", srb->Cdb[2], srb->Cdb[3], srb->Cdb[4], srb->Cdb[5]));
   1.360 -        //KdPrint((__DRIVER_NAME "       PMI = %d\n", srb->Cdb[8] & 1));
   1.361 +          FUNCTION_MSG("Command = READ_CAPACITY\n");
   1.362 +        //FUNCTION_MSG("  LUN = %d, RelAdr = %d\n", srb->Cdb[1] >> 4, srb->Cdb[1] & 1);
   1.363 +        //FUNCTION_MSG("  LBA = %02x%02x%02x%02x\n", srb->Cdb[2], srb->Cdb[3], srb->Cdb[4], srb->Cdb[5]);
   1.364 +        //FUNCTION_MSG("  PMI = %d\n", srb->Cdb[8] & 1);
   1.365          //data_buffer = LongLongToPtr(ScsiPortGetPhysicalAddress(xvdd, srb, srb->DataBuffer, &data_buffer_length).QuadPart);
   1.366          data_buffer = srb->DataBuffer;
   1.367          RtlZeroMemory(data_buffer, srb->DataTransferLength);
   1.368 -        if ((xvdd->total_sectors - 1) >> 32)
   1.369 -        {
   1.370 +        if ((xvdd->total_sectors - 1) >> 32) {
   1.371            data_buffer[0] = 0xff;
   1.372            data_buffer[1] = 0xff;
   1.373            data_buffer[2] = 0xff;
   1.374            data_buffer[3] = 0xff;
   1.375 -        }
   1.376 -        else
   1.377 -        {
   1.378 +        } else {
   1.379            data_buffer[0] = (unsigned char)((xvdd->total_sectors - 1) >> 24) & 0xff;
   1.380            data_buffer[1] = (unsigned char)((xvdd->total_sectors - 1) >> 16) & 0xff;
   1.381            data_buffer[2] = (unsigned char)((xvdd->total_sectors - 1) >> 8) & 0xff;
   1.382 @@ -881,10 +885,10 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.383          break;
   1.384        case SCSIOP_READ_CAPACITY16:
   1.385          //if (dump_mode)
   1.386 -          KdPrint((__DRIVER_NAME "     Command = READ_CAPACITY16\n"));
   1.387 -        //KdPrint((__DRIVER_NAME "       LUN = %d, RelAdr = %d\n", srb->Cdb[1] >> 4, srb->Cdb[1] & 1));
   1.388 -        //KdPrint((__DRIVER_NAME "       LBA = %02x%02x%02x%02x\n", srb->Cdb[2], srb->Cdb[3], srb->Cdb[4], srb->Cdb[5]));
   1.389 -        //KdPrint((__DRIVER_NAME "       PMI = %d\n", srb->Cdb[8] & 1));
   1.390 +          FUNCTION_MSG("Command = READ_CAPACITY16\n");
   1.391 +        //FUNCTION_MSG("  LUN = %d, RelAdr = %d\n", srb->Cdb[1] >> 4, srb->Cdb[1] & 1);
   1.392 +        //FUNCTION_MSG("  LBA = %02x%02x%02x%02x\n", srb->Cdb[2], srb->Cdb[3], srb->Cdb[4], srb->Cdb[5]);
   1.393 +        //FUNCTION_MSG("  PMI = %d\n", srb->Cdb[8] & 1);
   1.394          data_buffer = srb->DataBuffer;
   1.395          RtlZeroMemory(data_buffer, srb->DataTransferLength);
   1.396          data_buffer[0] = (unsigned char)((xvdd->total_sectors - 1) >> 56) & 0xff;
   1.397 @@ -915,7 +919,7 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.398            break;
   1.399          default:
   1.400            data_buffer[13] = 0; /* 512 byte hardware sectors */
   1.401 -          KdPrint((__DRIVER_NAME "     Unknown logical blocks per physical block %d (%d / %d)\n", xvdd->hw_bytes_per_sector / xvdd->bytes_per_sector, xvdd->hw_bytes_per_sector, xvdd->bytes_per_sector));
   1.402 +          FUNCTION_MSG("Unknown logical blocks per physical block %d (%d / %d)\n", xvdd->hw_bytes_per_sector / xvdd->bytes_per_sector, xvdd->hw_bytes_per_sector, xvdd->bytes_per_sector);
   1.403            break;
   1.404          }
   1.405          data_buffer[14] = 0xC0; //0;
   1.406 @@ -927,7 +931,7 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.407        case SCSIOP_MODE_SENSE:
   1.408        case SCSIOP_MODE_SENSE10:
   1.409          if (dump_mode)
   1.410 -          KdPrint((__DRIVER_NAME "     Command = MODE_SENSE (DBD = %d, PC = %d, Page Code = %02x)\n", srb->Cdb[1] & 0x08, srb->Cdb[2] & 0xC0, srb->Cdb[2] & 0x3F));
   1.411 +          FUNCTION_MSG("Command = MODE_SENSE (DBD = %d, PC = %d, Page Code = %02x)\n", srb->Cdb[1] & 0x08, srb->Cdb[2] & 0xC0, srb->Cdb[2] & 0x3F);
   1.412          data_transfer_length = XenVbd_FillModePage(xvdd, srb);
   1.413          srb_status = SRB_STATUS_SUCCESS;
   1.414          break;
   1.415 @@ -944,16 +948,18 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.416        case SCSIOP_WRITE_SAME16:
   1.417          /* not yet supported */
   1.418          FUNCTION_MSG("WRITE_SAME\n");
   1.419 -        break;
   1.420 +        srb_status = SRB_STATUS_ERROR;
   1.421 +       break;
   1.422        case SCSIOP_UNMAP:
   1.423          /* not yet supported */
   1.424          FUNCTION_MSG("UNMAP\n");
   1.425 +        srb_status = SRB_STATUS_ERROR;
   1.426          break;
   1.427        case SCSIOP_VERIFY:
   1.428        case SCSIOP_VERIFY16:
   1.429          // Should we do more here?
   1.430          if (dump_mode)
   1.431 -          KdPrint((__DRIVER_NAME "     Command = VERIFY\n"));
   1.432 +          FUNCTION_MSG("Command = VERIFY\n");
   1.433          srb_status = SRB_STATUS_SUCCESS;
   1.434          break;
   1.435        case SCSIOP_REPORT_LUNS:
   1.436 @@ -978,13 +984,13 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.437          break;
   1.438        case SCSIOP_REQUEST_SENSE:
   1.439          if (dump_mode)
   1.440 -          KdPrint((__DRIVER_NAME "     Command = REQUEST_SENSE\n"));
   1.441 +          FUNCTION_MSG("Command = REQUEST_SENSE\n");
   1.442          data_transfer_length = XenVbd_MakeSense(xvdd, srb, xvdd->last_sense_key, xvdd->last_additional_sense_code);
   1.443          srb_status = SRB_STATUS_SUCCESS;
   1.444          break;      
   1.445        case SCSIOP_READ_TOC:
   1.446 -        if (dump_mode)
   1.447 -          KdPrint((__DRIVER_NAME "     Command = READ_TOC\n"));
   1.448 +        //if (dump_mode)
   1.449 +          FUNCTION_MSG("Command = READ_TOC\n");
   1.450          data_buffer = srb->DataBuffer;
   1.451    /*
   1.452    #define READ_TOC_FORMAT_TOC         0x00
   1.453 @@ -993,15 +999,7 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.454    #define READ_TOC_FORMAT_PMA         0x03
   1.455    #define READ_TOC_FORMAT_ATIP        0x04
   1.456    */
   1.457 -  //      KdPrint((__DRIVER_NAME "     Msf = %d\n", cdb->READ_TOC.Msf));
   1.458 -  //      KdPrint((__DRIVER_NAME "     LogicalUnitNumber = %d\n", cdb->READ_TOC.LogicalUnitNumber));
   1.459 -  //      KdPrint((__DRIVER_NAME "     Format2 = %d\n", cdb->READ_TOC.Format2));
   1.460 -  //      KdPrint((__DRIVER_NAME "     StartingTrack = %d\n", cdb->READ_TOC.StartingTrack));
   1.461 -  //      KdPrint((__DRIVER_NAME "     AllocationLength = %d\n", (cdb->READ_TOC.AllocationLength[0] << 8) | cdb->READ_TOC.AllocationLength[1]));
   1.462 -  //      KdPrint((__DRIVER_NAME "     Control = %d\n", cdb->READ_TOC.Control));
   1.463 -  //      KdPrint((__DRIVER_NAME "     Format = %d\n", cdb->READ_TOC.Format));
   1.464 -        switch (cdb->READ_TOC.Format2)
   1.465 -        {
   1.466 +        switch (cdb->READ_TOC.Format2) {
   1.467          case READ_TOC_FORMAT_TOC:
   1.468            data_buffer[0] = 0; // length MSB
   1.469            data_buffer[1] = 10; // length LSB
   1.470 @@ -1030,25 +1028,29 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.471          }
   1.472          break;
   1.473        case SCSIOP_START_STOP_UNIT:
   1.474 -        KdPrint((__DRIVER_NAME "     Command = SCSIOP_START_STOP_UNIT\n"));
   1.475 +        FUNCTION_MSG("Command = SCSIOP_START_STOP_UNIT\n");
   1.476          srb_status = SRB_STATUS_SUCCESS;
   1.477          break;
   1.478        case SCSIOP_RESERVE_UNIT:
   1.479 -        KdPrint((__DRIVER_NAME "     Command = SCSIOP_RESERVE_UNIT\n"));
   1.480 +        FUNCTION_MSG("Command = SCSIOP_RESERVE_UNIT\n");
   1.481          srb_status = SRB_STATUS_SUCCESS;
   1.482          break;
   1.483        case SCSIOP_RELEASE_UNIT:
   1.484 -        KdPrint((__DRIVER_NAME "     Command = SCSIOP_RELEASE_UNIT\n"));
   1.485 +        FUNCTION_MSG("Command = SCSIOP_RELEASE_UNIT\n");
   1.486 +        srb_status = SRB_STATUS_SUCCESS;
   1.487 +        break;
   1.488 +      case SCSIOP_SYNCHRONIZE_CACHE:
   1.489 +        FUNCTION_MSG("Command = SCSIOP_SYNCHRONIZE_CACHE\n");
   1.490          srb_status = SRB_STATUS_SUCCESS;
   1.491          break;
   1.492        default:
   1.493 -        KdPrint((__DRIVER_NAME "     Unhandled EXECUTE_SCSI Command = %02X\n", srb->Cdb[0]));
   1.494 +        FUNCTION_MSG("Unhandled EXECUTE_SCSI Command = %02X\n", srb->Cdb[0]);
   1.495          xvdd->last_sense_key = SCSI_SENSE_ILLEGAL_REQUEST;
   1.496          srb_status = SRB_STATUS_ERROR;
   1.497          break;
   1.498        }
   1.499        if (srb_status == SRB_STATUS_ERROR) {
   1.500 -        KdPrint((__DRIVER_NAME "     EXECUTE_SCSI Command = %02X returned error %02x\n", srb->Cdb[0], xvdd->last_sense_key));
   1.501 +        FUNCTION_MSG("EXECUTE_SCSI Command = %02X returned error %02x\n", srb->Cdb[0], xvdd->last_sense_key);
   1.502          if (xvdd->last_sense_key == SCSI_SENSE_NO_SENSE) {
   1.503            xvdd->last_sense_key = SCSI_SENSE_ILLEGAL_REQUEST;
   1.504            xvdd->last_additional_sense_code = SCSI_ADSENSE_INVALID_CDB;
   1.505 @@ -1058,8 +1060,11 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.506          XenVbd_MakeAutoSense(xvdd, srb);
   1.507          SxxxPortNotification(RequestComplete, xvdd, srb);
   1.508        } else if (srb_status != SRB_STATUS_PENDING) {
   1.509 +        if (srb->ScsiStatus != 0) {
   1.510 +          FUNCTION_MSG("ScsiStatus = 0x%02x\n", srb->ScsiStatus);
   1.511 +        }
   1.512          if (data_transfer_length > srb->DataTransferLength)
   1.513 -          KdPrint((__DRIVER_NAME "     data_transfer_length too big - %d > %d\n", data_transfer_length, srb->DataTransferLength));
   1.514 +          FUNCTION_MSG("data_transfer_length too big - %d > %d\n", data_transfer_length, srb->DataTransferLength);
   1.515          
   1.516          if (srb_status == SRB_STATUS_SUCCESS && data_transfer_length < srb->DataTransferLength) {
   1.517            srb->SrbStatus = SRB_STATUS_DATA_OVERRUN;
   1.518 @@ -1073,97 +1078,104 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.519        }
   1.520        break;
   1.521      case SRB_FUNCTION_FLUSH:
   1.522 -      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_FLUSH %p, xvdd->shadow_free = %d\n", srb, xvdd->shadow_free));
   1.523 +      FUNCTION_MSG("SRB_FUNCTION_FLUSH %p, xvdd->shadow_free = %d\n", srb, xvdd->shadow_free);
   1.524        srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.525        SxxxPortNotification(RequestComplete, xvdd, srb);
   1.526        break;
   1.527      #ifdef _NTSTORPORT_      
   1.528      case SRB_FUNCTION_PNP:
   1.529 -      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_PNP\n"));
   1.530 +      FUNCTION_MSG("SRB_FUNCTION_PNP\n");
   1.531        sprb = (PSCSI_PNP_REQUEST_BLOCK)srb;
   1.532        switch (sprb->PnPAction)
   1.533        {
   1.534        case StorStartDevice:
   1.535 -        KdPrint((__DRIVER_NAME "      StorStartDevice\n"));
   1.536 +        FUNCTION_MSG(" StorStartDevice\n");
   1.537          break;
   1.538        case StorRemoveDevice:
   1.539 -        KdPrint((__DRIVER_NAME "      StorRemoveDevice\n"));
   1.540 +        FUNCTION_MSG(" StorRemoveDevice\n");
   1.541          break;
   1.542        case StorStopDevice:
   1.543 -        KdPrint((__DRIVER_NAME "      StorStopDevice\n"));
   1.544 +        FUNCTION_MSG(" StorStopDevice\n");
   1.545          break;
   1.546        case StorQueryCapabilities:
   1.547 -        KdPrint((__DRIVER_NAME "      StorQueryCapabilities\n"));
   1.548 +        FUNCTION_MSG(" StorQueryCapabilities\n");
   1.549          break;
   1.550        case StorFilterResourceRequirements:
   1.551 -        KdPrint((__DRIVER_NAME "      StorFilterResourceRequirements\n"));
   1.552 +        FUNCTION_MSG(" StorFilterResourceRequirements\n");
   1.553          break;
   1.554        default:
   1.555 -        KdPrint((__DRIVER_NAME "      Stor%d\n", sprb->PnPAction));
   1.556 +        FUNCTION_MSG(" Stor%d\n", sprb->PnPAction);
   1.557          break;
   1.558        }
   1.559 -      KdPrint((__DRIVER_NAME "      SrbPnPFlags = %08x\n", sprb->SrbPnPFlags));
   1.560 +      FUNCTION_MSG(" SrbPnPFlags = %08x\n", sprb->SrbPnPFlags);
   1.561        srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.562        SxxxPortNotification(RequestComplete, xvdd, srb);
   1.563        break;
   1.564        
   1.565      case SRB_FUNCTION_POWER:
   1.566 -      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_POWER\n"));
   1.567 +      FUNCTION_MSG("SRB_FUNCTION_POWER\n");   
   1.568 +      FUNCTION_MSG("IRQL = %d\n", KeGetCurrentIrql());
   1.569        spwrb = (PSCSI_POWER_REQUEST_BLOCK)srb;
   1.570 -      switch (spwrb->PowerAction)
   1.571 -      {
   1.572 -      case StorPowerActionNone:
   1.573 -        KdPrint((__DRIVER_NAME "      StorPowerActionNone\n"));
   1.574 -        break;
   1.575 -      case StorPowerActionReserved:
   1.576 -        KdPrint((__DRIVER_NAME "      StorPowerActionReserved\n"));
   1.577 -        break;
   1.578 -      case StorPowerActionSleep:
   1.579 -        KdPrint((__DRIVER_NAME "      StorPowerActionSleep\n"));
   1.580 -        break;
   1.581 -      case StorPowerActionHibernate:
   1.582 -        KdPrint((__DRIVER_NAME "      StorPowerActionHibernate\n"));
   1.583 -        break;
   1.584 -      case StorPowerActionShutdown:
   1.585 -        KdPrint((__DRIVER_NAME "      StorPowerActionShutdown\n"));
   1.586 -        break;
   1.587 -      case StorPowerActionShutdownReset:
   1.588 -        KdPrint((__DRIVER_NAME "      StorPowerActionShutdownReset\n"));
   1.589 -        break;
   1.590 -      case StorPowerActionShutdownOff:
   1.591 -        KdPrint((__DRIVER_NAME "      StorPowerActionShutdownOff\n"));
   1.592 -        break;
   1.593 -      case StorPowerActionWarmEject:
   1.594 -        KdPrint((__DRIVER_NAME "      StorPowerActionWarmEject\n"));
   1.595 -        break;
   1.596 -      default:
   1.597 -        KdPrint((__DRIVER_NAME "      Stor%d\n", spwrb->PowerAction));
   1.598 -        break;
   1.599 +      if (spwrb->DevicePowerState == StorPowerDeviceD0) {
   1.600 +        FUNCTION_MSG("Entering D0\n");
   1.601 +      } else {
   1.602 +        FUNCTION_MSG("Entering D%d (%d)\n", spwrb->DevicePowerState - StorPowerDeviceD0, spwrb->DevicePowerState);
   1.603 +        switch (spwrb->PowerAction) {
   1.604 +        case StorPowerActionNone:
   1.605 +          FUNCTION_MSG(" StorPowerActionNone\n");
   1.606 +          break;
   1.607 +        case StorPowerActionReserved:
   1.608 +          FUNCTION_MSG(" StorPowerActionReserved\n");
   1.609 +          break;
   1.610 +        case StorPowerActionSleep:
   1.611 +          FUNCTION_MSG(" StorPowerActionSleep\n");
   1.612 +          break;
   1.613 +        case StorPowerActionHibernate:
   1.614 +          FUNCTION_MSG(" StorPowerActionHibernate\n");
   1.615 +          break;
   1.616 +        case StorPowerActionShutdown:
   1.617 +          FUNCTION_MSG(" StorPowerActionShutdown\n");
   1.618 +          break;
   1.619 +        case StorPowerActionShutdownReset:
   1.620 +          FUNCTION_MSG(" StorPowerActionShutdownReset\n");
   1.621 +          break;
   1.622 +        case StorPowerActionShutdownOff:
   1.623 +          FUNCTION_MSG(" StorPowerActionShutdownOff\n");
   1.624 +          break;
   1.625 +        case StorPowerActionWarmEject:
   1.626 +          FUNCTION_MSG(" StorPowerActionWarmEject\n");
   1.627 +          break;
   1.628 +        default:
   1.629 +          FUNCTION_MSG(" Stor%d\n", spwrb->PowerAction);
   1.630 +          break;
   1.631 +        }
   1.632        }
   1.633 +      xvdd->power_state = spwrb->DevicePowerState;
   1.634 +      xvdd->power_action = spwrb->PowerAction;
   1.635        srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.636        SxxxPortNotification(RequestComplete, xvdd, srb);
   1.637        break;
   1.638      case SRB_FUNCTION_DUMP_POINTERS:
   1.639 -      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_DUMP_POINTERS\n"));
   1.640 -      KdPrint((__DRIVER_NAME "     DataTransferLength = %d\n", srb->DataTransferLength));
   1.641 +      FUNCTION_MSG("SRB_FUNCTION_DUMP_POINTERS\n");
   1.642 +      FUNCTION_MSG("DataTransferLength = %d\n", srb->DataTransferLength);
   1.643        dump_pointers = srb->DataBuffer;
   1.644 -      KdPrint((__DRIVER_NAME "      Version = %d\n", dump_pointers->Version));
   1.645 -      KdPrint((__DRIVER_NAME "      Size = %d\n", dump_pointers->Size));
   1.646 -      KdPrint((__DRIVER_NAME "      DriverName = %S\n", dump_pointers->DriverName));
   1.647 -      KdPrint((__DRIVER_NAME "      AdapterObject = %p\n", dump_pointers->AdapterObject));
   1.648 -      KdPrint((__DRIVER_NAME "      MappedRegisterBase = %d\n", dump_pointers->MappedRegisterBase));
   1.649 -      KdPrint((__DRIVER_NAME "      CommonBufferSize = %d\n", dump_pointers->CommonBufferSize));
   1.650 -      KdPrint((__DRIVER_NAME "      MiniportPrivateDumpData = %p\n", dump_pointers->MiniportPrivateDumpData));
   1.651 -      KdPrint((__DRIVER_NAME "      SystemIoBusNumber = %d\n", dump_pointers->SystemIoBusNumber));
   1.652 -      KdPrint((__DRIVER_NAME "      AdapterInterfaceType = %d\n", dump_pointers->AdapterInterfaceType));
   1.653 -      KdPrint((__DRIVER_NAME "      MaximumTransferLength = %d\n", dump_pointers->MaximumTransferLength));
   1.654 -      KdPrint((__DRIVER_NAME "      NumberOfPhysicalBreaks = %d\n", dump_pointers->NumberOfPhysicalBreaks));
   1.655 -      KdPrint((__DRIVER_NAME "      AlignmentMask = %d\n", dump_pointers->AlignmentMask));
   1.656 -      KdPrint((__DRIVER_NAME "      NumberOfAccessRanges = %d\n", dump_pointers->NumberOfAccessRanges));
   1.657 -      KdPrint((__DRIVER_NAME "      NumberOfBuses = %d\n", dump_pointers->NumberOfBuses));
   1.658 -      KdPrint((__DRIVER_NAME "      Master = %d\n", dump_pointers->Master));
   1.659 -      KdPrint((__DRIVER_NAME "      MapBuffers = %d\n", dump_pointers->MapBuffers));
   1.660 -      KdPrint((__DRIVER_NAME "      MaximumNumberOfTargets = %d\n", dump_pointers->MaximumNumberOfTargets));
   1.661 +      FUNCTION_MSG(" Version = %d\n", dump_pointers->Version);
   1.662 +      FUNCTION_MSG(" Size = %d\n", dump_pointers->Size);
   1.663 +      FUNCTION_MSG(" DriverName = %S\n", dump_pointers->DriverName);
   1.664 +      FUNCTION_MSG(" AdapterObject = %p\n", dump_pointers->AdapterObject);
   1.665 +      FUNCTION_MSG(" MappedRegisterBase = %d\n", dump_pointers->MappedRegisterBase);
   1.666 +      FUNCTION_MSG(" CommonBufferSize = %d\n", dump_pointers->CommonBufferSize);
   1.667 +      FUNCTION_MSG(" MiniportPrivateDumpData = %p\n", dump_pointers->MiniportPrivateDumpData);
   1.668 +      FUNCTION_MSG(" SystemIoBusNumber = %d\n", dump_pointers->SystemIoBusNumber);
   1.669 +      FUNCTION_MSG(" AdapterInterfaceType = %d\n", dump_pointers->AdapterInterfaceType);
   1.670 +      FUNCTION_MSG(" MaximumTransferLength = %d\n", dump_pointers->MaximumTransferLength);
   1.671 +      FUNCTION_MSG(" NumberOfPhysicalBreaks = %d\n", dump_pointers->NumberOfPhysicalBreaks);
   1.672 +      FUNCTION_MSG(" AlignmentMask = %d\n", dump_pointers->AlignmentMask);
   1.673 +      FUNCTION_MSG(" NumberOfAccessRanges = %d\n", dump_pointers->NumberOfAccessRanges);
   1.674 +      FUNCTION_MSG(" NumberOfBuses = %d\n", dump_pointers->NumberOfBuses);
   1.675 +      FUNCTION_MSG(" Master = %d\n", dump_pointers->Master);
   1.676 +      FUNCTION_MSG(" MapBuffers = %d\n", dump_pointers->MapBuffers);
   1.677 +      FUNCTION_MSG(" MaximumNumberOfTargets = %d\n", dump_pointers->MaximumNumberOfTargets);
   1.678  
   1.679        dump_pointers->Version = DUMP_MINIPORT_VERSION_1;
   1.680        dump_pointers->Size = sizeof(MINIPORT_DUMP_POINTERS);
   1.681 @@ -1172,40 +1184,39 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.682        dump_pointers->MappedRegisterBase = 0;
   1.683        dump_pointers->CommonBufferSize = 0;
   1.684        dump_pointers->MiniportPrivateDumpData = xvdd;
   1.685 -      dump_pointers->AdapterInterfaceType = Internal;
   1.686 -      dump_pointers->MaximumTransferLength = 4 * 1024 * 1024; //BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE;;
   1.687 -      dump_pointers->NumberOfPhysicalBreaks = dump_pointers->MaximumTransferLength >> PAGE_SHIFT; //BLKIF_MAX_SEGMENTS_PER_REQUEST - 1;
   1.688 +      dump_pointers->MaximumTransferLength = 4 * 1024 * 1024;
   1.689 +      dump_pointers->NumberOfPhysicalBreaks = dump_pointers->MaximumTransferLength >> PAGE_SHIFT;
   1.690        dump_pointers->AlignmentMask = 0;
   1.691 -      dump_pointers->NumberOfAccessRanges = 1;
   1.692 +      dump_pointers->NumberOfAccessRanges = 0;
   1.693        dump_pointers->NumberOfBuses = 1;
   1.694        dump_pointers->Master = TRUE;
   1.695        dump_pointers->MapBuffers = STOR_MAP_NON_READ_WRITE_BUFFERS;
   1.696        dump_pointers->MaximumNumberOfTargets = 2;
   1.697  
   1.698 -      KdPrint((__DRIVER_NAME "      Version = %d\n", dump_pointers->Version));
   1.699 -      KdPrint((__DRIVER_NAME "      Size = %d\n", dump_pointers->Size));
   1.700 -      //KdPrint((__DRIVER_NAME "      DriverName = %S\n", dump_pointers->DriverName));
   1.701 -      KdPrint((__DRIVER_NAME "      AdapterObject = %p\n", dump_pointers->AdapterObject));
   1.702 -      KdPrint((__DRIVER_NAME "      MappedRegisterBase = %d\n", dump_pointers->MappedRegisterBase));
   1.703 -      KdPrint((__DRIVER_NAME "      CommonBufferSize = %d\n", dump_pointers->CommonBufferSize));
   1.704 -      KdPrint((__DRIVER_NAME "      MiniportPrivateDumpData = %p\n", dump_pointers->MiniportPrivateDumpData));
   1.705 -      KdPrint((__DRIVER_NAME "      SystemIoBusNumber = %d\n", dump_pointers->SystemIoBusNumber));
   1.706 -      KdPrint((__DRIVER_NAME "      AdapterInterfaceType = %d\n", dump_pointers->AdapterInterfaceType));
   1.707 -      KdPrint((__DRIVER_NAME "      MaximumTransferLength = %d\n", dump_pointers->MaximumTransferLength));
   1.708 -      KdPrint((__DRIVER_NAME "      NumberOfPhysicalBreaks = %d\n", dump_pointers->NumberOfPhysicalBreaks));
   1.709 -      KdPrint((__DRIVER_NAME "      AlignmentMask = %d\n", dump_pointers->AlignmentMask));
   1.710 -      KdPrint((__DRIVER_NAME "      NumberOfAccessRanges = %d\n", dump_pointers->NumberOfAccessRanges));
   1.711 -      KdPrint((__DRIVER_NAME "      NumberOfBuses = %d\n", dump_pointers->NumberOfBuses));
   1.712 -      KdPrint((__DRIVER_NAME "      Master = %d\n", dump_pointers->Master));
   1.713 -      KdPrint((__DRIVER_NAME "      MapBuffers = %d\n", dump_pointers->MapBuffers));
   1.714 -      KdPrint((__DRIVER_NAME "      MaximumNumberOfTargets = %d\n", dump_pointers->MaximumNumberOfTargets));
   1.715 +      FUNCTION_MSG(" Version = %d\n", dump_pointers->Version);
   1.716 +      FUNCTION_MSG(" Size = %d\n", dump_pointers->Size);
   1.717 +      //FUNCTION_MSG(" DriverName = %S\n", dump_pointers->DriverName);
   1.718 +      FUNCTION_MSG(" AdapterObject = %p\n", dump_pointers->AdapterObject);
   1.719 +      FUNCTION_MSG(" MappedRegisterBase = %d\n", dump_pointers->MappedRegisterBase);
   1.720 +      FUNCTION_MSG(" CommonBufferSize = %d\n", dump_pointers->CommonBufferSize);
   1.721 +      FUNCTION_MSG(" MiniportPrivateDumpData = %p\n", dump_pointers->MiniportPrivateDumpData);
   1.722 +      FUNCTION_MSG(" SystemIoBusNumber = %d\n", dump_pointers->SystemIoBusNumber);
   1.723 +      FUNCTION_MSG(" AdapterInterfaceType = %d\n", dump_pointers->AdapterInterfaceType);
   1.724 +      FUNCTION_MSG(" MaximumTransferLength = %d\n", dump_pointers->MaximumTransferLength);
   1.725 +      FUNCTION_MSG(" NumberOfPhysicalBreaks = %d\n", dump_pointers->NumberOfPhysicalBreaks);
   1.726 +      FUNCTION_MSG(" AlignmentMask = %d\n", dump_pointers->AlignmentMask);
   1.727 +      FUNCTION_MSG(" NumberOfAccessRanges = %d\n", dump_pointers->NumberOfAccessRanges);
   1.728 +      FUNCTION_MSG(" NumberOfBuses = %d\n", dump_pointers->NumberOfBuses);
   1.729 +      FUNCTION_MSG(" Master = %d\n", dump_pointers->Master);
   1.730 +      FUNCTION_MSG(" MapBuffers = %d\n", dump_pointers->MapBuffers);
   1.731 +      FUNCTION_MSG(" MaximumNumberOfTargets = %d\n", dump_pointers->MaximumNumberOfTargets);
   1.732  
   1.733        srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.734        SxxxPortNotification(RequestComplete, xvdd, srb);
   1.735        break;
   1.736      #endif
   1.737      case SRB_FUNCTION_SHUTDOWN:
   1.738 -      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_SHUTDOWN %p, xvdd->shadow_free = %d\n", srb, xvdd->shadow_free));
   1.739 +      FUNCTION_MSG("SRB_FUNCTION_SHUTDOWN %p, xvdd->shadow_free = %d\n", srb, xvdd->shadow_free);
   1.740        srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.741        SxxxPortNotification(RequestComplete, xvdd, srb);
   1.742        break;
   1.743 @@ -1229,15 +1240,20 @@ XenVbd_ProcessSrbList(PXENVBD_DEVICE_DAT
   1.744        srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   1.745        SxxxPortNotification(RequestComplete, xvdd, srb);
   1.746        break;
   1.747 +    case 0x27:
   1.748 +      FUNCTION_MSG("SRB_FUNCTION_FREE_DUMP_POINTERS\n");
   1.749 +      srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.750 +      SxxxPortNotification(RequestComplete, xvdd, srb);
   1.751 +      break;
   1.752      default:
   1.753 -      KdPrint((__DRIVER_NAME "     Unhandled srb->Function = %08X\n", srb->Function));
   1.754 +      FUNCTION_MSG("Unhandled srb->Function = %08X\n", srb->Function);
   1.755        srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   1.756        SxxxPortNotification(RequestComplete, xvdd, srb);
   1.757        break;
   1.758      }
   1.759      if ((PLIST_ENTRY)srb_entry == xvdd->srb_list.Flink && srb_entry->offset == prev_offset) {
   1.760        FUNCTION_MSG("Same entry\n");
   1.761 -      /* same entry was put back onto the head of the list unchanged so we can't progress */
   1.762 +      /* same entry was put back onto the head of the list unchanged, so we can't progress */
   1.763        break;
   1.764      }
   1.765    }
     2.1 --- a/xenvbd_common/common_xen.h	Tue Feb 19 15:13:22 2013 +1100
     2.2 +++ b/xenvbd_common/common_xen.h	Tue Feb 19 15:14:53 2013 +1100
     2.3 @@ -25,6 +25,7 @@ XenVbd_Connect(PXENVBD_DEVICE_DATA xvdd,
     2.4    //BOOLEAN active = FALSE;
     2.5    NTSTATUS status;
     2.6    PCHAR mode;
     2.7 +  PCHAR uuid;
     2.8    PFN_NUMBER pfn;
     2.9  
    2.10    FUNCTION_ENTER();
    2.11 @@ -34,9 +35,8 @@ XenVbd_Connect(PXENVBD_DEVICE_DATA xvdd,
    2.12      FUNCTION_EXIT();
    2.13      return STATUS_SUCCESS;
    2.14    }
    2.15 -  
    2.16 -  xvdd->backend_state = XenbusStateUnknown;
    2.17    if (!suspend) {
    2.18 +    xvdd->backend_state = XenbusStateUnknown;
    2.19      if ((xvdd->handle = XnOpenDevice(xvdd->pdo, XenVbd_DeviceCallback, xvdd)) == NULL) {
    2.20        FUNCTION_MSG("Failed to open\n");
    2.21        return STATUS_UNSUCCESSFUL;
    2.22 @@ -44,6 +44,7 @@ XenVbd_Connect(PXENVBD_DEVICE_DATA xvdd,
    2.23    }
    2.24    xvdd->sring = (blkif_sring_t *)ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENVBD_POOL_TAG);
    2.25    if (!xvdd->sring) {
    2.26 +    FUNCTION_MSG("Failed to allocate sring\n");
    2.27      return STATUS_UNSUCCESSFUL;
    2.28    }
    2.29    pfn = (PFN_NUMBER)(MmGetPhysicalAddress(xvdd->sring).QuadPart >> PAGE_SHIFT);
    2.30 @@ -129,6 +130,15 @@ XenVbd_Connect(PXENVBD_DEVICE_DATA xvdd,
    2.31      FUNCTION_MSG("device-type = %s (This probably won't work!)\n", device_type);
    2.32      xvdd->device_type = XENVBD_DEVICETYPE_UNKNOWN;
    2.33    }
    2.34 +
    2.35 +  status = XnReadString(xvdd->handle, XN_BASE_FRONTEND, "device-type", &uuid);
    2.36 +  if (status == STATUS_SUCCESS) {
    2.37 +    RtlStringCbCopyA(xvdd->serial_number, ARRAY_SIZE(xvdd->serial_number), uuid);
    2.38 +    XnFreeMem(xvdd->handle, uuid);
    2.39 +  } else {
    2.40 +    RtlStringCbCopyA(xvdd->serial_number, ARRAY_SIZE(xvdd->serial_number), "        ");
    2.41 +  }  
    2.42 +
    2.43    XnFreeMem(xvdd->handle, device_type);
    2.44    status = XnWriteInt32(xvdd->handle, XN_BASE_FRONTEND, "state", XenbusStateConnected);
    2.45  
     3.1 --- a/xenvbd_filter/xenvbd_filter.c	Tue Feb 19 15:13:22 2013 +1100
     3.2 +++ b/xenvbd_filter/xenvbd_filter.c	Tue Feb 19 15:14:53 2013 +1100
     3.3 @@ -25,6 +25,12 @@ DRIVER_INITIALIZE DriverEntry;
     3.4  
     3.5  static EVT_WDF_DRIVER_UNLOAD XenVbd_EvtDriverUnload;
     3.6  static EVT_WDF_DRIVER_DEVICE_ADD XenVbd_EvtDeviceAdd;
     3.7 +static EVT_WDF_REQUEST_COMPLETION_ROUTINE XenVbd_SendRequestComplete;
     3.8 +static EVT_WDF_DEVICE_D0_ENTRY XenVbd_EvtDeviceD0Entry;
     3.9 +static EVT_WDF_DEVICE_D0_EXIT XenVbd_EvtDeviceD0Exit;
    3.10 +static EVT_WDFDEVICE_WDM_IRP_PREPROCESS XenVbd_EvtDeviceWdmIrpPreprocess_START_DEVICE;
    3.11 +static EVT_WDF_DPC XenVbd_EvtDpcEvent;
    3.12 +static IO_COMPLETION_ROUTINE XenVbd_IoCompletion_START_DEVICE;
    3.13  
    3.14  static VOID XenVbd_DeviceCallback(PVOID context, ULONG callback_type, PVOID value);
    3.15  static VOID XenVbd_HandleEventDIRQL(PVOID context);
    3.16 @@ -173,6 +179,10 @@ XenVbd_SendEvent(WDFDEVICE device) {
    3.17    PSRB_IO_CONTROL sic;
    3.18  
    3.19    status = WdfRequestCreate(WDF_NO_OBJECT_ATTRIBUTES, xvfd->wdf_target, &request);
    3.20 +  if (status != STATUS_SUCCESS) {
    3.21 +    /* this is bad - event will be dropped */
    3.22 +    return;
    3.23 +  }
    3.24  
    3.25    buf = ExAllocatePoolWithTag(NonPagedPool, sizeof(SCSI_REQUEST_BLOCK) + sizeof(SRB_IO_CONTROL), XENVBD_POOL_TAG);
    3.26    RtlZeroMemory(buf, sizeof(SCSI_REQUEST_BLOCK) + sizeof(SRB_IO_CONTROL));
     4.1 --- a/xenvbd_scsiport/common.h	Tue Feb 19 15:13:22 2013 +1100
     4.2 +++ b/xenvbd_scsiport/common.h	Tue Feb 19 15:14:53 2013 +1100
     4.3 @@ -50,6 +50,7 @@ struct {
     4.4    ULONG feature_flush_cache;
     4.5    ULONG feature_discard;
     4.6    ULONG feature_barrier;
     4.7 +  CHAR serial_number[64];
     4.8  
     4.9    /* miniport data */
    4.10    PVOID xvsd;
     5.1 --- a/xenvbd_scsiport/xenvbd.c	Tue Feb 19 15:13:22 2013 +1100
     5.2 +++ b/xenvbd_scsiport/xenvbd.c	Tue Feb 19 15:14:53 2013 +1100
     5.3 @@ -45,6 +45,14 @@ SxxxPortGetSystemAddress(PVOID device_ex
     5.4    return STATUS_SUCCESS;
     5.5  }
     5.6  
     5.7 +static PHYSICAL_ADDRESS
     5.8 +SxxxPortGetPhysicalAddress(PVOID device_extension, PSCSI_REQUEST_BLOCK srb, PVOID virtual_address, ULONG *length) {
     5.9 +  UNREFERENCED_PARAMETER(device_extension);
    5.10 +  UNREFERENCED_PARAMETER(srb);
    5.11 +  UNREFERENCED_PARAMETER(length);
    5.12 +  return MmGetPhysicalAddress(virtual_address);
    5.13 +}
    5.14 +
    5.15  #define SxxxPortNotification(NotificationType, DeviceExtension, ...) XenVbd_Notification##NotificationType(DeviceExtension, __VA_ARGS__)
    5.16  
    5.17  static VOID
    5.18 @@ -333,8 +341,6 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    5.19    if (!RegistryPath) {
    5.20      KdPrint((__DRIVER_NAME "     IRQL = %d (if you can read this we aren't in dump mode)\n", KeGetCurrentIrql()));
    5.21      dump_mode = TRUE;
    5.22 -    // TODO: what if hibernate and not dump?
    5.23 -    XnDumpModeHookDebugPrint();
    5.24    }
    5.25  
    5.26    FUNCTION_ENTER();
     6.1 --- a/xenvbd_storport/xenvbd.c	Tue Feb 19 15:13:22 2013 +1100
     6.2 +++ b/xenvbd_storport/xenvbd.c	Tue Feb 19 15:14:53 2013 +1100
     6.3 @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fi
     6.4  /* Not really necessary but keeps PREfast happy */
     6.5  DRIVER_INITIALIZE DriverEntry;
     6.6  static IO_WORKITEM_ROUTINE XenVbd_DisconnectWorkItem;
     6.7 +static IO_WORKITEM_ROUTINE XenVbd_ConnectWorkItem;
     6.8  
     6.9  static VOID XenVbd_HandleEventDpc(PSTOR_DPC dpc, PVOID DeviceExtension, PVOID arg1, PVOID arg2);
    6.10  static VOID XenVbd_HandleEventDIRQL(PVOID DeviceExtension);
    6.11 @@ -37,6 +38,7 @@ static VOID XenVbd_CompleteDisconnect(PX
    6.12  
    6.13  #define SxxxPortNotification(...) StorPortNotification(__VA_ARGS__)
    6.14  #define SxxxPortGetSystemAddress(xvdd, srb, system_address) StorPortGetSystemAddress(xvdd, srb, system_address)
    6.15 +#define SxxxPortGetPhysicalAddress(xvdd, srb, virtual_address, length) StorPortGetPhysicalAddress(xvdd, srb, virtual_address, length)
    6.16  
    6.17  static BOOLEAN dump_mode = FALSE;
    6.18  #define DUMP_MODE_ERROR_LIMIT 64
    6.19 @@ -89,6 +91,16 @@ XenVbd_DisconnectWorkItem(PDEVICE_OBJECT
    6.20  }
    6.21  
    6.22  static VOID
    6.23 +XenVbd_ConnectWorkItem(PDEVICE_OBJECT device_object, PVOID context) {
    6.24 +  PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)context;
    6.25 +
    6.26 +  UNREFERENCED_PARAMETER(device_object);
    6.27 +  FUNCTION_ENTER();
    6.28 +  XenVbd_Connect(xvdd, TRUE);
    6.29 +  FUNCTION_EXIT();
    6.30 +}
    6.31 +
    6.32 +static VOID
    6.33  XenVbd_CompleteDisconnect(PXENVBD_DEVICE_DATA xvdd) {
    6.34    IoQueueWorkItem(xvdd->disconnect_workitem, XenVbd_DisconnectWorkItem, DelayedWorkQueue, xvdd);
    6.35  }
    6.36 @@ -106,8 +118,8 @@ XenVbd_VirtualHwStorFindAdapter(PVOID De
    6.37    UNREFERENCED_PARAMETER(ArgumentString);
    6.38  
    6.39    FUNCTION_ENTER(); 
    6.40 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
    6.41 -  KdPrint((__DRIVER_NAME "     xvdd = %p\n", xvdd));
    6.42 +  FUNCTION_MSG("IRQL = %d\n", KeGetCurrentIrql());
    6.43 +  FUNCTION_MSG("xvdd = %p\n", xvdd);
    6.44  
    6.45    if (XnGetVersion() != 1) {
    6.46      FUNCTION_MSG("Wrong XnGetVersion\n");
    6.47 @@ -122,23 +134,19 @@ XenVbd_VirtualHwStorFindAdapter(PVOID De
    6.48    xvdd->pdo = (PDEVICE_OBJECT)HwContext; // TODO: maybe should get PDO from FDO below? HwContext isn't really documented
    6.49    xvdd->fdo = (PDEVICE_OBJECT)BusInformation;
    6.50    xvdd->disconnect_workitem = IoAllocateWorkItem(xvdd->fdo);
    6.51 +  xvdd->connect_workitem = IoAllocateWorkItem(xvdd->fdo);
    6.52    xvdd->aligned_buffer_in_use = FALSE;
    6.53    /* align the buffer to PAGE_SIZE */
    6.54    xvdd->aligned_buffer = (PVOID)((ULONG_PTR)((PUCHAR)xvdd->aligned_buffer_data + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1));
    6.55 -  KdPrint((__DRIVER_NAME "     aligned_buffer_data = %p\n", xvdd->aligned_buffer_data));
    6.56 -  KdPrint((__DRIVER_NAME "     aligned_buffer = %p\n", xvdd->aligned_buffer));
    6.57 +  FUNCTION_MSG("aligned_buffer_data = %p\n", xvdd->aligned_buffer_data);
    6.58 +  FUNCTION_MSG("aligned_buffer = %p\n", xvdd->aligned_buffer);
    6.59  
    6.60    ConfigInfo->MaximumTransferLength = 4 * 1024 * 1024; //BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE;
    6.61    ConfigInfo->NumberOfPhysicalBreaks = ConfigInfo->MaximumTransferLength >> PAGE_SHIFT; //BLKIF_MAX_SEGMENTS_PER_REQUEST - 1;
    6.62    FUNCTION_MSG("ConfigInfo->MaximumTransferLength = %d\n", ConfigInfo->MaximumTransferLength);
    6.63    FUNCTION_MSG("ConfigInfo->NumberOfPhysicalBreaks = %d\n", ConfigInfo->NumberOfPhysicalBreaks);
    6.64 -  if (!dump_mode) {
    6.65 -    ConfigInfo->VirtualDevice = TRUE;
    6.66 -    xvdd->aligned_buffer_size = BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE;
    6.67 -  } else {
    6.68 -    ConfigInfo->VirtualDevice = FALSE;
    6.69 -    xvdd->aligned_buffer_size = DUMP_MODE_UNALIGNED_PAGES * PAGE_SIZE;
    6.70 -  }
    6.71 +  ConfigInfo->VirtualDevice = TRUE;
    6.72 +  xvdd->aligned_buffer_size = BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE;
    6.73    status = XenVbd_Connect(DeviceExtension, FALSE);
    6.74   
    6.75    FUNCTION_MSG("ConfigInfo->VirtualDevice = %d\n", ConfigInfo->VirtualDevice);
    6.76 @@ -177,34 +185,40 @@ XenVbd_HwStorFindAdapter(PVOID DeviceExt
    6.77    UNREFERENCED_PARAMETER(ArgumentString);
    6.78    
    6.79    FUNCTION_ENTER();
    6.80 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
    6.81 -  KdPrint((__DRIVER_NAME "     xvdd = %p\n", xvdd));
    6.82 +  FUNCTION_MSG("IRQL = %d\n", KeGetCurrentIrql());
    6.83 +  FUNCTION_MSG("xvdd = %p\n", xvdd);
    6.84 +  FUNCTION_MSG("ArgumentString = %s\n", ArgumentString);
    6.85  
    6.86    memcpy(xvdd, ConfigInfo->Reserved, FIELD_OFFSET(XENVBD_DEVICE_DATA, aligned_buffer_data));
    6.87 +  if (xvdd->device_state != DEVICE_STATE_ACTIVE) {
    6.88 +    return SP_RETURN_ERROR;
    6.89 +  }
    6.90 +  /* make sure original xvdd is set to DISCONNECTED or resume will not work */
    6.91 +  ((PXENVBD_DEVICE_DATA)ConfigInfo->Reserved)->device_state = DEVICE_STATE_DISCONNECTED;
    6.92    InitializeListHead(&xvdd->srb_list);
    6.93    xvdd->aligned_buffer_in_use = FALSE;
    6.94    /* align the buffer to PAGE_SIZE */
    6.95    xvdd->aligned_buffer = (PVOID)((ULONG_PTR)((PUCHAR)xvdd->aligned_buffer_data + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1));
    6.96 -  KdPrint((__DRIVER_NAME "     aligned_buffer_data = %p\n", xvdd->aligned_buffer_data));
    6.97 -  KdPrint((__DRIVER_NAME "     aligned_buffer = %p\n", xvdd->aligned_buffer));
    6.98 +  xvdd->aligned_buffer_size = DUMP_MODE_UNALIGNED_PAGES * PAGE_SIZE;
    6.99 +  FUNCTION_MSG("aligned_buffer_data = %p\n", xvdd->aligned_buffer_data);
   6.100 +  FUNCTION_MSG("aligned_buffer = %p\n", xvdd->aligned_buffer);
   6.101  
   6.102    ConfigInfo->MaximumTransferLength = 4 * 1024 * 1024;
   6.103    ConfigInfo->NumberOfPhysicalBreaks = ConfigInfo->MaximumTransferLength >> PAGE_SHIFT;
   6.104    FUNCTION_MSG("ConfigInfo->MaximumTransferLength = %d\n", ConfigInfo->MaximumTransferLength);
   6.105    FUNCTION_MSG("ConfigInfo->NumberOfPhysicalBreaks = %d\n", ConfigInfo->NumberOfPhysicalBreaks);
   6.106    ConfigInfo->VirtualDevice = FALSE;
   6.107 -  xvdd->aligned_buffer_size = DUMP_MODE_UNALIGNED_PAGES * PAGE_SIZE;
   6.108    ConfigInfo->ScatterGather = TRUE;
   6.109    ConfigInfo->Master = TRUE;
   6.110    ConfigInfo->CachesData = FALSE;
   6.111 -  ConfigInfo->MapBuffers = STOR_MAP_ALL_BUFFERS;
   6.112 -  FUNCTION_MSG("ConfigInfo->NeedPhysicalAddresses = %d\n", ConfigInfo->NeedPhysicalAddresses);
   6.113 +  ConfigInfo->MapBuffers = STOR_MAP_NON_READ_WRITE_BUFFERS;
   6.114    ConfigInfo->SynchronizationModel = StorSynchronizeFullDuplex;
   6.115    ConfigInfo->AlignmentMask = 0;
   6.116    ConfigInfo->NumberOfBuses = 1;
   6.117    ConfigInfo->InitiatorBusId[0] = 1;
   6.118    ConfigInfo->MaximumNumberOfLogicalUnits = 1;
   6.119    ConfigInfo->MaximumNumberOfTargets = 2;
   6.120 +  ConfigInfo->VirtualDevice = FALSE;
   6.121    if (ConfigInfo->Dma64BitAddresses == SCSI_DMA64_SYSTEM_SUPPORTED) {
   6.122      ConfigInfo->Dma64BitAddresses = SCSI_DMA64_MINIPORT_SUPPORTED;
   6.123      FUNCTION_MSG("Dma64BitAddresses supported\n");
   6.124 @@ -226,8 +240,8 @@ XenVbd_HwStorInitialize(PVOID DeviceExte
   6.125    ULONG i;
   6.126    
   6.127    FUNCTION_ENTER();
   6.128 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   6.129 -  KdPrint((__DRIVER_NAME "     dump_mode = %d\n", dump_mode));
   6.130 +  FUNCTION_MSG("IRQL = %d\n", KeGetCurrentIrql());
   6.131 +  FUNCTION_MSG("dump_mode = %d\n", dump_mode);
   6.132    
   6.133    xvdd->shadow_free = 0;
   6.134    memset(xvdd->shadows, 0, sizeof(blkif_shadow_t) * SHADOW_ENTRIES);
   6.135 @@ -295,7 +309,7 @@ XenVbd_HwStorStartIo(PVOID DeviceExtensi
   6.136    STOR_LOCK_HANDLE lock_handle;
   6.137  
   6.138    //if (dump_mode) FUNCTION_ENTER();
   6.139 -  //if (dump_mode) KdPrint((__DRIVER_NAME "     srb = %p\n", srb));
   6.140 +  //if (dump_mode) FUNCTION_MSG("srb = %p\n", srb);
   6.141    
   6.142    StorPortAcquireSpinLock(DeviceExtension, StartIoLock, NULL, &lock_handle);
   6.143    
   6.144 @@ -333,46 +347,49 @@ XenVbd_HwStorAdapterControl(PVOID Device
   6.145    //KIRQL OldIrql;
   6.146  
   6.147    FUNCTION_ENTER();
   6.148 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   6.149 -  KdPrint((__DRIVER_NAME "     xvdd = %p\n", xvdd));
   6.150 +  FUNCTION_MSG("IRQL = %d\n", KeGetCurrentIrql());
   6.151 +  FUNCTION_MSG("ControlType = %d\n", ControlType);
   6.152  
   6.153 -  switch (ControlType)
   6.154 -  {
   6.155 +  switch (ControlType) {
   6.156    case ScsiQuerySupportedControlTypes:
   6.157      SupportedControlTypeList = (PSCSI_SUPPORTED_CONTROL_TYPE_LIST)Parameters;
   6.158 -    KdPrint((__DRIVER_NAME "     ScsiQuerySupportedControlTypes (Max = %d)\n", SupportedControlTypeList->MaxControlType));
   6.159 +    FUNCTION_MSG("ScsiQuerySupportedControlTypes (Max = %d)\n", SupportedControlTypeList->MaxControlType);
   6.160      SupportedControlTypeList->SupportedTypeList[ScsiQuerySupportedControlTypes] = TRUE;
   6.161      SupportedControlTypeList->SupportedTypeList[ScsiStopAdapter] = TRUE;
   6.162      SupportedControlTypeList->SupportedTypeList[ScsiRestartAdapter] = TRUE;
   6.163      break;
   6.164    case ScsiStopAdapter:
   6.165 -    KdPrint((__DRIVER_NAME "     ScsiStopAdapter\n"));
   6.166 -    if (xvdd->device_state == DEVICE_STATE_INACTIVE)
   6.167 -    {
   6.168 -      KdPrint((__DRIVER_NAME "     inactive - nothing to do\n"));
   6.169 +    FUNCTION_MSG("ScsiStopAdapter\n");
   6.170 +    if (xvdd->device_state == DEVICE_STATE_INACTIVE) {
   6.171 +      FUNCTION_MSG("inactive - nothing to do\n");
   6.172        break;
   6.173      }
   6.174 -    NT_ASSERT(IsListEmpty(&xvdd->srb_list));
   6.175 -    NT_ASSERT(xvdd->shadow_free == SHADOW_ENTRIES);
   6.176 +    XN_ASSERT(IsListEmpty(&xvdd->srb_list));
   6.177 +    XN_ASSERT(xvdd->shadow_free == SHADOW_ENTRIES);
   6.178 +    if (xvdd->power_action != StorPowerActionHibernate) {
   6.179 +      /* if hibernate then device_state will be set on our behalf in the hibernate FindAdapter */
   6.180 +      xvdd->device_state = DEVICE_STATE_DISCONNECTED;
   6.181 +      //XenVbd_Disconnect(??);
   6.182 +    }
   6.183      break;
   6.184    case ScsiRestartAdapter:
   6.185 -    KdPrint((__DRIVER_NAME "     ScsiRestartAdapter\n"));
   6.186 -    if (xvdd->device_state == DEVICE_STATE_INACTIVE)
   6.187 -    {
   6.188 -      KdPrint((__DRIVER_NAME "     inactive - nothing to do\n"));
   6.189 +    FUNCTION_MSG("ScsiRestartAdapter\n");
   6.190 +    if (xvdd->device_state == DEVICE_STATE_INACTIVE) {
   6.191 +      FUNCTION_MSG("inactive - nothing to do\n");
   6.192        break;
   6.193      }
   6.194      /* increase the tag every time we stop/start to track where the gref's came from */
   6.195      xvdd->grant_tag++;
   6.196 +    IoQueueWorkItem(xvdd->connect_workitem, XenVbd_ConnectWorkItem, DelayedWorkQueue, xvdd);
   6.197      break;
   6.198    case ScsiSetBootConfig:
   6.199 -    KdPrint((__DRIVER_NAME "     ScsiSetBootConfig\n"));
   6.200 +    FUNCTION_MSG("ScsiSetBootConfig\n");
   6.201      break;
   6.202    case ScsiSetRunningConfig:
   6.203 -    KdPrint((__DRIVER_NAME "     ScsiSetRunningConfig\n"));
   6.204 +    FUNCTION_MSG("ScsiSetRunningConfig\n");
   6.205      break;
   6.206    default:
   6.207 -    KdPrint((__DRIVER_NAME "     UNKNOWN\n"));
   6.208 +    FUNCTION_MSG("UNKNOWN\n");
   6.209      break;
   6.210    }
   6.211  
   6.212 @@ -381,34 +398,33 @@ XenVbd_HwStorAdapterControl(PVOID Device
   6.213    return Status;
   6.214  }
   6.215  
   6.216 +//BOOLEAN dump_mode_hooked = FALSE;
   6.217 +
   6.218  NTSTATUS
   6.219  DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) {
   6.220    ULONG status;
   6.221    VIRTUAL_HW_INITIALIZATION_DATA VHwInitializationData;
   6.222    HW_INITIALIZATION_DATA HwInitializationData;
   6.223 -  
   6.224 +
   6.225 +  FUNCTION_ENTER();
   6.226 +  FUNCTION_MSG("IRQL = %d\n", KeGetCurrentIrql());
   6.227 +  FUNCTION_MSG("DriverObject = %p, RegistryPath = %p\n", DriverObject, RegistryPath);
   6.228 +
   6.229 +  /* RegistryPath == NULL when we are invoked as a crash dump driver */
   6.230    if (!RegistryPath) {
   6.231      dump_mode = TRUE;
   6.232 -    // what if hibernate and not dump?
   6.233 -    XnDumpModeHookDebugPrint();
   6.234 +    XnPrintDump();
   6.235    }
   6.236  
   6.237 -  FUNCTION_ENTER();
   6.238 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   6.239 -  KdPrint((__DRIVER_NAME "     DriverObject = %p, RegistryPath = %p\n", DriverObject, RegistryPath));
   6.240 -
   6.241 -  /* RegistryPath == NULL when we are invoked as a crash dump driver */
   6.242 -  
   6.243    if (!dump_mode) {
   6.244      RtlZeroMemory(&VHwInitializationData, sizeof(VIRTUAL_HW_INITIALIZATION_DATA));
   6.245      VHwInitializationData.HwInitializationDataSize = sizeof(VIRTUAL_HW_INITIALIZATION_DATA);
   6.246 -    VHwInitializationData.AdapterInterfaceType = Internal; //PNPBus; /* maybe should be internal? */
   6.247 +    VHwInitializationData.AdapterInterfaceType = Internal;
   6.248      VHwInitializationData.DeviceExtensionSize = FIELD_OFFSET(XENVBD_DEVICE_DATA, aligned_buffer_data) + UNALIGNED_BUFFER_DATA_SIZE;
   6.249      VHwInitializationData.SpecificLuExtensionSize = 0;
   6.250      VHwInitializationData.SrbExtensionSize = sizeof(srb_list_entry_t);
   6.251      VHwInitializationData.NumberOfAccessRanges = 0;
   6.252      VHwInitializationData.MapBuffers = STOR_MAP_ALL_BUFFERS;
   6.253 -    //VHwInitializationData.NeedPhysicalAddresses  = TRUE;
   6.254      VHwInitializationData.TaggedQueuing = TRUE;
   6.255      VHwInitializationData.AutoRequestSense = TRUE;
   6.256      VHwInitializationData.MultipleRequestPerLu = TRUE;
   6.257 @@ -423,7 +439,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
   6.258    } else {
   6.259      RtlZeroMemory(&HwInitializationData, sizeof(HW_INITIALIZATION_DATA));
   6.260      HwInitializationData.HwInitializationDataSize = sizeof(HW_INITIALIZATION_DATA);
   6.261 -    HwInitializationData.AdapterInterfaceType = Internal; //PNPBus; /* not Internal */
   6.262 +    HwInitializationData.AdapterInterfaceType = Internal;
   6.263      HwInitializationData.DeviceExtensionSize = FIELD_OFFSET(XENVBD_DEVICE_DATA, aligned_buffer_data) + UNALIGNED_BUFFER_DATA_SIZE_DUMP_MODE;
   6.264      HwInitializationData.SrbExtensionSize = sizeof(srb_list_entry_t);
   6.265      HwInitializationData.NumberOfAccessRanges = 0;
     7.1 --- a/xenvbd_storport/xenvbd.h	Tue Feb 19 15:13:22 2013 +1100
     7.2 +++ b/xenvbd_storport/xenvbd.h	Tue Feb 19 15:14:53 2013 +1100
     7.3 @@ -45,42 +45,13 @@ Foundation, Inc., 51 Franklin Street, Fi
     7.4  
     7.5  #include "../xenvbd_common/common.h"
     7.6  
     7.7 -//#define XENVBD_POOL_TAG (ULONG) 'XVBD'
     7.8 -
     7.9  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
    7.10  #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
    7.11  
    7.12 -//#define SCSI_DEVICE_MANUFACTURER "XEN     "
    7.13 -//#define SCSI_DISK_MODEL          "PV DISK          "
    7.14 -//#define SCSI_CDROM_MODEL         "PV CDROM         "
    7.15 -
    7.16  #define SCSIOP_UNMAP 0x42
    7.17  
    7.18  #define VPD_BLOCK_LIMITS 0xB0
    7.19  
    7.20 -#if 0
    7.21 -typedef struct {
    7.22 -  LIST_ENTRY list_entry;
    7.23 -  PSCSI_REQUEST_BLOCK srb;
    7.24 -  ULONG length; /* cached srb length */
    7.25 -  ULONG offset; /* current srb offset */
    7.26 -  ULONG outstanding_requests; /* number of requests sent to xen for this srb */
    7.27 -  BOOLEAN error; /* true if any sub requests have returned an error */
    7.28 -} srb_list_entry_t;
    7.29 -
    7.30 -typedef struct {
    7.31 -  blkif_request_t req;
    7.32 -  srb_list_entry_t *srb_list_entry;
    7.33 -  PSCSI_REQUEST_BLOCK srb;
    7.34 -  PVOID system_address;
    7.35 -  ULONG length;
    7.36 -  BOOLEAN aligned_buffer_in_use;
    7.37 -  BOOLEAN reset;
    7.38 -  #if DBG && NTDDI_VERSION >= NTDDI_WINXP
    7.39 -  LARGE_INTEGER ring_submit_time;
    7.40 -  #endif
    7.41 -} blkif_shadow_t;
    7.42 -#endif
    7.43  #define MAX_SHADOW_ENTRIES  64
    7.44  #define SHADOW_ID_ID_MASK   0x03FF /* maximum of 1024 requests - currently use a maximum of 64 though */
    7.45  #define SHADOW_ID_DUMP_FLAG 0x8000 /* indicates the request was generated by dump mode */
    7.46 @@ -95,6 +66,7 @@ struct {
    7.47    KEVENT device_state_event;
    7.48    STOR_DPC dpc;
    7.49    PIO_WORKITEM disconnect_workitem;
    7.50 +  PIO_WORKITEM connect_workitem;
    7.51    blkif_shadow_t shadows[MAX_SHADOW_ENTRIES];
    7.52    USHORT shadow_free_list[MAX_SHADOW_ENTRIES];
    7.53    USHORT shadow_free;
    7.54 @@ -109,7 +81,6 @@ struct {
    7.55    grant_ref_t sring_gref; 
    7.56    KEVENT backend_event;
    7.57    ULONG backend_state;
    7.58 -  //ULONG frontend_state;
    7.59    UCHAR last_sense_key;
    7.60    UCHAR last_additional_sense_code;
    7.61    blkif_response_t tmp_rep;
    7.62 @@ -118,11 +89,14 @@ struct {
    7.63    ULONG bytes_per_sector; /* 512 for disk, 2048 for CDROM) */
    7.64    ULONG hw_bytes_per_sector; /* underlying hardware format, eg 4K */
    7.65    ULONGLONG total_sectors;
    7.66 +  CHAR serial_number[64];
    7.67    ULONG feature_flush_cache;
    7.68    ULONG feature_discard;
    7.69    ULONG feature_barrier;
    7.70    LIST_ENTRY srb_list;
    7.71    BOOLEAN aligned_buffer_in_use;
    7.72 +  STOR_POWER_ACTION power_action;
    7.73 +  STOR_DEVICE_POWER_STATE power_state;
    7.74    ULONG aligned_buffer_size;
    7.75    PVOID aligned_buffer;
    7.76  /*