win-pvdrivers

changeset 482:7656d3624f98

Changed back to scsiport driver - storport just doesn't work.
author James Harper <james.harper@bendigoit.com.au>
date Sat Dec 06 16:22:14 2008 +1100 (2008-12-06)
parents 2a18182e3090
children 59dc8e8f5647
files xenscsi/sources xenscsi/xenscsi.c xenscsi/xenscsi.h xenscsi/xenscsi.inx
line diff
     1.1 --- a/xenscsi/sources	Sat Dec 06 16:21:03 2008 +1100
     1.2 +++ b/xenscsi/sources	Sat Dec 06 16:22:14 2008 +1100
     1.3 @@ -2,6 +2,6 @@
     1.4  TARGETNAME=xenscsi
     1.5  TARGETTYPE=DRIVER
     1.6  INF_NAME=$(TARGETNAME)
     1.7 -TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\storport.lib
     1.8 +TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\scsiport.lib
     1.9  MISCFILES=..\Target\$(DDK_TARGET_OS)\$(INF_NAME).inf
    1.10  SOURCES=xenscsi.c
     2.1 --- a/xenscsi/xenscsi.c	Sat Dec 06 16:21:03 2008 +1100
     2.2 +++ b/xenscsi/xenscsi.c	Sat Dec 06 16:22:14 2008 +1100
     2.3 @@ -70,19 +70,7 @@ put_grant_on_freelist(PXENSCSI_DEVICE_DA
     2.4  }
     2.5  
     2.6  static BOOLEAN
     2.7 -XenScsi_HwStorInterrupt(PVOID DeviceExtension)
     2.8 -{
     2.9 -  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
    2.10 -  if (!dump_mode && !xsdd->vectors.EvtChn_AckEvent(xsdd->vectors.context, xsdd->event_channel))
    2.11 -    return FALSE;
    2.12 -  
    2.13 -  StorPortIssueDpc(DeviceExtension, &xsdd->dpc, NULL, NULL);
    2.14 -  
    2.15 -  return FALSE;
    2.16 -}
    2.17 -
    2.18 -static VOID
    2.19 -XenScsi_HwStorDpc(PSTOR_DPC Dpc, PVOID DeviceExtension, PVOID SystemArgument1, PVOID SystemArgument2)
    2.20 +XenScsi_HwScsiInterrupt(PVOID DeviceExtension)
    2.21  {
    2.22    PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
    2.23    PSCSI_REQUEST_BLOCK Srb;
    2.24 @@ -91,16 +79,21 @@ XenScsi_HwStorDpc(PSTOR_DPC Dpc, PVOID D
    2.25    vscsiif_response_t *rep;
    2.26    int more_to_do = TRUE;
    2.27    vscsiif_shadow_t *shadow;
    2.28 -  ULONG remaining;
    2.29 -  STOR_LOCK_HANDLE lock_handle;
    2.30  
    2.31 -  UNREFERENCED_PARAMETER(Dpc);
    2.32 -  UNREFERENCED_PARAMETER(SystemArgument1);
    2.33 -  UNREFERENCED_PARAMETER(SystemArgument2);
    2.34 +  if (xsdd->pause_ack != xsdd->pause_req)
    2.35 +  {
    2.36 +    xsdd->pause_ack = xsdd->pause_req;
    2.37 +    KdPrint((__DRIVER_NAME "     Pause state change to %d\n", xsdd->pause_ack));
    2.38 +    if (!xsdd->pause_ack)
    2.39 +    {
    2.40 +      ScsiPortNotification(NextRequest, DeviceExtension);
    2.41 +    }
    2.42 +  }
    2.43 +  if (!dump_mode && !xsdd->vectors.EvtChn_AckEvent(xsdd->vectors.context, xsdd->event_channel))
    2.44 +    return FALSE;
    2.45 +  
    2.46    //FUNCTION_ENTER();
    2.47  
    2.48 -  StorPortAcquireSpinLock(DeviceExtension, StartIoLock, NULL, &lock_handle);
    2.49 -
    2.50    while (more_to_do)
    2.51    {
    2.52      rp = xsdd->ring.sring->rsp_prod;
    2.53 @@ -111,55 +104,64 @@ XenScsi_HwStorDpc(PSTOR_DPC Dpc, PVOID D
    2.54        shadow = &xsdd->shadows[rep->rqid];
    2.55        Srb = shadow->Srb;
    2.56        Srb->ScsiStatus = (UCHAR)rep->rslt;
    2.57 -      if (rep->sense_len > 0 && Srb->SenseInfoBuffer != NULL)
    2.58 -      {
    2.59 -        memcpy(Srb->SenseInfoBuffer, rep->sense_buffer, min(Srb->SenseInfoBufferLength, rep->sense_len));
    2.60 -      }
    2.61 +/*
    2.62 +      for (j = 0; j < Srb->SenseInfoBufferLength; j++)
    2.63 +        KdPrint((__DRIVER_NAME "     sense before %02x: %02x\n", j, (ULONG)((PUCHAR)Srb->SenseInfoBuffer)[j]));
    2.64 +*/
    2.65 +      memset(Srb->SenseInfoBuffer, 0, Srb->SenseInfoBufferLength);
    2.66        switch(rep->rslt)
    2.67        {
    2.68        case 0:
    2.69 -        KdPrint((__DRIVER_NAME "     Xen Operation complete - result = 0x%08x, residual = %d\n", rep->rslt, rep->residual_len));
    2.70 +        //KdPrint((__DRIVER_NAME "     Xen Operation complete - result = 0x%08x, sense_len = %d, residual = %d\n", rep->rslt, rep->sense_len, rep->residual_len));
    2.71          Srb->SrbStatus = SRB_STATUS_SUCCESS;
    2.72          break;
    2.73        case 0x00010000: /* Device does not exist */
    2.74 -        KdPrint((__DRIVER_NAME "     Xen Operation returned error (result = 0x%08x)\n", rep->rslt));
    2.75 +        KdPrint((__DRIVER_NAME "     Xen Operation error - result = 0x%08x, sense_len = %d, residual = %d\n", rep->rslt, rep->sense_len, rep->residual_len));
    2.76          Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
    2.77          break;
    2.78        default:
    2.79 -        KdPrint((__DRIVER_NAME "     Xen Operation returned error (result = 0x%08x)\n", rep->rslt));
    2.80 +        KdPrint((__DRIVER_NAME "     Xen Operation error - result = 0x%08x, sense_len = %d, residual = %d\n", rep->rslt, rep->sense_len, rep->residual_len));
    2.81          Srb->SrbStatus = SRB_STATUS_ERROR;
    2.82          if (rep->sense_len > 0 && !(Srb->SrbFlags & SRB_FLAGS_DISABLE_AUTOSENSE) && Srb->SenseInfoBuffer != NULL)
    2.83          {
    2.84 +          KdPrint((__DRIVER_NAME "     Doing autosense\n"));
    2.85            Srb->SrbStatus |= SRB_STATUS_AUTOSENSE_VALID;
    2.86 +          memcpy(Srb->SenseInfoBuffer, rep->sense_buffer, min(Srb->SenseInfoBufferLength, rep->sense_len));
    2.87          }
    2.88        }
    2.89 +/*
    2.90 +      for (j = 0; j < Srb->SenseInfoBufferLength; j++)
    2.91 +        KdPrint((__DRIVER_NAME "     sense after %02x: %02x\n", j, (ULONG)((PUCHAR)Srb->SenseInfoBuffer)[j]));
    2.92 +*/
    2.93        /* work around a bug in scsiback that gives an incorrect result to REPORT_LUNS - fail it if the output is only 8 bytes */
    2.94        if (Srb->Cdb[0] == 0xa0 && Srb->SrbStatus == SRB_STATUS_SUCCESS &&
    2.95          Srb->DataTransferLength - rep->residual_len == 8)
    2.96        {
    2.97          /* SRB_STATUS_ERROR appears to be sufficient here - no need to worry about sense data or anything */
    2.98 +        KdPrint((__DRIVER_NAME "     Worked around bad REPORT_LUNS emulation for %d:%d:%d\n",
    2.99 +          Srb->PathId, Srb->TargetId, Srb->Lun));
   2.100          Srb->SrbStatus = SRB_STATUS_ERROR;
   2.101        }
   2.102 -      remaining = Srb->DataTransferLength;
   2.103 -      for (j = 0; remaining != 0; j++)
   2.104 +      //remaining = Srb->DataTransferLength;
   2.105 +      for (j = 0; j < shadow->req.nr_segments; j++)
   2.106        {
   2.107          xsdd->vectors.GntTbl_EndAccess(xsdd->vectors.context, shadow->req.seg[j].gref, TRUE);
   2.108          put_grant_on_freelist(xsdd, shadow->req.seg[j].gref);
   2.109          shadow->req.seg[j].gref = 0;
   2.110 -        remaining -= shadow->req.seg[j].length;
   2.111        }
   2.112  
   2.113        if (Srb->SrbStatus == SRB_STATUS_SUCCESS && rep->residual_len)
   2.114        {
   2.115 -        KdPrint((__DRIVER_NAME "     SRB_STATUS_DATA_OVERRUN DataTransferLength = %d, adjusted = %d\n",
   2.116 -          Srb->DataTransferLength, Srb->DataTransferLength - rep->residual_len));
   2.117 +//        KdPrint((__DRIVER_NAME "     SRB_STATUS_DATA_OVERRUN DataTransferLength = %d, adjusted = %d\n",
   2.118 +//          Srb->DataTransferLength, Srb->DataTransferLength - rep->residual_len));
   2.119          Srb->DataTransferLength -= rep->residual_len;
   2.120          Srb->SrbStatus = SRB_STATUS_DATA_OVERRUN;
   2.121        }
   2.122  
   2.123        put_shadow_on_freelist(xsdd, shadow);
   2.124 -      StorPortNotification(RequestComplete, xsdd, Srb);
   2.125 -      //StorPortNotification(NextRequest, xsdd);
   2.126 +      ScsiPortNotification(RequestComplete, xsdd, Srb);
   2.127 +      if (!xsdd->pause_ack)
   2.128 +        ScsiPortNotification(NextRequest, DeviceExtension);
   2.129      }
   2.130  
   2.131      xsdd->ring.rsp_cons = i;
   2.132 @@ -174,10 +176,9 @@ XenScsi_HwStorDpc(PSTOR_DPC Dpc, PVOID D
   2.133      }
   2.134    }
   2.135  
   2.136 -  StorPortReleaseSpinLock(DeviceExtension, &lock_handle);
   2.137    //FUNCTION_EXIT();
   2.138    
   2.139 -  return;
   2.140 +  return FALSE;
   2.141  }
   2.142  
   2.143  static VOID
   2.144 @@ -206,7 +207,26 @@ XenScsi_ParseBackendDevice(scsi_dev_t *d
   2.145      dev->host, dev->channel, dev->id, dev->lun));  
   2.146  }
   2.147  
   2.148 +static VOID
   2.149 +XenScsi_WaitPause(PVOID DeviceExtension)
   2.150 +{
   2.151 +  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   2.152 +  LARGE_INTEGER wait_time;
   2.153 +
   2.154 +  FUNCTION_ENTER();
   2.155 +  xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->vectors.pdo_event_channel);
   2.156 +  while (xsdd->pause_ack != xsdd->pause_req)
   2.157 +  {
   2.158 +    KdPrint((__DRIVER_NAME "     Waiting...\n"));
   2.159 +    wait_time.QuadPart = -1 * 1000 * 10; /* 1ms */
   2.160 +    KeDelayExecutionThread(KernelMode, FALSE, &wait_time);
   2.161 +    xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->vectors.pdo_event_channel);
   2.162 +  }  
   2.163 +  FUNCTION_EXIT();
   2.164 +}
   2.165 +
   2.166  /* CALLED AT PASSIVE LEVEL */
   2.167 +/* If Initialize fails then the watch still gets called but the waits will never be acked... */
   2.168  static VOID
   2.169  XenScsi_DevWatch(PCHAR path, PVOID DeviceExtension)
   2.170  {
   2.171 @@ -220,25 +240,14 @@ XenScsi_DevWatch(PCHAR path, PVOID Devic
   2.172    ULONG dev_no;
   2.173    ULONG state;
   2.174    BOOLEAN changes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
   2.175 -  STOR_LOCK_HANDLE lock_handle;
   2.176  
   2.177    UNREFERENCED_PARAMETER(path);
   2.178    
   2.179 +  /* this can only be called from a watch and so is always serialised */
   2.180    FUNCTION_ENTER();
   2.181 +  xsdd->pause_req = TRUE;
   2.182 +  XenScsi_WaitPause(DeviceExtension);
   2.183    
   2.184 -  StorPortAcquireSpinLock(DeviceExtension, StartIoLock, NULL, &lock_handle);
   2.185 -  if (!xsdd->paused)
   2.186 -  {
   2.187 -    xsdd->state = SCSI_STATE_ENUM_PENDING;
   2.188 -    xsdd->paused = TRUE;
   2.189 -    StorPortReleaseSpinLock(DeviceExtension, &lock_handle);
   2.190 -    StorPortPause(DeviceExtension, XENSCSI_MAX_ENUM_TIME);
   2.191 -  }
   2.192 -  else
   2.193 -  {
   2.194 -    StorPortReleaseSpinLock(DeviceExtension, &lock_handle);
   2.195 -  }
   2.196 -
   2.197    KdPrint((__DRIVER_NAME "     Watch triggered on %s\n", path));
   2.198    strncpy(tmp_path, xsdd->vectors.backend_path, 128);
   2.199    strncat(tmp_path, "/vscsi-devs", 128);
   2.200 @@ -331,29 +340,24 @@ XenScsi_DevWatch(PCHAR path, PVOID Devic
   2.201    }
   2.202    XenPci_FreeMem(devices);
   2.203  
   2.204 -  StorPortAcquireSpinLock(DeviceExtension, StartIoLock, NULL, &lock_handle);
   2.205 -  xsdd->state = SCSI_STATE_ENUM_COMPLETE;
   2.206 -  xsdd->paused = FALSE;
   2.207 -
   2.208    for (i = 0; i < 8; i++)
   2.209    {  
   2.210      if (changes[i])
   2.211      {
   2.212 -      KdPrint((__DRIVER_NAME "     Sending BusChangeDetected for channel %d... NOT!\n", i));
   2.213 -//      StorPortNotification(BusChangeDetected, DeviceExtension, i);
   2.214 +      KdPrint((__DRIVER_NAME "     Sending BusChangeDetected for channel %d\n", i));
   2.215 +      ScsiPortNotification(BusChangeDetected, DeviceExtension, i);
   2.216      }
   2.217    }
   2.218  
   2.219 +  xsdd->pause_req = FALSE;
   2.220 +  XenScsi_WaitPause(DeviceExtension);
   2.221    KdPrint((__DRIVER_NAME "     Unpaused\n"));
   2.222 -  StorPortResume(DeviceExtension);
   2.223 -
   2.224 -  StorPortReleaseSpinLock(DeviceExtension, &lock_handle);
   2.225  
   2.226    FUNCTION_EXIT();
   2.227  }
   2.228  
   2.229  static ULONG
   2.230 -XenScsi_HwStorFindAdapter(PVOID DeviceExtension, PVOID Reserved1, PVOID Reserved2, PCHAR ArgumentString, PPORT_CONFIGURATION_INFORMATION ConfigInfo, PUCHAR Reserved3)
   2.231 +XenScsi_HwScsiFindAdapter(PVOID DeviceExtension, PVOID Reserved1, PVOID Reserved2, PCHAR ArgumentString, PPORT_CONFIGURATION_INFORMATION ConfigInfo, PUCHAR Reserved3)
   2.232  {
   2.233    ULONG i;
   2.234    PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   2.235 @@ -371,6 +375,9 @@ XenScsi_HwStorFindAdapter(PVOID DeviceEx
   2.236  
   2.237    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));  
   2.238    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   2.239 +  
   2.240 +  xsdd->pause_req = TRUE;
   2.241 +  xsdd->pause_ack = TRUE;
   2.242  
   2.243    KdPrint((__DRIVER_NAME "     BusInterruptLevel = %d\n", ConfigInfo->BusInterruptLevel));
   2.244    KdPrint((__DRIVER_NAME "     BusInterruptVector = %03x\n", ConfigInfo->BusInterruptVector));
   2.245 @@ -386,7 +393,7 @@ XenScsi_HwStorFindAdapter(PVOID DeviceEx
   2.246    KdPrint((__DRIVER_NAME "     RangeStart = %08x, RangeLength = %08x\n",
   2.247      access_range->RangeStart.LowPart, access_range->RangeLength));
   2.248  
   2.249 -  ptr = StorPortGetDeviceBase(
   2.250 +  ptr = ScsiPortGetDeviceBase(
   2.251      DeviceExtension,
   2.252      ConfigInfo->AdapterInterfaceType,
   2.253      ConfigInfo->SystemIoBusNumber,
   2.254 @@ -460,37 +467,30 @@ XenScsi_HwStorFindAdapter(PVOID DeviceEx
   2.255      return SP_RETURN_BAD_CONFIG;
   2.256    }
   2.257  #endif
   2.258 -  ConfigInfo->MaximumTransferLength = VSCSIIF_SG_TABLESIZE * PAGE_SIZE;
   2.259 -  ConfigInfo->NumberOfPhysicalBreaks = VSCSIIF_SG_TABLESIZE - 1;
   2.260 +  
   2.261    ConfigInfo->ScatterGather = TRUE;
   2.262 -  ConfigInfo->AlignmentMask = 0;
   2.263 +  ConfigInfo->NumberOfPhysicalBreaks = VSCSIIF_SG_TABLESIZE - 1;
   2.264 +  ConfigInfo->MaximumTransferLength = VSCSIIF_SG_TABLESIZE * PAGE_SIZE;
   2.265    ConfigInfo->CachesData = FALSE;
   2.266 -  ConfigInfo->NumberOfBuses = SCSI_MAXIMUM_BUSES; //8
   2.267 +  ConfigInfo->NumberOfBuses = 4; //SCSI_MAXIMUM_BUSES; //8
   2.268    ConfigInfo->MaximumNumberOfTargets = 16;
   2.269    ConfigInfo->MaximumNumberOfLogicalUnits = SCSI_MAXIMUM_LOGICAL_UNITS; // 8
   2.270 +  ConfigInfo->BufferAccessScsiPortControlled = TRUE;
   2.271    if (ConfigInfo->Dma64BitAddresses == SCSI_DMA64_SYSTEM_SUPPORTED)
   2.272    {
   2.273 +    ConfigInfo->Master = TRUE;
   2.274      ConfigInfo->Dma64BitAddresses = SCSI_DMA64_MINIPORT_SUPPORTED;
   2.275      KdPrint((__DRIVER_NAME "     Dma64BitAddresses supported\n"));
   2.276    }
   2.277    else
   2.278    {
   2.279 +    ConfigInfo->Master = FALSE;
   2.280      KdPrint((__DRIVER_NAME "     Dma64BitAddresses not supported\n"));
   2.281    }
   2.282 -  /* from i2o example */
   2.283 -/*
   2.284    ConfigInfo->InitiatorBusId[0] = 7;
   2.285 -  ConfigInfo->AlignmentMask = 3;
   2.286 -  ConfigInfo->Dma32BitAddresses = TRUE;
   2.287 -  ConfigInfo->NeedPhysicalAddresses = TRUE;
   2.288 -  ConfigInfo->TaggedQueuing = TRUE;
   2.289 -  ConfigInfo->MapBuffers = STOR_MAP_NO_BUFFERS;
   2.290 -  ConfigInfo->CachesData = TRUE;
   2.291 -*/
   2.292 -  /* end */
   2.293 -  ConfigInfo->ResetTargetSupported = FALSE; // maybe?
   2.294 -  ConfigInfo->SynchronizationModel = StorSynchronizeFullDuplex;
   2.295 -  //ConfigInfo->WmiDataProvider = FALSE; /* i'm not supposed to do this... */
   2.296 +  ConfigInfo->InitiatorBusId[1] = 7;
   2.297 +  ConfigInfo->InitiatorBusId[2] = 7;
   2.298 +  ConfigInfo->InitiatorBusId[3] = 7;
   2.299    xsdd->shadow_free = 0;
   2.300    memset(xsdd->shadows, 0, sizeof(vscsiif_shadow_t) * SHADOW_ENTRIES);
   2.301    for (i = 0; i < SHADOW_ENTRIES; i++)
   2.302 @@ -503,48 +503,27 @@ XenScsi_HwStorFindAdapter(PVOID DeviceEx
   2.303    {
   2.304      InitializeListHead(&xsdd->dev_list_head);
   2.305      /* should do something if we haven't enumerated in a certain time */
   2.306 -    xsdd->state = SCSI_STATE_ENUM_PENDING;
   2.307      strncpy(path, xsdd->vectors.backend_path, 128);
   2.308      strncat(path, "/vscsi-devs", 128);
   2.309      xsdd->vectors.XenBus_AddWatch(xsdd->vectors.context, XBT_NIL, path,
   2.310        XenScsi_DevWatch, xsdd);
   2.311    }
   2.312 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));  
   2.313 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.314  
   2.315    return SP_RETURN_FOUND;
   2.316  }
   2.317  
   2.318  static BOOLEAN
   2.319 -XenScsi_HwPassiveInitialization(PVOID DeviceExtension)
   2.320 -{
   2.321 -  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   2.322 -  
   2.323 -  FUNCTION_ENTER();
   2.324 -  StorPortInitializeDpc(DeviceExtension, &xsdd->dpc, XenScsi_HwStorDpc);
   2.325 -  FUNCTION_EXIT();
   2.326 -  return TRUE;
   2.327 -}
   2.328 -
   2.329 -
   2.330 -static BOOLEAN
   2.331 -XenScsi_HwStorInitialize(PVOID DeviceExtension)
   2.332 +XenScsi_HwScsiInitialize(PVOID DeviceExtension)
   2.333  {
   2.334  //  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   2.335 -  BOOLEAN retval;
   2.336 +  UNREFERENCED_PARAMETER(DeviceExtension);
   2.337  
   2.338    FUNCTION_ENTER();
   2.339    
   2.340 -  if ((retval = StorPortEnablePassiveInitialization(DeviceExtension, XenScsi_HwPassiveInitialization)) == TRUE)
   2.341 -    KdPrint((__DRIVER_NAME "     StorPortEnablePassiveInitialization allowed\n"));
   2.342 -  else
   2.343 -  {
   2.344 -    // this is fatal...
   2.345 -    KdPrint((__DRIVER_NAME "     StorPortEnablePassiveInitialization not allowed\n"));
   2.346 -  }
   2.347 -
   2.348    FUNCTION_EXIT();
   2.349  
   2.350 -  return retval;
   2.351 +  return TRUE;
   2.352  }
   2.353  
   2.354  static VOID
   2.355 @@ -552,13 +531,13 @@ XenScsi_PutSrbOnRing(PXENSCSI_DEVICE_DAT
   2.356  {
   2.357    PHYSICAL_ADDRESS physical_address;
   2.358    ULONG remaining;
   2.359 -  ULONG i;
   2.360 +  PUCHAR ptr;
   2.361 +  //ULONG i;
   2.362    PFN_NUMBER pfn;
   2.363    vscsiif_shadow_t *shadow;
   2.364 -  PSTOR_SCATTER_GATHER_LIST sg_list;
   2.365    int notify;
   2.366  
   2.367 -  FUNCTION_ENTER();
   2.368 +  //FUNCTION_ENTER();
   2.369  
   2.370    shadow = get_shadow_from_freelist(xsdd);
   2.371    ASSERT(shadow);
   2.372 @@ -592,30 +571,30 @@ XenScsi_PutSrbOnRing(PXENSCSI_DEVICE_DAT
   2.373      shadow->req.sc_data_direction = DMA_NONE;
   2.374    }
   2.375  
   2.376 +/*  
   2.377 +  for (i = 0; i < Srb->CdbLength; i++)
   2.378 +  {
   2.379 +    KdPrint((__DRIVER_NAME "     Cdb[%02x] = %02x\n", i, (ULONG)Srb->Cdb[i]));
   2.380 +  }
   2.381 +*/
   2.382 +
   2.383    remaining = Srb->DataTransferLength;
   2.384    shadow->req.seg[0].offset = 0;
   2.385    shadow->req.seg[0].length = 0;
   2.386    shadow->req.nr_segments = 0;
   2.387  
   2.388 -  sg_list = StorPortGetScatterGatherList(xsdd, Srb);
   2.389 -  for (i = 0; i < sg_list->NumberOfElements; i++)
   2.390 +  for (ptr = Srb->DataBuffer, shadow->req.nr_segments = 0; remaining != 0; shadow->req.nr_segments++)
   2.391    {
   2.392 -    physical_address = sg_list->List[i].PhysicalAddress;
   2.393 -    //KdPrint((__DRIVER_NAME "     Physical address = 0x%08x%08x\n", physical_address.HighPart, physical_address.LowPart));
   2.394 -    remaining = sg_list->List[i].Length;
   2.395 -    while(remaining > 0)
   2.396 -    {
   2.397 -      pfn = (ULONG)(physical_address.QuadPart >> PAGE_SHIFT);
   2.398 -      shadow->req.seg[shadow->req.nr_segments].gref = get_grant_from_freelist(xsdd);
   2.399 -      ASSERT(shadow->req.seg[shadow->req.nr_segments].gref);
   2.400 -      xsdd->vectors.GntTbl_GrantAccess(xsdd->vectors.context, 0, (ULONG)pfn, 0, shadow->req.seg[shadow->req.nr_segments].gref);
   2.401 -      shadow->req.seg[shadow->req.nr_segments].offset = (USHORT)(physical_address.LowPart & (PAGE_SIZE - 1));
   2.402 -      shadow->req.seg[shadow->req.nr_segments].length = (USHORT)min((ULONG)(PAGE_SIZE - shadow->req.seg[shadow->req.nr_segments].offset), remaining);
   2.403 -      remaining -= shadow->req.seg[shadow->req.nr_segments].length;
   2.404 -      physical_address.QuadPart += shadow->req.seg[shadow->req.nr_segments].length;
   2.405 -      //KdPrint((__DRIVER_NAME "     Page = %d, Pfn = 0x%08x, Offset = 0x%03x, Length = %d, Remaining = %d\n", shadow->req.nr_segments, pfn, shadow->req.seg[shadow->req.nr_segments].offset, shadow->req.seg[shadow->req.nr_segments].length, remaining));
   2.406 -      shadow->req.nr_segments++;
   2.407 -    }
   2.408 +    physical_address = MmGetPhysicalAddress(ptr);
   2.409 +    pfn = (ULONG)(physical_address.QuadPart >> PAGE_SHIFT);
   2.410 +    shadow->req.seg[shadow->req.nr_segments].gref = get_grant_from_freelist(xsdd);
   2.411 +    ASSERT(shadow->req.seg[shadow->req.nr_segments].gref);
   2.412 +    xsdd->vectors.GntTbl_GrantAccess(xsdd->vectors.context, 0, (ULONG)pfn, 0, shadow->req.seg[shadow->req.nr_segments].gref);
   2.413 +    shadow->req.seg[shadow->req.nr_segments].offset = (USHORT)(physical_address.LowPart & (PAGE_SIZE - 1));
   2.414 +    shadow->req.seg[shadow->req.nr_segments].length = (USHORT)min(PAGE_SIZE - (ULONG)shadow->req.seg[shadow->req.nr_segments].offset, remaining);
   2.415 +    remaining -= (ULONG)shadow->req.seg[shadow->req.nr_segments].length;
   2.416 +    ptr += shadow->req.seg[shadow->req.nr_segments].length;
   2.417 +    //KdPrint((__DRIVER_NAME "     Page = %d, Offset = %d, Length = %d, Remaining = %d\n", shadow->req.nr_segments, shadow->req.seg[shadow->req.nr_segments].offset, shadow->req.seg[shadow->req.nr_segments].length, remaining));
   2.418    }
   2.419    *RING_GET_REQUEST(&xsdd->ring, xsdd->ring.req_prod_pvt) = shadow->req;
   2.420    xsdd->ring.req_prod_pvt++;
   2.421 @@ -623,36 +602,29 @@ XenScsi_PutSrbOnRing(PXENSCSI_DEVICE_DAT
   2.422    if (notify)
   2.423      xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->event_channel);
   2.424  
   2.425 -  FUNCTION_EXIT();
   2.426 +  //FUNCTION_EXIT();
   2.427  }
   2.428  
   2.429  static BOOLEAN
   2.430 -XenScsi_HwStorBuildIo(PVOID DeviceExtension, PSCSI_REQUEST_BLOCK Srb)
   2.431 -{
   2.432 -//  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   2.433 -  UNREFERENCED_PARAMETER(DeviceExtension);
   2.434 -  UNREFERENCED_PARAMETER(Srb);
   2.435 -
   2.436 -  return TRUE;
   2.437 -}
   2.438 -
   2.439 -/* Called with StartIoLock held */
   2.440 -static BOOLEAN
   2.441 -XenScsi_HwStorStartIo(PVOID DeviceExtension, PSCSI_REQUEST_BLOCK Srb)
   2.442 +XenScsi_HwScsiStartIo(PVOID DeviceExtension, PSCSI_REQUEST_BLOCK Srb)
   2.443  {
   2.444    PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   2.445    scsi_dev_t *dev;
   2.446  
   2.447 -  // FUNCTION_ENTER();
   2.448 -  if (xsdd->state != SCSI_STATE_ENUM_COMPLETE)
   2.449 +  //FUNCTION_ENTER();
   2.450 +  
   2.451 +  if (xsdd->pause_ack != xsdd->pause_req)
   2.452    {
   2.453 -    if (!xsdd->paused)
   2.454 -    {
   2.455 -      xsdd->paused = TRUE;
   2.456 -      StorPortPause(DeviceExtension, XENSCSI_MAX_ENUM_TIME);
   2.457 -    }
   2.458 -    Srb->SrbStatus = SRB_STATUS_PENDING;
   2.459 -    StorPortNotification(RequestComplete, DeviceExtension, Srb);
   2.460 +    xsdd->pause_ack = xsdd->pause_req;
   2.461 +  }
   2.462 +
   2.463 +  if (xsdd->pause_ack)
   2.464 +  {
   2.465 +    FUNCTION_ENTER();
   2.466 +    KdPrint((__DRIVER_NAME "     Busy\n"));
   2.467 +    Srb->SrbStatus = SRB_STATUS_BUSY;
   2.468 +    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   2.469 +    FUNCTION_EXIT();
   2.470      return TRUE;
   2.471    }
   2.472  
   2.473 @@ -666,8 +638,10 @@ XenScsi_HwStorStartIo(PVOID DeviceExtens
   2.474    if (dev == (scsi_dev_t *)&xsdd->dev_list_head)
   2.475    {
   2.476      Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
   2.477 -    StorPortNotification(RequestComplete, DeviceExtension, Srb);
   2.478 +    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   2.479      //KdPrint((__DRIVER_NAME "     Out of bounds\n"));
   2.480 +    ScsiPortNotification(NextRequest, DeviceExtension);
   2.481 +    //FUNCTION_EXIT();
   2.482      return TRUE;
   2.483    }
   2.484  
   2.485 @@ -680,17 +654,20 @@ XenScsi_HwStorStartIo(PVOID DeviceExtens
   2.486    case SRB_FUNCTION_IO_CONTROL:
   2.487      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_IO_CONTROL\n"));
   2.488      Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   2.489 -    StorPortNotification(RequestComplete, DeviceExtension, Srb);
   2.490 +    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   2.491 +    ScsiPortNotification(NextRequest, DeviceExtension);
   2.492      break;
   2.493    case SRB_FUNCTION_FLUSH:
   2.494      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_FLUSH\n"));
   2.495      Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   2.496 -    StorPortNotification(RequestComplete, DeviceExtension, Srb);
   2.497 +    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   2.498 +    ScsiPortNotification(NextRequest, DeviceExtension);
   2.499      break;
   2.500    default:
   2.501      KdPrint((__DRIVER_NAME "     Unhandled Srb->Function = %08X\n", Srb->Function));
   2.502      Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   2.503 -    StorPortNotification(RequestComplete, DeviceExtension, Srb);
   2.504 +    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   2.505 +    ScsiPortNotification(NextRequest, DeviceExtension);
   2.506      break;
   2.507    }
   2.508  
   2.509 @@ -699,7 +676,7 @@ XenScsi_HwStorStartIo(PVOID DeviceExtens
   2.510  }
   2.511  
   2.512  static BOOLEAN
   2.513 -XenScsi_HwStorResetBus(PVOID DeviceExtension, ULONG PathId)
   2.514 +XenScsi_HwScsiResetBus(PVOID DeviceExtension, ULONG PathId)
   2.515  {
   2.516    UNREFERENCED_PARAMETER(DeviceExtension);
   2.517    UNREFERENCED_PARAMETER(PathId);
   2.518 @@ -707,13 +684,14 @@ XenScsi_HwStorResetBus(PVOID DeviceExten
   2.519  
   2.520    FUNCTION_ENTER();
   2.521    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   2.522 +  ScsiPortNotification(NextRequest, DeviceExtension);
   2.523    FUNCTION_EXIT();
   2.524  
   2.525    return TRUE;
   2.526  }
   2.527  
   2.528  static SCSI_ADAPTER_CONTROL_STATUS
   2.529 -XenScsi_HwStorAdapterControl(PVOID DeviceExtension, SCSI_ADAPTER_CONTROL_TYPE ControlType, PVOID Parameters)
   2.530 +XenScsi_HwScsiAdapterControl(PVOID DeviceExtension, SCSI_ADAPTER_CONTROL_TYPE ControlType, PVOID Parameters)
   2.531  {
   2.532    SCSI_ADAPTER_CONTROL_STATUS Status = ScsiAdapterControlSuccess;
   2.533    PSCSI_SUPPORTED_CONTROL_TYPE_LIST SupportedControlTypeList;
   2.534 @@ -779,25 +757,24 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
   2.535    HwInitializationData.SpecificLuExtensionSize = 0;
   2.536    HwInitializationData.SrbExtensionSize = 0;
   2.537    HwInitializationData.NumberOfAccessRanges = 1;
   2.538 -  HwInitializationData.MapBuffers = STOR_MAP_NO_BUFFERS;
   2.539 -  HwInitializationData.NeedPhysicalAddresses = TRUE; // must be TRUE
   2.540 +  HwInitializationData.MapBuffers = FALSE;
   2.541 +  HwInitializationData.NeedPhysicalAddresses = TRUE;
   2.542    HwInitializationData.TaggedQueuing = TRUE;
   2.543    HwInitializationData.AutoRequestSense = TRUE;
   2.544    HwInitializationData.MultipleRequestPerLu = TRUE;
   2.545  
   2.546 -  HwInitializationData.HwInitialize = XenScsi_HwStorInitialize;
   2.547 -  HwInitializationData.HwBuildIo = XenScsi_HwStorBuildIo;
   2.548 -  HwInitializationData.HwStartIo = XenScsi_HwStorStartIo;
   2.549 -  HwInitializationData.HwInterrupt = XenScsi_HwStorInterrupt;
   2.550 -  HwInitializationData.HwFindAdapter = XenScsi_HwStorFindAdapter;
   2.551 -  HwInitializationData.HwResetBus = XenScsi_HwStorResetBus;
   2.552 -  HwInitializationData.HwAdapterControl = XenScsi_HwStorAdapterControl;
   2.553 +  HwInitializationData.HwInitialize = XenScsi_HwScsiInitialize;
   2.554 +  HwInitializationData.HwStartIo = XenScsi_HwScsiStartIo;
   2.555 +  HwInitializationData.HwInterrupt = XenScsi_HwScsiInterrupt;
   2.556 +  HwInitializationData.HwFindAdapter = XenScsi_HwScsiFindAdapter;
   2.557 +  HwInitializationData.HwResetBus = XenScsi_HwScsiResetBus;
   2.558 +  HwInitializationData.HwAdapterControl = XenScsi_HwScsiAdapterControl;
   2.559  
   2.560 -  Status = StorPortInitialize(DriverObject, RegistryPath, &HwInitializationData, NULL);
   2.561 +  Status = ScsiPortInitialize(DriverObject, RegistryPath, &HwInitializationData, NULL);
   2.562    
   2.563    if(!NT_SUCCESS(Status))
   2.564    {
   2.565 -    KdPrint((__DRIVER_NAME " StorPortInitialize failed with status 0x%08x\n", Status));
   2.566 +    KdPrint((__DRIVER_NAME " ScsiPortInitialize failed with status 0x%08x\n", Status));
   2.567    }
   2.568  
   2.569    FUNCTION_EXIT();
     3.1 --- a/xenscsi/xenscsi.h	Sat Dec 06 16:21:03 2008 +1100
     3.2 +++ b/xenscsi/xenscsi.h	Sat Dec 06 16:22:14 2008 +1100
     3.3 @@ -24,7 +24,8 @@
     3.4  #include <io/vscsiif.h>
     3.5  
     3.6  //#include <io/blkif.h>
     3.7 -#include <storport.h>
     3.8 +//#include <storport.h>
     3.9 +#include <scsi.h>
    3.10  //#include <ntddscsi.h>
    3.11  //#include <ntdddisk.h>
    3.12  #include <stdlib.h>
    3.13 @@ -85,12 +86,10 @@ struct
    3.14    
    3.15    LIST_ENTRY dev_list_head;
    3.16    
    3.17 -  STOR_DPC dpc;
    3.18 +  //STOR_DPC dpc;
    3.19    
    3.20 -  /* protected by StartIoLock */
    3.21 -  BOOLEAN paused;  
    3.22 -  ULONG state;
    3.23 -
    3.24 +  BOOLEAN pause_req;
    3.25 +  BOOLEAN pause_ack;
    3.26  } typedef XENSCSI_DEVICE_DATA, *PXENSCSI_DEVICE_DATA;
    3.27  
    3.28  enum dma_data_direction {
     4.1 --- a/xenscsi/xenscsi.inx	Sat Dec 06 16:21:03 2008 +1100
     4.2 +++ b/xenscsi/xenscsi.inx	Sat Dec 06 16:22:14 2008 +1100
     4.3 @@ -73,7 +73,8 @@ ServiceBinary  = %12%\xenconfig.sys
     4.4  AddReg = XenConfig_Service_AddReg
     4.5  
     4.6  [XenConfig_Service_AddReg]
     4.7 -HKR,"Parameters\PnpInterface", "0", 0x00010001, 0x00000001
     4.8 +HKR,"Parameters\PnpInterface", "0", %FLG_ADDREG_TYPE_DWORD%, 1
     4.9 +HKR,"Parameters", "BusType", %FLG_ADDREG_TYPE_DWORD%, 1
    4.10  
    4.11  [SourceDisksFiles]
    4.12  xenscsi.sys=1