win-pvdrivers

changeset 271:da9b1e17fbc0 wdm

xennet now working. working on graceful shutdown
author James Harper <james.harper@bendigoit.com.au>
date Thu May 15 00:25:25 2008 +1000 (2008-05-15)
parents 1c1ae7c8a41f
children 909b775a891f
files dirs xennet/xennet.c xennet/xennet.h xennet/xennet.inx xennet/xennet_common.c xennet/xennet_oid.c xennet/xennet_rx.c xennet/xennet_tx.c xenpci/xenbus.c xenpci/xenpci.c xenpci/xenpci.h xenpci/xenpci_fdo.c xenpci/xenpci_pdo.c
line diff
     1.1 --- a/dirs	Wed May 14 11:52:32 2008 +1000
     1.2 +++ b/dirs	Thu May 15 00:25:25 2008 +1000
     1.3 @@ -1,1 +1,1 @@
     1.4 -DIRS=xenpci xenhide xenvbd
     1.5 \ No newline at end of file
     1.6 +DIRS=xenpci xenhide xenvbd xennet
     1.7 \ No newline at end of file
     2.1 --- a/xennet/xennet.c	Wed May 14 11:52:32 2008 +1000
     2.2 +++ b/xennet/xennet.c	Thu May 15 00:25:25 2008 +1000
     2.3 @@ -80,101 +80,38 @@ simple_strtoul(const char *cp,char **end
     2.4  
     2.5  // Called at DISPATCH_LEVEL
     2.6  
     2.7 -static BOOLEAN
     2.8 -XenNet_Interrupt(
     2.9 -  PKINTERRUPT Interrupt,
    2.10 -  PVOID ServiceContext
    2.11 -  )
    2.12 +static VOID
    2.13 +XenNet_InterruptIsr(
    2.14 +  PBOOLEAN InterruptRecognized,
    2.15 +  PBOOLEAN QueueMiniportHandleInterrupt,
    2.16 +  NDIS_HANDLE MiniportAdapterContext)
    2.17  {
    2.18 -  struct xennet_info *xi = ServiceContext;
    2.19 +  struct xennet_info *xi = MiniportAdapterContext;
    2.20 +  
    2.21 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    2.22  
    2.23 -  UNREFERENCED_PARAMETER(Interrupt);
    2.24 +  *QueueMiniportHandleInterrupt = (BOOLEAN)!!xi->connected;
    2.25 +  *InterruptRecognized = FALSE; /* we can't be sure here... */
    2.26  
    2.27 -//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    2.28 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    2.29 +}
    2.30 +
    2.31 +static VOID
    2.32 +XenNet_InterruptDpc(NDIS_HANDLE  MiniportAdapterContext)
    2.33 +{
    2.34 +  struct xennet_info *xi = MiniportAdapterContext;
    2.35 +
    2.36 +  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    2.37    if (xi->connected)
    2.38    {
    2.39      XenNet_TxBufferGC(xi);
    2.40      XenNet_RxBufferCheck(xi);
    2.41    }
    2.42 -//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    2.43 -
    2.44 -  return TRUE;
    2.45 +  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    2.46  }
    2.47  
    2.48  // Called at <= DISPATCH_LEVEL
    2.49  
    2.50 -static VOID
    2.51 -XenNet_BackEndStateHandler(char *Path, PVOID Data)
    2.52 -{
    2.53 -  struct xennet_info *xi = Data;
    2.54 -  char *Value;
    2.55 -  char *err;
    2.56 -  ULONG new_backend_state;
    2.57 -
    2.58 -//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    2.59 -//  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
    2.60 -
    2.61 -  err = xi->XenInterface.XenBus_Read(xi->XenInterface.InterfaceHeader.Context,
    2.62 -    XBT_NIL, Path, &Value);
    2.63 -  if (err)
    2.64 -  {
    2.65 -    KdPrint(("Failed to read %s\n", Path, err));
    2.66 -    return;
    2.67 -  }
    2.68 -  new_backend_state = atoi(Value);
    2.69 -  xi->XenInterface.FreeMem(Value);
    2.70 -
    2.71 -  if (xi->backend_state == new_backend_state)
    2.72 -  {
    2.73 -    KdPrint((__DRIVER_NAME "     state unchanged\n"));
    2.74 -    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    2.75 -    return;
    2.76 -  }    
    2.77 -
    2.78 -  xi->backend_state = new_backend_state;
    2.79 -
    2.80 -  switch (xi->backend_state)
    2.81 -  {
    2.82 -  case XenbusStateUnknown:
    2.83 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Unknown\n"));  
    2.84 -    break;
    2.85 -
    2.86 -  case XenbusStateInitialising:
    2.87 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Initialising\n"));  
    2.88 -    break;
    2.89 -
    2.90 -  case XenbusStateInitWait:
    2.91 -    KdPrint((__DRIVER_NAME "     Backend State Changed to InitWait\n"));  
    2.92 -    break;
    2.93 -
    2.94 -  case XenbusStateInitialised:
    2.95 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Initialised\n"));
    2.96 -    break;
    2.97 -
    2.98 -  case XenbusStateConnected:
    2.99 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Connected\n"));  
   2.100 -    break;
   2.101 -
   2.102 -  case XenbusStateClosing:
   2.103 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Closing\n"));  
   2.104 -    break;
   2.105 -
   2.106 -  case XenbusStateClosed:
   2.107 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Closed\n"));  
   2.108 -    break;
   2.109 -
   2.110 -  default:
   2.111 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Undefined = %d\n", xi->backend_state));
   2.112 -    break;
   2.113 -  }
   2.114 -
   2.115 -  KeSetEvent(&xi->backend_state_change_event, 1, FALSE);
   2.116 -
   2.117 -//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.118 -
   2.119 -  return;
   2.120 -}
   2.121 -
   2.122  static NDIS_STATUS
   2.123  XenNet_Init(
   2.124    OUT PNDIS_STATUS OpenErrorStatus,
   2.125 @@ -186,36 +123,18 @@ XenNet_Init(
   2.126    )
   2.127  {
   2.128    NDIS_STATUS status;
   2.129 -  LARGE_INTEGER timeout;
   2.130 -  UINT i;
   2.131 +  UINT i, j;
   2.132    BOOLEAN medium_found = FALSE;
   2.133    struct xennet_info *xi = NULL;
   2.134    ULONG length;
   2.135 -  WDF_OBJECT_ATTRIBUTES wdf_attrs;
   2.136 -  char *res;
   2.137 -  char *Value;
   2.138 -  char TmpPath[MAX_XENBUS_STR_LEN];
   2.139 -  struct set_params {
   2.140 -    char *name;
   2.141 -    int value;
   2.142 -  } params[] = {
   2.143 -    {"tx-ring-ref", 0},
   2.144 -    {"rx-ring-ref", 0},
   2.145 -    {"event-channel", 0},
   2.146 -    {"feature-no-csum-offload", 1},
   2.147 -    {"feature-sg", 1},
   2.148 -    {"feature-gso-tcpv4", 1},
   2.149 -    {"request-rx-copy", 1},
   2.150 -    {"feature-rx-notify", 1},
   2.151 -    {NULL, 0},
   2.152 -  };
   2.153 -  int retry = 0;
   2.154 -  char *err;
   2.155 -  xenbus_transaction_t xbt = 0;
   2.156 -  NDIS_HANDLE config_handle;
   2.157 -  NDIS_STRING config_param_name;
   2.158 -  PNDIS_CONFIGURATION_PARAMETER config_param;
   2.159 -
   2.160 +  PNDIS_RESOURCE_LIST nrl;
   2.161 +  PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
   2.162 +  KIRQL irq_level;
   2.163 +  ULONG irq_vector;
   2.164 +  UCHAR type;
   2.165 +  PUCHAR ptr;
   2.166 +  PCHAR setting, value;
   2.167 +  
   2.168    UNREFERENCED_PARAMETER(OpenErrorStatus);
   2.169  
   2.170    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.171 @@ -246,13 +165,304 @@ XenNet_Init(
   2.172      goto err;
   2.173    }
   2.174    RtlZeroMemory(xi, sizeof(*xi));
   2.175 -
   2.176 -  /* init xennet_info */
   2.177    xi->adapter_handle = MiniportAdapterHandle;
   2.178    xi->rx_target     = RX_DFL_MIN_TARGET;
   2.179    xi->rx_min_target = RX_DFL_MIN_TARGET;
   2.180    xi->rx_max_target = RX_MAX_TARGET;
   2.181 +  NdisMSetAttributesEx(xi->adapter_handle, (NDIS_HANDLE) xi,
   2.182 +    0, NDIS_ATTRIBUTE_DESERIALIZE, // | NDIS_ATTRIBUTE_BUS_MASTER),
   2.183 +    NdisInterfaceInternal);
   2.184  
   2.185 +  NdisMQueryAdapterResources(&status, WrapperConfigurationContext,
   2.186 +    NULL, (PUINT)&length);
   2.187 +  NdisAllocateMemoryWithTag(&nrl, length, XENNET_POOL_TAG);
   2.188 +  NdisMQueryAdapterResources(&status, WrapperConfigurationContext,
   2.189 +    nrl, (PUINT)&length);
   2.190 +  if (status != NDIS_STATUS_SUCCESS)
   2.191 +  {
   2.192 +    KdPrint(("Could not get Adapter Resources 0x%x\n", status));
   2.193 +    return NDIS_ERROR_CODE_ADAPTER_NOT_FOUND;
   2.194 +  }
   2.195 +  xi->event_channel = 0;
   2.196 +  xi->config_csum = 1;
   2.197 +  xi->config_sg = 1;
   2.198 +  xi->config_gso = 1;
   2.199 +
   2.200 +  for (i = 0; i < nrl->Count; i++)
   2.201 +  {
   2.202 +    prd = &nrl->PartialDescriptors[i];
   2.203 +
   2.204 +    switch(prd->Type)
   2.205 +    {
   2.206 +    case CmResourceTypeInterrupt:
   2.207 +      irq_vector = prd->u.Interrupt.Vector;
   2.208 +      irq_level = (KIRQL)prd->u.Interrupt.Level;
   2.209 +      KdPrint((__DRIVER_NAME "     irq_vector = %03x, irq_level = %03x\n", irq_vector, irq_level));
   2.210 +      break;
   2.211 +
   2.212 +    case CmResourceTypeMemory:
   2.213 +      NdisMMapIoSpace(&ptr, MiniportAdapterHandle, prd->u.Memory.Start, PAGE_SIZE);
   2.214 +      while((type = GET_XEN_INIT_RSP(&ptr, &setting, &value)) != XEN_INIT_TYPE_END)
   2.215 +      {
   2.216 +        switch(type)
   2.217 +        {
   2.218 +        case XEN_INIT_TYPE_RING: /* frontend ring */
   2.219 +          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, value));
   2.220 +          if (strcmp(setting, "tx-ring-ref") == 0)
   2.221 +          {
   2.222 +            FRONT_RING_INIT(&xi->tx, (netif_tx_sring_t *)value, PAGE_SIZE);
   2.223 +          } else if (strcmp(setting, "rx-ring-ref") == 0)
   2.224 +          {
   2.225 +            FRONT_RING_INIT(&xi->rx, (netif_rx_sring_t *)value, PAGE_SIZE);
   2.226 +          }
   2.227 +          break;
   2.228 +        case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel */
   2.229 +          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, PtrToUlong(value)));
   2.230 +          if (strcmp(setting, "event-channel") == 0)
   2.231 +          {
   2.232 +            xi->event_channel = PtrToUlong(value);
   2.233 +          }
   2.234 +          break;
   2.235 +        case XEN_INIT_TYPE_READ_STRING_BACK:
   2.236 +        case XEN_INIT_TYPE_READ_STRING_FRONT:
   2.237 +          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = %s\n", setting, value));
   2.238 +          if (strcmp(setting, "mac") == 0)
   2.239 +          {
   2.240 +            char *s, *e;
   2.241 +            s = value;
   2.242 +            for (j = 0; j < ETH_ALEN; j++) {
   2.243 +              xi->perm_mac_addr[j] = (UINT8)simple_strtoul(s, &e, 16);
   2.244 +              if ((s == e) || (*e != ((j == ETH_ALEN-1) ? '\0' : ':'))) {
   2.245 +                KdPrint((__DRIVER_NAME "Error parsing MAC address\n"));
   2.246 +              }
   2.247 +              s = e + 1;
   2.248 +            }
   2.249 +            memcpy(xi->curr_mac_addr, xi->perm_mac_addr, ETH_ALEN);
   2.250 +          }
   2.251 +          break;
   2.252 +        case XEN_INIT_TYPE_VECTORS:
   2.253 +          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
   2.254 +          if (((PXENPCI_VECTORS)value)->length != sizeof(XENPCI_VECTORS) ||
   2.255 +            ((PXENPCI_VECTORS)value)->magic != XEN_DATA_MAGIC)
   2.256 +          {
   2.257 +            KdPrint((__DRIVER_NAME "     vectors mismatch (magic = %08x, length = %d)\n",
   2.258 +              ((PXENPCI_VECTORS)value)->magic, ((PXENPCI_VECTORS)value)->length));
   2.259 +            KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.260 +            return NDIS_ERROR_CODE_ADAPTER_NOT_FOUND;
   2.261 +          }
   2.262 +          else
   2.263 +            memcpy(&xi->vectors, value, sizeof(XENPCI_VECTORS));
   2.264 +          break;
   2.265 +        default:
   2.266 +          KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
   2.267 +          break;
   2.268 +        }
   2.269 +      }
   2.270 +      break;
   2.271 +    }
   2.272 +  } 
   2.273 +
   2.274 +  KeInitializeSpinLock(&xi->rx_lock);
   2.275 +
   2.276 +  InitializeListHead(&xi->tx_waiting_pkt_list);
   2.277 +
   2.278 +  NdisAllocatePacketPool(&status, &xi->packet_pool, XN_RX_QUEUE_LEN * 8,
   2.279 +    PROTOCOL_RESERVED_SIZE_IN_PACKET);
   2.280 +  if (status != NDIS_STATUS_SUCCESS)
   2.281 +  {
   2.282 +    KdPrint(("NdisAllocatePacketPool failed with 0x%x\n", status));
   2.283 +    status = NDIS_STATUS_RESOURCES;
   2.284 +    goto err;
   2.285 +  }
   2.286 +  NdisSetPacketPoolProtocolId(xi->packet_pool, NDIS_PROTOCOL_ID_TCP_IP);
   2.287 +
   2.288 +  NdisAllocateBufferPool(&status, &xi->buffer_pool, XN_RX_QUEUE_LEN);
   2.289 +  if (status != NDIS_STATUS_SUCCESS)
   2.290 +  {
   2.291 +    KdPrint(("NdisAllocateBufferPool failed with 0x%x\n", status));
   2.292 +    status = NDIS_STATUS_RESOURCES;
   2.293 +    goto err;
   2.294 +  }
   2.295 +
   2.296 +  NdisMGetDeviceProperty(MiniportAdapterHandle, &xi->pdo, &xi->fdo,
   2.297 +    &xi->lower_do, NULL, NULL);
   2.298 +  xi->packet_filter = NDIS_PACKET_TYPE_PROMISCUOUS;
   2.299 +
   2.300 +  status = IoGetDeviceProperty(xi->pdo, DevicePropertyDeviceDescription,
   2.301 +    NAME_SIZE, xi->dev_desc, &length);
   2.302 +  if (!NT_SUCCESS(status))
   2.303 +  {
   2.304 +    KdPrint(("IoGetDeviceProperty failed with 0x%x\n", status));
   2.305 +    status = NDIS_STATUS_FAILURE;
   2.306 +    goto err;
   2.307 +  }
   2.308 +
   2.309 +  KeInitializeEvent(&xi->shutdown_event, SynchronizationEvent, FALSE);  
   2.310 +
   2.311 +  XenNet_TxInit(xi);
   2.312 +  XenNet_RxInit(xi);
   2.313 +
   2.314 +  xi->connected = TRUE;
   2.315 +
   2.316 +  KeMemoryBarrier(); // packets could be received anytime after we set Frontent to Connected
   2.317 +
   2.318 +  status = NdisMRegisterInterrupt(&xi->interrupt, MiniportAdapterHandle, irq_vector, irq_level,
   2.319 +    TRUE, TRUE, NdisInterruptLatched);
   2.320 +  /* send fake arp? */
   2.321 +  if (!NT_SUCCESS(status))
   2.322 +  {
   2.323 +    KdPrint(("NdisMRegisterInterrupt failed with 0x%x\n", status));
   2.324 +    //status = NDIS_STATUS_FAILURE;
   2.325 +    //goto err;
   2.326 +  }
   2.327 +
   2.328 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.329 +
   2.330 +  return NDIS_STATUS_SUCCESS;
   2.331 +
   2.332 +err:
   2.333 +  NdisFreeMemory(xi, 0, 0);
   2.334 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (error path)\n"));
   2.335 +  return status;
   2.336 +}
   2.337 +
   2.338 +VOID
   2.339 +XenNet_PnPEventNotify(
   2.340 +  IN NDIS_HANDLE MiniportAdapterContext,
   2.341 +  IN NDIS_DEVICE_PNP_EVENT PnPEvent,
   2.342 +  IN PVOID InformationBuffer,
   2.343 +  IN ULONG InformationBufferLength
   2.344 +  )
   2.345 +{
   2.346 +  UNREFERENCED_PARAMETER(MiniportAdapterContext);
   2.347 +  UNREFERENCED_PARAMETER(PnPEvent);
   2.348 +  UNREFERENCED_PARAMETER(InformationBuffer);
   2.349 +  UNREFERENCED_PARAMETER(InformationBufferLength);
   2.350 +
   2.351 +  KdPrint((__FUNCTION__ " called\n"));
   2.352 +}
   2.353 +
   2.354 +/* Called when machine is shutting down, so just quiesce the HW and be done fast. */
   2.355 +VOID
   2.356 +XenNet_Shutdown(
   2.357 +  IN NDIS_HANDLE MiniportAdapterContext
   2.358 +  )
   2.359 +{
   2.360 +  UNREFERENCED_PARAMETER(MiniportAdapterContext);
   2.361 +
   2.362 +  KdPrint((__FUNCTION__ " called\n"));
   2.363 +}
   2.364 +
   2.365 +/* Opposite of XenNet_Init */
   2.366 +VOID
   2.367 +XenNet_Halt(
   2.368 +  IN NDIS_HANDLE MiniportAdapterContext
   2.369 +  )
   2.370 +{
   2.371 +  struct xennet_info *xi = MiniportAdapterContext;
   2.372 +//  CHAR TmpPath[MAX_XENBUS_STR_LEN];
   2.373 +//  PVOID if_cxt = xi->XenInterface.InterfaceHeader.Context;
   2.374 +//  LARGE_INTEGER timeout;
   2.375 +
   2.376 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.377 +  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   2.378 +
   2.379 +#if 0
   2.380 +  // set frontend state to 'closing'
   2.381 +  xi->state = XenbusStateClosing;
   2.382 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
   2.383 +  xi->XenInterface.XenBus_Printf(if_cxt, XBT_NIL, TmpPath, "%d", xi->state);
   2.384 +
   2.385 +  // wait for backend to set 'Closing' state
   2.386 +
   2.387 +  while (xi->backend_state != XenbusStateClosing)
   2.388 +  {
   2.389 +    timeout.QuadPart = -5 * 1000 * 1000 * 100; // 5 seconds
   2.390 +    if (KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, &timeout) != STATUS_SUCCESS)
   2.391 +      KdPrint((__DRIVER_NAME "     Still Waiting for Closing...\n"));
   2.392 +  }
   2.393 +
   2.394 +  // set frontend state to 'closed'
   2.395 +  xi->state = XenbusStateClosed;
   2.396 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
   2.397 +  xi->XenInterface.XenBus_Printf(if_cxt, XBT_NIL, TmpPath, "%d", xi->state);
   2.398 +
   2.399 +  // wait for backend to set 'Closed' state
   2.400 +  while (xi->backend_state != XenbusStateClosed)
   2.401 +  {
   2.402 +    timeout.QuadPart = -5 * 1000 * 1000 * 100; // 5 seconds
   2.403 +    if (KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, &timeout) != STATUS_SUCCESS)
   2.404 +      KdPrint((__DRIVER_NAME "     Still Waiting for Closed...\n"));
   2.405 +  }
   2.406 +
   2.407 +  // set frontend state to 'Initialising'
   2.408 +  xi->state = XenbusStateInitialising;
   2.409 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
   2.410 +  xi->XenInterface.XenBus_Printf(if_cxt, XBT_NIL, TmpPath, "%d", xi->state);
   2.411 +
   2.412 +  // wait for backend to set 'InitWait' state
   2.413 +  while (xi->backend_state != XenbusStateInitWait)
   2.414 +  {
   2.415 +    timeout.QuadPart = -5 * 1000 * 1000 * 100; // 5 seconds
   2.416 +    if (KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, &timeout) != STATUS_SUCCESS)
   2.417 +      KdPrint((__DRIVER_NAME "     Still Waiting for InitWait...\n"));
   2.418 +  }
   2.419 +#endif
   2.420 +  // Disables the interrupt
   2.421 +  XenNet_Shutdown(xi);
   2.422 +
   2.423 +  xi->connected = FALSE;
   2.424 +  KeMemoryBarrier(); /* make sure everyone sees that we are now shut down */
   2.425 +
   2.426 +  // TODO: remove event channel xenbus entry (how?)
   2.427 +
   2.428 +  XenNet_TxShutdown(xi);
   2.429 +  XenNet_RxShutdown(xi);
   2.430 +
   2.431 +#if 0
   2.432 +
   2.433 +  /* Remove watch on backend state */
   2.434 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->backend_path);
   2.435 +  xi->XenInterface.XenBus_RemWatch(if_cxt, XBT_NIL, TmpPath,
   2.436 +    XenNet_BackEndStateHandler, xi);
   2.437 +
   2.438 +#endif
   2.439 +
   2.440 +  NdisFreeBufferPool(xi->buffer_pool);
   2.441 +  NdisFreePacketPool(xi->packet_pool);
   2.442 +
   2.443 +  NdisFreeMemory(xi, 0, 0); // <= DISPATCH_LEVEL
   2.444 +
   2.445 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.446 +}
   2.447 +
   2.448 +static PDRIVER_DISPATCH XenNet_Pnp_Original;
   2.449 +
   2.450 +static NTSTATUS
   2.451 +XenNet_Pnp(PDEVICE_OBJECT device_object, PIRP irp)
   2.452 +{
   2.453 +  PIO_STACK_LOCATION stack;
   2.454 +  NTSTATUS status;
   2.455 +  PCM_RESOURCE_LIST old_crl, new_crl;
   2.456 +  PCM_PARTIAL_RESOURCE_LIST prl;
   2.457 +  PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
   2.458 +  ULONG old_length, new_length;
   2.459 +  PMDL mdl;
   2.460 +  PUCHAR start, ptr;
   2.461 +  //NDIS_STRING config_param_name;
   2.462 +  //PNDIS_CONFIGURATION_PARAMETER config_param;
   2.463 +
   2.464 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.465 +
   2.466 +  stack = IoGetCurrentIrpStackLocation(irp);
   2.467 +
   2.468 +  // check if the Irp is meant for us... maybe the stack->DeviceObject field?
   2.469 +  
   2.470 +  switch (stack->MinorFunction)
   2.471 +  {
   2.472 +  case IRP_MN_START_DEVICE:
   2.473 +  
   2.474 +#if 0
   2.475    NdisOpenConfiguration(&status, &config_handle, WrapperConfigurationContext);
   2.476    if (!NT_SUCCESS(status))
   2.477    {
   2.478 @@ -320,342 +530,70 @@ XenNet_Init(
   2.479    xi->config_max_pkt_size = max(xi->config_mtu + XN_HDR_SIZE, xi->config_gso + XN_HDR_SIZE);
   2.480    
   2.481    NdisCloseConfiguration(config_handle);
   2.482 -
   2.483 -  xi->state = XenbusStateUnknown;
   2.484 -  xi->backend_state = XenbusStateUnknown;
   2.485 -
   2.486 -  KeInitializeSpinLock(&xi->rx_lock);
   2.487 -
   2.488 -  InitializeListHead(&xi->tx_waiting_pkt_list);
   2.489 -
   2.490 -  NdisAllocatePacketPool(&status, &xi->packet_pool, XN_RX_QUEUE_LEN * 8,
   2.491 -    PROTOCOL_RESERVED_SIZE_IN_PACKET);
   2.492 -  if (status != NDIS_STATUS_SUCCESS)
   2.493 -  {
   2.494 -    KdPrint(("NdisAllocatePacketPool failed with 0x%x\n", status));
   2.495 -    status = NDIS_STATUS_RESOURCES;
   2.496 -    goto err;
   2.497 -  }
   2.498 -  NdisSetPacketPoolProtocolId(xi->packet_pool, NDIS_PROTOCOL_ID_TCP_IP);
   2.499 -
   2.500 -  NdisAllocateBufferPool(&status, &xi->buffer_pool, XN_RX_QUEUE_LEN);
   2.501 -  if (status != NDIS_STATUS_SUCCESS)
   2.502 -  {
   2.503 -    KdPrint(("NdisAllocateBufferPool failed with 0x%x\n", status));
   2.504 -    status = NDIS_STATUS_RESOURCES;
   2.505 -    goto err;
   2.506 -  }
   2.507 -
   2.508 -  NdisMGetDeviceProperty(MiniportAdapterHandle, &xi->pdo, &xi->fdo,
   2.509 -    &xi->lower_do, NULL, NULL);
   2.510 -  xi->pdo_data = (PXENPCI_XEN_DEVICE_DATA)xi->pdo->DeviceExtension;
   2.511 -
   2.512 -  xi->packet_filter = NDIS_PACKET_TYPE_PROMISCUOUS;
   2.513 -
   2.514 -  status = IoGetDeviceProperty(xi->pdo, DevicePropertyDeviceDescription,
   2.515 -    NAME_SIZE, xi->dev_desc, &length);
   2.516 -  if (!NT_SUCCESS(status))
   2.517 -  {
   2.518 -    KdPrint(("IoGetDeviceProperty failed with 0x%x\n", status));
   2.519 -    status = NDIS_STATUS_FAILURE;
   2.520 -    goto err;
   2.521 -  }
   2.522 -
   2.523 -  NdisMSetAttributesEx(xi->adapter_handle, (NDIS_HANDLE) xi,
   2.524 -    0, NDIS_ATTRIBUTE_DESERIALIZE, // | NDIS_ATTRIBUTE_BUS_MASTER),
   2.525 -    NdisInterfaceInternal);
   2.526 -
   2.527 -#if 0
   2.528 -  if (xi->config_sg)
   2.529 -  {
   2.530 -    status = NdisMInitializeScatterGatherDma(xi->adapter_handle, TRUE, xi->config_max_pkt_size);
   2.531 -    if (!NT_SUCCESS(status))
   2.532 -    {
   2.533 -      KdPrint(("NdisMInitializeScatterGatherDma failed with 0x%x\n", status));
   2.534 -      status = NDIS_STATUS_FAILURE;
   2.535 -      goto err;
   2.536 -    }
   2.537 -  }
   2.538  #endif
   2.539  
   2.540 -  WDF_OBJECT_ATTRIBUTES_INIT(&wdf_attrs);
   2.541 -
   2.542 -  status = WdfDeviceMiniportCreate(WdfGetDriver(), &wdf_attrs, xi->fdo,
   2.543 -    xi->lower_do, xi->pdo, &xi->wdf_device);
   2.544 -  if (!NT_SUCCESS(status))
   2.545 -  {
   2.546 -    KdPrint(("WdfDeviceMiniportCreate failed with 0x%x\n", status));
   2.547 -    status = NDIS_STATUS_FAILURE;
   2.548 -    goto err;
   2.549 -  }
   2.550 -
   2.551 -  /* get lower (Xen) interfaces */
   2.552 -
   2.553 -  status = WdfFdoQueryForInterface(xi->wdf_device, &GUID_XEN_IFACE,
   2.554 -    (PINTERFACE) &xi->XenInterface, sizeof(XEN_IFACE), 2, NULL);
   2.555 -  if(!NT_SUCCESS(status))
   2.556 -  {
   2.557 -    KdPrint(("WdfFdoQueryForInterface failed with status 0x%08x\n", status));
   2.558 -    status = NDIS_STATUS_FAILURE;
   2.559 -    goto err;
   2.560 -  }
   2.561 -
   2.562 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath),
   2.563 -      "%s/backend", xi->pdo_data->Path);
   2.564 -  res = xi->XenInterface.XenBus_Read(xi->XenInterface.InterfaceHeader.Context,
   2.565 -      XBT_NIL, TmpPath, &Value);
   2.566 -  if (res)
   2.567 -  {
   2.568 -    KdPrint((__DRIVER_NAME "    Failed to read backend path\n"));
   2.569 -    xi->XenInterface.FreeMem(res);
   2.570 -    status = NDIS_STATUS_FAILURE;
   2.571 -    goto err;
   2.572 -  }
   2.573 -  RtlStringCbCopyA(xi->backend_path, ARRAY_SIZE(xi->backend_path), Value);
   2.574 -  xi->XenInterface.FreeMem(Value);
   2.575 -  KdPrint((__DRIVER_NAME "backend path = %s\n", xi->backend_path));
   2.576 -
   2.577 -  KeInitializeEvent(&xi->backend_state_change_event, SynchronizationEvent, FALSE);  
   2.578 -  KeInitializeEvent(&xi->shutdown_event, SynchronizationEvent, FALSE);  
   2.579 +    KdPrint((__DRIVER_NAME "     IRP_MN_START_DEVICE - DeviceObject = %p\n", stack->DeviceObject));
   2.580 +    old_crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
   2.581 +    if (old_crl != NULL)
   2.582 +    {
   2.583 +      mdl = AllocatePage();
   2.584 +      old_length = FIELD_OFFSET(CM_RESOURCE_LIST, List) + 
   2.585 +        FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
   2.586 +        FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
   2.587 +        sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * old_crl->List[0].PartialResourceList.Count;
   2.588 +      new_length = old_length + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1;
   2.589 +      new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENNET_POOL_TAG);
   2.590 +      memcpy(new_crl, old_crl, old_length);
   2.591 +      prl = &new_crl->List[0].PartialResourceList;
   2.592 +      prd = &prl->PartialDescriptors[prl->Count++];
   2.593 +      prd->Type = CmResourceTypeMemory;
   2.594 +      prd->ShareDisposition = CmResourceShareDeviceExclusive;
   2.595 +      prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE|CM_RESOURCE_MEMORY_PREFETCHABLE|CM_RESOURCE_MEMORY_CACHEABLE;
   2.596 +      prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
   2.597 +      prd->u.Memory.Length = PAGE_SIZE;
   2.598 +      KdPrint((__DRIVER_NAME "     Start = %08x, Length = %d\n", prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
   2.599 +      ptr = start = MmGetMdlVirtualAddress(mdl);
   2.600 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "tx-ring-ref", NULL);
   2.601 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "rx-ring-ref", NULL);
   2.602 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_EVENT_CHANNEL_IRQ, "event-channel", NULL);
   2.603 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "mac", NULL);
   2.604 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "feature-no-csum-offload", "0");
   2.605 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "feature-sg", "1");
   2.606 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "feature-gso-tcpv4", "1");
   2.607 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "request-rx-copy", "1");
   2.608 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_WRITE_STRING, "feature-rx-notify", "1");
   2.609 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_VECTORS, NULL, NULL);
   2.610 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);
   2.611 +      
   2.612 +      stack->Parameters.StartDevice.AllocatedResourcesTranslated = new_crl;
   2.613  
   2.614 -  /* Add watch on backend state */
   2.615 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->backend_path);
   2.616 -  xi->XenInterface.XenBus_AddWatch(xi->XenInterface.InterfaceHeader.Context,
   2.617 -      XBT_NIL, TmpPath, XenNet_BackEndStateHandler, xi);
   2.618 -
   2.619 -  /* Tell backend we're coming up */
   2.620 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
   2.621 -  xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
   2.622 -    XBT_NIL, TmpPath, "%d", XenbusStateInitialising);
   2.623 -
   2.624 -  // wait here for signal that we are all set up
   2.625 -  while (xi->backend_state != XenbusStateInitWait)
   2.626 -    KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, NULL);
   2.627 -
   2.628 -  xi->event_channel = xi->XenInterface.EvtChn_AllocUnbound(
   2.629 -    xi->XenInterface.InterfaceHeader.Context, 0);
   2.630 -  xi->XenInterface.EvtChn_BindDpc(xi->XenInterface.InterfaceHeader.Context,
   2.631 -    xi->event_channel, XenNet_Interrupt, xi);
   2.632 -
   2.633 -  XenNet_TxInit(xi);
   2.634 -  XenNet_RxInit(xi);
   2.635 -
   2.636 -  /* fixup array for dynamic values */
   2.637 -  params[0].value = xi->tx_ring_ref;
   2.638 -  params[1].value = xi->rx_ring_ref;
   2.639 -  params[2].value = xi->event_channel;
   2.640 -  params[3].value = !xi->config_csum;
   2.641 -  params[4].value = xi->config_sg;
   2.642 -  params[5].value = !!xi->config_gso;
   2.643 -  xi->XenInterface.XenBus_StartTransaction(
   2.644 -    xi->XenInterface.InterfaceHeader.Context, &xbt);
   2.645 -
   2.646 -  for (err = NULL, i = 0; params[i].name; i++)
   2.647 -  {
   2.648 -    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/%s",
   2.649 -      xi->pdo_data->Path, params[i].name);
   2.650 -    err = xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
   2.651 -      XBT_NIL, TmpPath, "%d", params[i].value);
   2.652 -    if (err)
   2.653 +      old_crl = stack->Parameters.StartDevice.AllocatedResources;
   2.654 +      new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENNET_POOL_TAG);
   2.655 +      memcpy(new_crl, old_crl, old_length);
   2.656 +      prl = &new_crl->List[0].PartialResourceList;
   2.657 +      prd = &prl->PartialDescriptors[prl->Count++];
   2.658 +      prd->Type = CmResourceTypeMemory;
   2.659 +      prd->ShareDisposition = CmResourceShareDeviceExclusive;
   2.660 +      prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE|CM_RESOURCE_MEMORY_PREFETCHABLE|CM_RESOURCE_MEMORY_CACHEABLE;
   2.661 +      prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
   2.662 +      prd->u.Memory.Length = PAGE_SIZE;
   2.663 +      stack->Parameters.StartDevice.AllocatedResources = new_crl;
   2.664 +      IoCopyCurrentIrpStackLocationToNext(irp);
   2.665 +    }
   2.666 +    else
   2.667      {
   2.668 -      KdPrint(("setting %s failed, err = %s\n", params[i].name, err));
   2.669 -      break;
   2.670 +      KdPrint((__DRIVER_NAME "     AllocatedResource == NULL\n"));
   2.671      }
   2.672 +    status = XenNet_Pnp_Original(device_object, irp);
   2.673 +    break;
   2.674 +  default:
   2.675 +    status = XenNet_Pnp_Original(device_object, irp);
   2.676 +    break;
   2.677    }
   2.678  
   2.679 -  xi->XenInterface.XenBus_EndTransaction(xi->XenInterface.InterfaceHeader.Context,
   2.680 -    xbt, 1, &retry);
   2.681 -  if (err)
   2.682 -  {
   2.683 -    status = NDIS_STATUS_FAILURE;
   2.684 -    goto err;
   2.685 -  } 
   2.686 -
   2.687 -  xi->connected = TRUE;
   2.688 -
   2.689 -  KeMemoryBarrier(); // packets could be received anytime after we set Frontent to Connected
   2.690 -
   2.691 -  xi->state = XenbusStateConnected;
   2.692 -  KdPrint((__DRIVER_NAME "     Set Frontend state to Connected\n"));
   2.693 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
   2.694 -  xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
   2.695 -    XBT_NIL, TmpPath, "%d", xi->state);
   2.696 -
   2.697 -  KdPrint((__DRIVER_NAME "     Waiting for backend to connect\n"));
   2.698 -
   2.699 -  // wait here for signal that we are all set up
   2.700 -  while (xi->backend_state != XenbusStateConnected)
   2.701 -  {
   2.702 -    timeout.QuadPart = -5 * 1000 * 1000 * 100; // 5 seconds
   2.703 -    if (KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, &timeout) != STATUS_SUCCESS)
   2.704 -      KdPrint((__DRIVER_NAME "     Still Waiting for Connected...\n"));
   2.705 -  }
   2.706 -
   2.707 -  KdPrint((__DRIVER_NAME "     Backend Connected\n"));
   2.708 -
   2.709 -  /* get mac address */
   2.710 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/mac", xi->backend_path);
   2.711 -  xi->XenInterface.XenBus_Read(xi->XenInterface.InterfaceHeader.Context,
   2.712 -      XBT_NIL, TmpPath, &Value);
   2.713 -  if (!Value)
   2.714 -  {
   2.715 -    KdPrint((__DRIVER_NAME "    mac Read Failed\n"));
   2.716 -    status = NDIS_STATUS_FAILURE;
   2.717 -    goto err;
   2.718 -  }
   2.719 -  else
   2.720 -  {
   2.721 -    char *s, *e;
   2.722 -    s = Value;
   2.723 -    for (i = 0; i < ETH_ALEN; i++) {
   2.724 -      xi->perm_mac_addr[i] = (UINT8)simple_strtoul(s, &e, 16);
   2.725 -      if ((s == e) || (*e != ((i == ETH_ALEN-1) ? '\0' : ':'))) {
   2.726 -        KdPrint((__DRIVER_NAME "Error parsing MAC address\n"));
   2.727 -        xi->XenInterface.FreeMem(Value);
   2.728 -        status = NDIS_STATUS_FAILURE;
   2.729 -        goto err;
   2.730 -      }
   2.731 -      s = e + 1;
   2.732 -    }
   2.733 -    memcpy(xi->curr_mac_addr, xi->perm_mac_addr, ETH_ALEN);
   2.734 -    xi->XenInterface.FreeMem(Value);
   2.735 -  }
   2.736 -
   2.737 -  /* send fake arp? */
   2.738 -
   2.739 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.740 -
   2.741 -  return NDIS_STATUS_SUCCESS;
   2.742 -
   2.743 -err:
   2.744 -  NdisFreeMemory(xi, 0, 0);
   2.745 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.746 -  return status;
   2.747 -}
   2.748 -
   2.749 -VOID
   2.750 -XenNet_PnPEventNotify(
   2.751 -  IN NDIS_HANDLE MiniportAdapterContext,
   2.752 -  IN NDIS_DEVICE_PNP_EVENT PnPEvent,
   2.753 -  IN PVOID InformationBuffer,
   2.754 -  IN ULONG InformationBufferLength
   2.755 -  )
   2.756 -{
   2.757 -  UNREFERENCED_PARAMETER(MiniportAdapterContext);
   2.758 -  UNREFERENCED_PARAMETER(PnPEvent);
   2.759 -  UNREFERENCED_PARAMETER(InformationBuffer);
   2.760 -  UNREFERENCED_PARAMETER(InformationBufferLength);
   2.761 -
   2.762 -  KdPrint((__FUNCTION__ " called\n"));
   2.763 -}
   2.764 -
   2.765 -/* Called when machine is shutting down, so just quiesce the HW and be done fast. */
   2.766 -VOID
   2.767 -XenNet_Shutdown(
   2.768 -  IN NDIS_HANDLE MiniportAdapterContext
   2.769 -  )
   2.770 -{
   2.771 -  struct xennet_info *xi = MiniportAdapterContext;
   2.772 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
   2.773  
   2.774 -  /* turn off interrupt */
   2.775 -  xi->XenInterface.EvtChn_Unbind(xi->XenInterface.InterfaceHeader.Context,
   2.776 -    xi->event_channel);
   2.777 -
   2.778 -  KdPrint((__FUNCTION__ " called\n"));
   2.779 -}
   2.780 -
   2.781 -/* Opposite of XenNet_Init */
   2.782 -VOID
   2.783 -XenNet_Halt(
   2.784 -  IN NDIS_HANDLE MiniportAdapterContext
   2.785 -  )
   2.786 -{
   2.787 -  struct xennet_info *xi = MiniportAdapterContext;
   2.788 -  CHAR TmpPath[MAX_XENBUS_STR_LEN];
   2.789 -  PVOID if_cxt = xi->XenInterface.InterfaceHeader.Context;
   2.790 -  LARGE_INTEGER timeout;
   2.791 -
   2.792 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.793 -  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   2.794 -
   2.795 -  // set frontend state to 'closing'
   2.796 -  xi->state = XenbusStateClosing;
   2.797 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
   2.798 -  xi->XenInterface.XenBus_Printf(if_cxt, XBT_NIL, TmpPath, "%d", xi->state);
   2.799 -
   2.800 -  // wait for backend to set 'Closing' state
   2.801 -
   2.802 -  while (xi->backend_state != XenbusStateClosing)
   2.803 -  {
   2.804 -    timeout.QuadPart = -5 * 1000 * 1000 * 100; // 5 seconds
   2.805 -    if (KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, &timeout) != STATUS_SUCCESS)
   2.806 -      KdPrint((__DRIVER_NAME "     Still Waiting for Closing...\n"));
   2.807 -  }
   2.808 -
   2.809 -  // set frontend state to 'closed'
   2.810 -  xi->state = XenbusStateClosed;
   2.811 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
   2.812 -  xi->XenInterface.XenBus_Printf(if_cxt, XBT_NIL, TmpPath, "%d", xi->state);
   2.813 -
   2.814 -  // wait for backend to set 'Closed' state
   2.815 -  while (xi->backend_state != XenbusStateClosed)
   2.816 -  {
   2.817 -    timeout.QuadPart = -5 * 1000 * 1000 * 100; // 5 seconds
   2.818 -    if (KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, &timeout) != STATUS_SUCCESS)
   2.819 -      KdPrint((__DRIVER_NAME "     Still Waiting for Closed...\n"));
   2.820 -  }
   2.821 -
   2.822 -  // set frontend state to 'Initialising'
   2.823 -  xi->state = XenbusStateInitialising;
   2.824 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
   2.825 -  xi->XenInterface.XenBus_Printf(if_cxt, XBT_NIL, TmpPath, "%d", xi->state);
   2.826 -
   2.827 -  // wait for backend to set 'InitWait' state
   2.828 -  while (xi->backend_state != XenbusStateInitWait)
   2.829 -  {
   2.830 -    timeout.QuadPart = -5 * 1000 * 1000 * 100; // 5 seconds
   2.831 -    if (KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, &timeout) != STATUS_SUCCESS)
   2.832 -      KdPrint((__DRIVER_NAME "     Still Waiting for InitWait...\n"));
   2.833 -  }
   2.834 -
   2.835 -  // Disables the interrupt
   2.836 -  XenNet_Shutdown(xi);
   2.837 -
   2.838 -  xi->connected = FALSE;
   2.839 -  KeMemoryBarrier(); /* make sure everyone sees that we are now shut down */
   2.840 -
   2.841 -  // TODO: remove event channel xenbus entry (how?)
   2.842 -
   2.843 -  XenNet_TxShutdown(xi);
   2.844 -  XenNet_RxShutdown(xi);
   2.845 -
   2.846 -  /* Remove watch on backend state */
   2.847 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->backend_path);
   2.848 -  xi->XenInterface.XenBus_RemWatch(if_cxt, XBT_NIL, TmpPath,
   2.849 -    XenNet_BackEndStateHandler, xi);
   2.850 -
   2.851 -  xi->XenInterface.InterfaceHeader.InterfaceDereference(NULL);
   2.852 -
   2.853 -  NdisFreeBufferPool(xi->buffer_pool);
   2.854 -  NdisFreePacketPool(xi->packet_pool);
   2.855 -
   2.856 -  NdisFreeMemory(xi, 0, 0); // <= DISPATCH_LEVEL
   2.857 -
   2.858 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.859 -}
   2.860 -
   2.861 -VOID
   2.862 -XenNet_Unload(
   2.863 -  PDRIVER_OBJECT  DriverObject
   2.864 -  )
   2.865 -{
   2.866 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.867 -
   2.868 -  UNREFERENCED_PARAMETER(DriverObject);
   2.869 -
   2.870 -  WdfDriverMiniportUnload(WdfGetDriver());
   2.871 -  
   2.872 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.873 +  return status;
   2.874  }
   2.875  
   2.876  NTSTATUS
   2.877 @@ -665,11 +603,9 @@ DriverEntry(
   2.878    )
   2.879  {
   2.880    NTSTATUS status;
   2.881 -  WDF_DRIVER_CONFIG config;
   2.882    NDIS_HANDLE ndis_wrapper_handle;
   2.883    NDIS_MINIPORT_CHARACTERISTICS mini_chars;
   2.884  
   2.885 -
   2.886    ProfTime_TxBufferGC.QuadPart = 0;
   2.887    ProfTime_RxBufferAlloc.QuadPart = 0;
   2.888    ProfTime_ReturnPacket.QuadPart = 0;
   2.889 @@ -698,17 +634,6 @@ DriverEntry(
   2.890  
   2.891    RtlZeroMemory(&mini_chars, sizeof(mini_chars));
   2.892  
   2.893 -  WDF_DRIVER_CONFIG_INIT(&config, WDF_NO_EVENT_CALLBACK);
   2.894 -  config.DriverInitFlags |= WdfDriverInitNoDispatchOverride;
   2.895 -
   2.896 -  status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES,
   2.897 -    &config, WDF_NO_HANDLE);
   2.898 -  if (!NT_SUCCESS(status))
   2.899 -  {
   2.900 -    KdPrint(("WdfDriverCreate failed err = 0x%x\n", status));
   2.901 -    return status;
   2.902 -  }
   2.903 -
   2.904    NdisMInitializeWrapper(&ndis_wrapper_handle, DriverObject, RegistryPath, NULL);
   2.905    if (!ndis_wrapper_handle)
   2.906    {
   2.907 @@ -722,7 +647,8 @@ DriverEntry(
   2.908  
   2.909    mini_chars.HaltHandler = XenNet_Halt;
   2.910    mini_chars.InitializeHandler = XenNet_Init;
   2.911 -  mini_chars.ISRHandler = NULL; // needed if we register interrupt?
   2.912 +  mini_chars.ISRHandler = XenNet_InterruptIsr;
   2.913 +  mini_chars.HandleInterruptHandler = XenNet_InterruptDpc;
   2.914    mini_chars.QueryInformationHandler = XenNet_QueryInformation;
   2.915    mini_chars.ResetHandler = NULL; //TODO: fill in
   2.916    mini_chars.SetInformationHandler = XenNet_SetInformation;
   2.917 @@ -747,7 +673,9 @@ DriverEntry(
   2.918      return status;
   2.919    }
   2.920  
   2.921 -  NdisMRegisterUnloadHandler(ndis_wrapper_handle, XenNet_Unload);
   2.922 +  /* this is a bit naughty... */
   2.923 +  XenNet_Pnp_Original = DriverObject->MajorFunction[IRP_MJ_PNP];
   2.924 +  DriverObject->MajorFunction[IRP_MJ_PNP] = XenNet_Pnp;
   2.925  
   2.926    return status;
   2.927  }
     3.1 --- a/xennet/xennet.h	Wed May 14 11:52:32 2008 +1000
     3.2 +++ b/xennet/xennet.h	Thu May 15 00:25:25 2008 +1000
     3.3 @@ -22,8 +22,8 @@ Foundation, Inc., 51 Franklin Street, Fi
     3.4  #pragma warning(disable: 4214)
     3.5  
     3.6  #include <wdm.h>
     3.7 -#include <wdf.h>
     3.8 -#include <wdfminiport.h>
     3.9 +//#include <wdf.h>
    3.10 +//#include <wdfminiport.h>
    3.11  #include <initguid.h>
    3.12  #define NDIS_MINIPORT_DRIVER
    3.13  #if NTDDI_VERSION < NTDDI_WINXP
    3.14 @@ -152,24 +152,25 @@ struct xennet_info
    3.15    PDEVICE_OBJECT pdo;
    3.16    PDEVICE_OBJECT fdo;
    3.17    PDEVICE_OBJECT lower_do;
    3.18 -  WDFDEVICE wdf_device;
    3.19 +  //WDFDEVICE wdf_device;
    3.20    WCHAR dev_desc[NAME_SIZE];
    3.21  
    3.22    /* NDIS-related vars */
    3.23    NDIS_HANDLE adapter_handle;
    3.24    NDIS_HANDLE packet_pool;
    3.25    NDIS_HANDLE buffer_pool;
    3.26 +  NDIS_MINIPORT_INTERRUPT interrupt;
    3.27    ULONG packet_filter;
    3.28    int connected;
    3.29    UINT8 perm_mac_addr[ETH_ALEN];
    3.30    UINT8 curr_mac_addr[ETH_ALEN];
    3.31  
    3.32    /* Misc. Xen vars */
    3.33 -  XEN_IFACE XenInterface;
    3.34 -  PXENPCI_XEN_DEVICE_DATA pdo_data;
    3.35 +  //XEN_IFACE XenInterface;
    3.36 +  //PXENPCI_XEN_DEVICE_DATA pdo_data;
    3.37 +  XENPCI_VECTORS vectors;
    3.38    evtchn_port_t event_channel;
    3.39    ULONG state;
    3.40 -  KEVENT backend_state_change_event;
    3.41    KEVENT shutdown_event;
    3.42    char backend_path[MAX_XENBUS_STR_LEN];
    3.43    ULONG backend_state;
    3.44 @@ -181,9 +182,6 @@ struct xennet_info
    3.45    KSPIN_LOCK tx_lock;
    3.46    LIST_ENTRY tx_waiting_pkt_list;
    3.47    struct netif_tx_front_ring tx;
    3.48 -  grant_ref_t tx_ring_ref;
    3.49 -  struct netif_tx_sring *tx_pgs;
    3.50 -  PMDL tx_mdl;
    3.51    ULONG tx_id_free;
    3.52    ULONG tx_no_id_used;
    3.53    USHORT tx_id_list[NET_TX_RING_SIZE];
    3.54 @@ -193,9 +191,6 @@ struct xennet_info
    3.55  
    3.56    /* rx_related - protected by rx_lock */
    3.57    struct netif_rx_front_ring rx;
    3.58 -  grant_ref_t rx_ring_ref;
    3.59 -  struct netif_rx_sring *rx_pgs;
    3.60 -  PMDL rx_mdl;
    3.61    ULONG rx_id_free;
    3.62    PNDIS_BUFFER rx_buffers[NET_RX_RING_SIZE];
    3.63    freelist_t rx_freelist;
     4.1 --- a/xennet/xennet.inx	Wed May 14 11:52:32 2008 +1000
     4.2 +++ b/xennet/xennet.inx	Thu May 15 00:25:25 2008 +1000
     4.3 @@ -6,36 +6,19 @@ Provider=%XenGplPv%
     4.4  
     4.5  [DestinationDirs]
     4.6  DefaultDestDir = 12
     4.7 -ClassInstall32_CopyFiles=11
     4.8 -CoInstaller_CopyFiles = 11
     4.9 -
    4.10 -; ================= Class section =====================
    4.11 -
    4.12 -[ClassInstall32]
    4.13 -Addreg=ClassInstall32_AddReg
    4.14 -CopyFiles=ClassInstall32_CopyFiles
    4.15 -
    4.16 -[ClassInstall32_AddReg]
    4.17 -HKR,,,0,%ClassName%
    4.18 -HKR,,Icon,,-5
    4.19 -HKR,,DeviceCharacteristics,0x10001,0x100
    4.20 -HKR,,Security,,"D:P(A;;GA;;;SY)(A;;GA;;;BA)"
    4.21 -
    4.22 -[ClassInstall32_CopyFiles]
    4.23  
    4.24  [ControlFlags]
    4.25  ExcludeFromSelect=*
    4.26  
    4.27 -
    4.28  [Manufacturer]
    4.29  %XenGplPv%=XenGplPv,NTx86
    4.30  %XenGplPv%=XenGplPv,NTamd64
    4.31  
    4.32  [XenGplPv.NTx86]
    4.33 -%XenNet.DRVDESC%=XenNet_Inst, XEN\VIFDEV
    4.34 +%XenNet.DRVDESC%=XenNet_Inst, XEN\VIF
    4.35  
    4.36  [XenGplPv.NTamd64]
    4.37 -%XenNet.DRVDESC%=XenNet_Inst, XEN\VIFDEV
    4.38 +%XenNet.DRVDESC%=XenNet_Inst, XEN\VIF
    4.39  
    4.40  [XenNet_Inst.NT]
    4.41  CopyFiles=XenNet.CopyFiles
    4.42 @@ -82,7 +65,6 @@ xennet.sys
    4.43  
    4.44  [SourceDisksFiles]
    4.45  xennet.sys=1
    4.46 -WdfCoinstaller$KMDFCOINSTALLERVERSION$.dll=1,,
    4.47  
    4.48  [SourceDisksNames.x86]
    4.49  1 = %DISK_NAME%,,,\i386
    4.50 @@ -107,23 +89,8 @@ AddReg = XenNet_Service_AddReg
    4.51  
    4.52  [XenNet_Service_AddReg]
    4.53  ; 5 = PciBus, 0 = Internal, 15 = PnpBus
    4.54 -HKR,"Parameters\PnpInterface", "15", 0x00010001, 0x00000001
    4.55 -
    4.56 -[XenNet_Inst.NT.CoInstallers]
    4.57 -AddReg=CoInstaller_AddReg
    4.58 -CopyFiles=CoInstaller_CopyFiles
    4.59 -
    4.60 -[CoInstaller_CopyFiles]
    4.61 -WdfCoinstaller$KMDFCOINSTALLERVERSION$.dll,,,2
    4.62 -
    4.63 -[CoInstaller_AddReg]
    4.64 -HKR,,CoInstallers32,0x00010000, "WdfCoinstaller$KMDFCOINSTALLERVERSION$.dll,WdfCoInstaller"
    4.65 -
    4.66 -[XenNet_Inst.NT.Wdf]
    4.67 -KmdfService = xennet, xennet_wdfsect
    4.68 -
    4.69 -[xennet_wdfsect]
    4.70 -KmdfLibraryVersion = $KMDFVERSION$
    4.71 +HKR,"Parameters\PnpInterface", "0", 0x00010001, 0x00000001
    4.72 +HKLM,SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318},UpperFilters,0x00010008,XenHide
    4.73  
    4.74  [Strings]
    4.75  XenGplPv = "Xen GPL PV Driver Developers"
     5.1 --- a/xennet/xennet_common.c	Wed May 14 11:52:32 2008 +1000
     5.2 +++ b/xennet/xennet_common.c	Thu May 15 00:25:25 2008 +1000
     5.3 @@ -162,7 +162,7 @@ XenFreelist_Timer(
     5.4  
     5.5    KeAcquireSpinLockAtDpcLevel(fl->lock);
     5.6  
     5.7 -  KdPrint((__DRIVER_NAME " --- timer - page_free_lowest = %d\n", fl->page_free_lowest));
     5.8 +  //KdPrint((__DRIVER_NAME " --- timer - page_free_lowest = %d\n", fl->page_free_lowest));
     5.9  //  KdPrint((__DRIVER_NAME " --- rx_outstanding = %d, rx_id_free = %d\n", xi->rx_outstanding, xi->rx_id_free));
    5.10  
    5.11    if (fl->page_free_lowest > fl->page_free_target) // lots of potential for tuning here
    5.12 @@ -170,11 +170,11 @@ XenFreelist_Timer(
    5.13      for (i = 0; i < (int)min(16, fl->page_free_lowest - fl->page_free_target); i++)
    5.14      {
    5.15        mdl = XenFreelist_GetPage(fl);
    5.16 -      fl->xi->XenInterface.GntTbl_EndAccess(fl->xi->XenInterface.InterfaceHeader.Context,
    5.17 +      fl->xi->vectors.GntTbl_EndAccess(fl->xi->vectors.context,
    5.18          *(grant_ref_t *)(((UCHAR *)mdl) + MmSizeOfMdl(0, PAGE_SIZE)), 0);
    5.19        FreePages(mdl);
    5.20      }
    5.21 -    KdPrint((__DRIVER_NAME " --- timer - freed %d pages\n", i));
    5.22 +    //KdPrint((__DRIVER_NAME " --- timer - freed %d pages\n", i));
    5.23    }
    5.24  
    5.25    fl->page_free_lowest = fl->page_free;
    5.26 @@ -204,8 +204,8 @@ XenFreelist_GetPage(freelist_t *fl)
    5.27    if (fl->page_free == 0)
    5.28    {
    5.29      mdl = AllocatePagesExtra(1, sizeof(grant_ref_t));
    5.30 -    *(grant_ref_t *)(((UCHAR *)mdl) + MmSizeOfMdl(0, PAGE_SIZE)) = fl->xi->XenInterface.GntTbl_GrantAccess(
    5.31 -      fl->xi->XenInterface.InterfaceHeader.Context, 0,
    5.32 +    *(grant_ref_t *)(((UCHAR *)mdl) + MmSizeOfMdl(0, PAGE_SIZE)) = fl->xi->vectors.GntTbl_GrantAccess(
    5.33 +      fl->xi->vectors.context, 0,
    5.34        *MmGetMdlPfnArray(mdl), FALSE, 0);
    5.35    }
    5.36    else
    5.37 @@ -238,7 +238,7 @@ XenFreelist_Dispose(freelist_t *fl)
    5.38    {
    5.39      fl->page_free--;
    5.40      mdl = fl->page_list[fl->page_free];
    5.41 -    fl->xi->XenInterface.GntTbl_EndAccess(fl->xi->XenInterface.InterfaceHeader.Context,
    5.42 +    fl->xi->vectors.GntTbl_EndAccess(fl->xi->vectors.context,
    5.43        *(grant_ref_t *)(((UCHAR *)mdl) + MmSizeOfMdl(0, PAGE_SIZE)), 0);
    5.44      FreePages(mdl);
    5.45    }
     6.1 --- a/xennet/xennet_oid.c	Wed May 14 11:52:32 2008 +1000
     6.2 +++ b/xennet/xennet_oid.c	Thu May 15 00:25:25 2008 +1000
     6.3 @@ -102,9 +102,15 @@ XenNet_QueryInformation(
     6.4        break;
     6.5      case OID_GEN_HARDWARE_STATUS:
     6.6        if (!xi->connected)
     6.7 +      {
     6.8          temp_data = NdisHardwareStatusInitializing;
     6.9 +        KdPrint((__DRIVER_NAME " --- " __FUNCTION__ " NdisHardwareStatusInitializing\n"));
    6.10 +      }
    6.11        else
    6.12 +      {
    6.13          temp_data = NdisHardwareStatusReady;
    6.14 +        KdPrint((__DRIVER_NAME " --- " __FUNCTION__ " NdisHardwareStatusReady\n"));
    6.15 +      }
    6.16        break;
    6.17      case OID_GEN_MEDIA_SUPPORTED:
    6.18        temp_data = NdisMedium802_3;
     7.1 --- a/xennet/xennet_rx.c	Wed May 14 11:52:32 2008 +1000
     7.2 +++ b/xennet/xennet_rx.c	Thu May 15 00:25:25 2008 +1000
     7.3 @@ -71,8 +71,7 @@ XenNet_RxBufferAlloc(struct xennet_info 
     7.4    RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xi->rx, notify);
     7.5    if (notify)
     7.6    {
     7.7 -    xi->XenInterface.EvtChn_Notify(xi->XenInterface.InterfaceHeader.Context,
     7.8 -      xi->event_channel);
     7.9 +    xi->vectors.EvtChn_Notify(xi->vectors.context, xi->event_channel);
    7.10    }
    7.11  
    7.12  
    7.13 @@ -379,6 +378,8 @@ XenNet_RxBufferCheck(struct xennet_info 
    7.14  
    7.15    KeAcquireSpinLockAtDpcLevel(&xi->rx_lock);
    7.16  
    7.17 +  //KdPrint((__DRIVER_NAME " --- " __FUNCTION__ " xi->rx.sring->rsp_prod = %d, xi->rx.rsp_cons = %d\n", xi->rx.sring->rsp_prod, xi->rx.rsp_cons));
    7.18 +    
    7.19    do {
    7.20      ASSERT(cycles++ < 256);
    7.21      prod = xi->rx.sring->rsp_prod;
    7.22 @@ -562,13 +563,6 @@ XenNet_RxInit(xennet_info_t *xi)
    7.23  
    7.24    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    7.25  
    7.26 -  xi->rx_mdl = AllocatePage();
    7.27 -  xi->rx_pgs = MmGetMdlVirtualAddress(xi->rx_mdl);
    7.28 -  SHARED_RING_INIT(xi->rx_pgs);
    7.29 -  FRONT_RING_INIT(&xi->rx, xi->rx_pgs, PAGE_SIZE);
    7.30 -  xi->rx_ring_ref = xi->XenInterface.GntTbl_GrantAccess(
    7.31 -    xi->XenInterface.InterfaceHeader.Context, 0,
    7.32 -    *MmGetMdlPfnArray(xi->rx_mdl), FALSE, 0);
    7.33    xi->rx_id_free = NET_RX_RING_SIZE;
    7.34  
    7.35    for (i = 0; i < NET_RX_RING_SIZE; i++)
    7.36 @@ -603,10 +597,6 @@ XenNet_RxShutdown(xennet_info_t *xi)
    7.37    packet_freelist_dispose(xi);
    7.38  
    7.39    /* free RX resources */
    7.40 -  ASSERT(xi->XenInterface.GntTbl_EndAccess(
    7.41 -    xi->XenInterface.InterfaceHeader.Context, xi->rx_ring_ref, 0));
    7.42 -  FreePages(xi->rx_mdl);
    7.43 -  xi->rx_pgs = NULL;
    7.44  
    7.45    ASSERT(xi->rx_outstanding == 0);
    7.46  
     8.1 --- a/xennet/xennet_tx.c	Wed May 14 11:52:32 2008 +1000
     8.2 +++ b/xennet/xennet_tx.c	Thu May 15 00:25:25 2008 +1000
     8.3 @@ -278,8 +278,7 @@ XenNet_SendQueuedPackets(struct xennet_i
     8.4    RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xi->tx, notify);
     8.5    if (notify)
     8.6    {
     8.7 -    xi->XenInterface.EvtChn_Notify(xi->XenInterface.InterfaceHeader.Context,
     8.8 -      xi->event_channel);
     8.9 +    xi->vectors.EvtChn_Notify(xi->vectors.context, xi->event_channel);
    8.10    }
    8.11  
    8.12  #if defined(XEN_PROFILE)
    8.13 @@ -361,6 +360,8 @@ XenNet_TxBufferGC(struct xennet_info *xi
    8.14  
    8.15    KeReleaseSpinLockFromDpcLevel(&xi->tx_lock);
    8.16  
    8.17 +//  if (packet_count)
    8.18 +//    KdPrint((__DRIVER_NAME " --- " __FUNCTION__ " %d packets completed\n"));
    8.19    for (i = 0; i < packet_count; i++)
    8.20    {
    8.21      /* A miniport driver must release any spin lock that it is holding before
    8.22 @@ -402,7 +403,7 @@ XenNet_SendPackets(
    8.23  
    8.24    KeAcquireSpinLock(&xi->tx_lock, &OldIrql);
    8.25  
    8.26 -  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    8.27 +//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ " (packets = %d, free_requests = %d)\n", NumberOfPackets, free_requests(xi)));
    8.28    for (i = 0; i < NumberOfPackets; i++)
    8.29    {
    8.30      packet = PacketArray[i];
    8.31 @@ -443,7 +444,7 @@ XenNet_SendPackets(
    8.32      KdPrint((__DRIVER_NAME "     TxPackets         Total = %10d, Csum Offload = %10d, Large Offload    = %10d\n", ProfCount_TxPacketsTotal, ProfCount_TxPacketsCsumOffload, ProfCount_TxPacketsLargeOffload));
    8.33    }
    8.34  #endif
    8.35 -  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    8.36 +//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    8.37  }
    8.38  
    8.39  BOOLEAN
    8.40 @@ -453,13 +454,6 @@ XenNet_TxInit(xennet_info_t *xi)
    8.41  
    8.42    KeInitializeSpinLock(&xi->tx_lock);
    8.43  
    8.44 -  xi->tx_mdl = AllocatePage();
    8.45 -  xi->tx_pgs = MmGetMdlVirtualAddress(xi->tx_mdl);
    8.46 -  SHARED_RING_INIT(xi->tx_pgs);
    8.47 -  FRONT_RING_INIT(&xi->tx, xi->tx_pgs, PAGE_SIZE);
    8.48 -  xi->tx_ring_ref = xi->XenInterface.GntTbl_GrantAccess(
    8.49 -    xi->XenInterface.InterfaceHeader.Context, 0,
    8.50 -    *MmGetMdlPfnArray(xi->tx_mdl), FALSE, 0);
    8.51    xi->tx_id_free = 0;
    8.52    xi->tx_no_id_used = 0;
    8.53    for (i = 0; i < NET_TX_RING_SIZE; i++)
    8.54 @@ -515,11 +509,6 @@ XenNet_TxShutdown(xennet_info_t *xi)
    8.55    XenFreelist_Dispose(&xi->tx_freelist);
    8.56  
    8.57    /* free TX resources */
    8.58 -  ASSERT(xi->XenInterface.GntTbl_EndAccess(
    8.59 -    xi->XenInterface.InterfaceHeader.Context, xi->tx_ring_ref, 0));
    8.60 -  FreePages(xi->tx_mdl);
    8.61 -  xi->tx_pgs = NULL;
    8.62 -
    8.63    KeReleaseSpinLock(&xi->tx_lock, OldIrql);
    8.64  
    8.65    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
     9.1 --- a/xenpci/xenbus.c	Wed May 14 11:52:32 2008 +1000
     9.2 +++ b/xenpci/xenbus.c	Thu May 15 00:25:25 2008 +1000
     9.3 @@ -272,6 +272,8 @@ XenBus_Write(
     9.4    struct write_req req[] = {
     9.5      {path, (ULONG)strlen(path) + 1},
     9.6      {value, (ULONG)strlen(value) + 1},
     9.7 +//    {path, (ULONG)strlen(path)},
     9.8 +//    {value, (ULONG)strlen(value)},
     9.9    };
    9.10    struct xsd_sockmsg *rep;
    9.11    char *msg;
    10.1 --- a/xenpci/xenpci.c	Wed May 14 11:52:32 2008 +1000
    10.2 +++ b/xenpci/xenpci.c	Thu May 15 00:25:25 2008 +1000
    10.3 @@ -65,13 +65,6 @@ XenPci_AddDevice(PDRIVER_OBJECT DriverOb
    10.4  {
    10.5    NTSTATUS status;
    10.6    PDEVICE_OBJECT fdo = NULL;
    10.7 -/*
    10.8 -  WDF_CHILD_LIST_CONFIG config;
    10.9 -  WDF_OBJECT_ATTRIBUTES attributes;
   10.10 -  WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks;
   10.11 -  WDF_IO_QUEUE_CONFIG IoQConfig;
   10.12 -  WDF_INTERRUPT_CONFIG InterruptConfig;
   10.13 -*/
   10.14  //  PNP_BUS_INFORMATION busInfo;
   10.15  //  DECLARE_CONST_UNICODE_STRING(DeviceName, L"\\Device\\XenShutdown");
   10.16  //  DECLARE_CONST_UNICODE_STRING(SymbolicName, L"\\DosDevices\\XenShutdown");
   10.17 @@ -108,6 +101,22 @@ XenPci_AddDevice(PDRIVER_OBJECT DriverOb
   10.18    }
   10.19    InitializeListHead(&xpdd->child_list);
   10.20  
   10.21 +  status = IoRegisterDeviceInterface(
   10.22 +    PhysicalDeviceObject,
   10.23 +    (LPGUID)&GUID_XEN_IFACE,
   10.24 +    NULL,
   10.25 +    &xpdd->interface_name);
   10.26 +
   10.27 +  if (!NT_SUCCESS(status))
   10.28 +  {
   10.29 +    KdPrint((__DRIVER_NAME "     IoRegisterDeviceInterface failed with status 0x%08x\n", status));
   10.30 +  }
   10.31 +  else
   10.32 +  {
   10.33 +    KdPrint((__DRIVER_NAME "     IoRegisterDeviceInterface succeeded - %wZ\n", &xpdd->interface_name));
   10.34 +  }
   10.35 +  
   10.36 +
   10.37    fdo->Flags &= ~DO_DEVICE_INITIALIZING;
   10.38  
   10.39  #if 0
    11.1 --- a/xenpci/xenpci.h	Wed May 14 11:52:32 2008 +1000
    11.2 +++ b/xenpci/xenpci.h	Thu May 15 00:25:25 2008 +1000
    11.3 @@ -166,6 +166,8 @@ typedef struct {
    11.4    LIST_ENTRY child_list;
    11.5    
    11.6    int suspending;
    11.7 +  
    11.8 +  UNICODE_STRING interface_name;
    11.9  } XENPCI_DEVICE_DATA, *PXENPCI_DEVICE_DATA;
   11.10  
   11.11  typedef struct {  
    12.1 --- a/xenpci/xenpci_fdo.c	Wed May 14 11:52:32 2008 +1000
    12.2 +++ b/xenpci/xenpci_fdo.c	Thu May 15 00:25:25 2008 +1000
    12.3 @@ -221,6 +221,12 @@ XenPci_Pnp_StartDeviceCallback(PDEVICE_O
    12.4  
    12.5    XenBus_Init(xpdd);
    12.6  
    12.7 +  status = IoSetDeviceInterfaceState(&xpdd->interface_name, TRUE);
    12.8 +  if (!NT_SUCCESS(status))
    12.9 +  {
   12.10 +    KdPrint((__DRIVER_NAME "     IoSetDeviceInterfaceState failed with status 0x%08x\n", status));
   12.11 +  }
   12.12 +
   12.13    irp->IoStatus.Status = status;
   12.14    
   12.15    IoCompleteRequest(irp, IO_NO_INCREMENT);
    13.1 --- a/xenpci/xenpci_pdo.c	Wed May 14 11:52:32 2008 +1000
    13.2 +++ b/xenpci/xenpci_pdo.c	Thu May 15 00:25:25 2008 +1000
    13.3 @@ -140,6 +140,7 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
    13.4    PUCHAR in_ptr = NULL, in_start = NULL;
    13.5    PUCHAR out_ptr, out_start = NULL;
    13.6    XENPCI_VECTORS vectors;
    13.7 +  LARGE_INTEGER timeout;
    13.8  
    13.9    UNREFERENCED_PARAMETER(device_object);
   13.10  
   13.11 @@ -169,7 +170,11 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
   13.12  
   13.13    // wait here for signal that we are all set up - we should probably add a timeout to make sure we don't hang forever
   13.14    while (xppdd->backend_state != XenbusStateInitWait)
   13.15 -    KeWaitForSingleObject(&xppdd->backend_state_event, Executive, KernelMode, FALSE, NULL);
   13.16 +  {
   13.17 +    timeout.QuadPart = -5 * 1000 * 1000 * 100; // 5 seconds
   13.18 +    if (KeWaitForSingleObject(&xppdd->backend_state_event, Executive, KernelMode, FALSE, &timeout) != STATUS_SUCCESS)
   13.19 +      KdPrint((__DRIVER_NAME "     Still Waiting for InitWait...\n"));
   13.20 +  }
   13.21  
   13.22    res_list = &stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList;
   13.23    for (i = 0; i < res_list->Count; i++)
   13.24 @@ -244,7 +249,11 @@ XenPci_Pnp_StartDevice(PDEVICE_OBJECT de
   13.25  
   13.26    // wait here for signal that we are all set up - we should probably add a timeout to make sure we don't hang forever
   13.27    while (xppdd->backend_state != XenbusStateConnected)
   13.28 -    KeWaitForSingleObject(&xppdd->backend_state_event, Executive, KernelMode, FALSE, NULL);
   13.29 +  {
   13.30 +    timeout.QuadPart = -5 * 1000 * 1000 * 100; // 5 seconds
   13.31 +    if (KeWaitForSingleObject(&xppdd->backend_state_event, Executive, KernelMode, FALSE, &timeout) != STATUS_SUCCESS)
   13.32 +      KdPrint((__DRIVER_NAME "     Still Waiting for Connected...\n"));
   13.33 +  }
   13.34  
   13.35    res_list = &stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList;
   13.36    for (i = 0; i < res_list->Count; i++)
   13.37 @@ -613,13 +622,6 @@ XenPci_Pnp_Pdo(PDEVICE_OBJECT device_obj
   13.38        status = XenPci_Pnp_QueryTargetRelations(device_object, irp);
   13.39        break;  
   13.40      default:
   13.41 -/*
   13.42 -KdPrint((__DRIVER_NAME "     int 0xb1 (xenvbd) (from xenpci)"));
   13.43 -__asm {
   13.44 -  int 0x81
   13.45 -  int 0xb1
   13.46 -};
   13.47 -*/
   13.48        status = irp->IoStatus.Status;
   13.49        break;
   13.50      }