win-pvdrivers

changeset 107:1937a3bf6f64

xennet: tidy up/rearrange device context struct, rename vars for consistency, other misc cleanups
author Andy Grover <andy.grover@oracle.com>
date Thu Jan 10 10:59:49 2008 -0800 (2008-01-10)
parents 64f2791889f4
children fb19fc778b9d
files xennet/xennet.c xennet/xennet.h
line diff
     1.1 --- a/xennet/xennet.c	Wed Jan 09 12:10:32 2008 -0800
     1.2 +++ b/xennet/xennet.c	Thu Jan 10 10:59:49 2008 -0800
     1.3 @@ -45,26 +45,41 @@ Foundation, Inc., 51 Franklin Street, Fi
     1.4  
     1.5  struct xennet_info
     1.6  {
     1.7 +  /* Base device vars */
     1.8    PDEVICE_OBJECT pdo;
     1.9    PDEVICE_OBJECT fdo;
    1.10    PDEVICE_OBJECT lower_do;
    1.11    WDFDEVICE wdf_device;
    1.12 -  PXENPCI_XEN_DEVICE_DATA pdoData;
    1.13 +  WCHAR dev_desc[NAME_SIZE];
    1.14  
    1.15 -  WCHAR name[NAME_SIZE];
    1.16 +  /* NDIS-related vars */
    1.17    NDIS_HANDLE adapter_handle;
    1.18 +  NDIS_HANDLE packet_pool;
    1.19 +  NDIS_HANDLE buffer_pool;
    1.20    ULONG packet_filter;
    1.21    int connected;
    1.22    UINT8 perm_mac_addr[ETH_ALEN];
    1.23    UINT8 curr_mac_addr[ETH_ALEN];
    1.24  
    1.25 -//  char Path[128];
    1.26 -  char BackendPath[128];
    1.27 +  /* Misc. Xen vars */
    1.28    XEN_IFACE XenInterface;
    1.29 +  PXENPCI_XEN_DEVICE_DATA pdo_data;
    1.30 +  evtchn_port_t event_channel;
    1.31 +  ULONG state;
    1.32 +  KEVENT backend_state_change_event;
    1.33 +  char backend_path[MAX_XENBUS_STR_LEN];
    1.34 +  ULONG backend_state;
    1.35  
    1.36 -  /* ring control structures */
    1.37 +  /* Xen ring-related vars */
    1.38 +  KSPIN_LOCK rx_lock;
    1.39 +  KSPIN_LOCK tx_lock;
    1.40 +
    1.41 +  LIST_ENTRY rx_free_pkt_list;
    1.42 +
    1.43    struct netif_tx_front_ring tx;
    1.44    struct netif_rx_front_ring rx;
    1.45 +  grant_ref_t tx_ring_ref;
    1.46 +  grant_ref_t rx_ring_ref;
    1.47  
    1.48    /* ptrs to the actual rings themselvves */
    1.49    struct netif_tx_sring *tx_pgs;
    1.50 @@ -84,12 +99,6 @@ struct xennet_info
    1.51    grant_ref_t gref_rx_head;
    1.52    grant_ref_t grant_rx_ref[NET_TX_RING_SIZE];
    1.53  
    1.54 -  UINT irq;
    1.55 -  evtchn_port_t event_channel;
    1.56 -
    1.57 -  grant_ref_t tx_ring_ref;
    1.58 -  grant_ref_t rx_ring_ref;
    1.59 -
    1.60    /* Receive-ring batched refills. */
    1.61  #define RX_MIN_TARGET 8
    1.62  #define RX_DFL_MIN_TARGET 64
    1.63 @@ -98,24 +107,12 @@ struct xennet_info
    1.64    ULONG rx_max_target;
    1.65    ULONG rx_min_target;
    1.66  
    1.67 -  NDIS_HANDLE packet_pool;
    1.68 -  NDIS_HANDLE buffer_pool;
    1.69 -
    1.70    /* stats */
    1.71    ULONG64 stat_tx_ok;
    1.72    ULONG64 stat_rx_ok;
    1.73    ULONG64 stat_tx_error;
    1.74    ULONG64 stat_rx_error;
    1.75    ULONG64 stat_rx_no_buffer;
    1.76 -
    1.77 -//  KEVENT backend_ready_event;
    1.78 -  KEVENT backend_state_change_event;
    1.79 -
    1.80 -  ULONG state;
    1.81 -  ULONG backend_state;
    1.82 -
    1.83 -  KSPIN_LOCK RxLock;
    1.84 -  KSPIN_LOCK TxLock;
    1.85  };
    1.86  
    1.87  /* This function copied from linux's lib/vsprintf.c, see it for attribution */
    1.88 @@ -177,7 +174,7 @@ XenNet_TxBufferGC(struct xennet_info *xi
    1.89  
    1.90  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    1.91  
    1.92 -  KeAcquireSpinLock(&xi->TxLock, &OldIrql);
    1.93 +  KeAcquireSpinLock(&xi->tx_lock, &OldIrql);
    1.94  
    1.95    do {
    1.96      prod = xi->tx.sring->rsp_prod;
    1.97 @@ -224,7 +221,7 @@ XenNet_TxBufferGC(struct xennet_info *xi
    1.98    /* if queued packets, send them now?
    1.99    network_maybe_wake_tx(dev); */
   1.100  
   1.101 -  KeReleaseSpinLock(&xi->TxLock, OldIrql);
   1.102 +  KeReleaseSpinLock(&xi->tx_lock, OldIrql);
   1.103  
   1.104  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   1.105  
   1.106 @@ -348,7 +345,7 @@ XenNet_RxBufferFree(struct xennet_info *
   1.107  
   1.108    ASSERT(!xi->connected);
   1.109  
   1.110 -  KeAcquireSpinLock(&xi->RxLock, &OldIrql);
   1.111 +  KeAcquireSpinLock(&xi->rx_lock, &OldIrql);
   1.112  
   1.113    for (i = 0; i < NET_RX_RING_SIZE; i++)
   1.114    {
   1.115 @@ -370,7 +367,7 @@ XenNet_RxBufferFree(struct xennet_info *
   1.116      NdisFreePacket(packet);
   1.117    }
   1.118  
   1.119 -  KeReleaseSpinLock(&xi->RxLock, OldIrql);
   1.120 +  KeReleaseSpinLock(&xi->rx_lock, OldIrql);
   1.121  }
   1.122  
   1.123  // Called at DISPATCH_LEVEL
   1.124 @@ -392,7 +389,7 @@ XenNet_RxBufferCheck(struct xennet_info 
   1.125  
   1.126    ASSERT(xi->connected);
   1.127  
   1.128 -  KeAcquireSpinLock(&xi->RxLock, &OldIrql);
   1.129 +  KeAcquireSpinLock(&xi->rx_lock, &OldIrql);
   1.130  
   1.131    do {
   1.132      prod = xi->rx.sring->rsp_prod;
   1.133 @@ -454,7 +451,7 @@ XenNet_RxBufferCheck(struct xennet_info 
   1.134    /* Give netback more buffers */
   1.135    XenNet_RxBufferAlloc(xi);
   1.136  
   1.137 -  KeReleaseSpinLock(&xi->RxLock, OldIrql);
   1.138 +  KeReleaseSpinLock(&xi->rx_lock, OldIrql);
   1.139  
   1.140    //xi->rx.sring->rsp_event = xi->rx.rsp_cons + 1;
   1.141  
   1.142 @@ -494,7 +491,7 @@ XenNet_BackEndStateHandler(char *Path, P
   1.143  {
   1.144    struct xennet_info *xi = Data;
   1.145    char *Value;
   1.146 -  char TmpPath[128];
   1.147 +  char TmpPath[MAX_XENBUS_STR_LEN];
   1.148    xenbus_transaction_t xbt = 0;
   1.149    int retry = 0;
   1.150    char *err;
   1.151 @@ -580,7 +577,7 @@ XenNet_BackEndStateHandler(char *Path, P
   1.152      for (i = 0; params[i].name; i++)
   1.153      {
   1.154        RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/%s",
   1.155 -        xi->pdoData->Path, params[i].name);
   1.156 +        xi->pdo_data->Path, params[i].name);
   1.157        err = xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
   1.158          XBT_NIL, TmpPath, "%d", params[i].value);
   1.159        if (err)
   1.160 @@ -598,7 +595,7 @@ XenNet_BackEndStateHandler(char *Path, P
   1.161  
   1.162      xi->state = XenbusStateConnected;
   1.163      KdPrint((__DRIVER_NAME "     Set Frontend state to Connected\n"));
   1.164 -    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdoData->Path);
   1.165 +    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
   1.166      xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
   1.167        XBT_NIL, TmpPath, "%d", xi->state);
   1.168  
   1.169 @@ -660,7 +657,7 @@ XenNet_Init(
   1.170    WDF_OBJECT_ATTRIBUTES wdf_attrs;
   1.171    char *res;
   1.172    char *Value;
   1.173 -  char TmpPath[128];
   1.174 +  char TmpPath[MAX_XENBUS_STR_LEN];
   1.175  
   1.176    UNREFERENCED_PARAMETER(OpenErrorStatus);
   1.177    UNREFERENCED_PARAMETER(WrapperConfigurationContext);
   1.178 @@ -703,8 +700,9 @@ XenNet_Init(
   1.179    xi->state = XenbusStateUnknown;
   1.180    xi->backend_state = XenbusStateUnknown;
   1.181  
   1.182 -  KeInitializeSpinLock(&xi->TxLock);
   1.183 -  KeInitializeSpinLock(&xi->RxLock);
   1.184 +  KeInitializeSpinLock(&xi->tx_lock);
   1.185 +  KeInitializeSpinLock(&xi->rx_lock);
   1.186 +  NdisInitializeListHead(&xi->rx_free_pkt_list);
   1.187  
   1.188    NdisAllocatePacketPool(&status, &xi->packet_pool, NET_RX_RING_SIZE,
   1.189      PROTOCOL_RESERVED_SIZE_IN_PACKET);
   1.190 @@ -726,7 +724,7 @@ XenNet_Init(
   1.191  
   1.192    NdisMGetDeviceProperty(MiniportAdapterHandle, &xi->pdo, &xi->fdo,
   1.193      &xi->lower_do, NULL, NULL);
   1.194 -  xi->pdoData = (PXENPCI_XEN_DEVICE_DATA)xi->pdo->DeviceExtension;
   1.195 +  xi->pdo_data = (PXENPCI_XEN_DEVICE_DATA)xi->pdo->DeviceExtension;
   1.196  
   1.197    /* Initialize tx_pkts as a free chain containing every entry. */
   1.198    for (i = 0; i < NET_TX_RING_SIZE+1; i++) {
   1.199 @@ -742,7 +740,7 @@ XenNet_Init(
   1.200    xi->packet_filter = NDIS_PACKET_TYPE_PROMISCUOUS;
   1.201  
   1.202    status = IoGetDeviceProperty(xi->pdo, DevicePropertyDeviceDescription,
   1.203 -    NAME_SIZE, xi->name, &length);
   1.204 +    NAME_SIZE, xi->dev_desc, &length);
   1.205    if (!NT_SUCCESS(status))
   1.206    {
   1.207      KdPrint(("IoGetDeviceProperty failed with 0x%x\n", status));
   1.208 @@ -777,7 +775,7 @@ XenNet_Init(
   1.209    }
   1.210  
   1.211    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath),
   1.212 -      "%s/backend", xi->pdoData->Path);
   1.213 +      "%s/backend", xi->pdo_data->Path);
   1.214    KdPrint(("About to read %s to get backend path\n", TmpPath));
   1.215    res = xi->XenInterface.XenBus_Read(xi->XenInterface.InterfaceHeader.Context,
   1.216        XBT_NIL, TmpPath, &Value);
   1.217 @@ -788,10 +786,10 @@ XenNet_Init(
   1.218      status = NDIS_STATUS_FAILURE;
   1.219      goto err;
   1.220    }
   1.221 -  RtlStringCbCopyA(xi->BackendPath, ARRAY_SIZE(xi->BackendPath), Value);
   1.222 -  KdPrint((__DRIVER_NAME "backend path = %s\n", xi->BackendPath));
   1.223 +  RtlStringCbCopyA(xi->backend_path, ARRAY_SIZE(xi->backend_path), Value);
   1.224 +  KdPrint((__DRIVER_NAME "backend path = %s\n", xi->backend_path));
   1.225  
   1.226 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/type", xi->BackendPath);
   1.227 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/type", xi->backend_path);
   1.228    res = xi->XenInterface.XenBus_Read(xi->XenInterface.InterfaceHeader.Context,
   1.229        XBT_NIL, TmpPath, &Value);
   1.230  
   1.231 @@ -807,12 +805,12 @@ XenNet_Init(
   1.232    KeInitializeEvent(&xi->backend_state_change_event, SynchronizationEvent, FALSE);  
   1.233  
   1.234    /* Add watch on backend state */
   1.235 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->BackendPath);
   1.236 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->backend_path);
   1.237    xi->XenInterface.XenBus_AddWatch(xi->XenInterface.InterfaceHeader.Context,
   1.238        XBT_NIL, TmpPath, XenNet_BackEndStateHandler, xi);
   1.239  
   1.240    /* Tell backend we're coming up */
   1.241 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdoData->Path);
   1.242 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
   1.243    xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
   1.244      XBT_NIL, TmpPath, "%d", XenbusStateInitialising);
   1.245  
   1.246 @@ -825,7 +823,7 @@ XenNet_Init(
   1.247    KdPrint((__DRIVER_NAME "     Connected\n"));
   1.248  
   1.249    /* get mac address */
   1.250 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/mac", xi->BackendPath);
   1.251 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/mac", xi->backend_path);
   1.252    xi->XenInterface.XenBus_Read(xi->XenInterface.InterfaceHeader.Context,
   1.253        XBT_NIL, TmpPath, &Value);
   1.254    if (!Value)
   1.255 @@ -1450,7 +1448,7 @@ XenNet_SendPackets(
   1.256  
   1.257  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   1.258  
   1.259 -  KeAcquireSpinLock(&xi->TxLock, &OldIrql);
   1.260 +  KeAcquireSpinLock(&xi->tx_lock, &OldIrql);
   1.261  
   1.262    for (i = 0; i < NumberOfPackets; i++)
   1.263    {
   1.264 @@ -1501,7 +1499,7 @@ XenNet_SendPackets(
   1.265        xi->event_channel);
   1.266    }
   1.267  
   1.268 -  KeReleaseSpinLock(&xi->TxLock, OldIrql);
   1.269 +  KeReleaseSpinLock(&xi->tx_lock, OldIrql);
   1.270  
   1.271  //  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   1.272  }
   1.273 @@ -1543,7 +1541,7 @@ XenNet_Halt(
   1.274    )
   1.275  {
   1.276    struct xennet_info *xi = MiniportAdapterContext;
   1.277 -  CHAR TmpPath[128];
   1.278 +  CHAR TmpPath[MAX_XENBUS_STR_LEN];
   1.279  
   1.280    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   1.281    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
   1.282 @@ -1552,7 +1550,7 @@ XenNet_Halt(
   1.283  
   1.284    // set frontend state to 'closing'
   1.285    xi->state = XenbusStateClosing;
   1.286 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdoData->Path);
   1.287 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
   1.288    xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
   1.289      XBT_NIL, TmpPath, "%d", xi->state);
   1.290  
   1.291 @@ -1563,7 +1561,7 @@ XenNet_Halt(
   1.292  
   1.293    // set frontend state to 'closed'
   1.294    xi->state = XenbusStateClosed;
   1.295 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdoData->Path);
   1.296 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
   1.297    xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
   1.298      XBT_NIL, TmpPath, "%d", xi->state);
   1.299  
   1.300 @@ -1592,7 +1590,7 @@ XenNet_Halt(
   1.301    XenNet_RxBufferFree(MiniportAdapterContext);
   1.302  
   1.303    /* Remove watch on backend state */
   1.304 -  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->BackendPath);
   1.305 +  RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->backend_path);
   1.306    xi->XenInterface.XenBus_RemWatch(xi->XenInterface.InterfaceHeader.Context,
   1.307        XBT_NIL, TmpPath, XenNet_BackEndStateHandler, xi);
   1.308  
     2.1 --- a/xennet/xennet.h	Wed Jan 09 12:10:32 2008 -0800
     2.2 +++ b/xennet/xennet.h	Thu Jan 10 10:59:49 2008 -0800
     2.3 @@ -60,4 +60,5 @@ Foundation, Inc., 51 Franklin Street, Fi
     2.4  #define XN_MAX_SEND_PKTS 16
     2.5  
     2.6  #define XENSOURCE_MAC_HDR 0x00163E
     2.7 -#define XN_VENDOR_DESC "Xensource"
     2.8 \ No newline at end of file
     2.9 +#define XN_VENDOR_DESC "Xensource"
    2.10 +#define MAX_XENBUS_STR_LEN 128
    2.11 \ No newline at end of file