win-pvdrivers

changeset 471:babd1ef136ac

converted xenscsi to a storport driver. Compiles now but won't work.
author James Harper <james.harper@bendigoit.com.au>
date Thu Nov 27 21:24:20 2008 +1100 (2008-11-27)
parents bc403c97a002
children c33db88c95a8 3c592df57caf
files xenscsi/sources xenscsi/xenscsi.c xenscsi/xenscsi.h xenscsi/xenscsi.inx
line diff
     1.1 --- a/xenscsi/sources	Thu Nov 27 21:15:09 2008 +1100
     1.2 +++ b/xenscsi/sources	Thu Nov 27 21:24:20 2008 +1100
     1.3 @@ -2,6 +2,6 @@
     1.4  TARGETNAME=xenscsi
     1.5  TARGETTYPE=DRIVER
     1.6  INF_NAME=$(TARGETNAME)
     1.7 -TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\scsiport.lib
     1.8 +TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\storport.lib
     1.9  MISCFILES=..\Target\$(DDK_TARGET_OS)\$(INF_NAME).inf
    1.10  SOURCES=xenscsi.c
     2.1 --- a/xenscsi/xenscsi.c	Thu Nov 27 21:15:09 2008 +1100
     2.2 +++ b/xenscsi/xenscsi.c	Thu Nov 27 21:24:20 2008 +1100
     2.3 @@ -18,14 +18,6 @@ Foundation, Inc., 51 Franklin Street, Fi
     2.4  */
     2.5  
     2.6  #include "xenscsi.h"
     2.7 -#include <io/blkif.h>
     2.8 -#include <scsi.h>
     2.9 -#include <ntddscsi.h>
    2.10 -#include <ntdddisk.h>
    2.11 -#include <stdlib.h>
    2.12 -#include <xen_public.h>
    2.13 -#include <io/xenbus.h>
    2.14 -#include <io/protocols.h>
    2.15  
    2.16  DRIVER_INITIALIZE DriverEntry;
    2.17  
    2.18 @@ -77,8 +69,8 @@ put_grant_on_freelist(PXENSCSI_DEVICE_DA
    2.19    xsdd->grant_free++;
    2.20  }
    2.21  
    2.22 -static VOID
    2.23 -XenScsi_HwScsiInterrupt_Scsi(PVOID DeviceExtension)
    2.24 +static BOOLEAN
    2.25 +XenScsi_HwScsiInterrupt(PVOID DeviceExtension)
    2.26  {
    2.27    PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
    2.28    PSCSI_REQUEST_BLOCK Srb;
    2.29 @@ -89,7 +81,10 @@ XenScsi_HwScsiInterrupt_Scsi(PVOID Devic
    2.30    vscsiif_shadow_t *shadow;
    2.31    ULONG remaining;
    2.32  
    2.33 -  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    2.34 +  FUNCTION_ENTER();
    2.35 +
    2.36 +  if (!dump_mode && !xsdd->vectors.EvtChn_AckEvent(xsdd->vectors.context, xsdd->event_channel))
    2.37 +    return FALSE;
    2.38  
    2.39    while (more_to_do)
    2.40    {
    2.41 @@ -128,8 +123,8 @@ XenScsi_HwScsiInterrupt_Scsi(PVOID Devic
    2.42          remaining -= shadow->req.seg[j].length;
    2.43        }
    2.44        put_shadow_on_freelist(xsdd, shadow);
    2.45 -      ScsiPortNotification(RequestComplete, xsdd, Srb);
    2.46 -      ScsiPortNotification(NextRequest, xsdd);
    2.47 +      StorPortNotification(RequestComplete, xsdd, Srb);
    2.48 +      StorPortNotification(NextRequest, xsdd);
    2.49      }
    2.50  
    2.51      xsdd->ring.rsp_cons = i;
    2.52 @@ -145,189 +140,8 @@ XenScsi_HwScsiInterrupt_Scsi(PVOID Devic
    2.53    }
    2.54  
    2.55    //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    2.56 -}
    2.57 -
    2.58 -#define ENUM_STATE_LIST_DEVS  0
    2.59 -#define ENUM_STATE_READ_DEVID 1
    2.60 -#define ENUM_STATE_READ_VDEV  2
    2.61 -#define ENUM_STATE_READ_STATE 3
    2.62 -
    2.63 -static VOID
    2.64 -XenScsi_CommIfaceList(PVOID DeviceExtension, PUCHAR path)
    2.65 -{
    2.66 -  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
    2.67 -  xsdd->comm_iface->packet_type = COMM_IFACE_CMD_XENBUS_LIST;
    2.68 -  strcpy(xsdd->comm_iface->packet.list_req.path, path);
    2.69 -  xsdd->comm_iface->req_prod++;
    2.70 -  KeMemoryBarrier();
    2.71 -  xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->comm_iface->pdo_event_channel);
    2.72 -}
    2.73 -
    2.74 -static VOID
    2.75 -XenScsi_CommIfaceRead(PVOID DeviceExtension, PUCHAR path)
    2.76 -{
    2.77 -  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
    2.78 -  xsdd->comm_iface->packet_type = COMM_IFACE_CMD_XENBUS_READ;
    2.79 -  strcpy(xsdd->comm_iface->packet.read_req.path, path);
    2.80 -  xsdd->comm_iface->req_prod++;
    2.81 -  KeMemoryBarrier();
    2.82 -  xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->comm_iface->pdo_event_channel);
    2.83 -}
    2.84 -
    2.85 -/*
    2.86 -static VOID
    2.87 -strcatshort(UCHAR path, SHORT number)
    2.88 -{
    2.89 -  int i;
    2.90 -  UCHAR buf[6];
    2.91 -  int tmp = number;
    2.92 -  
    2.93 -  buf[5] = 0;
    2.94 -  
    2.95 -  for (i = 0; tmp > 0; i++)
    2.96 -  {
    2.97 -    tmp /= 10;
    2.98 -  }
    2.99    
   2.100 -}
   2.101 -*/
   2.102 -
   2.103 -static BOOLEAN
   2.104 -XenScsi_EnumDevs(PVOID DeviceExtension)
   2.105 -{
   2.106 -  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   2.107 -  UCHAR path[128];
   2.108 -  enum_vars_t *vars = &xsdd->enum_vars;
   2.109 -
   2.110 -  FUNCTION_ENTER();
   2.111 -
   2.112 -  switch (vars->state)
   2.113 -  {
   2.114 -  case 0:
   2.115 -    XenScsi_CommIfaceList(DeviceExtension, path);
   2.116 -    vars->state = 1;
   2.117 -    break;
   2.118 -  case 1:
   2.119 -    
   2.120 -    xsdd->comm_iface->packet_type = COMM_IFACE_CMD_XENBUS_LIST;
   2.121 -    strcpy(xsdd->comm_iface->packet.list_req.path, xsdd->comm_iface->backend_path);
   2.122 -    strcat(xsdd->comm_iface->packet.list_req.path, "/vscsi-devs");
   2.123 -    xsdd->comm_iface->req_prod++;
   2.124 -    KeMemoryBarrier();
   2.125 -    xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->comm_iface->pdo_event_channel);
   2.126 -    break;
   2.127 -  case ENUM_STATE_READ_DEVID:
   2.128 -    strcpy(path, xsdd->comm_iface->backend_path);
   2.129 -    strcat(path, "/dev-0");
   2.130 -    //itoa(0, path + strlen(path), 10); //strcatshort(path, ...);
   2.131 -    XenScsi_CommIfaceRead(DeviceExtension, path);
   2.132 -    break;
   2.133 -  case ENUM_STATE_READ_VDEV:
   2.134 -  case ENUM_STATE_READ_STATE:
   2.135 -    break;
   2.136 -  }
   2.137 -  return TRUE;
   2.138 -}
   2.139 -#endif
   2.140 -
   2.141 -#if 0
   2.142 -#define JAMES_START() switch (vars->state) { case 0:
   2.143 -#define XenBus_List(___path, ___result) xsdd->comm_iface->packet_type = COMM_IFACE_CMD_XENBUS_LIST; \
   2.144 -    strcpy(xsdd->comm_iface->packet.list_req.path, (___path)); \
   2.145 -    xsdd->comm_iface->req_prod++; \
   2.146 -    KeMemoryBarrier(); \
   2.147 -    xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->comm_iface->pdo_event_channel); \
   2.148 -    vars->state = __LINE__; \
   2.149 -    return; \
   2.150 -    case __LINE__: \
   2.151 -    if (xsdd->comm_iface->packet_status == COMM_IFACE_STATUS_SUCCESS) \
   2.152 -      memcpy(xsdd->comm_iface->packet.list_rsp.values, ___result, 1024); \
   2.153 -    else \
   2.154 -      *(___result) = 0;
   2.155 -
   2.156 -#define JAMES_END() default: break; }
   2.157 -
   2.158 -static VOID
   2.159 -XenScsi_EnumDevs(PVOID DeviceExtension)
   2.160 -{
   2.161 -  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   2.162 -  enum_vars_t *vars = &xsdd->enum_vars;
   2.163 -  //UCHAR path[128];
   2.164 -  //UCHAR **devs;
   2.165 -
   2.166 -  JAMES_START()
   2.167 -  strcpy(path, xsdd->comm_iface->backend_path);
   2.168 -  strcat(path, "/vscsi-devs");
   2.169 -  vars->ptr = vars->devs;
   2.170 -  XenBus_List(vars->path, vars->devs);
   2.171 -  if (*vars->devs != 0)
   2.172 -  {
   2.173 -    PCHAR ptr;
   2.174 -    KdPrint((__DRIVER_NAME "     result:\n"));
   2.175 -    for (ptr = xsdd->comm_iface->packet.list_rsp.values; *ptr; ptr += strlen(ptr) + 1)
   2.176 -    {
   2.177 -      KdPrint((__DRIVER_NAME "       %s\n", ptr));
   2.178 -    }
   2.179 -  }
   2.180 -  JAMES_END()
   2.181 -}
   2.182 -#endif
   2.183 -
   2.184 -static VOID
   2.185 -XenScsi_HwScsiInterrupt_Xen(PVOID DeviceExtension)
   2.186 -{
   2.187 -  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   2.188 -    
   2.189 -  FUNCTION_ENTER();
   2.190 -  
   2.191 -  if (xsdd->comm_iface->rsp_prod == xsdd->rsp_cons)
   2.192 -    return;
   2.193 -  xsdd->rsp_cons = xsdd->comm_iface->rsp_prod;
   2.194 -  
   2.195 -  XenScsi_EnumDevs(DeviceExtension);
   2.196 -#if 0
   2.197 -  switch(xsdd->comm_iface->packet_type)
   2.198 -  {
   2.199 -  case COMM_IFACE_CMD_XENBUS_READ:
   2.200 -    KdPrint((__DRIVER_NAME "     COMM_IFACE_CMD_XENBUS_READ, status = %d\n", xsdd->comm_iface->packet_status));
   2.201 -    if (xsdd->comm_iface->packet_status == COMM_IFACE_STATUS_SUCCESS)
   2.202 -    {
   2.203 -      KdPrint((__DRIVER_NAME "     result = %s\n", xsdd->comm_iface->packet.read_rsp.value));
   2.204 -    }
   2.205 -    break;
   2.206 -  case COMM_IFACE_CMD_XENBUS_LIST:
   2.207 -    KdPrint((__DRIVER_NAME "     COMM_IFACE_CMD_XENBUS_LIST, status = %d\n", xsdd->comm_iface->packet_status));
   2.208 -    if (xsdd->comm_iface->packet_status == COMM_IFACE_STATUS_SUCCESS)
   2.209 -    {
   2.210 -      PCHAR ptr;
   2.211 -      KdPrint((__DRIVER_NAME "     result:\n"));
   2.212 -      for (ptr = xsdd->comm_iface->packet.list_rsp.values; *ptr; ptr += strlen(ptr) + 1)
   2.213 -      {
   2.214 -        KdPrint((__DRIVER_NAME "       %s\n", ptr));
   2.215 -      }
   2.216 -    }
   2.217 -    break;
   2.218 -  default:
   2.219 -    KdPrint((__DRIVER_NAME "     Unknown packet type = %d\n", xsdd->comm_iface->packet_type));
   2.220 -    break;
   2.221 -  }
   2.222 -#endif
   2.223 -
   2.224 -  FUNCTION_EXIT();
   2.225 -}
   2.226 -
   2.227 -static BOOLEAN
   2.228 -XenScsi_HwScsiInterrupt(PVOID DeviceExtension)
   2.229 -{
   2.230 -  PXENSCSI_DEVICE_DATA xsdd = DeviceExtension;
   2.231 -
   2.232 -  if (dump_mode || xsdd->vectors.EvtChn_AckEvent(xsdd->vectors.context, xsdd->event_channel))
   2.233 -    XenScsi_HwScsiInterrupt_Scsi(DeviceExtension);
   2.234 -
   2.235 -  if (!dump_mode && xsdd->vectors.EvtChn_AckEvent(xsdd->vectors.context, xsdd->comm_iface->fdo_event_channel))
   2.236 -    XenScsi_HwScsiInterrupt_Xen(DeviceExtension);
   2.237 -    
   2.238 -  return FALSE; /* we always return FALSE */
   2.239 +  return FALSE;
   2.240  }
   2.241  
   2.242  static VOID
   2.243 @@ -393,7 +207,7 @@ XenScsi_HwScsiFindAdapter(PVOID DeviceEx
   2.244    KdPrint((__DRIVER_NAME "     RangeStart = %08x, RangeLength = %08x\n",
   2.245      access_range->RangeStart.LowPart, access_range->RangeLength));
   2.246  
   2.247 -  ptr = ScsiPortGetDeviceBase(
   2.248 +  ptr = StorPortGetDeviceBase(
   2.249      DeviceExtension,
   2.250      ConfigInfo->AdapterInterfaceType,
   2.251      ConfigInfo->SystemIoBusNumber,
   2.252 @@ -457,9 +271,6 @@ XenScsi_HwScsiFindAdapter(PVOID DeviceEx
   2.253        memcpy(&xsdd->grant_free_list, value, sizeof(grant_ref_t) * xsdd->grant_entries);
   2.254        xsdd->grant_free = xsdd->grant_entries;
   2.255        break;
   2.256 -    case XEN_INIT_TYPE_COMM_IFACE:
   2.257 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_COMM_IFACE - %p\n", PtrToUlong(value)));
   2.258 -      xsdd->comm_iface = (PXEN_COMM_IFACE)value;
   2.259      default:
   2.260        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
   2.261        break;
   2.262 @@ -525,8 +336,6 @@ XenScsi_HwScsiInitialize(PVOID DeviceExt
   2.263    
   2.264    FUNCTION_ENTER();
   2.265  
   2.266 -  XenScsi_EnumDevs(DeviceExtension);
   2.267 -
   2.268    FUNCTION_EXIT();
   2.269  
   2.270    return TRUE;
   2.271 @@ -615,8 +424,8 @@ XenScsi_HwScsiStartIo(PVOID DeviceExtens
   2.272  //  if (Srb->PathId != 0 || Srb->TargetId != 0)
   2.273  //  {
   2.274      Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
   2.275 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   2.276 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
   2.277 +    StorPortNotification(RequestComplete, DeviceExtension, Srb);
   2.278 +    StorPortNotification(NextRequest, DeviceExtension, NULL);
   2.279      KdPrint((__DRIVER_NAME "     Out of bounds\n"));
   2.280      FUNCTION_EXIT();
   2.281      return TRUE;
   2.282 @@ -631,25 +440,25 @@ XenScsi_HwScsiStartIo(PVOID DeviceExtens
   2.283      if (notify)
   2.284        xsdd->vectors.EvtChn_Notify(xsdd->vectors.context, xsdd->event_channel);
   2.285      if (!xsdd->shadow_free)
   2.286 -      ScsiPortNotification(NextRequest, DeviceExtension);
   2.287 +      StorPortNotification(NextRequest, DeviceExtension);
   2.288      break;
   2.289    case SRB_FUNCTION_IO_CONTROL:
   2.290      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_IO_CONTROL\n"));
   2.291      Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   2.292 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   2.293 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
   2.294 +    StorPortNotification(RequestComplete, DeviceExtension, Srb);
   2.295 +    StorPortNotification(NextRequest, DeviceExtension, NULL);
   2.296      break;
   2.297    case SRB_FUNCTION_FLUSH:
   2.298      KdPrint((__DRIVER_NAME "     SRB_FUNCTION_FLUSH\n"));
   2.299      Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   2.300 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   2.301 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
   2.302 +    StorPortNotification(RequestComplete, DeviceExtension, Srb);
   2.303 +    StorPortNotification(NextRequest, DeviceExtension, NULL);
   2.304      break;
   2.305    default:
   2.306      KdPrint((__DRIVER_NAME "     Unhandled Srb->Function = %08X\n", Srb->Function));
   2.307      Srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   2.308 -    ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
   2.309 -    ScsiPortNotification(NextRequest, DeviceExtension, NULL);
   2.310 +    StorPortNotification(RequestComplete, DeviceExtension, Srb);
   2.311 +    StorPortNotification(NextRequest, DeviceExtension, NULL);
   2.312      break;
   2.313    }
   2.314  
   2.315 @@ -767,11 +576,11 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
   2.316    HwInitializationData.HwAdapterState = XenScsi_HwScsiAdapterState;
   2.317    HwInitializationData.HwAdapterControl = XenScsi_HwScsiAdapterControl;
   2.318  
   2.319 -  Status = ScsiPortInitialize(DriverObject, RegistryPath, &HwInitializationData, NULL);
   2.320 +  Status = StorPortInitialize(DriverObject, RegistryPath, &HwInitializationData, NULL);
   2.321    
   2.322    if(!NT_SUCCESS(Status))
   2.323    {
   2.324 -    KdPrint((__DRIVER_NAME " ScsiPortInitialize failed with status 0x%08x\n", Status));
   2.325 +    KdPrint((__DRIVER_NAME " StorPortInitialize failed with status 0x%08x\n", Status));
   2.326    }
   2.327  
   2.328    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
     3.1 --- a/xenscsi/xenscsi.h	Thu Nov 27 21:15:09 2008 +1100
     3.2 +++ b/xenscsi/xenscsi.h	Thu Nov 27 21:24:20 2008 +1100
     3.3 @@ -6,7 +6,7 @@
     3.4  #include <wdm.h>
     3.5  #include <initguid.h>
     3.6  #include <ntdddisk.h>
     3.7 -#include <srb.h>
     3.8 +//#include <srb.h>
     3.9  
    3.10  #define NTSTRSAFE_LIB
    3.11  #include <ntstrsafe.h>
    3.12 @@ -23,6 +23,15 @@
    3.13  #include <io/ring.h>
    3.14  #include <io/vscsiif.h>
    3.15  
    3.16 +//#include <io/blkif.h>
    3.17 +#include <storport.h>
    3.18 +//#include <ntddscsi.h>
    3.19 +//#include <ntdddisk.h>
    3.20 +#include <stdlib.h>
    3.21 +#include <io/xenbus.h>
    3.22 +#include <io/protocols.h>
    3.23 +
    3.24 +
    3.25  typedef struct vscsiif_request vscsiif_request_t;
    3.26  typedef struct vscsiif_response vscsiif_response_t;
    3.27  
    3.28 @@ -43,12 +52,14 @@ typedef struct {
    3.29  #define SCSI_DEV_STATE_PRESENT 1
    3.30  #define SCSI_DEV_STATE_ACTIVE  2
    3.31  
    3.32 +#define SCSI_DEV_NODEV ((ULONG)-1)
    3.33 +
    3.34  typedef struct {
    3.35 -  USHORT channel
    3.36 +  ULONG dev_no; // SCSI_DEV_NODEV == end
    3.37 +  USHORT channel;
    3.38    USHORT id;
    3.39    USHORT lun;
    3.40 -  UCHAR state; /* SCSI_DEV_STATE_XXX */
    3.41 -  ULONG dev_no;
    3.42 +//  UCHAR state; /* SCSI_DEV_STATE_XXX */
    3.43  } scsi_dev_t;
    3.44  
    3.45  typedef struct {
    3.46 @@ -78,9 +89,6 @@ struct
    3.47    int lun;
    3.48  
    3.49    XENPCI_VECTORS vectors;
    3.50 -  PXEN_COMM_IFACE comm_iface;
    3.51 -  USHORT rsp_cons;
    3.52 -  enum_vars_t enum_vars;
    3.53  } typedef XENSCSI_DEVICE_DATA, *PXENSCSI_DEVICE_DATA;
    3.54  
    3.55  enum dma_data_direction {
     4.1 --- a/xenscsi/xenscsi.inx	Thu Nov 27 21:15:09 2008 +1100
     4.2 +++ b/xenscsi/xenscsi.inx	Thu Nov 27 21:24:20 2008 +1100
     4.3 @@ -57,7 +57,6 @@ AddReg = XenScsi_XenConfig_AddReg, XenSc
     4.4  [XenScsi_XenConfig_AddReg]
     4.5  HKR,"XenConfig\ring-ref", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_RING%
     4.6  HKR,"XenConfig\event-channel", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_EVENT_CHANNEL_IRQ%
     4.7 -;HKR,"XenConfig\b-dev", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_FRONT%
     4.8  HKR,"XenConfig\grants", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_GRANT_ENTRIES%
     4.9  HKR,"XenConfig\grants", "value", %FLG_ADDREG_TYPE_DWORD%, 144
    4.10