win-pvdrivers

changeset 85:fa61e0b63dd6

Started filling in the 'Halt' function.
Now sends a 'Closing' to Dom0, then a 'Closed'.
Still BSoD's on Disable though...
author James Harper <james.harper@bendigoit.com.au>
date Tue Jan 01 22:40:19 2008 +1100 (2008-01-01)
parents 9afa5fd5e5b2
children 58f32e252d01
files xennet/sources xennet/xennet.c
line diff
     1.1 --- a/xennet/sources	Tue Jan 01 13:54:15 2008 +1100
     1.2 +++ b/xennet/sources	Tue Jan 01 22:40:19 2008 +1100
     1.3 @@ -1,7 +1,7 @@
     1.4  TARGETNAME=XENNET
     1.5  TARGETTYPE=DRIVER
     1.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.7 -VERSION=0.5.0.34
     1.8 +VERSION=0.5.0.37
     1.9  KMDF_VERSION=1
    1.10  MSC_WARNING_LEVEL=/W4
    1.11  INF_NAME=xennet
     2.1 --- a/xennet/xennet.c	Tue Jan 01 13:54:15 2008 +1100
     2.2 +++ b/xennet/xennet.c	Tue Jan 01 22:40:19 2008 +1100
     2.3 @@ -108,7 +108,12 @@ struct xennet_info
     2.4    ULONG64 stat_rx_error;
     2.5    ULONG64 stat_rx_no_buffer;
     2.6  
     2.7 -  KEVENT backend_ready_event;
     2.8 +//  KEVENT backend_ready_event;
     2.9 +  KEVENT backend_state_change_event;
    2.10 +
    2.11 +  ULONG state;
    2.12 +  ULONG backend_state;
    2.13 +
    2.14    KSPIN_LOCK Lock;
    2.15  };
    2.16  
    2.17 @@ -165,6 +170,7 @@ XenNet_TxBufferGC(struct xennet_info *xi
    2.18    unsigned short id;
    2.19    PNDIS_PACKET pkt;
    2.20    PMDL pmdl;
    2.21 +  int notify;
    2.22  
    2.23    ASSERT(xi->connected);
    2.24  
    2.25 @@ -211,7 +217,14 @@ XenNet_TxBufferGC(struct xennet_info *xi
    2.26        prod + ((xi->tx.sring->req_prod - prod) >> 1) + 1;
    2.27      KeMemoryBarrier();
    2.28    } while ((cons == prod) && (prod != xi->tx.sring->rsp_prod));
    2.29 -
    2.30 +/*
    2.31 +  RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xi->tx, notify);
    2.32 +  if (notify)
    2.33 +  {
    2.34 +    xi->XenInterface.EvtChn_Notify(xi->XenInterface.InterfaceHeader.Context,
    2.35 +      xi->event_channel);
    2.36 +  }
    2.37 +*/
    2.38    /* if queued packets, send them now?
    2.39    network_maybe_wake_tx(dev); */
    2.40  
    2.41 @@ -388,7 +401,7 @@ XenNet_Interrupt(
    2.42  
    2.43  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    2.44  
    2.45 -  KeAcquireSpinLock(&xi->Lock, &OldIrql);
    2.46 +  KeAcquireSpinLock(xi->Lock, &OldIrql);
    2.47  
    2.48    //KdPrint((__DRIVER_NAME "     ***XenNet Interrupt***\n"));  
    2.49  
    2.50 @@ -398,7 +411,7 @@ XenNet_Interrupt(
    2.51      XenNet_RxBufferCheck(xi);
    2.52    }
    2.53  
    2.54 -  KeReleaseSpinLock(&xi->Lock, OldIrql);
    2.55 +  KeReleaseSpinLock(xi->Lock, OldIrql);
    2.56  
    2.57  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    2.58  
    2.59 @@ -410,7 +423,6 @@ XenNet_BackEndStateHandler(char *Path, P
    2.60  {
    2.61    struct xennet_info *xi = Data;
    2.62    char *Value;
    2.63 -  int be_state;
    2.64    char TmpPath[128];
    2.65    xenbus_transaction_t xbt = 0;
    2.66    int retry = 0;
    2.67 @@ -436,10 +448,10 @@ XenNet_BackEndStateHandler(char *Path, P
    2.68  
    2.69    xi->XenInterface.XenBus_Read(xi->XenInterface.InterfaceHeader.Context,
    2.70      XBT_NIL, Path, &Value);
    2.71 -  be_state = atoi(Value);
    2.72 +  xi->backend_state = atoi(Value);
    2.73    xi->XenInterface.FreeMem(Value);
    2.74  
    2.75 -  switch (be_state)
    2.76 +  switch (xi->backend_state)
    2.77    {
    2.78    case XenbusStateUnknown:
    2.79      KdPrint((__DRIVER_NAME "     Backend State Changed to Unknown\n"));  
    2.80 @@ -502,10 +514,11 @@ XenNet_BackEndStateHandler(char *Path, P
    2.81  
    2.82      XenNet_AllocRXBuffers(xi);
    2.83  
    2.84 +    xi->state = XenbusStateConnected;
    2.85      KdPrint((__DRIVER_NAME "     Set Frontend state to Connected\n"));
    2.86      RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdoData->Path);
    2.87      xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
    2.88 -      XBT_NIL, TmpPath, "%d", XenbusStateConnected);
    2.89 +      XBT_NIL, TmpPath, "%d", xi->state);
    2.90  
    2.91      /* send fake arp? */
    2.92  
    2.93 @@ -519,7 +532,6 @@ XenNet_BackEndStateHandler(char *Path, P
    2.94  
    2.95    case XenbusStateConnected:
    2.96      KdPrint((__DRIVER_NAME "     Backend State Changed to Connected\n"));  
    2.97 -    KeSetEvent(&xi->backend_ready_event, 1, FALSE);
    2.98      break;
    2.99  
   2.100    case XenbusStateClosing:
   2.101 @@ -531,10 +543,12 @@ XenNet_BackEndStateHandler(char *Path, P
   2.102      break;
   2.103  
   2.104    default:
   2.105 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Undefined = %d\n", be_state));
   2.106 +    KdPrint((__DRIVER_NAME "     Backend State Changed to Undefined = %d\n", xi->backend_state));
   2.107      break;
   2.108    }
   2.109  
   2.110 +  KeSetEvent(&xi->backend_state_change_event, 1, FALSE);
   2.111 +
   2.112    return;
   2.113  
   2.114  trouble:
   2.115 @@ -549,7 +563,39 @@ XenNet_Halt(
   2.116    IN NDIS_HANDLE MiniportAdapterContext
   2.117    )
   2.118  {
   2.119 -  UNREFERENCED_PARAMETER(MiniportAdapterContext);
   2.120 +  struct xennet_info *xi = MiniportAdapterContext;
   2.121 +  CHAR TmpPath[128];
   2.122 +
   2.123 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.124 +  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   2.125 +
   2.126 +  // set frontend state to 'closing'
   2.127 +  xi->state = XenbusStateClosing;
   2.128 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdoData->Path);
   2.129 +  xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
   2.130 +    XBT_NIL, TmpPath, "%d", xi->state);
   2.131 +
   2.132 +  // wait for backend to set 'Closing' state
   2.133 +  while (xi->backend_state != XenbusStateClosing)
   2.134 +    KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, NULL);
   2.135 +
   2.136 +  // set frontend state to 'closed'
   2.137 +  xi->state = XenbusStateClosed;
   2.138 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdoData->Path);
   2.139 +  xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
   2.140 +    XBT_NIL, TmpPath, "%d", xi->state);
   2.141 +
   2.142 +  // wait for backend to set 'Closed' state
   2.143 +  while (xi->backend_state != XenbusStateClosed)
   2.144 +    KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, NULL);
   2.145 +
   2.146 +  // remove event channel xenbus entry
   2.147 +  // unbind event channel
   2.148 +  // remove tx/rx ring entries
   2.149 +  // clean up all grant table entries
   2.150 +  // free all memory
   2.151 +
   2.152 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.153  }
   2.154  
   2.155  static NDIS_STATUS
   2.156 @@ -568,6 +614,7 @@ XenNet_Init(
   2.157    struct xennet_info *xi = NULL;
   2.158    ULONG length;
   2.159    WDF_OBJECT_ATTRIBUTES wdf_attrs;
   2.160 +  char *msg;
   2.161    char *Value;
   2.162    char TmpPath[128];
   2.163  
   2.164 @@ -606,6 +653,9 @@ XenNet_Init(
   2.165    xi->rx_min_target = RX_DFL_MIN_TARGET;
   2.166    xi->rx_max_target = RX_MAX_TARGET;
   2.167  
   2.168 +  xi->state = XenbusStateUnknown;
   2.169 +  xi->backend_state = XenbusStateUnknown;
   2.170 +
   2.171    KeInitializeSpinLock(&xi->Lock);
   2.172  
   2.173    NdisAllocatePacketPool(&status, &xi->packet_pool, NET_RX_RING_SIZE,
   2.174 @@ -692,7 +742,7 @@ XenNet_Init(
   2.175    RtlStringCbCopyA(xi->BackendPath, ARRAY_SIZE(xi->BackendPath), Value);
   2.176    KdPrint((__DRIVER_NAME "backend path = %s\n", xi->BackendPath));
   2.177  
   2.178 -  KeInitializeEvent(&xi->backend_ready_event, SynchronizationEvent, FALSE);  
   2.179 +  KeInitializeEvent(&xi->backend_state_change_event, SynchronizationEvent, FALSE);  
   2.180  
   2.181    /* Add watch on backend state */
   2.182    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->BackendPath);
   2.183 @@ -700,7 +750,8 @@ XenNet_Init(
   2.184        XBT_NIL, TmpPath, XenNet_BackEndStateHandler, xi);
   2.185  
   2.186    // wait here for signal that we are all set up
   2.187 -  KeWaitForSingleObject(&xi->backend_ready_event, Executive, KernelMode, FALSE, NULL);
   2.188 +  while (xi->backend_state != XenbusStateConnected)
   2.189 +    KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, NULL);
   2.190  
   2.191    /* get mac address */
   2.192    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/mac", xi->BackendPath);
   2.193 @@ -950,7 +1001,7 @@ XenNet_SetInformation(
   2.194    struct xennet_info *xi = MiniportAdapterContext;
   2.195    PULONG64 data = InformationBuffer;
   2.196  
   2.197 -//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.198 +  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.199  
   2.200    UNREFERENCED_PARAMETER(MiniportAdapterContext);
   2.201    UNREFERENCED_PARAMETER(InformationBufferLength);
   2.202 @@ -1087,7 +1138,7 @@ XenNet_SetInformation(
   2.203        status = NDIS_STATUS_NOT_SUPPORTED;
   2.204        break;
   2.205    }
   2.206 -//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.207 +  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.208    return status;
   2.209  }
   2.210  
   2.211 @@ -1177,11 +1228,11 @@ XenNet_SendPackets(
   2.212    int notify;
   2.213    PMDL pmdl;
   2.214    UINT pkt_size;
   2.215 -  KIRQL OldIrql;
   2.216 +  PKIRQL OldIrql;
   2.217  
   2.218  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.219  
   2.220 -  KeAcquireSpinLock(&xi->Lock, &OldIrql);
   2.221 +  KeAcquireSpinLock(xi->Lock, &OldIrql);
   2.222  
   2.223    for (i = 0; i < NumberOfPackets; i++)
   2.224    {
   2.225 @@ -1230,7 +1281,7 @@ XenNet_SendPackets(
   2.226        xi->event_channel);
   2.227    }
   2.228  
   2.229 -  KeReleaseSpinLock(&xi->Lock, OldIrql);
   2.230 +  KeReleaseSpinLock(xi->Lock, OldIrql);
   2.231  
   2.232  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.233  }
   2.234 @@ -1256,7 +1307,9 @@ XenNet_Shutdown(
   2.235    IN NDIS_HANDLE MiniportAdapterContext
   2.236    )
   2.237  {
   2.238 -  UNREFERENCED_PARAMETER(MiniportAdapterContext);
   2.239 +  struct xennet_info *xi = MiniportAdapterContext;
   2.240 +
   2.241 +  // I think all we are supposed to do here is reset the adapter, which for us might be nothing...
   2.242  
   2.243    KdPrint((__FUNCTION__ " called\n"));
   2.244  }