win-pvdrivers

changeset 466:88cf95a1b34a

Started configuration updates - this may not even compile
author James Harper <james.harper@bendigoit.com.au>
date Thu Nov 27 09:29:25 2008 +1100 (2008-11-27)
parents 82dbbaac8d17
children 6800498baafd
files xenscsi/scsiport.c xenscsi/sources xenscsi/xenscsi.c xenscsi/xenscsi.h xenscsi/xenscsi.inx
line diff
     1.1 --- a/xenscsi/scsiport.c	Thu Nov 27 09:28:57 2008 +1100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,543 +0,0 @@
     1.4 -/*
     1.5 -PV Drivers for Windows Xen HVM Domains
     1.6 -Copyright (C) 2007 James Harper
     1.7 -
     1.8 -This program is free software; you can redistribute it and/or
     1.9 -modify it under the terms of the GNU General Public License
    1.10 -as published by the Free Software Foundation; either version 2
    1.11 -of the License, or (at your option) any later version.
    1.12 -
    1.13 -This program is distributed in the hope that it will be useful,
    1.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.16 -GNU General Public License for more details.
    1.17 -
    1.18 -You should have received a copy of the GNU General Public License
    1.19 -along with this program; if not, write to the Free Software
    1.20 -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    1.21 -*/
    1.22 -
    1.23 -#include "xenscsi.h"
    1.24 -#include <scsi.h>
    1.25 -#include <ntddscsi.h>
    1.26 -#include <ntdddisk.h>
    1.27 -#include <stdlib.h>
    1.28 -#include <xen_public.h>
    1.29 -#include <io/xenbus.h>
    1.30 -#include <io/protocols.h>
    1.31 -
    1.32 -#pragma warning(disable: 4127)
    1.33 -
    1.34 -static vscsiif_shadow_t *
    1.35 -get_shadow_from_freelist(PXENSCSI_DEVICE_DATA xsdd)
    1.36 -{
    1.37 -  if (xsdd->shadow_free == 0)
    1.38 -  {
    1.39 -    KdPrint((__DRIVER_NAME "     No more shadow entries\n"));    
    1.40 -    return NULL;
    1.41 -  }
    1.42 -  xsdd->shadow_free--;
    1.43 -  return &xsdd->shadows[xsdd->shadow_free_list[xsdd->shadow_free]];
    1.44 -}
    1.45 -
    1.46 -static VOID
    1.47 -put_shadow_on_freelist(PXENSCSI_DEVICE_DATA xsdd, vscsiif_shadow_t *shadow)
    1.48 -{
    1.49 -  xsdd->shadow_free_list[xsdd->shadow_free] = (USHORT)shadow->req.rqid;
    1.50 -  shadow->Srb = NULL;
    1.51 -  xsdd->shadow_free++;
    1.52 -}
    1.53 -
    1.54 -static grant_ref_t
    1.55 -get_grant_from_freelist(PXENSCSI_DEVICE_DATA xsdd)
    1.56 -{
    1.57 -  if (xsdd->grant_free == 0)
    1.58 -  {
    1.59 -    KdPrint((__DRIVER_NAME "     No more grant refs\n"));    
    1.60 -    return (grant_ref_t)0x0FFFFFFF;
    1.61 -  }
    1.62 -  xsdd->grant_free--;
    1.63 -  return xsdd->grant_free_list[xsdd->grant_free];
    1.64 -}
    1.65 -
    1.66 -static VOID
    1.67 -put_grant_on_freelist(PXENSCSI_DEVICE_DATA xsdd, grant_ref_t grant)
    1.68 -{
    1.69 -  xsdd->grant_free_list[xsdd->grant_free] = grant;
    1.70 -  xsdd->grant_free++;
    1.71 -}
    1.72 -
    1.73 -static BOOLEAN
    1.74 -XenScsi_HwScsiInterrupt(PVOID DeviceExtension)
    1.75 -{
    1.76 -  PXENSCSI_DEVICE_DATA xsdd = (PXENSCSI_DEVICE_DATA)DeviceExtension;
    1.77 -  PSCSI_REQUEST_BLOCK Srb;
    1.78 -  RING_IDX i, rp;
    1.79 -  int j;
    1.80 -  vscsiif_response_t *rep;
    1.81 -  int more_to_do = TRUE;
    1.82 -  vscsiif_shadow_t *shadow;
    1.83 -  ULONG remaining;
    1.84 -
    1.85 -  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    1.86 -
    1.87 -  while (more_to_do)
    1.88 -  {
    1.89 -    rp = xsdd->ring.sring->rsp_prod;
    1.90 -    KeMemoryBarrier();
    1.91 -    for (i = xsdd->ring.rsp_cons; i != rp; i++)
    1.92 -    {
    1.93 -      rep = RING_GET_RESPONSE(&xsdd->ring, i);
    1.94 -      shadow = &xsdd->shadows[rep->rqid];
    1.95 -      KdPrint((__DRIVER_NAME "     Operation complete - result = 0x%08x\n", rep->rslt));
    1.96 -      Srb = shadow->Srb;
    1.97 -      Srb->ScsiStatus = (UCHAR)rep->rslt;
    1.98 -      if (rep->sense_len > 0 && Srb->SenseInfoBuffer != NULL)
    1.99 -      {
   1.100 -        memcpy(Srb->SenseInfoBuffer, rep->sense_buffer, min(Srb->SenseInfoBufferLength, rep->sense_len));
   1.101 -      }
   1.102 -      if (!rep->rslt)
   1.103 -      {
   1.104 -        Srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.105 -      }
   1.106 -      else
   1.107 -      {
   1.108 -        KdPrint((__DRIVER_NAME "     Xen Operation returned error (result = 0x%08x)\n", rep->rslt));
   1.109 -        Srb->SrbStatus = SRB_STATUS_ERROR;
   1.110 -        if (rep->sense_len > 0 && !(Srb->SrbFlags & SRB_FLAGS_DISABLE_AUTOSENSE) && Srb->SenseInfoBuffer != NULL)
   1.111 -        {
   1.112 -          Srb->SrbStatus |= SRB_STATUS_AUTOSENSE_VALID;
   1.113 -        }
   1.114 -      }
   1.115 -      remaining = Srb->DataTransferLength;
   1.116 -      for (j = 0; remaining != 0; j++)
   1.117 -      {
   1.118 -        xsdd->vectors.GntTbl_EndAccess(xsdd->vectors.context, shadow->req.seg[j].gref, TRUE);
   1.119 -        put_grant_on_freelist(xsdd, shadow->req.seg[j].gref);
   1.120 -        shadow->req.seg[j].gref = 0;
   1.121 -        remaining -= shadow->req.seg[j].length;
   1.122 -      }
   1.123 -      put_shadow_on_freelist(xsdd, shadow);
   1.124 -      ScsiPortNotification(RequestComplete, xsdd, Srb);
   1.125 -      ScsiPortNotification(NextRequest, xsdd);
   1.126 -    }
   1.127 -
   1.128 -    xsdd->ring.rsp_cons = i;
   1.129 -    if (i != xsdd->ring.req_prod_pvt)
   1.130 -    {
   1.131 -      RING_FINAL_CHECK_FOR_RESPONSES(&xsdd->ring, more_to_do);
   1.132 -    }
   1.133 -    else
   1.134 -    {
   1.135 -      xsdd->ring.sring->rsp_event = i + 1;
   1.136 -      more_to_do = FALSE;
   1.137 -    }
   1.138 -  }
   1.139 -
   1.140 -  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   1.141 -  
   1.142 -  return FALSE; /* we just don't know... */
   1.143 -}
   1.144 -
   1.145 -static VOID
   1.146 -XenScsi_ParseBackendDevice(PXENSCSI_DEVICE_DATA xsdd, PCHAR value)
   1.147 -{
   1.148 -  int i = 0;
   1.149 -  int j = 0;
   1.150 -  BOOLEAN scanning = TRUE;
   1.151 -
   1.152 -  while (scanning)
   1.153 -  {
   1.154 -    if (value[i] == 0)
   1.155 -      scanning = FALSE;
   1.156 -    if (value[i] == ':' || value[i] == 0)
   1.157 -    {
   1.158 -       value[i] = 0;
   1.159 -       xsdd->host = xsdd->channel;
   1.160 -       xsdd->channel = xsdd->id;
   1.161 -       xsdd->id = xsdd->lun;
   1.162 -       xsdd->lun = atoi(&value[j]);
   1.163 -       j = i + 1;
   1.164 -    }
   1.165 -    i++;
   1.166 -  }
   1.167 -  KdPrint((__DRIVER_NAME "     host = %d, channel = %d, id = %d, lun = %d\n",
   1.168 -    xsdd->host, xsdd->channel, xsdd->id, xsdd->lun));  
   1.169 -}
   1.170 -
   1.171 -static ULONG
   1.172 -XenScsi_HwScsiFindAdapter(PVOID DeviceExtension, PVOID HwContext, PVOID BusInformation, PCHAR ArgumentString, PPORT_CONFIGURATION_INFORMATION ConfigInfo, PBOOLEAN Again)
   1.173 -{
   1.174 -  ULONG i;
   1.175 -//  PACCESS_RANGE AccessRange;
   1.176 -  PXENSCSI_DEVICE_DATA xsdd = (PXENSCSI_DEVICE_DATA)DeviceExtension;
   1.177 -//  ULONG status;
   1.178 -//  PXENPCI_XEN_DEVICE_DATA XenDeviceData;
   1.179 -  PACCESS_RANGE access_range;
   1.180 -  PUCHAR ptr;
   1.181 -  USHORT type;
   1.182 -  PCHAR setting, value;
   1.183 -  vscsiif_sring_t *sring;
   1.184 -
   1.185 -  UNREFERENCED_PARAMETER(HwContext);
   1.186 -  UNREFERENCED_PARAMETER(BusInformation);
   1.187 -  UNREFERENCED_PARAMETER(ArgumentString);
   1.188 -
   1.189 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));  
   1.190 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   1.191 -
   1.192 -  *Again = FALSE;
   1.193 -
   1.194 -  KdPrint((__DRIVER_NAME "     BusInterruptLevel = %d\n", ConfigInfo->BusInterruptLevel));
   1.195 -  KdPrint((__DRIVER_NAME "     BusInterruptVector = %03x\n", ConfigInfo->BusInterruptVector));
   1.196 -
   1.197 -  if (ConfigInfo->NumberOfAccessRanges != 1)
   1.198 -  {
   1.199 -    KdPrint((__DRIVER_NAME "     NumberOfAccessRanges = %d\n", ConfigInfo->NumberOfAccessRanges));    
   1.200 -    return SP_RETURN_BAD_CONFIG;
   1.201 -  }
   1.202 -
   1.203 -  access_range = &((*(ConfigInfo->AccessRanges))[0]);
   1.204 -
   1.205 -  KdPrint((__DRIVER_NAME "     RangeStart = %08x, RangeLength = %08x\n",
   1.206 -    access_range->RangeStart.LowPart, access_range->RangeLength));
   1.207 -
   1.208 -  ptr = ScsiPortGetDeviceBase(
   1.209 -    DeviceExtension,
   1.210 -    ConfigInfo->AdapterInterfaceType,
   1.211 -    ConfigInfo->SystemIoBusNumber,
   1.212 -    access_range->RangeStart,
   1.213 -    access_range->RangeLength,
   1.214 -    !access_range->RangeInMemory);
   1.215 -  //ptr = MmMapIoSpace(access_range->RangeStart, access_range->RangeLength, MmCached);
   1.216 -  if (ptr == NULL)
   1.217 -  {
   1.218 -    KdPrint((__DRIVER_NAME "     Unable to map range\n"));
   1.219 -    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));  
   1.220 -    return SP_RETURN_BAD_CONFIG;
   1.221 -  }
   1.222 -
   1.223 -  sring = NULL;
   1.224 -  xsdd->event_channel = 0;
   1.225 -  while((type = GET_XEN_INIT_RSP(&ptr, &setting, &value)) != XEN_INIT_TYPE_END)
   1.226 -  {
   1.227 -    switch(type)
   1.228 -    {
   1.229 -    case XEN_INIT_TYPE_RING: /* frontend ring */
   1.230 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, value));
   1.231 -      if (strcmp(setting, "ring-ref") == 0)
   1.232 -      {
   1.233 -        sring = (vscsiif_sring_t *)value;
   1.234 -        FRONT_RING_INIT(&xsdd->ring, sring, PAGE_SIZE);
   1.235 -      }
   1.236 -      break;
   1.237 -    case XEN_INIT_TYPE_EVENT_CHANNEL: /* frontend event channel */
   1.238 -    case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel */
   1.239 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, PtrToUlong(value)));
   1.240 -      if (strcmp(setting, "event-channel") == 0)
   1.241 -      {
   1.242 -        xsdd->event_channel = PtrToUlong(value);
   1.243 -      }
   1.244 -      break;
   1.245 -    case XEN_INIT_TYPE_READ_STRING_BACK:
   1.246 -    case XEN_INIT_TYPE_READ_STRING_FRONT:
   1.247 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value));
   1.248 -      if (strcmp(setting, "b-dev") == 0)
   1.249 -      {
   1.250 -        XenScsi_ParseBackendDevice(xsdd, value);
   1.251 -      }
   1.252 -      break;
   1.253 -    case XEN_INIT_TYPE_VECTORS:
   1.254 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
   1.255 -      if (((PXENPCI_VECTORS)value)->length != sizeof(XENPCI_VECTORS) ||
   1.256 -        ((PXENPCI_VECTORS)value)->magic != XEN_DATA_MAGIC)
   1.257 -      {
   1.258 -        KdPrint((__DRIVER_NAME "     vectors mismatch (magic = %08x, length = %d)\n",
   1.259 -          ((PXENPCI_VECTORS)value)->magic, ((PXENPCI_VECTORS)value)->length));
   1.260 -        KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   1.261 -        return SP_RETURN_BAD_CONFIG;
   1.262 -      }
   1.263 -      else
   1.264 -        memcpy(&xsdd->vectors, value, sizeof(XENPCI_VECTORS));
   1.265 -      break;
   1.266 -    case XEN_INIT_TYPE_GRANT_ENTRIES:
   1.267 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_GRANT_ENTRIES - %d\n", PtrToUlong(setting)));
   1.268 -      xsdd->grant_entries = (USHORT)PtrToUlong(setting);
   1.269 -      memcpy(&xsdd->grant_free_list, value, sizeof(grant_ref_t) * xsdd->grant_entries);
   1.270 -      xsdd->grant_free = xsdd->grant_entries;
   1.271 -      break;
   1.272 -    default:
   1.273 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
   1.274 -      break;
   1.275 -    }
   1.276 -  }
   1.277 -#if 0
   1.278 -  if (xsdd->device_type == XENSCSI_DEVICETYPE_UNKNOWN
   1.279 -    || sring == NULL
   1.280 -    || xsdd->event_channel == 0)
   1.281 -  {
   1.282 -    KdPrint((__DRIVER_NAME "     Missing settings\n"));
   1.283 -    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   1.284 -    return SP_RETURN_BAD_CONFIG;
   1.285 -  }
   1.286 -#endif
   1.287 -  ConfigInfo->MaximumTransferLength = VSCSIIF_SG_TABLESIZE * PAGE_SIZE;
   1.288 -  ConfigInfo->NumberOfPhysicalBreaks = VSCSIIF_SG_TABLESIZE - 1;
   1.289 -  ConfigInfo->ScatterGather = TRUE;
   1.290 -  ConfigInfo->AlignmentMask = 0;
   1.291 -  ConfigInfo->NumberOfBuses = 1;
   1.292 -  ConfigInfo->InitiatorBusId[0] = 1;
   1.293 -  ConfigInfo->MaximumNumberOfLogicalUnits = 1;
   1.294 -  ConfigInfo->MaximumNumberOfTargets = 2;
   1.295 -  ConfigInfo->BufferAccessScsiPortControlled = TRUE;
   1.296 -  if (ConfigInfo->Dma64BitAddresses == SCSI_DMA64_SYSTEM_SUPPORTED)
   1.297 -  {
   1.298 -    ConfigInfo->Master = TRUE;
   1.299 -    ConfigInfo->Dma64BitAddresses = SCSI_DMA64_MINIPORT_SUPPORTED;
   1.300 -    KdPrint((__DRIVER_NAME "     Dma64BitAddresses supported\n"));
   1.301 -  }
   1.302 -  else
   1.303 -  {
   1.304 -    ConfigInfo->Master = FALSE;
   1.305 -    KdPrint((__DRIVER_NAME "     Dma64BitAddresses not supported\n"));
   1.306 -  }
   1.307 -
   1.308 -  xsdd->shadow_free = 0;
   1.309 -  memset(xsdd->shadows, 0, sizeof(vscsiif_shadow_t) * SHADOW_ENTRIES);
   1.310 -  for (i = 0; i < SHADOW_ENTRIES; i++)
   1.311 -  {
   1.312 -    xsdd->shadows[i].req.rqid = (USHORT)i;
   1.313 -    put_shadow_on_freelist(xsdd, &xsdd->shadows[i]);
   1.314 -  }
   1.315 -
   1.316 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));  
   1.317 -
   1.318 -  return SP_RETURN_FOUND;
   1.319 -}
   1.320 -
   1.321 -static BOOLEAN
   1.322 -XenScsi_HwScsiInitialize(PVOID DeviceExtension)
   1.323 -{
   1.324 -  //PXENSCSI_DEVICE_DATA xsdd = (PXENSCSI_DEVICE_DATA)DeviceExtension;
   1.325 -  
   1.326 -  UNREFERENCED_PARAMETER(DeviceExtension);
   1.327 -
   1.328 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   1.329 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   1.330 -
   1.331 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   1.332 -
   1.333 -  return TRUE;
   1.334 -}
   1.335 -
   1.336 -static VOID
   1.337 -XenScsi_PutSrbOnRing(PXENSCSI_DEVICE_DATA xsdd, PSCSI_REQUEST_BLOCK Srb)
   1.338 -{
   1.339 -  PUCHAR ptr;
   1.340 -  PHYSICAL_ADDRESS physical_address;
   1.341 -  PFN_NUMBER pfn;
   1.342 -  //int i;
   1.343 -  vscsiif_shadow_t *shadow;
   1.344 -  int remaining;
   1.345 -
   1.346 -//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   1.347 -
   1.348 -  shadow = get_shadow_from_freelist(xsdd);
   1.349 -  ASSERT(shadow);
   1.350 -  shadow->Srb = Srb;
   1.351 -  shadow->req.cmd = VSCSIIF_CMND_SCSI;
   1.352 -  memset(shadow->req.cmnd, 0, VSCSIIF_MAX_COMMAND_SIZE);
   1.353 -  memcpy(shadow->req.cmnd, Srb->Cdb, Srb->CdbLength);
   1.354 -  shadow->req.cmd_len = Srb->CdbLength;
   1.355 -  shadow->req.id = (USHORT)xsdd->id;
   1.356 -  shadow->req.lun = (USHORT)xsdd->lun;
   1.357 -  shadow->req.channel = (USHORT)xsdd->channel;
   1.358 -  if (Srb->DataTransferLength && (Srb->SrbFlags & SRB_FLAGS_DATA_IN) && (Srb->SrbFlags & SRB_FLAGS_DATA_OUT))
   1.359 -  {
   1.360 -    KdPrint((__DRIVER_NAME "     Cmd = %02x, Length = %d, DMA_BIDIRECTIONAL\n", Srb->Cdb[0], Srb->DataTransferLength));
   1.361 -    shadow->req.sc_data_direction = DMA_BIDIRECTIONAL;
   1.362 -  }
   1.363 -  else if (Srb->DataTransferLength && (Srb->SrbFlags & SRB_FLAGS_DATA_IN))
   1.364 -  {
   1.365 -    KdPrint((__DRIVER_NAME "     Cmd = %02x, Length = %d, DMA_FROM_DEVICE\n", Srb->Cdb[0], Srb->DataTransferLength));
   1.366 -    shadow->req.sc_data_direction = DMA_FROM_DEVICE;
   1.367 -  }
   1.368 -  else if (Srb->DataTransferLength && (Srb->SrbFlags & SRB_FLAGS_DATA_OUT))
   1.369 -  {
   1.370 -    KdPrint((__DRIVER_NAME "     Cmd = %02x, Length = %d, DMA_TO_DEVICE\n", Srb->Cdb[0], Srb->DataTransferLength));
   1.371 -    shadow->req.sc_data_direction = DMA_TO_DEVICE;
   1.372 -  }
   1.373 -  else
   1.374 -  {
   1.375 -    KdPrint((__DRIVER_NAME "     Cmd = %02x, Length = %d, DMA_NONE\n", Srb->Cdb[0], Srb->DataTransferLength));
   1.376 -    shadow->req.sc_data_direction = DMA_NONE;
   1.377 -  }
   1.378 -  //shadow->req.use_sg = (UINT8)((Srb->DataTransferLength + PAGE_SIZE - 1) >> PAGE_SHIFT);
   1.379 -  shadow->req.request_bufflen = Srb->DataTransferLength;
   1.380 -
   1.381 -  remaining = Srb->DataTransferLength;
   1.382 -  shadow->req.seg[0].offset = 0;
   1.383 -  shadow->req.seg[0].length = 0;
   1.384 -
   1.385 -  ptr = Srb->DataBuffer;
   1.386 -
   1.387 -  for (shadow->req.use_sg = 0; remaining != 0; shadow->req.use_sg++)
   1.388 -  {
   1.389 -    physical_address = MmGetPhysicalAddress(ptr);
   1.390 -    pfn = (ULONG)(physical_address.QuadPart >> PAGE_SHIFT);
   1.391 -    shadow->req.seg[shadow->req.use_sg].gref = get_grant_from_freelist(xsdd);
   1.392 -    ASSERT(shadow->req.seg[shadow->req.use_sg].gref);
   1.393 -    xsdd->vectors.GntTbl_GrantAccess(xsdd->vectors.context, 0, (ULONG)pfn, 0, shadow->req.seg[shadow->req.use_sg].gref);
   1.394 -    shadow->req.seg[shadow->req.use_sg].offset = (USHORT)(physical_address.LowPart & (PAGE_SIZE - 1));
   1.395 -    shadow->req.seg[shadow->req.use_sg].length = (USHORT)min(PAGE_SIZE - shadow->req.seg[shadow->req.use_sg].offset, remaining);
   1.396 -    remaining -= shadow->req.seg[shadow->req.use_sg].length;
   1.397 -    ptr += shadow->req.seg[shadow->req.use_sg].length;
   1.398 -    //KdPrint((__DRIVER_NAME "     Page = %d, Offset = %d, Length = %d, Remaining = %d\n", shadow->req.use_sg, shadow->req.seg[shadow->req.use_sg].offset, shadow->req.seg[shadow->req.use_sg].length, remaining));
   1.399 -  }
   1.400 -  *RING_GET_REQUEST(&xsdd->ring, xsdd->ring.req_prod_pvt) = shadow->req;
   1.401 -  xsdd->ring.req_prod_pvt++;
   1.402 -
   1.403 -//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   1.404 -}
   1.405 -
   1.406 -static BOOLEAN
   1.407 -XenScsi_HwScsiStartIo(PVOID DeviceExtension, PSCSI_REQUEST_BLOCK Srb)
   1.408 -{
   1.409 -  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   1.410 -  int notify;
   1.411 -
   1.412 -  //KdPrint((__DRIVER_NAME " --> HwScsiStartIo PathId = %d, TargetId = %d, Lun = %d\n", Srb->PathId, Srb->TargetId, Srb->Lun));
   1.413 -
   1.414 -//  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   1.415 -
   1.416 -  if (Srb->PathId != 0 || Srb->TargetId != 0)
   1.417 -  {
   1.418 -    Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
   1.419 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   1.420 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
   1.421 -    KdPrint((__DRIVER_NAME " --- HwScsiStartIo (Out of bounds)\n"));
   1.422 -    return TRUE;
   1.423 -  }
   1.424 -
   1.425 -  switch (Srb->Function)
   1.426 -  {
   1.427 -  case SRB_FUNCTION_EXECUTE_SCSI:
   1.428 -    XenScsi_PutSrbOnRing(xsdd, Srb);
   1.429 -    RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xsdd->ring, notify);
   1.430 -    if (notify)
   1.431 -      xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->event_channel);
   1.432 -    if (!xsdd->shadow_free)
   1.433 -      ScsiPortNotification(NextRequest, DeviceExtension);
   1.434 -    break;
   1.435 -  case SRB_FUNCTION_IO_CONTROL:
   1.436 -    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_IO_CONTROL\n"));
   1.437 -    Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   1.438 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   1.439 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
   1.440 -    break;
   1.441 -  case SRB_FUNCTION_FLUSH:
   1.442 -    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_FLUSH\n"));
   1.443 -    Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   1.444 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   1.445 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
   1.446 -    break;
   1.447 -  default:
   1.448 -    KdPrint((__DRIVER_NAME "     Unhandled Srb->Function = %08X\n", Srb->Function));
   1.449 -    Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   1.450 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   1.451 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
   1.452 -    break;
   1.453 -  }
   1.454 -
   1.455 -  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   1.456 -  return TRUE;
   1.457 -}
   1.458 -
   1.459 -static BOOLEAN
   1.460 -XenScsi_HwScsiResetBus(PVOID DeviceExtension, ULONG PathId)
   1.461 -{
   1.462 -  UNREFERENCED_PARAMETER(DeviceExtension);
   1.463 -  UNREFERENCED_PARAMETER(PathId);
   1.464 -
   1.465 -
   1.466 -  KdPrint((__DRIVER_NAME " --> HwScsiResetBus\n"));
   1.467 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   1.468 -
   1.469 -  KdPrint((__DRIVER_NAME " <-- HwScsiResetBus\n"));
   1.470 -
   1.471 -  return TRUE;
   1.472 -}
   1.473 -
   1.474 -static BOOLEAN
   1.475 -XenScsi_HwScsiAdapterState(PVOID DeviceExtension, PVOID Context, BOOLEAN SaveState)
   1.476 -{
   1.477 -  UNREFERENCED_PARAMETER(DeviceExtension);
   1.478 -  UNREFERENCED_PARAMETER(Context);
   1.479 -  UNREFERENCED_PARAMETER(SaveState);
   1.480 -
   1.481 -  KdPrint((__DRIVER_NAME " --> HwScsiAdapterState\n"));
   1.482 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   1.483 -
   1.484 -  KdPrint((__DRIVER_NAME " <-- HwScsiAdapterState\n"));
   1.485 -
   1.486 -  return TRUE;
   1.487 -}
   1.488 -
   1.489 -static SCSI_ADAPTER_CONTROL_STATUS
   1.490 -XenScsi_HwScsiAdapterControl(PVOID DeviceExtension, SCSI_ADAPTER_CONTROL_TYPE ControlType, PVOID Parameters)
   1.491 -{
   1.492 -  SCSI_ADAPTER_CONTROL_STATUS Status = ScsiAdapterControlSuccess;
   1.493 -  PSCSI_SUPPORTED_CONTROL_TYPE_LIST SupportedControlTypeList;
   1.494 -  //KIRQL OldIrql;
   1.495 -
   1.496 -  UNREFERENCED_PARAMETER(DeviceExtension);
   1.497 -
   1.498 -  KdPrint((__DRIVER_NAME " --> HwScsiAdapterControl\n"));
   1.499 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   1.500 -
   1.501 -  switch (ControlType)
   1.502 -  {
   1.503 -  case ScsiQuerySupportedControlTypes:
   1.504 -    SupportedControlTypeList = (PSCSI_SUPPORTED_CONTROL_TYPE_LIST)Parameters;
   1.505 -    KdPrint((__DRIVER_NAME "     ScsiQuerySupportedControlTypes (Max = %d)\n", SupportedControlTypeList->MaxControlType));
   1.506 -    SupportedControlTypeList->SupportedTypeList[ScsiQuerySupportedControlTypes] = TRUE;
   1.507 -    SupportedControlTypeList->SupportedTypeList[ScsiStopAdapter] = TRUE;
   1.508 -    break;
   1.509 -  case ScsiStopAdapter:
   1.510 -    KdPrint((__DRIVER_NAME "     ScsiStopAdapter\n"));
   1.511 -    break;
   1.512 -  case ScsiRestartAdapter:
   1.513 -    KdPrint((__DRIVER_NAME "     ScsiRestartAdapter\n"));
   1.514 -    break;
   1.515 -  case ScsiSetBootConfig:
   1.516 -    KdPrint((__DRIVER_NAME "     ScsiSetBootConfig\n"));
   1.517 -    break;
   1.518 -  case ScsiSetRunningConfig:
   1.519 -    KdPrint((__DRIVER_NAME "     ScsiSetRunningConfig\n"));
   1.520 -    break;
   1.521 -  default:
   1.522 -    KdPrint((__DRIVER_NAME "     UNKNOWN\n"));
   1.523 -    break;
   1.524 -  }
   1.525 -
   1.526 -  KdPrint((__DRIVER_NAME " <-- HwScsiAdapterControl\n"));
   1.527 -
   1.528 -  return Status;
   1.529 -}
   1.530 -
   1.531 -VOID
   1.532 -XenScsi_FillInitCallbacks(PHW_INITIALIZATION_DATA HwInitializationData)
   1.533 -{
   1.534 -  KdPrint((__DRIVER_NAME " --> "__FUNCTION__ "\n"));
   1.535 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   1.536 -
   1.537 -  HwInitializationData->HwInitialize = XenScsi_HwScsiInitialize;
   1.538 -  HwInitializationData->HwStartIo = XenScsi_HwScsiStartIo;
   1.539 -  HwInitializationData->HwInterrupt = XenScsi_HwScsiInterrupt;
   1.540 -  HwInitializationData->HwFindAdapter = XenScsi_HwScsiFindAdapter;
   1.541 -  HwInitializationData->HwResetBus = XenScsi_HwScsiResetBus;
   1.542 -  HwInitializationData->HwAdapterState = XenScsi_HwScsiAdapterState;
   1.543 -  HwInitializationData->HwAdapterControl = XenScsi_HwScsiAdapterControl;
   1.544 -
   1.545 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   1.546 -}
     2.1 --- a/xenscsi/sources	Thu Nov 27 09:28:57 2008 +1100
     2.2 +++ b/xenscsi/sources	Thu Nov 27 09:29:25 2008 +1100
     2.3 @@ -4,4 +4,4 @@ TARGETTYPE=DRIVER
     2.4  INF_NAME=$(TARGETNAME)
     2.5  TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\scsiport.lib
     2.6  MISCFILES=..\Target\$(DDK_TARGET_OS)\$(INF_NAME).inf
     2.7 -SOURCES=xenscsi.c scsiport.c
     2.8 +SOURCES=xenscsi.c
     3.1 --- a/xenscsi/xenscsi.c	Thu Nov 27 09:28:57 2008 +1100
     3.2 +++ b/xenscsi/xenscsi.c	Thu Nov 27 09:29:25 2008 +1100
     3.3 @@ -27,29 +27,709 @@ Foundation, Inc., 51 Franklin Street, Fi
     3.4  #include <io/xenbus.h>
     3.5  #include <io/protocols.h>
     3.6  
     3.7 -#pragma warning(disable: 4127)
     3.8 -
     3.9  DRIVER_INITIALIZE DriverEntry;
    3.10  
    3.11 -static ULONG
    3.12 -XenScsi_HwScsiFindAdapter(PVOID DeviceExtension, PVOID HwContext, PVOID BusInformation, PCHAR ArgumentString, PPORT_CONFIGURATION_INFORMATION ConfigInfo, PBOOLEAN Again);
    3.13 -static BOOLEAN
    3.14 -XenScsi_HwScsiInitialize(PVOID DeviceExtension);
    3.15 -static BOOLEAN
    3.16 -XenScsi_HwScsiStartIo(PVOID DeviceExtension, PSCSI_REQUEST_BLOCK Srb);
    3.17 -static BOOLEAN
    3.18 -XenScsi_HwScsiInterrupt(PVOID DeviceExtension);
    3.19 -static BOOLEAN
    3.20 -XenScsi_HwScsiResetBus(PVOID DeviceExtension, ULONG PathId);
    3.21 -static BOOLEAN
    3.22 -XenScsi_HwScsiAdapterState(PVOID DeviceExtension, PVOID Context, BOOLEAN SaveState);
    3.23 -static SCSI_ADAPTER_CONTROL_STATUS
    3.24 -XenScsi_HwScsiAdapterControl(PVOID DeviceExtension, SCSI_ADAPTER_CONTROL_TYPE ControlType, PVOID Parameters);
    3.25 -
    3.26  #ifdef ALLOC_PRAGMA
    3.27  #pragma alloc_text (INIT, DriverEntry)
    3.28  #endif
    3.29  
    3.30 +#pragma warning(disable: 4127)
    3.31 +
    3.32 +static BOOLEAN dump_mode = FALSE;
    3.33 +static BOOLEAN global_inactive = FALSE;
    3.34 +
    3.35 +static vscsiif_shadow_t *
    3.36 +get_shadow_from_freelist(PXENSCSI_DEVICE_DATA xsdd)
    3.37 +{
    3.38 +  if (xsdd->shadow_free == 0)
    3.39 +  {
    3.40 +    KdPrint((__DRIVER_NAME "     No more shadow entries\n"));    
    3.41 +    return NULL;
    3.42 +  }
    3.43 +  xsdd->shadow_free--;
    3.44 +  return &xsdd->shadows[xsdd->shadow_free_list[xsdd->shadow_free]];
    3.45 +}
    3.46 +
    3.47 +static VOID
    3.48 +put_shadow_on_freelist(PXENSCSI_DEVICE_DATA xsdd, vscsiif_shadow_t *shadow)
    3.49 +{
    3.50 +  xsdd->shadow_free_list[xsdd->shadow_free] = (USHORT)shadow->req.rqid;
    3.51 +  shadow->Srb = NULL;
    3.52 +  xsdd->shadow_free++;
    3.53 +}
    3.54 +
    3.55 +static grant_ref_t
    3.56 +get_grant_from_freelist(PXENSCSI_DEVICE_DATA xsdd)
    3.57 +{
    3.58 +  if (xsdd->grant_free == 0)
    3.59 +  {
    3.60 +    KdPrint((__DRIVER_NAME "     No more grant refs\n"));    
    3.61 +    return (grant_ref_t)0x0FFFFFFF;
    3.62 +  }
    3.63 +  xsdd->grant_free--;
    3.64 +  return xsdd->grant_free_list[xsdd->grant_free];
    3.65 +}
    3.66 +
    3.67 +static VOID
    3.68 +put_grant_on_freelist(PXENSCSI_DEVICE_DATA xsdd, grant_ref_t grant)
    3.69 +{
    3.70 +  xsdd->grant_free_list[xsdd->grant_free] = grant;
    3.71 +  xsdd->grant_free++;
    3.72 +}
    3.73 +
    3.74 +static VOID
    3.75 +XenScsi_HwScsiInterrupt_Scsi(PVOID DeviceExtension)
    3.76 +{
    3.77 +  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
    3.78 +  PSCSI_REQUEST_BLOCK Srb;
    3.79 +  RING_IDX i, rp;
    3.80 +  int j;
    3.81 +  vscsiif_response_t *rep;
    3.82 +  int more_to_do = TRUE;
    3.83 +  vscsiif_shadow_t *shadow;
    3.84 +  ULONG remaining;
    3.85 +
    3.86 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    3.87 +
    3.88 +  while (more_to_do)
    3.89 +  {
    3.90 +    rp = xsdd->ring.sring->rsp_prod;
    3.91 +    KeMemoryBarrier();
    3.92 +    for (i = xsdd->ring.rsp_cons; i != rp; i++)
    3.93 +    {
    3.94 +      rep = RING_GET_RESPONSE(&xsdd->ring, i);
    3.95 +      shadow = &xsdd->shadows[rep->rqid];
    3.96 +      KdPrint((__DRIVER_NAME "     Operation complete - result = 0x%08x\n", rep->rslt));
    3.97 +      Srb = shadow->Srb;
    3.98 +      Srb->ScsiStatus = (UCHAR)rep->rslt;
    3.99 +      if (rep->sense_len > 0 && Srb->SenseInfoBuffer != NULL)
   3.100 +      {
   3.101 +        memcpy(Srb->SenseInfoBuffer, rep->sense_buffer, min(Srb->SenseInfoBufferLength, rep->sense_len));
   3.102 +      }
   3.103 +      if (!rep->rslt)
   3.104 +      {
   3.105 +        Srb->SrbStatus = SRB_STATUS_SUCCESS;
   3.106 +      }
   3.107 +      else
   3.108 +      {
   3.109 +        KdPrint((__DRIVER_NAME "     Xen Operation returned error (result = 0x%08x)\n", rep->rslt));
   3.110 +        Srb->SrbStatus = SRB_STATUS_ERROR;
   3.111 +        if (rep->sense_len > 0 && !(Srb->SrbFlags & SRB_FLAGS_DISABLE_AUTOSENSE) && Srb->SenseInfoBuffer != NULL)
   3.112 +        {
   3.113 +          Srb->SrbStatus |= SRB_STATUS_AUTOSENSE_VALID;
   3.114 +        }
   3.115 +      }
   3.116 +      remaining = Srb->DataTransferLength;
   3.117 +      for (j = 0; remaining != 0; j++)
   3.118 +      {
   3.119 +        xsdd->vectors.GntTbl_EndAccess(xsdd->vectors.context, shadow->req.seg[j].gref, TRUE);
   3.120 +        put_grant_on_freelist(xsdd, shadow->req.seg[j].gref);
   3.121 +        shadow->req.seg[j].gref = 0;
   3.122 +        remaining -= shadow->req.seg[j].length;
   3.123 +      }
   3.124 +      put_shadow_on_freelist(xsdd, shadow);
   3.125 +      ScsiPortNotification(RequestComplete, xsdd, Srb);
   3.126 +      ScsiPortNotification(NextRequest, xsdd);
   3.127 +    }
   3.128 +
   3.129 +    xsdd->ring.rsp_cons = i;
   3.130 +    if (i != xsdd->ring.req_prod_pvt)
   3.131 +    {
   3.132 +      RING_FINAL_CHECK_FOR_RESPONSES(&xsdd->ring, more_to_do);
   3.133 +    }
   3.134 +    else
   3.135 +    {
   3.136 +      xsdd->ring.sring->rsp_event = i + 1;
   3.137 +      more_to_do = FALSE;
   3.138 +    }
   3.139 +  }
   3.140 +
   3.141 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   3.142 +}
   3.143 +
   3.144 +#define ENUM_STATE_LIST_DEVS  0
   3.145 +#define ENUM_STATE_READ_DEVID 1
   3.146 +#define ENUM_STATE_READ_VDEV  2
   3.147 +#define ENUM_STATE_READ_STATE 3
   3.148 +
   3.149 +static VOID
   3.150 +XenScsi_CommIfaceList(PVOID DeviceExtension, PUCHAR path)
   3.151 +{
   3.152 +  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   3.153 +  xsdd->comm_iface->packet_type = COMM_IFACE_CMD_XENBUS_LIST;
   3.154 +  strcpy(xsdd->comm_iface->packet.list_req.path, path);
   3.155 +  xsdd->comm_iface->req_prod++;
   3.156 +  KeMemoryBarrier();
   3.157 +  xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->comm_iface->pdo_event_channel);
   3.158 +}
   3.159 +
   3.160 +static VOID
   3.161 +XenScsi_CommIfaceRead(PVOID DeviceExtension, PUCHAR path)
   3.162 +{
   3.163 +  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   3.164 +  xsdd->comm_iface->packet_type = COMM_IFACE_CMD_XENBUS_READ;
   3.165 +  strcpy(xsdd->comm_iface->packet.read_req.path, path);
   3.166 +  xsdd->comm_iface->req_prod++;
   3.167 +  KeMemoryBarrier();
   3.168 +  xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->comm_iface->pdo_event_channel);
   3.169 +}
   3.170 +
   3.171 +/*
   3.172 +static VOID
   3.173 +strcatshort(UCHAR path, SHORT number)
   3.174 +{
   3.175 +  int i;
   3.176 +  UCHAR buf[6];
   3.177 +  int tmp = number;
   3.178 +  
   3.179 +  buf[5] = 0;
   3.180 +  
   3.181 +  for (i = 0; tmp > 0; i++)
   3.182 +  {
   3.183 +    tmp /= 10;
   3.184 +  }
   3.185 +  
   3.186 +}
   3.187 +*/
   3.188 +
   3.189 +static BOOLEAN
   3.190 +XenScsi_EnumDevs(PVOID DeviceExtension)
   3.191 +{
   3.192 +  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   3.193 +  UCHAR path[128];
   3.194 +  enum_vars_t *vars = &xsdd->enum_vars;
   3.195 +
   3.196 +  FUNCTION_ENTER();
   3.197 +
   3.198 +  switch (vars->state)
   3.199 +  {
   3.200 +  case 0:
   3.201 +    XenScsi_CommIfaceList(DeviceExtension, path);
   3.202 +    vars->state = 1;
   3.203 +    break;
   3.204 +  case 1:
   3.205 +    
   3.206 +    xsdd->comm_iface->packet_type = COMM_IFACE_CMD_XENBUS_LIST;
   3.207 +    strcpy(xsdd->comm_iface->packet.list_req.path, xsdd->comm_iface->backend_path);
   3.208 +    strcat(xsdd->comm_iface->packet.list_req.path, "/vscsi-devs");
   3.209 +    xsdd->comm_iface->req_prod++;
   3.210 +    KeMemoryBarrier();
   3.211 +    xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->comm_iface->pdo_event_channel);
   3.212 +    break;
   3.213 +  case ENUM_STATE_READ_DEVID:
   3.214 +    strcpy(path, xsdd->comm_iface->backend_path);
   3.215 +    strcat(path, "/dev-0");
   3.216 +    //itoa(0, path + strlen(path), 10); //strcatshort(path, ...);
   3.217 +    XenScsi_CommIfaceRead(DeviceExtension, path);
   3.218 +    break;
   3.219 +  case ENUM_STATE_READ_VDEV:
   3.220 +  case ENUM_STATE_READ_STATE:
   3.221 +    break;
   3.222 +  }
   3.223 +  return TRUE;
   3.224 +}
   3.225 +#endif
   3.226 +
   3.227 +#if 0
   3.228 +#define JAMES_START() switch (vars->state) { case 0:
   3.229 +#define XenBus_List(___path, ___result) xsdd->comm_iface->packet_type = COMM_IFACE_CMD_XENBUS_LIST; \
   3.230 +    strcpy(xsdd->comm_iface->packet.list_req.path, (___path)); \
   3.231 +    xsdd->comm_iface->req_prod++; \
   3.232 +    KeMemoryBarrier(); \
   3.233 +    xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->comm_iface->pdo_event_channel); \
   3.234 +    vars->state = __LINE__; \
   3.235 +    return; \
   3.236 +    case __LINE__: \
   3.237 +    if (xsdd->comm_iface->packet_status == COMM_IFACE_STATUS_SUCCESS) \
   3.238 +      memcpy(xsdd->comm_iface->packet.list_rsp.values, ___result, 1024); \
   3.239 +    else \
   3.240 +      *(___result) = 0;
   3.241 +
   3.242 +#define JAMES_END() default: break; }
   3.243 +
   3.244 +static VOID
   3.245 +XenScsi_EnumDevs(PVOID DeviceExtension)
   3.246 +{
   3.247 +  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   3.248 +  enum_vars_t *vars = &xsdd->enum_vars;
   3.249 +  //UCHAR path[128];
   3.250 +  //UCHAR **devs;
   3.251 +
   3.252 +  JAMES_START()
   3.253 +  strcpy(path, xsdd->comm_iface->backend_path);
   3.254 +  strcat(path, "/vscsi-devs");
   3.255 +  vars->ptr = vars->devs;
   3.256 +  XenBus_List(vars->path, vars->devs);
   3.257 +  if (*vars->devs != 0)
   3.258 +  {
   3.259 +    PCHAR ptr;
   3.260 +    KdPrint((__DRIVER_NAME "     result:\n"));
   3.261 +    for (ptr = xsdd->comm_iface->packet.list_rsp.values; *ptr; ptr += strlen(ptr) + 1)
   3.262 +    {
   3.263 +      KdPrint((__DRIVER_NAME "       %s\n", ptr));
   3.264 +    }
   3.265 +  }
   3.266 +  JAMES_END()
   3.267 +}
   3.268 +#endif
   3.269 +
   3.270 +static VOID
   3.271 +XenScsi_HwScsiInterrupt_Xen(PVOID DeviceExtension)
   3.272 +{
   3.273 +  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   3.274 +    
   3.275 +  FUNCTION_ENTER();
   3.276 +  
   3.277 +  if (xsdd->comm_iface->rsp_prod == xsdd->rsp_cons)
   3.278 +    return;
   3.279 +  xsdd->rsp_cons = xsdd->comm_iface->rsp_prod;
   3.280 +  
   3.281 +  XenScsi_EnumDevs(DeviceExtension);
   3.282 +#if 0
   3.283 +  switch(xsdd->comm_iface->packet_type)
   3.284 +  {
   3.285 +  case COMM_IFACE_CMD_XENBUS_READ:
   3.286 +    KdPrint((__DRIVER_NAME "     COMM_IFACE_CMD_XENBUS_READ, status = %d\n", xsdd->comm_iface->packet_status));
   3.287 +    if (xsdd->comm_iface->packet_status == COMM_IFACE_STATUS_SUCCESS)
   3.288 +    {
   3.289 +      KdPrint((__DRIVER_NAME "     result = %s\n", xsdd->comm_iface->packet.read_rsp.value));
   3.290 +    }
   3.291 +    break;
   3.292 +  case COMM_IFACE_CMD_XENBUS_LIST:
   3.293 +    KdPrint((__DRIVER_NAME "     COMM_IFACE_CMD_XENBUS_LIST, status = %d\n", xsdd->comm_iface->packet_status));
   3.294 +    if (xsdd->comm_iface->packet_status == COMM_IFACE_STATUS_SUCCESS)
   3.295 +    {
   3.296 +      PCHAR ptr;
   3.297 +      KdPrint((__DRIVER_NAME "     result:\n"));
   3.298 +      for (ptr = xsdd->comm_iface->packet.list_rsp.values; *ptr; ptr += strlen(ptr) + 1)
   3.299 +      {
   3.300 +        KdPrint((__DRIVER_NAME "       %s\n", ptr));
   3.301 +      }
   3.302 +    }
   3.303 +    break;
   3.304 +  default:
   3.305 +    KdPrint((__DRIVER_NAME "     Unknown packet type = %d\n", xsdd->comm_iface->packet_type));
   3.306 +    break;
   3.307 +  }
   3.308 +#endif
   3.309 +
   3.310 +  FUNCTION_EXIT();
   3.311 +}
   3.312 +
   3.313 +static BOOLEAN
   3.314 +XenScsi_HwScsiInterrupt(PVOID DeviceExtension)
   3.315 +{
   3.316 +  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   3.317 +
   3.318 +  if (dump_mode || xsdd->vectors.EvtChn_AckEvent(xsdd->vectors.context, xsdd->event_channel))
   3.319 +    XenScsi_HwScsiInterrupt_Scsi(DeviceExtension);
   3.320 +
   3.321 +  if (!dump_mode && xsdd->vectors.EvtChn_AckEvent(xsdd->vectors.context, xsdd->comm_iface->fdo_event_channel))
   3.322 +    XenScsi_HwScsiInterrupt_Xen(DeviceExtension);
   3.323 +    
   3.324 +  return FALSE; /* we always return FALSE */
   3.325 +}
   3.326 +
   3.327 +static VOID
   3.328 +XenScsi_ParseBackendDevice(PXENSCSI_DEVICE_DATA xsdd, PCHAR value)
   3.329 +{
   3.330 +  int i = 0;
   3.331 +  int j = 0;
   3.332 +  BOOLEAN scanning = TRUE;
   3.333 +
   3.334 +  while (scanning)
   3.335 +  {
   3.336 +    if (value[i] == 0)
   3.337 +      scanning = FALSE;
   3.338 +    if (value[i] == ':' || value[i] == 0)
   3.339 +    {
   3.340 +       value[i] = 0;
   3.341 +       xsdd->host = xsdd->channel;
   3.342 +       xsdd->channel = xsdd->id;
   3.343 +       xsdd->id = xsdd->lun;
   3.344 +       xsdd->lun = atoi(&value[j]);
   3.345 +       j = i + 1;
   3.346 +    }
   3.347 +    i++;
   3.348 +  }
   3.349 +  KdPrint((__DRIVER_NAME "     host = %d, channel = %d, id = %d, lun = %d\n",
   3.350 +    xsdd->host, xsdd->channel, xsdd->id, xsdd->lun));  
   3.351 +}
   3.352 +
   3.353 +static ULONG
   3.354 +XenScsi_HwScsiFindAdapter(PVOID DeviceExtension, PVOID HwContext, PVOID BusInformation, PCHAR ArgumentString, PPORT_CONFIGURATION_INFORMATION ConfigInfo, PBOOLEAN Again)
   3.355 +{
   3.356 +  ULONG i;
   3.357 +//  PACCESS_RANGE AccessRange;
   3.358 +  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   3.359 +//  ULONG status;
   3.360 +//  PXENPCI_XEN_DEVICE_DATA XenDeviceData;
   3.361 +  PACCESS_RANGE access_range;
   3.362 +  PUCHAR ptr;
   3.363 +  USHORT type;
   3.364 +  PCHAR setting, value;
   3.365 +  vscsiif_sring_t *sring;
   3.366 +
   3.367 +  UNREFERENCED_PARAMETER(HwContext);
   3.368 +  UNREFERENCED_PARAMETER(BusInformation);
   3.369 +  UNREFERENCED_PARAMETER(ArgumentString);
   3.370 +
   3.371 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));  
   3.372 +  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   3.373 +
   3.374 +  *Again = FALSE;
   3.375 +
   3.376 +  KdPrint((__DRIVER_NAME "     BusInterruptLevel = %d\n", ConfigInfo->BusInterruptLevel));
   3.377 +  KdPrint((__DRIVER_NAME "     BusInterruptVector = %03x\n", ConfigInfo->BusInterruptVector));
   3.378 +
   3.379 +  if (ConfigInfo->NumberOfAccessRanges != 1)
   3.380 +  {
   3.381 +    KdPrint((__DRIVER_NAME "     NumberOfAccessRanges = %d\n", ConfigInfo->NumberOfAccessRanges));    
   3.382 +    return SP_RETURN_BAD_CONFIG;
   3.383 +  }
   3.384 +
   3.385 +  access_range = &((*(ConfigInfo->AccessRanges))[0]);
   3.386 +
   3.387 +  KdPrint((__DRIVER_NAME "     RangeStart = %08x, RangeLength = %08x\n",
   3.388 +    access_range->RangeStart.LowPart, access_range->RangeLength));
   3.389 +
   3.390 +  ptr = ScsiPortGetDeviceBase(
   3.391 +    DeviceExtension,
   3.392 +    ConfigInfo->AdapterInterfaceType,
   3.393 +    ConfigInfo->SystemIoBusNumber,
   3.394 +    access_range->RangeStart,
   3.395 +    access_range->RangeLength,
   3.396 +    !access_range->RangeInMemory);
   3.397 +  //ptr = MmMapIoSpace(access_range->RangeStart, access_range->RangeLength, MmCached);
   3.398 +  if (ptr == NULL)
   3.399 +  {
   3.400 +    KdPrint((__DRIVER_NAME "     Unable to map range\n"));
   3.401 +    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));  
   3.402 +    return SP_RETURN_BAD_CONFIG;
   3.403 +  }
   3.404 +
   3.405 +  sring = NULL;
   3.406 +  xsdd->event_channel = 0;
   3.407 +  while((type = GET_XEN_INIT_RSP(&ptr, &setting, &value)) != XEN_INIT_TYPE_END)
   3.408 +  {
   3.409 +    switch(type)
   3.410 +    {
   3.411 +    case XEN_INIT_TYPE_RING: /* frontend ring */
   3.412 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, value));
   3.413 +      if (strcmp(setting, "ring-ref") == 0)
   3.414 +      {
   3.415 +        sring = (vscsiif_sring_t *)value;
   3.416 +        FRONT_RING_INIT(&xsdd->ring, sring, PAGE_SIZE);
   3.417 +      }
   3.418 +      break;
   3.419 +    case XEN_INIT_TYPE_EVENT_CHANNEL: /* frontend event channel */
   3.420 +    case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel */
   3.421 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, PtrToUlong(value)));
   3.422 +      if (strcmp(setting, "event-channel") == 0)
   3.423 +      {
   3.424 +        xsdd->event_channel = PtrToUlong(value);
   3.425 +      }
   3.426 +      break;
   3.427 +    case XEN_INIT_TYPE_READ_STRING_BACK:
   3.428 +    case XEN_INIT_TYPE_READ_STRING_FRONT:
   3.429 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value));
   3.430 +      if (strcmp(setting, "b-dev") == 0)
   3.431 +      {
   3.432 +        XenScsi_ParseBackendDevice(xsdd, value);
   3.433 +      }
   3.434 +      break;
   3.435 +    case XEN_INIT_TYPE_VECTORS:
   3.436 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
   3.437 +      if (((PXENPCI_VECTORS)value)->length != sizeof(XENPCI_VECTORS) ||
   3.438 +        ((PXENPCI_VECTORS)value)->magic != XEN_DATA_MAGIC)
   3.439 +      {
   3.440 +        KdPrint((__DRIVER_NAME "     vectors mismatch (magic = %08x, length = %d)\n",
   3.441 +          ((PXENPCI_VECTORS)value)->magic, ((PXENPCI_VECTORS)value)->length));
   3.442 +        KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   3.443 +        return SP_RETURN_BAD_CONFIG;
   3.444 +      }
   3.445 +      else
   3.446 +        memcpy(&xsdd->vectors, value, sizeof(XENPCI_VECTORS));
   3.447 +      break;
   3.448 +    case XEN_INIT_TYPE_GRANT_ENTRIES:
   3.449 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_GRANT_ENTRIES - %d\n", PtrToUlong(setting)));
   3.450 +      xsdd->grant_entries = (USHORT)PtrToUlong(setting);
   3.451 +      memcpy(&xsdd->grant_free_list, value, sizeof(grant_ref_t) * xsdd->grant_entries);
   3.452 +      xsdd->grant_free = xsdd->grant_entries;
   3.453 +      break;
   3.454 +    case XEN_INIT_TYPE_COMM_IFACE:
   3.455 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_COMM_IFACE - %p\n", PtrToUlong(value)));
   3.456 +      xsdd->comm_iface = (PXEN_COMM_IFACE)value;
   3.457 +    default:
   3.458 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
   3.459 +      break;
   3.460 +    }
   3.461 +  }
   3.462 +#if 0
   3.463 +  if (xsdd->device_type == XENSCSI_DEVICETYPE_UNKNOWN
   3.464 +    || sring == NULL
   3.465 +    || xsdd->event_channel == 0)
   3.466 +  {
   3.467 +    KdPrint((__DRIVER_NAME "     Missing settings\n"));
   3.468 +    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   3.469 +    return SP_RETURN_BAD_CONFIG;
   3.470 +  }
   3.471 +#endif
   3.472 +  ConfigInfo->MaximumTransferLength = VSCSIIF_SG_TABLESIZE * PAGE_SIZE;
   3.473 +  ConfigInfo->NumberOfPhysicalBreaks = VSCSIIF_SG_TABLESIZE - 1;
   3.474 +  ConfigInfo->ScatterGather = TRUE;
   3.475 +  ConfigInfo->AlignmentMask = 0;
   3.476 +  ConfigInfo->NumberOfBuses = 8;
   3.477 +  ConfigInfo->InitiatorBusId[0] = 7;
   3.478 +  ConfigInfo->InitiatorBusId[1] = 7;
   3.479 +  ConfigInfo->InitiatorBusId[2] = 7;
   3.480 +  ConfigInfo->InitiatorBusId[3] = 7;
   3.481 +  ConfigInfo->InitiatorBusId[4] = 7;
   3.482 +  ConfigInfo->InitiatorBusId[5] = 7;
   3.483 +  ConfigInfo->InitiatorBusId[6] = 7;
   3.484 +  ConfigInfo->InitiatorBusId[7] = 7;
   3.485 +  ConfigInfo->MaximumNumberOfTargets = 16;
   3.486 +  ConfigInfo->MaximumNumberOfLogicalUnits = 255;
   3.487 +  ConfigInfo->BufferAccessScsiPortControlled = TRUE;
   3.488 +  if (ConfigInfo->Dma64BitAddresses == SCSI_DMA64_SYSTEM_SUPPORTED)
   3.489 +  {
   3.490 +    ConfigInfo->Master = TRUE;
   3.491 +    ConfigInfo->Dma64BitAddresses = SCSI_DMA64_MINIPORT_SUPPORTED;
   3.492 +    KdPrint((__DRIVER_NAME "     Dma64BitAddresses supported\n"));
   3.493 +  }
   3.494 +  else
   3.495 +  {
   3.496 +    ConfigInfo->Master = FALSE;
   3.497 +    KdPrint((__DRIVER_NAME "     Dma64BitAddresses not supported\n"));
   3.498 +  }
   3.499 +
   3.500 +  xsdd->shadow_free = 0;
   3.501 +  memset(xsdd->shadows, 0, sizeof(vscsiif_shadow_t) * SHADOW_ENTRIES);
   3.502 +  for (i = 0; i < SHADOW_ENTRIES; i++)
   3.503 +  {
   3.504 +    xsdd->shadows[i].req.rqid = (USHORT)i;
   3.505 +    put_shadow_on_freelist(xsdd, &xsdd->shadows[i]);
   3.506 +  }
   3.507 +
   3.508 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));  
   3.509 +
   3.510 +  return SP_RETURN_FOUND;
   3.511 +}
   3.512 +
   3.513 +static BOOLEAN
   3.514 +XenScsi_HwScsiInitialize(PVOID DeviceExtension)
   3.515 +{
   3.516 +//  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   3.517 +
   3.518 +  UNREFERENCED_PARAMETER(DeviceExtension);
   3.519 +  
   3.520 +  FUNCTION_ENTER();
   3.521 +
   3.522 +  XenScsi_EnumDevs(DeviceExtension);
   3.523 +
   3.524 +  FUNCTION_EXIT();
   3.525 +
   3.526 +  return TRUE;
   3.527 +}
   3.528 +
   3.529 +static VOID
   3.530 +XenScsi_PutSrbOnRing(PXENSCSI_DEVICE_DATA xsdd, PSCSI_REQUEST_BLOCK Srb)
   3.531 +{
   3.532 +  PUCHAR ptr;
   3.533 +  PHYSICAL_ADDRESS physical_address;
   3.534 +  PFN_NUMBER pfn;
   3.535 +  //int i;
   3.536 +  vscsiif_shadow_t *shadow;
   3.537 +  int remaining;
   3.538 +
   3.539 +//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   3.540 +
   3.541 +  shadow = get_shadow_from_freelist(xsdd);
   3.542 +  ASSERT(shadow);
   3.543 +  shadow->Srb = Srb;
   3.544 +  shadow->req.act = VSCSIIF_ACT_SCSI_CDB;
   3.545 +  memset(shadow->req.cmnd, 0, VSCSIIF_MAX_COMMAND_SIZE);
   3.546 +  memcpy(shadow->req.cmnd, Srb->Cdb, Srb->CdbLength);
   3.547 +  shadow->req.cmd_len = Srb->CdbLength;
   3.548 +  shadow->req.id = (USHORT)xsdd->id;
   3.549 +  shadow->req.lun = (USHORT)xsdd->lun;
   3.550 +  shadow->req.channel = (USHORT)xsdd->channel;
   3.551 +  if (Srb->DataTransferLength && (Srb->SrbFlags & SRB_FLAGS_DATA_IN) && (Srb->SrbFlags & SRB_FLAGS_DATA_OUT))
   3.552 +  {
   3.553 +    KdPrint((__DRIVER_NAME "     Cmd = %02x, Length = %d, DMA_BIDIRECTIONAL\n", Srb->Cdb[0], Srb->DataTransferLength));
   3.554 +    shadow->req.sc_data_direction = DMA_BIDIRECTIONAL;
   3.555 +  }
   3.556 +  else if (Srb->DataTransferLength && (Srb->SrbFlags & SRB_FLAGS_DATA_IN))
   3.557 +  {
   3.558 +    KdPrint((__DRIVER_NAME "     Cmd = %02x, Length = %d, DMA_FROM_DEVICE\n", Srb->Cdb[0], Srb->DataTransferLength));
   3.559 +    shadow->req.sc_data_direction = DMA_FROM_DEVICE;
   3.560 +  }
   3.561 +  else if (Srb->DataTransferLength && (Srb->SrbFlags & SRB_FLAGS_DATA_OUT))
   3.562 +  {
   3.563 +    KdPrint((__DRIVER_NAME "     Cmd = %02x, Length = %d, DMA_TO_DEVICE\n", Srb->Cdb[0], Srb->DataTransferLength));
   3.564 +    shadow->req.sc_data_direction = DMA_TO_DEVICE;
   3.565 +  }
   3.566 +  else
   3.567 +  {
   3.568 +    KdPrint((__DRIVER_NAME "     Cmd = %02x, Length = %d, DMA_NONE\n", Srb->Cdb[0], Srb->DataTransferLength));
   3.569 +    shadow->req.sc_data_direction = DMA_NONE;
   3.570 +  }
   3.571 +  //shadow->req.nr_segments = (UINT8)((Srb->DataTransferLength + PAGE_SIZE - 1) >> PAGE_SHIFT);
   3.572 +  //shadow->req.request_bufflen = Srb->DataTransferLength;
   3.573 +
   3.574 +  remaining = Srb->DataTransferLength;
   3.575 +  shadow->req.seg[0].offset = 0;
   3.576 +  shadow->req.seg[0].length = 0;
   3.577 +
   3.578 +  ptr = Srb->DataBuffer;
   3.579 +
   3.580 +  for (shadow->req.nr_segments = 0; remaining != 0; shadow->req.nr_segments++)
   3.581 +  {
   3.582 +    physical_address = MmGetPhysicalAddress(ptr);
   3.583 +    pfn = (ULONG)(physical_address.QuadPart >> PAGE_SHIFT);
   3.584 +    shadow->req.seg[shadow->req.nr_segments].gref = get_grant_from_freelist(xsdd);
   3.585 +    ASSERT(shadow->req.seg[shadow->req.nr_segments].gref);
   3.586 +    xsdd->vectors.GntTbl_GrantAccess(xsdd->vectors.context, 0, (ULONG)pfn, 0, shadow->req.seg[shadow->req.nr_segments].gref);
   3.587 +    shadow->req.seg[shadow->req.nr_segments].offset = (USHORT)(physical_address.LowPart & (PAGE_SIZE - 1));
   3.588 +    shadow->req.seg[shadow->req.nr_segments].length = (USHORT)min(PAGE_SIZE - shadow->req.seg[shadow->req.nr_segments].offset, remaining);
   3.589 +    remaining -= shadow->req.seg[shadow->req.nr_segments].length;
   3.590 +    ptr += shadow->req.seg[shadow->req.nr_segments].length;
   3.591 +    //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));
   3.592 +  }
   3.593 +  *RING_GET_REQUEST(&xsdd->ring, xsdd->ring.req_prod_pvt) = shadow->req;
   3.594 +  xsdd->ring.req_prod_pvt++;
   3.595 +
   3.596 +//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   3.597 +}
   3.598 +
   3.599 +static BOOLEAN
   3.600 +XenScsi_HwScsiStartIo(PVOID DeviceExtension, PSCSI_REQUEST_BLOCK Srb)
   3.601 +{
   3.602 +//  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   3.603 +//  int notify;
   3.604 +
   3.605 +  FUNCTION_ENTER();
   3.606 +  //KdPrint((__DRIVER_NAME " --> HwScsiStartIo PathId = %d, TargetId = %d, Lun = %d\n", Srb->PathId, Srb->TargetId, Srb->Lun));
   3.607 +
   3.608 +//  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   3.609 +//  if (Srb->PathId != 0 || Srb->TargetId != 0)
   3.610 +//  {
   3.611 +    Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
   3.612 +    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   3.613 +    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
   3.614 +    KdPrint((__DRIVER_NAME "     Out of bounds\n"));
   3.615 +    FUNCTION_EXIT();
   3.616 +    return TRUE;
   3.617 +//  }
   3.618 +
   3.619 +#if 0
   3.620 +  switch (Srb->Function)
   3.621 +  {
   3.622 +  case SRB_FUNCTION_EXECUTE_SCSI:
   3.623 +    XenScsi_PutSrbOnRing(xsdd, Srb);
   3.624 +    RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xsdd->ring, notify);
   3.625 +    if (notify)
   3.626 +      xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->event_channel);
   3.627 +    if (!xsdd->shadow_free)
   3.628 +      ScsiPortNotification(NextRequest, DeviceExtension);
   3.629 +    break;
   3.630 +  case SRB_FUNCTION_IO_CONTROL:
   3.631 +    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_IO_CONTROL\n"));
   3.632 +    Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   3.633 +    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   3.634 +    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
   3.635 +    break;
   3.636 +  case SRB_FUNCTION_FLUSH:
   3.637 +    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_FLUSH\n"));
   3.638 +    Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   3.639 +    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   3.640 +    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
   3.641 +    break;
   3.642 +  default:
   3.643 +    KdPrint((__DRIVER_NAME "     Unhandled Srb->Function = %08X\n", Srb->Function));
   3.644 +    Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   3.645 +    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   3.646 +    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
   3.647 +    break;
   3.648 +  }
   3.649 +
   3.650 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   3.651 +  return TRUE;
   3.652 +#endif
   3.653 +}
   3.654 +
   3.655 +static BOOLEAN
   3.656 +XenScsi_HwScsiResetBus(PVOID DeviceExtension, ULONG PathId)
   3.657 +{
   3.658 +  UNREFERENCED_PARAMETER(DeviceExtension);
   3.659 +  UNREFERENCED_PARAMETER(PathId);
   3.660 +
   3.661 +
   3.662 +  KdPrint((__DRIVER_NAME " --> HwScsiResetBus\n"));
   3.663 +  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   3.664 +
   3.665 +  KdPrint((__DRIVER_NAME " <-- HwScsiResetBus\n"));
   3.666 +
   3.667 +  return TRUE;
   3.668 +}
   3.669 +
   3.670 +static BOOLEAN
   3.671 +XenScsi_HwScsiAdapterState(PVOID DeviceExtension, PVOID Context, BOOLEAN SaveState)
   3.672 +{
   3.673 +  UNREFERENCED_PARAMETER(DeviceExtension);
   3.674 +  UNREFERENCED_PARAMETER(Context);
   3.675 +  UNREFERENCED_PARAMETER(SaveState);
   3.676 +
   3.677 +  KdPrint((__DRIVER_NAME " --> HwScsiAdapterState\n"));
   3.678 +  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   3.679 +
   3.680 +  KdPrint((__DRIVER_NAME " <-- HwScsiAdapterState\n"));
   3.681 +
   3.682 +  return TRUE;
   3.683 +}
   3.684 +
   3.685 +static SCSI_ADAPTER_CONTROL_STATUS
   3.686 +XenScsi_HwScsiAdapterControl(PVOID DeviceExtension, SCSI_ADAPTER_CONTROL_TYPE ControlType, PVOID Parameters)
   3.687 +{
   3.688 +  SCSI_ADAPTER_CONTROL_STATUS Status = ScsiAdapterControlSuccess;
   3.689 +  PSCSI_SUPPORTED_CONTROL_TYPE_LIST SupportedControlTypeList;
   3.690 +  //KIRQL OldIrql;
   3.691 +
   3.692 +  UNREFERENCED_PARAMETER(DeviceExtension);
   3.693 +
   3.694 +  KdPrint((__DRIVER_NAME " --> HwScsiAdapterControl\n"));
   3.695 +  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   3.696 +
   3.697 +  switch (ControlType)
   3.698 +  {
   3.699 +  case ScsiQuerySupportedControlTypes:
   3.700 +    SupportedControlTypeList = (PSCSI_SUPPORTED_CONTROL_TYPE_LIST)Parameters;
   3.701 +    KdPrint((__DRIVER_NAME "     ScsiQuerySupportedControlTypes (Max = %d)\n", SupportedControlTypeList->MaxControlType));
   3.702 +    SupportedControlTypeList->SupportedTypeList[ScsiQuerySupportedControlTypes] = TRUE;
   3.703 +    SupportedControlTypeList->SupportedTypeList[ScsiStopAdapter] = TRUE;
   3.704 +    break;
   3.705 +  case ScsiStopAdapter:
   3.706 +    KdPrint((__DRIVER_NAME "     ScsiStopAdapter\n"));
   3.707 +    break;
   3.708 +  case ScsiRestartAdapter:
   3.709 +    KdPrint((__DRIVER_NAME "     ScsiRestartAdapter\n"));
   3.710 +    break;
   3.711 +  case ScsiSetBootConfig:
   3.712 +    KdPrint((__DRIVER_NAME "     ScsiSetBootConfig\n"));
   3.713 +    break;
   3.714 +  case ScsiSetRunningConfig:
   3.715 +    KdPrint((__DRIVER_NAME "     ScsiSetRunningConfig\n"));
   3.716 +    break;
   3.717 +  default:
   3.718 +    KdPrint((__DRIVER_NAME "     UNKNOWN\n"));
   3.719 +    break;
   3.720 +  }
   3.721 +
   3.722 +  KdPrint((__DRIVER_NAME " <-- HwScsiAdapterControl\n"));
   3.723 +
   3.724 +  return Status;
   3.725 +}
   3.726 +
   3.727  NTSTATUS
   3.728  DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
   3.729  {
   3.730 @@ -79,7 +759,13 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
   3.731    HwInitializationData.DeviceIdLength = 0;
   3.732    HwInitializationData.DeviceId = NULL;
   3.733  
   3.734 -  XenScsi_FillInitCallbacks(&HwInitializationData);
   3.735 +  HwInitializationData.HwInitialize = XenScsi_HwScsiInitialize;
   3.736 +  HwInitializationData.HwStartIo = XenScsi_HwScsiStartIo;
   3.737 +  HwInitializationData.HwInterrupt = XenScsi_HwScsiInterrupt;
   3.738 +  HwInitializationData.HwFindAdapter = XenScsi_HwScsiFindAdapter;
   3.739 +  HwInitializationData.HwResetBus = XenScsi_HwScsiResetBus;
   3.740 +  HwInitializationData.HwAdapterState = XenScsi_HwScsiAdapterState;
   3.741 +  HwInitializationData.HwAdapterControl = XenScsi_HwScsiAdapterControl;
   3.742  
   3.743    Status = ScsiPortInitialize(DriverObject, RegistryPath, &HwInitializationData, NULL);
   3.744    
     4.1 --- a/xenscsi/xenscsi.h	Thu Nov 27 09:28:57 2008 +1100
     4.2 +++ b/xenscsi/xenscsi.h	Thu Nov 27 09:29:25 2008 +1100
     4.3 @@ -39,6 +39,25 @@ typedef struct {
     4.4  #define SHADOW_ENTRIES 32
     4.5  #define MAX_GRANT_ENTRIES 512
     4.6  
     4.7 +#define SCSI_DEV_STATE_MISSING 0
     4.8 +#define SCSI_DEV_STATE_PRESENT 1
     4.9 +#define SCSI_DEV_STATE_ACTIVE  2
    4.10 +
    4.11 +typedef struct {
    4.12 +  USHORT channel
    4.13 +  USHORT id;
    4.14 +  USHORT lun;
    4.15 +  UCHAR state; /* SCSI_DEV_STATE_XXX */
    4.16 +  ULONG dev_no;
    4.17 +} scsi_dev_t;
    4.18 +
    4.19 +typedef struct {
    4.20 +  USHORT state;
    4.21 +  UCHAR devs[1024];
    4.22 +  UCHAR path[128];
    4.23 +  PUCHAR ptr;
    4.24 +} enum_vars_t;
    4.25 +
    4.26  struct
    4.27  {
    4.28    vscsiif_shadow_t shadows[SHADOW_ENTRIES];
    4.29 @@ -59,6 +78,9 @@ struct
    4.30    int lun;
    4.31  
    4.32    XENPCI_VECTORS vectors;
    4.33 +  PXEN_COMM_IFACE comm_iface;
    4.34 +  USHORT rsp_cons;
    4.35 +  enum_vars_t enum_vars;
    4.36  } typedef XENSCSI_DEVICE_DATA, *PXENSCSI_DEVICE_DATA;
    4.37  
    4.38  enum dma_data_direction {
     5.1 --- a/xenscsi/xenscsi.inx	Thu Nov 27 09:28:57 2008 +1100
     5.2 +++ b/xenscsi/xenscsi.inx	Thu Nov 27 09:29:25 2008 +1100
     5.3 @@ -57,7 +57,7 @@ AddReg = XenScsi_XenConfig_AddReg, XenSc
     5.4  [XenScsi_XenConfig_AddReg]
     5.5  HKR,"XenConfig\ring-ref", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_RING%
     5.6  HKR,"XenConfig\event-channel", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_EVENT_CHANNEL_IRQ%
     5.7 -HKR,"XenConfig\b-dev", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_FRONT%
     5.8 +;HKR,"XenConfig\b-dev", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_FRONT%
     5.9  HKR,"XenConfig\grants", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_GRANT_ENTRIES%
    5.10  HKR,"XenConfig\grants", "value", %FLG_ADDREG_TYPE_DWORD%, 144
    5.11