win-pvdrivers

changeset 370:d76831a77d19

merge
author Andy Grover <andy.grover@oracle.com>
date Wed Jul 09 00:26:05 2008 -0700 (2008-07-09)
parents 5a762fd1fba9 2ff96a909c28
children f7fa99be363d
files xennet/xennet.c xenpci/xenpci.h
line diff
     1.1 --- a/common.inc	Wed Jul 09 00:20:30 2008 -0700
     1.2 +++ b/common.inc	Wed Jul 09 00:26:05 2008 -0700
     1.3 @@ -1,4 +1,4 @@
     1.4 -VERSION=0.9.10.4
     1.5 +VERSION=0.9.10.5
     1.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.7  MSC_WARNING_LEVEL=/W4
     1.8  INCLUDES = ..\common\include;..\common\include\public
     2.1 --- a/installer.nsi	Wed Jul 09 00:20:30 2008 -0700
     2.2 +++ b/installer.nsi	Wed Jul 09 00:26:05 2008 -0700
     2.3 @@ -3,7 +3,7 @@
     2.4  
     2.5  !define AppName "Xen PV Drivers"
     2.6  !define StartMenu "$SMPROGRAMS\${AppName}"
     2.7 -!define Version "0.9.11-pre4"
     2.8 +!define Version "0.9.11-pre5"
     2.9  #!define Version "$%VERSION%"
    2.10  Name "${AppName}"
    2.11  InstallDir "$PROGRAMFILES\${AppName}"
     3.1 --- a/xenhide/xenhide.c	Wed Jul 09 00:20:30 2008 -0700
     3.2 +++ b/xenhide/xenhide.c	Wed Jul 09 00:26:05 2008 -0700
     3.3 @@ -60,8 +60,8 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
     3.4    UNICODE_STRING RegValueName;
     3.5    HANDLE RegHandle;
     3.6    OBJECT_ATTRIBUTES RegObjectAttributes;
     3.7 -  char Buf[200];
     3.8 -  ULONG BufLen = 200;
     3.9 +  char Buf[300];// Sometimes bigger then 200 if system reboot from crash
    3.10 +  ULONG BufLen = 300;
    3.11    PKEY_VALUE_PARTIAL_INFORMATION KeyPartialValue;
    3.12    int State = 0;
    3.13    size_t StartPos = 0;
    3.14 @@ -199,7 +199,7 @@ XenHide_IdSuffixMatches(PDEVICE_OBJECT p
    3.15        if (string_length >= wcslen(matching_id))
    3.16        {
    3.17          ptr += string_length - wcslen(matching_id);
    3.18 -        string_length -= wcslen(matching_id);
    3.19 +        string_length -= (ULONG)wcslen(matching_id);
    3.20        }
    3.21        //KdPrint((__DRIVER_NAME "     Comparing '%S' and '%S'\n", ptr, matching_id));
    3.22        if (wcscmp(ptr, matching_id) == 0)
    3.23 @@ -226,7 +226,7 @@ XenHide_AddDevice(
    3.24    USHORT hide_type;
    3.25    PXENHIDE_HIDE_LIST_ENTRY list_entry;
    3.26  
    3.27 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    3.28 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    3.29  
    3.30    
    3.31    length = 512;
    3.32 @@ -249,8 +249,9 @@ XenHide_AddDevice(
    3.33    if (gplpv)
    3.34    {
    3.35      /* hide only specific devices */
    3.36 -    if (XenHide_IdSuffixMatches(PhysicalDeviceObject, L"VEN_8086&DEV_7010")
    3.37 -      || XenHide_IdSuffixMatches(PhysicalDeviceObject, L"VEN_10EC&DEV_8139"))
    3.38 +    if (XenHide_IdSuffixMatches(PhysicalDeviceObject, L"VEN_8086&DEV_7010") // Qemu IDE
    3.39 +      || XenHide_IdSuffixMatches(PhysicalDeviceObject, L"VEN_10EC&DEV_8139") // Qemu Network
    3.40 +      || XenHide_IdSuffixMatches(PhysicalDeviceObject, L"VEN_1000&DEV_0012"))// Qemu SCSI
    3.41      {
    3.42        hide_type = XENHIDE_TYPE_DEVICE;
    3.43      }
    3.44 @@ -268,11 +269,11 @@ XenHide_AddDevice(
    3.45  
    3.46    if (hide_type == XENHIDE_TYPE_NONE)
    3.47    {
    3.48 -    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (filter not required for %S)\n", device_description));
    3.49 +    //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (filter not required for %S)\n", device_description));
    3.50      return STATUS_SUCCESS;
    3.51    }
    3.52  
    3.53 -  KdPrint((__DRIVER_NAME "     Installing Filter for %S\n", device_description));
    3.54 +  //KdPrint((__DRIVER_NAME "     Installing Filter for %S\n", device_description));
    3.55  
    3.56    if (gplpv && hide_type == XENHIDE_TYPE_DEVICE)
    3.57    {
    3.58 @@ -316,7 +317,7 @@ XenHide_AddDevice(
    3.59  
    3.60    deviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
    3.61  
    3.62 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    3.63 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    3.64  
    3.65    return STATUS_SUCCESS;
    3.66  }
    3.67 @@ -397,16 +398,16 @@ XenHide_Pnp(PDEVICE_OBJECT device_object
    3.68  
    3.69    switch (stack->MinorFunction) {
    3.70    case IRP_MN_START_DEVICE:
    3.71 -    KdPrint((__DRIVER_NAME "     IRP_MN_START_DEVICE\n"));
    3.72 +    //KdPrint((__DRIVER_NAME "     IRP_MN_START_DEVICE\n"));
    3.73      if (xhdd->hide_type == XENHIDE_TYPE_DEVICE)
    3.74      {
    3.75 -      KdPrint((__DRIVER_NAME "     hide_type == XENHIDE_TYPE_DEVICE\n"));
    3.76 +      //KdPrint((__DRIVER_NAME "     hide_type == XENHIDE_TYPE_DEVICE\n"));
    3.77        status = irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
    3.78        IoCompleteRequest(irp, IO_NO_INCREMENT);
    3.79      }
    3.80      else
    3.81      {
    3.82 -      KdPrint((__DRIVER_NAME "     hide_type != XENHIDE_TYPE_DEVICE\n"));
    3.83 +      //KdPrint((__DRIVER_NAME "     hide_type != XENHIDE_TYPE_DEVICE\n"));
    3.84        IoSkipCurrentIrpStackLocation(irp);
    3.85        status = IoCallDriver(xhdd->lower_do, irp);
    3.86      }
    3.87 @@ -414,7 +415,7 @@ XenHide_Pnp(PDEVICE_OBJECT device_object
    3.88    case IRP_MN_QUERY_DEVICE_RELATIONS:
    3.89      if (xhdd->hide_type == XENHIDE_TYPE_PCI_BUS && stack->Parameters.QueryDeviceRelations.Type == BusRelations)
    3.90      {
    3.91 -      KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_DEVICE_RELATIONS - BusRelations\n"));
    3.92 +      //KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_DEVICE_RELATIONS - BusRelations\n"));
    3.93        IoMarkIrpPending(irp);
    3.94        status = XenHide_SendAndWaitForIrp(device_object, irp);
    3.95        relations = (PDEVICE_RELATIONS)irp->IoStatus.Information;
    3.96 @@ -428,7 +429,7 @@ XenHide_Pnp(PDEVICE_OBJECT device_object
    3.97          {
    3.98            if (relations->Objects[i] == list_entry->pdo)
    3.99            {
   3.100 -            KdPrint((__DRIVER_NAME "     Hiding %p\n", relations->Objects[i]));
   3.101 +            //KdPrint((__DRIVER_NAME "     Hiding %p\n", relations->Objects[i]));
   3.102              break;
   3.103            }
   3.104            list_entry = (PXENHIDE_HIDE_LIST_ENTRY)list_entry->entry.Flink;
     4.1 --- a/xennet/xennet.c	Wed Jul 09 00:20:30 2008 -0700
     4.2 +++ b/xennet/xennet.c	Wed Jul 09 00:26:05 2008 -0700
     4.3 @@ -22,32 +22,6 @@ Foundation, Inc., 51 Franklin Street, Fi
     4.4  #include <io/xenbus.h>
     4.5  #include "xennet.h"
     4.6  
     4.7 -LARGE_INTEGER ProfTime_TxBufferGC;
     4.8 -LARGE_INTEGER ProfTime_RxBufferAlloc;
     4.9 -LARGE_INTEGER ProfTime_ReturnPacket;
    4.10 -LARGE_INTEGER ProfTime_RxBufferCheck;
    4.11 -LARGE_INTEGER ProfTime_Linearize;
    4.12 -LARGE_INTEGER ProfTime_SendPackets;
    4.13 -LARGE_INTEGER ProfTime_SendQueuedPackets;
    4.14 -LARGE_INTEGER ProfTime_RxBufferCheckTopHalf;
    4.15 -LARGE_INTEGER ProfTime_RxBufferCheckBotHalf;
    4.16 -
    4.17 -int ProfCount_TxBufferGC;
    4.18 -int ProfCount_RxBufferAlloc;
    4.19 -int ProfCount_ReturnPacket;
    4.20 -int ProfCount_RxBufferCheck;
    4.21 -int ProfCount_Linearize;
    4.22 -int ProfCount_SendPackets;
    4.23 -int ProfCount_PacketsPerSendPackets;
    4.24 -int ProfCount_SendQueuedPackets;
    4.25 -
    4.26 -int ProfCount_TxPacketsTotal;
    4.27 -int ProfCount_TxPacketsCsumOffload;
    4.28 -int ProfCount_TxPacketsLargeOffload;
    4.29 -int ProfCount_RxPacketsTotal;
    4.30 -int ProfCount_RxPacketsCsumOffload;
    4.31 -int ProfCount_CallsToIndicateReceive;
    4.32 -
    4.33  /* ----- BEGIN Other people's code --------- */
    4.34  /* from linux/include/linux/ctype.h, used under GPLv2 */
    4.35  #define _U      0x01    /* upper */
    4.36 @@ -669,32 +643,6 @@ DriverEntry(
    4.37    NDIS_HANDLE ndis_wrapper_handle;
    4.38    NDIS_MINIPORT_CHARACTERISTICS mini_chars;
    4.39  
    4.40 -  ProfTime_TxBufferGC.QuadPart = 0;
    4.41 -  ProfTime_RxBufferAlloc.QuadPart = 0;
    4.42 -  ProfTime_ReturnPacket.QuadPart = 0;
    4.43 -  ProfTime_RxBufferCheck.QuadPart = 0;
    4.44 -  ProfTime_RxBufferCheckTopHalf.QuadPart = 0;
    4.45 -  ProfTime_RxBufferCheckBotHalf.QuadPart = 0;
    4.46 -  ProfTime_Linearize.QuadPart = 0;
    4.47 -  ProfTime_SendPackets.QuadPart = 0;
    4.48 -  ProfTime_SendQueuedPackets.QuadPart = 0;
    4.49 -
    4.50 -  ProfCount_TxBufferGC = 0;
    4.51 -  ProfCount_RxBufferAlloc = 0;
    4.52 -  ProfCount_ReturnPacket = 0;
    4.53 -  ProfCount_RxBufferCheck = 0;
    4.54 -  ProfCount_Linearize = 0;
    4.55 -  ProfCount_SendPackets = 0;
    4.56 -  ProfCount_PacketsPerSendPackets = 0;
    4.57 -  ProfCount_SendQueuedPackets = 0;
    4.58 -
    4.59 -  ProfCount_TxPacketsTotal = 0;
    4.60 -  ProfCount_TxPacketsCsumOffload = 0;
    4.61 -  ProfCount_TxPacketsLargeOffload = 0;
    4.62 -  ProfCount_RxPacketsTotal = 0;
    4.63 -  ProfCount_RxPacketsCsumOffload = 0;
    4.64 -  ProfCount_CallsToIndicateReceive = 0;
    4.65 -
    4.66    RtlZeroMemory(&mini_chars, sizeof(mini_chars));
    4.67  
    4.68    NdisMInitializeWrapper(&ndis_wrapper_handle, DriverObject, RegistryPath, NULL);
     5.1 --- a/xenpci/evtchn.c	Wed Jul 09 00:20:30 2008 -0700
     5.2 +++ b/xenpci/evtchn.c	Wed Jul 09 00:26:05 2008 -0700
     5.3 @@ -73,15 +73,11 @@ static inline int test_and_clear_bit(int
     5.4    #define synch_clear_bit(p1, p2) test_and_clear_bit(p1, p2)
     5.5    #define synch_set_bit(p1, p2) test_and_set_bit(p1, p2)
     5.6    #define bit_scan_forward(p1, p2) BitScanForward(p1, p2)
     5.7 -
     5.8 -#elif defined(_WIN32)
     5.9 +#elif defined(_X86_)
    5.10    #define xchg(p1, p2) _InterlockedExchange(p1, p2)
    5.11    #define synch_clear_bit(p1, p2) _interlockedbittestandreset(p2, p1)
    5.12    #define synch_set_bit(p1, p2) _interlockedbittestandset(p2, p1)
    5.13    #define bit_scan_forward(p1, p2) _BitScanForward(p1, p2)
    5.14 -
    5.15 -
    5.16 -
    5.17  #else
    5.18    #define xchg(p1, p2) _InterlockedExchange64(p1, p2)
    5.19    #define synch_clear_bit(p1, p2) _interlockedbittestandreset64(p2, p1)
    5.20 @@ -101,9 +97,14 @@ EvtChn_DpcBounce(PRKDPC Dpc, PVOID Conte
    5.21    //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    5.22  
    5.23    if (action->type == EVT_ACTION_TYPE_IRQ)
    5.24 +  {
    5.25 +    //KdPrint((__DRIVER_NAME "     Calling interrupt vector %02x\n", action->vector));
    5.26      sw_interrupt((UCHAR)action->vector);
    5.27 +  }
    5.28    else
    5.29 +  {
    5.30      action->ServiceRoutine(NULL, action->ServiceContext);
    5.31 +  }
    5.32    //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    5.33  }
    5.34  
    5.35 @@ -119,8 +120,9 @@ EvtChn_Interrupt(PKINTERRUPT Interrupt, 
    5.36    unsigned long evt_bit;
    5.37    unsigned int port;
    5.38    ev_action_t *ev_action;
    5.39 +  BOOLEAN handled = FALSE;
    5.40  
    5.41 -//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ " (cpu = %d)\n", cpu));
    5.42 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ " (cpu = %d)\n", cpu));
    5.43  
    5.44    UNREFERENCED_PARAMETER(Interrupt);
    5.45  
    5.46 @@ -135,6 +137,7 @@ EvtChn_Interrupt(PKINTERRUPT Interrupt, 
    5.47      evt_words &= ~(1 << evt_word);
    5.48      while (bit_scan_forward(&evt_bit, shared_info_area->evtchn_pending[evt_word] & ~shared_info_area->evtchn_mask[evt_word]))
    5.49      {
    5.50 +      handled = TRUE;
    5.51        port = (evt_word << 5) + evt_bit;
    5.52        ev_action = &xpdd->ev_actions[port];
    5.53        switch (ev_action->type)
    5.54 @@ -154,9 +157,9 @@ EvtChn_Interrupt(PKINTERRUPT Interrupt, 
    5.55      }
    5.56    }
    5.57  
    5.58 -//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    5.59 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    5.60  
    5.61 -  return TRUE;
    5.62 +  return handled;
    5.63  }
    5.64  
    5.65  NTSTATUS
    5.66 @@ -366,7 +369,23 @@ EvtChn_Init(PXENPCI_DEVICE_DATA xpdd)
    5.67  NTSTATUS
    5.68  EvtChn_Shutdown(PXENPCI_DEVICE_DATA xpdd)
    5.69  {
    5.70 +#if (NTDDI_VERSION < NTDDI_WINXP)
    5.71 +  int i;
    5.72 +#endif
    5.73 +
    5.74    IoDisconnectInterrupt(xpdd->interrupt);
    5.75  
    5.76 +#if (NTDDI_VERSION >= NTDDI_WINXP)
    5.77 +  KeFlushQueuedDpcs();
    5.78 +#else
    5.79 +  for (i = 0; i < NR_EVENTS; i++)
    5.80 +  {
    5.81 +    if (xpdd->ev_actions[i].type == EVT_ACTION_TYPE_DPC || xpdd->ev_actions[i].type == EVT_ACTION_TYPE_IRQ)
    5.82 +    {
    5.83 +      KeRemoveQueueDpc(&xpdd->ev_actions[i].Dpc);
    5.84 +    }
    5.85 +  }
    5.86 +#endif
    5.87 +
    5.88    return STATUS_SUCCESS;
    5.89  }
     6.1 --- a/xenpci/gnttbl.c	Wed Jul 09 00:20:30 2008 -0700
     6.2 +++ b/xenpci/gnttbl.c	Wed Jul 09 00:26:05 2008 -0700
     6.3 @@ -149,28 +149,59 @@ GntTbl_EndAccess(
     6.4    return TRUE;
     6.5  }
     6.6  
     6.7 +#if defined(_X86_)
     6.8 +static unsigned int 
     6.9 +GntTbl_QueryMaxFrames(PXENPCI_DEVICE_DATA xpdd)
    6.10 +{
    6.11 +  struct gnttab_query_size query;
    6.12 +  int rc;
    6.13 +
    6.14 +  query.dom = DOMID_SELF;
    6.15 +
    6.16 +  rc = HYPERVISOR_grant_table_op(xpdd,GNTTABOP_query_size, &query, 1);
    6.17 +  if ((rc < 0) || (query.status != GNTST_okay))
    6.18 +  {
    6.19 +    KdPrint((__DRIVER_NAME "     ***CANNOT QUERY MAX GRANT FRAME***\n"));
    6.20 +    return 4; /* Legacy max supported number of frames */
    6.21 +  }
    6.22 +  return query.max_nr_frames;
    6.23 +}
    6.24 +#endif
    6.25 +
    6.26  VOID
    6.27  GntTbl_Init(PXENPCI_DEVICE_DATA xpdd)
    6.28  {
    6.29    int i;
    6.30 -
    6.31 +  int max_grant_frames = NR_GRANT_FRAMES;
    6.32 +  int max_grant_entries = NR_GRANT_ENTRIES;
    6.33    //KdPrint((__DRIVER_NAME " --> GntTbl_Init\n"));
    6.34    
    6.35    KeInitializeSpinLock(&xpdd->grant_lock);
    6.36  
    6.37 -  for (i = NR_RESERVED_ENTRIES; i < NR_GRANT_ENTRIES; i++)
    6.38 +#if defined(_X86_)
    6.39 +  max_grant_frames = GntTbl_QueryMaxFrames(xpdd);
    6.40 +  max_grant_entries = min(NR_GRANT_ENTRIES,(max_grant_frames * PAGE_SIZE / sizeof(grant_entry_t)));
    6.41 +  KdPrint((__DRIVER_NAME "     max_grant_entries : %d\n",max_grant_entries));
    6.42 +#else
    6.43 +  #if defined(_AMD64_)
    6.44 +    KdPrint((__DRIVER_NAME "     AMD64 cannot support HYPERVISOR_grant_table_op now\n"));
    6.45 +  #endif
    6.46 +#endif
    6.47 +
    6.48 +  xpdd->gnttab_list = ExAllocatePoolWithTag(NonPagedPool, sizeof(grant_ref_t) * max_grant_entries, XENPCI_POOL_TAG);// Where to free?
    6.49 +  for (i = NR_RESERVED_ENTRIES; i < max_grant_entries; i++)
    6.50      GntTbl_PutRef(xpdd, i);
    6.51  
    6.52    xpdd->gnttab_table_physical = XenPci_AllocMMIO(xpdd,
    6.53 -    PAGE_SIZE * NR_GRANT_FRAMES);
    6.54 +    PAGE_SIZE * max_grant_frames);
    6.55    xpdd->gnttab_table = MmMapIoSpace(xpdd->gnttab_table_physical,
    6.56 -    PAGE_SIZE * NR_GRANT_FRAMES, MmNonCached);
    6.57 +    PAGE_SIZE * max_grant_frames, MmNonCached);
    6.58    if (!xpdd->gnttab_table)
    6.59    {
    6.60      KdPrint((__DRIVER_NAME "     Error Mapping Grant Table Shared Memory\n"));
    6.61      return;
    6.62    }
    6.63 -  GntTbl_Map(xpdd, 0, NR_GRANT_FRAMES - 1);
    6.64 +  GntTbl_Map(xpdd, 0, max_grant_frames - 1);
    6.65  
    6.66    //KdPrint((__DRIVER_NAME " <-- GntTbl_Init table mapped at %p\n", gnttab_table));
    6.67  }
     7.1 --- a/xenpci/xenpci.h	Wed Jul 09 00:20:30 2008 -0700
     7.2 +++ b/xenpci/xenpci.h	Wed Jul 09 00:26:05 2008 -0700
     7.3 @@ -57,7 +57,7 @@ DEFINE_GUID( GUID_XENPCI_DEVCLASS, 0xC82
     7.4  #define XENPCI_POOL_TAG (ULONG) 'XenP'
     7.5  
     7.6  #define NR_RESERVED_ENTRIES 8
     7.7 -#define NR_GRANT_FRAMES 4
     7.8 +#define NR_GRANT_FRAMES 32
     7.9  #define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t))
    7.10  
    7.11  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
    7.12 @@ -184,7 +184,7 @@ typedef struct {
    7.13  
    7.14    grant_entry_t *gnttab_table;
    7.15    PHYSICAL_ADDRESS gnttab_table_physical;
    7.16 -  grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
    7.17 +  grant_ref_t *gnttab_list;
    7.18  
    7.19    ev_action_t ev_actions[NR_EVENTS];
    7.20  //  unsigned long bound_ports[NR_EVENTS/(8*sizeof(unsigned long))];
     8.1 --- a/xenpci/xenpci_fdo.c	Wed Jul 09 00:20:30 2008 -0700
     8.2 +++ b/xenpci/xenpci_fdo.c	Wed Jul 09 00:26:05 2008 -0700
     8.3 @@ -449,7 +449,6 @@ XenPci_BeginSuspend(PXENPCI_DEVICE_DATA 
     8.4      }
     8.5      KeMemoryBarrier();
     8.6      EvtChn_Shutdown(xpdd);
     8.7 -    KeFlushQueuedDpcs();
     8.8  
     8.9      //ActiveProcessorCount = KeQueryActiveProcessorCount(&ActiveProcessorMask); // this is for Vista+
    8.10      ActiveProcessorCount = (ULONG)KeNumberProcessors;
     9.1 --- a/xenpci/xenpci_pdo.c	Wed Jul 09 00:20:30 2008 -0700
     9.2 +++ b/xenpci/xenpci_pdo.c	Wed Jul 09 00:26:05 2008 -0700
     9.3 @@ -106,6 +106,8 @@ XenPci_BackEndStateHandler(char *Path, P
     9.4    err = XenBus_Read(xpdd, XBT_NIL, Path, &value);
     9.5    if (err)
     9.6    {
     9.7 +    if (xpdd->suspending)
     9.8 +      return;
     9.9      KdPrint(("Failed to read %s, assuming closed\n", path, err));
    9.10      new_backend_state = XenbusStateClosed;
    9.11      XenPci_FreeMem(err);
    9.12 @@ -461,6 +463,7 @@ XenPci_XenConfigDeviceSpecifyBuffers(PVO
    9.13    // first pass, possibly before state == Connected
    9.14    while((type = GET_XEN_INIT_REQ(&in_ptr, (PVOID)&setting, (PVOID)&value)) != XEN_INIT_TYPE_END)
    9.15    {
    9.16 +  
    9.17      if (!done_xenbus_init)
    9.18      {
    9.19        if (XenPci_ChangeFrontendState(xppdd, XenbusStateInitialising, XenbusStateInitWait, 30000) != STATUS_SUCCESS)
    9.20 @@ -498,7 +501,7 @@ XenPci_XenConfigDeviceSpecifyBuffers(PVO
    9.21            ADD_XEN_INIT_RSP(&xppdd->assigned_resources_ptr, type, setting, ring);
    9.22            // add the grant entry too so it gets freed automatically
    9.23            __ADD_XEN_INIT_UCHAR(&xppdd->assigned_resources_ptr, XEN_INIT_TYPE_GRANT_ENTRIES);
    9.24 -          __ADD_XEN_INIT_ULONG(&xppdd->assigned_resources_ptr, PtrToUlong(1));
    9.25 +          __ADD_XEN_INIT_ULONG(&xppdd->assigned_resources_ptr, 1);
    9.26            __ADD_XEN_INIT_ULONG(&xppdd->assigned_resources_ptr, gref);
    9.27          }
    9.28          else
    9.29 @@ -738,7 +741,7 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
    9.30      {
    9.31      case CmResourceTypeInterrupt:
    9.32        KdPrint((__DRIVER_NAME "     CmResourceTypeInterrupt\n"));
    9.33 -      KdPrint((__DRIVER_NAME "     irq_vector = %03x\n", prd->u.Interrupt.Vector));
    9.34 +      KdPrint((__DRIVER_NAME "     irq_vector = %02x\n", prd->u.Interrupt.Vector));
    9.35        KdPrint((__DRIVER_NAME "     irq_level = %d\n", prd->u.Interrupt.Level));
    9.36        xppdd->irq_vector = prd->u.Interrupt.Vector;
    9.37        xppdd->irq_level = (KIRQL)prd->u.Interrupt.Level;
    9.38 @@ -804,17 +807,19 @@ XenPci_Pnp_RemoveDevice(PDEVICE_OBJECT d
    9.39  static NTSTATUS
    9.40  XenPci_QueryResourceRequirements(PDEVICE_OBJECT device_object, PIRP irp)
    9.41  {
    9.42 -  //PXENPCI_PDO_DEVICE_DATA xppdd = (PXENPCI_PDO_DEVICE_DATA)device_object->DeviceExtension;
    9.43 -  //PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
    9.44 +  PXENPCI_PDO_DEVICE_DATA xppdd = (PXENPCI_PDO_DEVICE_DATA)device_object->DeviceExtension;
    9.45 +  PXENPCI_DEVICE_DATA xpdd = xppdd->bus_fdo->DeviceExtension;
    9.46    PIO_RESOURCE_REQUIREMENTS_LIST irrl;
    9.47    PIO_RESOURCE_DESCRIPTOR ird;
    9.48    ULONG length;
    9.49 +  ULONG available_interrupts[] = {2, 3, 4, 5, 7, 10, 11, 14, 15};
    9.50 +  int i;
    9.51  
    9.52    UNREFERENCED_PARAMETER(device_object);
    9.53  
    9.54    length = FIELD_OFFSET(IO_RESOURCE_REQUIREMENTS_LIST, List) +
    9.55      FIELD_OFFSET(IO_RESOURCE_LIST, Descriptors) +
    9.56 -    sizeof(IO_RESOURCE_DESCRIPTOR) * 2;
    9.57 +    sizeof(IO_RESOURCE_DESCRIPTOR) * ARRAY_SIZE(available_interrupts);
    9.58    irrl = ExAllocatePoolWithTag(PagedPool,
    9.59      length,
    9.60      XENPCI_POOL_TAG);
    9.61 @@ -828,34 +833,19 @@ XenPci_QueryResourceRequirements(PDEVICE
    9.62    irrl->List[0].Revision = 1;
    9.63    irrl->List[0].Count = 0;
    9.64  
    9.65 -  ird = &irrl->List[0].Descriptors[irrl->List[0].Count++];
    9.66 -  ird->Option = 0;
    9.67 -  ird->Type = CmResourceTypeInterrupt;
    9.68 -  ird->ShareDisposition = CmResourceShareShared;
    9.69 -  ird->Flags = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;
    9.70 -  ird->u.Interrupt.MinimumVector = 1;
    9.71 -  ird->u.Interrupt.MaximumVector = 6;
    9.72 -
    9.73 -  ird = &irrl->List[0].Descriptors[irrl->List[0].Count++];
    9.74 -  ird->Option = IO_RESOURCE_ALTERNATIVE;
    9.75 -  ird->Type = CmResourceTypeInterrupt;
    9.76 -  ird->ShareDisposition = CmResourceShareShared;
    9.77 -  ird->Flags = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;
    9.78 -  ird->u.Interrupt.MinimumVector = 10;
    9.79 -  ird->u.Interrupt.MaximumVector = 14;
    9.80 +  for (i = 0; i < ARRAY_SIZE(available_interrupts); i++)
    9.81 +  {
    9.82 +    if (i == (int)xpdd->irq_number)
    9.83 +      continue;
    9.84 +    ird = &irrl->List[0].Descriptors[irrl->List[0].Count++];
    9.85 +    ird->Option = i?IO_RESOURCE_ALTERNATIVE:0;
    9.86 +    ird->Type = CmResourceTypeInterrupt;
    9.87 +    ird->ShareDisposition = CmResourceShareShared;
    9.88 +    ird->Flags = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;
    9.89 +    ird->u.Interrupt.MinimumVector = available_interrupts[i];
    9.90 +    ird->u.Interrupt.MaximumVector = available_interrupts[i];
    9.91 +  }
    9.92    
    9.93 -#if 0 
    9.94 -  ird = &irrl->List[0].Descriptors[irrl->List[0].Count++];
    9.95 -  ird->Option = 0;  
    9.96 -  ird->Type = CmResourceTypeMemory;
    9.97 -  ird->ShareDisposition = CmResourceShareDeviceExclusive;
    9.98 -  ird->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
    9.99 -  ird->u.Memory.Length = PAGE_SIZE;
   9.100 -  ird->u.Memory.Alignment = PAGE_SIZE;
   9.101 -  ird->u.Memory.MinimumAddress.QuadPart = 0; //MmGetMdlPfnArray(xppdd->config_mdl)[0] << PAGE_SHIFT;
   9.102 -  ird->u.Memory.MaximumAddress.QuadPart = 0xFFFFFFFFFFFFFFFF; //ird->u.Memory.MinimumAddress.QuadPart + PAGE_SIZE - 1;
   9.103 -#endif
   9.104 -
   9.105    irp->IoStatus.Information = (ULONG_PTR)irrl;
   9.106    return STATUS_SUCCESS;
   9.107  }
    10.1 --- a/xenvbd/scsiport.c	Wed Jul 09 00:20:30 2008 -0700
    10.2 +++ b/xenvbd/scsiport.c	Wed Jul 09 00:26:05 2008 -0700
    10.3 @@ -94,6 +94,10 @@ XenVbd_PutRequest(PXENVBD_DEVICE_DATA xv
    10.4  {
    10.5    blkif_other_request_t *other_req;
    10.6  
    10.7 +  //KdPrint((__DRIVER_NAME "     ring.sring->rsp_prod = %d\n", xvdd->ring.sring->rsp_prod));
    10.8 +  //KdPrint((__DRIVER_NAME "     ring.sring->rsp_event = %d\n", xvdd->ring.sring->rsp_event));
    10.9 +  //KdPrint((__DRIVER_NAME "     ring.rsp_cons = %d\n", xvdd->ring.rsp_cons));
   10.10 +  //KdPrint((__DRIVER_NAME "     ring.req_prod_pvt = %d\n", xvdd->ring.req_prod_pvt));
   10.11    if (!xvdd->use_other)
   10.12    {
   10.13      *RING_GET_REQUEST(&xvdd->ring, xvdd->ring.req_prod_pvt) = *req;
   10.14 @@ -109,6 +113,10 @@ XenVbd_PutRequest(PXENVBD_DEVICE_DATA xv
   10.15      memcpy(other_req->seg, req->seg, sizeof(struct blkif_request_segment) * req->nr_segments);
   10.16    }
   10.17    xvdd->ring.req_prod_pvt++;
   10.18 +  //KdPrint((__DRIVER_NAME "     ring.sring->rsp_prod = %d\n", xvdd->ring.sring->rsp_prod));
   10.19 +  //KdPrint((__DRIVER_NAME "     ring.sring->rsp_event = %d\n", xvdd->ring.sring->rsp_event));
   10.20 +  //KdPrint((__DRIVER_NAME "     ring.rsp_cons = %d\n", xvdd->ring.rsp_cons));
   10.21 +  //KdPrint((__DRIVER_NAME "     ring.req_prod_pvt = %d\n", xvdd->ring.req_prod_pvt));
   10.22  }
   10.23  
   10.24  static ULONG
   10.25 @@ -129,7 +137,7 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
   10.26      switch(type)
   10.27      {
   10.28      case XEN_INIT_TYPE_RING: /* frontend ring */
   10.29 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, value));
   10.30 +      //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, value));
   10.31        if (strcmp(setting, "ring-ref") == 0)
   10.32        {
   10.33          xvdd->sring = (blkif_sring_t *)value;
   10.34 @@ -141,7 +149,7 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
   10.35        break;
   10.36      case XEN_INIT_TYPE_EVENT_CHANNEL: /* frontend event channel */
   10.37      case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel */
   10.38 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, PtrToUlong(value)));
   10.39 +      //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, PtrToUlong(value)));
   10.40        if (strcmp(setting, "event-channel") == 0)
   10.41        {
   10.42          xvdd->event_channel = PtrToUlong(value);
   10.43 @@ -149,7 +157,7 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
   10.44        break;
   10.45      case XEN_INIT_TYPE_READ_STRING_BACK:
   10.46      case XEN_INIT_TYPE_READ_STRING_FRONT:
   10.47 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value));
   10.48 +      //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value));
   10.49        if (strcmp(setting, "sectors") == 0)
   10.50          xvdd->total_sectors = atoi(value);
   10.51        else if (strcmp(setting, "sector-size") == 0)
   10.52 @@ -172,9 +180,27 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
   10.53            xvdd->device_type = XENVBD_DEVICETYPE_UNKNOWN;
   10.54          }
   10.55        }
   10.56 +      else if (strcmp(setting, "mode") == 0)
   10.57 +      {
   10.58 +        if (strncmp(value, "r", 1) == 0)
   10.59 +        {
   10.60 +          KdPrint((__DRIVER_NAME "     mode = r\n"));    
   10.61 +          xvdd->device_mode = XENVBD_DEVICEMODE_READ;
   10.62 +        }
   10.63 +        else if (strncmp(value, "w", 1) == 0)
   10.64 +        {
   10.65 +          KdPrint((__DRIVER_NAME "     mode = w\n"));    
   10.66 +          xvdd->device_mode = XENVBD_DEVICEMODE_WRITE;
   10.67 +        }
   10.68 +        else
   10.69 +        {
   10.70 +          KdPrint((__DRIVER_NAME "     mode = unknown\n"));
   10.71 +          xvdd->device_mode = XENVBD_DEVICEMODE_UNKNOWN;
   10.72 +        }
   10.73 +      }
   10.74        break;
   10.75      case XEN_INIT_TYPE_VECTORS:
   10.76 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
   10.77 +      //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
   10.78        if (((PXENPCI_VECTORS)value)->length != sizeof(XENPCI_VECTORS) ||
   10.79          ((PXENPCI_VECTORS)value)->magic != XEN_DATA_MAGIC)
   10.80        {
   10.81 @@ -187,17 +213,17 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
   10.82          memcpy(&xvdd->vectors, value, sizeof(XENPCI_VECTORS));
   10.83        break;
   10.84      case XEN_INIT_TYPE_GRANT_ENTRIES:
   10.85 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_GRANT_ENTRIES - %d\n", PtrToUlong(setting)));
   10.86 +      //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_GRANT_ENTRIES - %d\n", PtrToUlong(setting)));
   10.87        xvdd->grant_entries = (USHORT)PtrToUlong(setting);
   10.88        memcpy(&xvdd->grant_free_list, value, sizeof(grant_ref_t) * xvdd->grant_entries);
   10.89        xvdd->grant_free = xvdd->grant_entries;
   10.90        break;
   10.91      case XEN_INIT_TYPE_STATE_PTR:
   10.92 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_DEVICE_STATE - %p\n", PtrToUlong(value)));
   10.93 +      //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_DEVICE_STATE - %p\n", PtrToUlong(value)));
   10.94        xvdd->device_state = (PXENPCI_DEVICE_STATE)value;
   10.95        break;
   10.96      default:
   10.97 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
   10.98 +      //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
   10.99        break;
  10.100      }
  10.101    }
  10.102 @@ -237,7 +263,7 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
  10.103    PUCHAR ptr;
  10.104    int notify;
  10.105  
  10.106 -//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  10.107 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  10.108  
  10.109    //ASSERT(!(srb_offset == 0 && xvdd->split_request_in_progress));
  10.110    block_count = (srb->Cdb[7] << 8) | srb->Cdb[8];
  10.111 @@ -287,7 +313,7 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
  10.112    if (PtrToUlong(srb->DataBuffer) & 511) /* use SrbExtension intead of DataBuffer if DataBuffer is not aligned to sector size */
  10.113    {
  10.114      shadow->req.sector_number += srb_offset / 512; //xvdd->bytes_per_sector;
  10.115 -    KdPrint((__DRIVER_NAME "     Using unaligned buffer - DataBuffer = %p, SrbExtension = %p, total length = %d, offset = %d, length = %d, sector = %d\n", srb->DataBuffer, srb->SrbExtension, block_count * 512, shadow->offset, shadow->length, shadow->req.sector_number));
  10.116 +    //KdPrint((__DRIVER_NAME "     Using unaligned buffer - DataBuffer = %p, SrbExtension = %p, total length = %d, offset = %d, length = %d, sector = %d\n", srb->DataBuffer, srb->SrbExtension, block_count * 512, shadow->offset, shadow->length, shadow->req.sector_number));
  10.117      if (srb->Cdb[0] == SCSIOP_WRITE)
  10.118      {
  10.119        memcpy(ptr, ((PUCHAR)srb->DataBuffer) + srb_offset, shadow->length);
  10.120 @@ -297,7 +323,10 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
  10.121    {
  10.122      ptr = srb->DataBuffer;
  10.123    }
  10.124 -
  10.125 +  //KdPrint((__DRIVER_NAME "     sector_number = %d\n", (ULONG)shadow->req.sector_number));
  10.126 +  //KdPrint((__DRIVER_NAME "     handle = %d\n", shadow->req.handle));
  10.127 +  //KdPrint((__DRIVER_NAME "     operation = %d\n", shadow->req.operation));
  10.128 +    
  10.129    remaining = shadow->length;  
  10.130    while (remaining > 0)
  10.131    {
  10.132 @@ -313,14 +342,21 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
  10.133      shadow->req.seg[shadow->req.nr_segments].last_sect = (UCHAR)(((offset + length) >> 9) - 1);
  10.134      remaining -= length;
  10.135      ptr += length;
  10.136 +    //KdPrint((__DRIVER_NAME "     seg[%d].gref = %d\n", shadow->req.nr_segments, shadow->req.seg[shadow->req.nr_segments].gref));
  10.137 +    //KdPrint((__DRIVER_NAME "     seg[%d].first_sect = %d\n", shadow->req.nr_segments, shadow->req.seg[shadow->req.nr_segments].first_sect));
  10.138 +    //KdPrint((__DRIVER_NAME "     seg[%d].last_sect = %d\n", shadow->req.nr_segments, shadow->req.seg[shadow->req.nr_segments].last_sect));
  10.139      shadow->req.nr_segments++;
  10.140    }
  10.141 -    
  10.142 +  //KdPrint((__DRIVER_NAME "     nr_segments = %d\n", shadow->req.nr_segments));
  10.143 +
  10.144    XenVbd_PutRequest(xvdd, &shadow->req);
  10.145  
  10.146    RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xvdd->ring, notify);
  10.147    if (notify)
  10.148 +  {
  10.149 +    //KdPrint((__DRIVER_NAME "     Notifying\n"));
  10.150      xvdd->vectors.EvtChn_Notify(xvdd->vectors.context, xvdd->event_channel);
  10.151 +  }
  10.152  
  10.153    if (xvdd->shadow_free && srb_offset == 0)
  10.154      ScsiPortNotification(NextLuRequest, xvdd, 0, 0, 0);
  10.155 @@ -339,14 +375,6 @@ XenVbd_HwScsiTimer(PVOID DeviceExtension
  10.156    ULONG shadow_entries;
  10.157    blkif_shadow_t *shadow;  
  10.158  
  10.159 -/*
  10.160 -  KdPrint((__DRIVER_NAME "     aligned requests   = %I64d, aligned bytes   = %I64d\n", xvdd->aligned_requests, xvdd->aligned_bytes));
  10.161 -  KdPrint((__DRIVER_NAME "     unaligned requests = %I64d, unaligned bytes = %I64d\n", xvdd->unaligned_requests, xvdd->unaligned_bytes));
  10.162 -  KdPrint((__DRIVER_NAME "     interrupts = %I64d\n", xvdd->interrupts));
  10.163 -  KdPrint((__DRIVER_NAME "     no_free_grant_requests = %I64d\n", xvdd->no_free_grant_requests));
  10.164 -  xvdd->shadow_min_free = xvdd->shadow_free;
  10.165 -*/
  10.166 -
  10.167    if (xvdd->device_state->resume_state == RESUME_STATE_FRONTEND_RESUME)
  10.168    {
  10.169      KdPrint((__DRIVER_NAME "     found device in resume state\n"));
  10.170 @@ -476,22 +504,22 @@ XenVbd_HwScsiInitialize(PVOID DeviceExte
  10.171    req = RING_GET_REQUEST(&xvdd->ring, xvdd->ring.req_prod_pvt);
  10.172    req->operation = 0xff;
  10.173    req->nr_segments = 0;
  10.174 -  for (i = 0; i < req->nr_segments; i++)
  10.175 +  for (i = 0; i < BLKIF_MAX_SEGMENTS_PER_REQUEST; i++)
  10.176    {
  10.177 -    req->seg[i].gref = 0xffffffff;
  10.178 -    req->seg[i].first_sect = 0xff;
  10.179 -    req->seg[i].last_sect = 0xff;
  10.180 +    req->seg[i].gref = 0; //0xffffffff;
  10.181 +    req->seg[i].first_sect = 0; //0xff;
  10.182 +    req->seg[i].last_sect = 0; //0xff;
  10.183    }
  10.184    xvdd->ring.req_prod_pvt++;
  10.185  
  10.186    req = RING_GET_REQUEST(&xvdd->ring, xvdd->ring.req_prod_pvt);
  10.187    req->operation = 0xff;
  10.188    req->nr_segments = 0;
  10.189 -  for (i = 0; i < req->nr_segments; i++)
  10.190 +  for (i = 0; i < BLKIF_MAX_SEGMENTS_PER_REQUEST; i++)
  10.191    {
  10.192 -    req->seg[i].gref = 0xffffffff;
  10.193 -    req->seg[i].first_sect = 0xff;
  10.194 -    req->seg[i].last_sect = 0xff;
  10.195 +    req->seg[i].gref = 0; //0xffffffff;
  10.196 +    req->seg[i].first_sect = 0; //0xff;
  10.197 +    req->seg[i].last_sect = 0; //0xff;
  10.198    }
  10.199    xvdd->ring.req_prod_pvt++;
  10.200  
  10.201 @@ -534,6 +562,12 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
  10.202    parameter_header->BlockDescriptorLength = 0;
  10.203    offset += sizeof(MODE_PARAMETER_HEADER);
  10.204    
  10.205 +  if (xvdd->device_mode == XENVBD_DEVICEMODE_READ)
  10.206 +  {
  10.207 +    KdPrint((__DRIVER_NAME " Mode sense to a read only disk.\n"));
  10.208 +    parameter_header->DeviceSpecificParameter|=MODE_DSP_WRITE_PROTECT; 
  10.209 +  }
  10.210 +  
  10.211    if (!cdb->MODE_SENSE.Dbd)
  10.212    {
  10.213      parameter_header->BlockDescriptorLength += sizeof(MODE_PARAMETER_BLOCK);
  10.214 @@ -671,9 +705,10 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
  10.215            xvdd->use_other = TRUE;
  10.216          }
  10.217          xvdd->ring_detect_state = 2;
  10.218 -        ScsiPortNotification(NextLuRequest, DeviceExtension, 0, 0, 0);
  10.219 +        ScsiPortNotification(NextRequest, DeviceExtension);
  10.220          break;
  10.221        case 2:
  10.222 +        //KdPrint((__DRIVER_NAME "     ring_detect_state = %d, operation = %x, id = %lx, status = %d\n", xvdd->ring_detect_state, rep->operation, rep->id, rep->status));
  10.223          shadow = &xvdd->shadows[rep->id];
  10.224          srb = shadow->srb;
  10.225          ASSERT(srb != NULL);
  10.226 @@ -745,6 +780,11 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
  10.227      }
  10.228    }
  10.229  
  10.230 +  //KdPrint((__DRIVER_NAME "     ring.sring->rsp_prod = %d\n", xvdd->ring.sring->rsp_prod));
  10.231 +  //KdPrint((__DRIVER_NAME "     ring.sring->rsp_event = %d\n", xvdd->ring.sring->rsp_event));
  10.232 +  //KdPrint((__DRIVER_NAME "     ring.rsp_cons = %d\n", xvdd->ring.rsp_cons));
  10.233 +  //KdPrint((__DRIVER_NAME "     ring.req_prod_pvt = %d\n", xvdd->ring.req_prod_pvt));
  10.234 +
  10.235    //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
  10.236    
  10.237    return FALSE; /* we just don't know... */
  10.238 @@ -799,10 +839,10 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
  10.239        Srb->ScsiStatus = 0;
  10.240        break;
  10.241      case SCSIOP_INQUIRY:
  10.242 -      KdPrint((__DRIVER_NAME "     Command = INQUIRY\n"));
  10.243 -      KdPrint((__DRIVER_NAME "     (LUN = %d, EVPD = %d, Page Code = %02X)\n", Srb->Cdb[1] >> 5, Srb->Cdb[1] & 1, Srb->Cdb[2]));
  10.244 -      KdPrint((__DRIVER_NAME "     (Length = %d)\n", Srb->DataTransferLength));
  10.245 -      KdPrint((__DRIVER_NAME "     (Srb->Databuffer = %08x)\n", Srb->DataBuffer));
  10.246 +//      KdPrint((__DRIVER_NAME "     Command = INQUIRY\n"));
  10.247 +//      KdPrint((__DRIVER_NAME "     (LUN = %d, EVPD = %d, Page Code = %02X)\n", Srb->Cdb[1] >> 5, Srb->Cdb[1] & 1, Srb->Cdb[2]));
  10.248 +//      KdPrint((__DRIVER_NAME "     (Length = %d)\n", Srb->DataTransferLength));
  10.249 +//      KdPrint((__DRIVER_NAME "     (Srb->Databuffer = %08x)\n", Srb->DataBuffer));
  10.250        DataBuffer = Srb->DataBuffer;
  10.251        RtlZeroMemory(DataBuffer, Srb->DataTransferLength);
  10.252        Srb->SrbStatus = SRB_STATUS_SUCCESS;
  10.253 @@ -841,7 +881,7 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
  10.254              memset(&DataBuffer[4], ' ', 8);
  10.255              break;
  10.256            default:
  10.257 -            KdPrint((__DRIVER_NAME "     Unknown Page %02x requested\n", Srb->Cdb[2]));
  10.258 +            //KdPrint((__DRIVER_NAME "     Unknown Page %02x requested\n", Srb->Cdb[2]));
  10.259              Srb->SrbStatus = SRB_STATUS_ERROR;
  10.260              break;
  10.261            }
  10.262 @@ -888,14 +928,14 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
  10.263              DataBuffer[11] = 0x38;
  10.264              break;
  10.265            default:
  10.266 -            KdPrint((__DRIVER_NAME "     Unknown Page %02x requested\n", Srb->Cdb[2]));
  10.267 +            //KdPrint((__DRIVER_NAME "     Unknown Page %02x requested\n", Srb->Cdb[2]));
  10.268              Srb->SrbStatus = SRB_STATUS_ERROR;
  10.269              break;
  10.270            }
  10.271          }
  10.272          break;
  10.273        default:
  10.274 -        KdPrint((__DRIVER_NAME "     Unknown DeviceType %02x requested\n", xvdd->device_type));
  10.275 +        //KdPrint((__DRIVER_NAME "     Unknown DeviceType %02x requested\n", xvdd->device_type));
  10.276          Srb->SrbStatus = SRB_STATUS_ERROR;
  10.277          break;
  10.278        }
  10.279 @@ -929,25 +969,25 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
  10.280        Srb->SrbStatus = SRB_STATUS_SUCCESS;
  10.281        break;
  10.282      case SCSIOP_MODE_SENSE:
  10.283 -      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));
  10.284 +//      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));
  10.285        XenVbd_FillModePage(xvdd, Srb);
  10.286        break;
  10.287      case SCSIOP_WRITE:
  10.288      case SCSIOP_READ:
  10.289 -      //KdPrint((__DRIVER_NAME "     Command = READ/WRITE\n"));
  10.290 +//      KdPrint((__DRIVER_NAME "     Command = READ/WRITE\n"));
  10.291        XenVbd_PutSrbOnRing(xvdd, Srb, 0);
  10.292        break;
  10.293      case SCSIOP_VERIFY:
  10.294        // Should we do more here?
  10.295 -      KdPrint((__DRIVER_NAME "     Command = VERIFY\n"));
  10.296 +//      KdPrint((__DRIVER_NAME "     Command = VERIFY\n"));
  10.297        Srb->SrbStatus = SRB_STATUS_SUCCESS;
  10.298        break;
  10.299      case SCSIOP_REPORT_LUNS:
  10.300 -      KdPrint((__DRIVER_NAME "     Command = REPORT_LUNS\n"));
  10.301 +//      KdPrint((__DRIVER_NAME "     Command = REPORT_LUNS\n"));
  10.302        Srb->SrbStatus = SRB_STATUS_SUCCESS;;
  10.303        break;
  10.304      case SCSIOP_REQUEST_SENSE:
  10.305 -      KdPrint((__DRIVER_NAME "     Command = REQUEST_SENSE\n"));
  10.306 +//      KdPrint((__DRIVER_NAME "     Command = REQUEST_SENSE\n"));
  10.307        XenVbd_MakeSense(xvdd, Srb, xvdd->last_sense_key, xvdd->last_additional_sense_code);
  10.308        Srb->SrbStatus = SRB_STATUS_SUCCESS;
  10.309        break;      
  10.310 @@ -961,14 +1001,14 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
  10.311  #define READ_TOC_FORMAT_PMA         0x03
  10.312  #define READ_TOC_FORMAT_ATIP        0x04
  10.313  */
  10.314 -      KdPrint((__DRIVER_NAME "     Command = READ_TOC\n"));
  10.315 -      KdPrint((__DRIVER_NAME "     Msf = %d\n", cdb->READ_TOC.Msf));
  10.316 -      KdPrint((__DRIVER_NAME "     LogicalUnitNumber = %d\n", cdb->READ_TOC.LogicalUnitNumber));
  10.317 -      KdPrint((__DRIVER_NAME "     Format2 = %d\n", cdb->READ_TOC.Format2));
  10.318 -      KdPrint((__DRIVER_NAME "     StartingTrack = %d\n", cdb->READ_TOC.StartingTrack));
  10.319 -      KdPrint((__DRIVER_NAME "     AllocationLength = %d\n", (cdb->READ_TOC.AllocationLength[0] << 8) | cdb->READ_TOC.AllocationLength[1]));
  10.320 -      KdPrint((__DRIVER_NAME "     Control = %d\n", cdb->READ_TOC.Control));
  10.321 -      KdPrint((__DRIVER_NAME "     Format = %d\n", cdb->READ_TOC.Format));
  10.322 +//      KdPrint((__DRIVER_NAME "     Command = READ_TOC\n"));
  10.323 +//      KdPrint((__DRIVER_NAME "     Msf = %d\n", cdb->READ_TOC.Msf));
  10.324 +//      KdPrint((__DRIVER_NAME "     LogicalUnitNumber = %d\n", cdb->READ_TOC.LogicalUnitNumber));
  10.325 +//      KdPrint((__DRIVER_NAME "     Format2 = %d\n", cdb->READ_TOC.Format2));
  10.326 +//      KdPrint((__DRIVER_NAME "     StartingTrack = %d\n", cdb->READ_TOC.StartingTrack));
  10.327 +//      KdPrint((__DRIVER_NAME "     AllocationLength = %d\n", (cdb->READ_TOC.AllocationLength[0] << 8) | cdb->READ_TOC.AllocationLength[1]));
  10.328 +//      KdPrint((__DRIVER_NAME "     Control = %d\n", cdb->READ_TOC.Control));
  10.329 +//      KdPrint((__DRIVER_NAME "     Format = %d\n", cdb->READ_TOC.Format));
  10.330        switch (cdb->READ_TOC.Format2)
  10.331        {
  10.332        case READ_TOC_FORMAT_TOC:
  10.333 @@ -995,25 +1035,25 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
  10.334        }
  10.335        break;
  10.336      case SCSIOP_START_STOP_UNIT:
  10.337 -      KdPrint((__DRIVER_NAME "     Command = SCSIOP_START_STOP_UNIT\n"));
  10.338 +//      KdPrint((__DRIVER_NAME "     Command = SCSIOP_START_STOP_UNIT\n"));
  10.339        Srb->SrbStatus = SRB_STATUS_SUCCESS;
  10.340        break;
  10.341      case SCSIOP_RESERVE_UNIT:
  10.342 -      KdPrint((__DRIVER_NAME "     Command = SCSIOP_RESERVE_UNIT\n"));
  10.343 +//      KdPrint((__DRIVER_NAME "     Command = SCSIOP_RESERVE_UNIT\n"));
  10.344        Srb->SrbStatus = SRB_STATUS_SUCCESS;
  10.345        break;
  10.346      case SCSIOP_RELEASE_UNIT:
  10.347 -      KdPrint((__DRIVER_NAME "     Command = SCSIOP_RELEASE_UNIT\n"));
  10.348 +//      KdPrint((__DRIVER_NAME "     Command = SCSIOP_RELEASE_UNIT\n"));
  10.349        Srb->SrbStatus = SRB_STATUS_SUCCESS;
  10.350        break;
  10.351      default:
  10.352 -      KdPrint((__DRIVER_NAME "     Unhandled EXECUTE_SCSI Command = %02X\n", Srb->Cdb[0]));
  10.353 +      //KdPrint((__DRIVER_NAME "     Unhandled EXECUTE_SCSI Command = %02X\n", Srb->Cdb[0]));
  10.354        Srb->SrbStatus = SRB_STATUS_ERROR;
  10.355        break;
  10.356      }
  10.357      if (Srb->SrbStatus == SRB_STATUS_ERROR)
  10.358      {
  10.359 -      KdPrint((__DRIVER_NAME "     EXECUTE_SCSI Command = %02X returned error %02x\n", Srb->Cdb[0], xvdd->last_sense_key));
  10.360 +      //KdPrint((__DRIVER_NAME "     EXECUTE_SCSI Command = %02X returned error %02x\n", Srb->Cdb[0], xvdd->last_sense_key));
  10.361        if (xvdd->last_sense_key == SCSI_SENSE_NO_SENSE)
  10.362        {
  10.363          xvdd->last_sense_key = SCSI_SENSE_ILLEGAL_REQUEST;
  10.364 @@ -1033,19 +1073,19 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
  10.365      }
  10.366      break;
  10.367    case SRB_FUNCTION_IO_CONTROL:
  10.368 -    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_IO_CONTROL\n"));
  10.369 +    //KdPrint((__DRIVER_NAME "     SRB_FUNCTION_IO_CONTROL\n"));
  10.370      Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
  10.371      ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
  10.372      ScsiPortNotification(NextLuRequest, DeviceExtension, 0, 0, 0);
  10.373      break;
  10.374    case SRB_FUNCTION_FLUSH:
  10.375 -    KdPrint((__DRIVER_NAME "     SRB_FUNCTION_FLUSH\n"));
  10.376 +    //KdPrint((__DRIVER_NAME "     SRB_FUNCTION_FLUSH\n"));
  10.377      Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
  10.378      ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
  10.379      ScsiPortNotification(NextLuRequest, DeviceExtension, 0, 0, 0);
  10.380      break;
  10.381    default:
  10.382 -    KdPrint((__DRIVER_NAME "     Unhandled Srb->Function = %08X\n", Srb->Function));
  10.383 +    //KdPrint((__DRIVER_NAME "     Unhandled Srb->Function = %08X\n", Srb->Function));
  10.384      Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
  10.385      ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
  10.386      ScsiPortNotification(NextLuRequest, DeviceExtension, 0, 0, 0);
  10.387 @@ -1063,10 +1103,13 @@ XenVbd_HwScsiResetBus(PVOID DeviceExtens
  10.388    UNREFERENCED_PARAMETER(PathId);
  10.389  
  10.390    KdPrint((__DRIVER_NAME " --> HwScsiResetBus\n"));
  10.391 +
  10.392    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
  10.393 +  ScsiPortNotification(NextRequest, DeviceExtension);
  10.394  
  10.395    KdPrint((__DRIVER_NAME " <-- HwScsiResetBus\n"));
  10.396  
  10.397 +
  10.398    return TRUE;
  10.399  }
  10.400  
    11.1 --- a/xenvbd/xenvbd.h	Wed Jul 09 00:20:30 2008 -0700
    11.2 +++ b/xenvbd/xenvbd.h	Wed Jul 09 00:26:05 2008 -0700
    11.3 @@ -90,6 +90,12 @@ typedef enum {
    11.4    XENVBD_DEVICETYPE_CONTROLLER // Not yet used
    11.5  } XENVBD_DEVICETYPE;
    11.6  
    11.7 +typedef enum {
    11.8 +  XENVBD_DEVICEMODE_UNKNOWN,
    11.9 +  XENVBD_DEVICEMODE_READ,
   11.10 +  XENVBD_DEVICEMODE_WRITE
   11.11 +} XENVBD_DEVICEMODE;
   11.12 +
   11.13  struct
   11.14  {
   11.15    blkif_shadow_t shadows[SHADOW_ENTRIES];
   11.16 @@ -115,6 +121,7 @@ struct
   11.17    UCHAR last_additional_sense_code;
   11.18    blkif_response_t tmp_rep;
   11.19    XENVBD_DEVICETYPE device_type;
   11.20 +  XENVBD_DEVICEMODE device_mode;
   11.21    DISK_GEOMETRY Geometry;
   11.22    ULONG bytes_per_sector;
   11.23    ULONGLONG total_sectors;
    12.1 --- a/xenvbd/xenvbd.inx	Wed Jul 09 00:20:30 2008 -0700
    12.2 +++ b/xenvbd/xenvbd.inx	Wed Jul 09 00:26:05 2008 -0700
    12.3 @@ -62,6 +62,7 @@ AddReg = XenVbd_XenConfig_AddReg, XenVbd
    12.4  HKR,"XenConfig\ring-ref", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_RING%
    12.5  HKR,"XenConfig\event-channel", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_EVENT_CHANNEL_IRQ%
    12.6  HKR,"XenConfig\device-type", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_FRONT%
    12.7 +HKR,"XenConfig\mode", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_BACK%
    12.8  HKR,"XenConfig\sectors", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_BACK%
    12.9  HKR,"XenConfig\sector-size", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_BACK%
   12.10  HKR,"XenConfig\vectors", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_VECTORS%