win-pvdrivers

changeset 11:9e029b33b66b

Add rudimentary net support
author Andy Grover <andy@groveronline.com>
date Tue Nov 27 11:21:35 2007 -0800 (2007-11-27)
parents 7dd1e28542fe
children 5712dede5a1b
files target/netxen.inf xennet/makefile xennet/sources xennet/xennet.c xennet/xennet.h
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/target/netxen.inf	Tue Nov 27 11:21:35 2007 -0800
     1.3 @@ -0,0 +1,100 @@
     1.4 +[Version]
     1.5 +Signature="$WINDOWS NT$"
     1.6 +Class=Net
     1.7 +ClassGuid={4D36E972-E325-11CE-BFC1-08002BE10318}
     1.8 +Provider=%JAMESHARPER%
     1.9 +DriverVer=11/11/2007,1.0.1.290
    1.10 +
    1.11 +[DestinationDirs]
    1.12 +DefaultDestDir = 12
    1.13 +ClassInstall32_CopyFiles=11
    1.14 +CoInstaller_CopyFiles = 11
    1.15 +
    1.16 +; ================= Class section =====================
    1.17 +
    1.18 +[ClassInstall32]
    1.19 +Addreg=ClassInstall32_AddReg
    1.20 +CopyFiles=ClassInstall32_CopyFiles
    1.21 +
    1.22 +[ClassInstall32_AddReg]
    1.23 +HKR,,,0,%ClassName%
    1.24 +HKR,,Icon,,-5
    1.25 +HKR,,DeviceCharacteristics,0x10001,0x100
    1.26 +HKR,,Security,,"D:P(A;;GA;;;SY)(A;;GA;;;BA)"
    1.27 +
    1.28 +[ClassInstall32_CopyFiles]
    1.29 +
    1.30 +[ControlFlags]
    1.31 +ExcludeFromSelect=*
    1.32 +
    1.33 +
    1.34 +[Manufacturer]
    1.35 +%JAMESHARPER%=JAMESHARPER,NTx86
    1.36 +
    1.37 +[JAMESHARPER]
    1.38 +%XenNet.DRVDESC%=XenNet_Inst, XEN\VIF
    1.39 +
    1.40 +[JAMESHARPER.NTx86]
    1.41 +%XenNet.DRVDESC%=XenNet_Inst, XEN\VIF
    1.42 +
    1.43 +[XenNet_Inst.NT]
    1.44 +CopyFiles=XenNet.CopyFiles
    1.45 +Characteristics = 0x1 ; NCF_VIRTUAL
    1.46 +AddReg = XenNet_Reg
    1.47 +
    1.48 +[XenNet_Reg]
    1.49 +HKR, Ndi, Service, 0, "XenNet"
    1.50 +HKR, Ndi\Interfaces, UpperRange, 0, "ndis5"
    1.51 +HKR, Ndi\Interfaces, LowerRange, 0, "ethernet"
    1.52 +
    1.53 +[XenNet.CopyFiles]
    1.54 +xennet.sys
    1.55 +
    1.56 +[SourceDisksFiles]
    1.57 +xennet.sys=1
    1.58 +WdfCoinstaller01005.dll=1,,
    1.59 +
    1.60 +[SourceDisksNames.x86]
    1.61 +1 = %DISK_NAME%,,,\i386
    1.62 +
    1.63 +[XenNet_Inst.Services]
    1.64 +AddService=XenNet,2,XenNet_Service 
    1.65 +
    1.66 +[XenNet_Inst.NT.Services]
    1.67 +AddService=XenNet,2,XenNet_Service 
    1.68 +
    1.69 +[XenNet_Service]
    1.70 +DisplayName    = %XenNet.SVCDESC%                            
    1.71 +ServiceType    = 1
    1.72 +StartType      = 3
    1.73 +ErrorControl   = 1
    1.74 +LoadOrderGroup = NDIS
    1.75 +ServiceBinary  = %12%\xennet.sys                            
    1.76 +AddReg = XenNet_Service_AddReg
    1.77 +
    1.78 +[XenNet_Service_AddReg]
    1.79 +; 5 = PciBus, 0 = Internal, 15 = PnpBus
    1.80 +HKR,"Parameters\PnpInterface", "15", 0x00010001, 0x00000001
    1.81 +
    1.82 +[XenNet_Inst.NT.CoInstallers]
    1.83 +AddReg=CoInstaller_AddReg
    1.84 +CopyFiles=CoInstaller_CopyFiles
    1.85 +
    1.86 +[CoInstaller_CopyFiles]
    1.87 +WdfCoinstaller01005.dll,,,2
    1.88 +
    1.89 +[CoInstaller_AddReg]
    1.90 +HKR,,CoInstallers32,0x00010000, "WdfCoinstaller01005.dll,WdfCoInstaller"
    1.91 +
    1.92 +[XenNet_Inst.NT.Wdf]
    1.93 +KmdfService = xennet, xennet_wdfsect
    1.94 +
    1.95 +[xennet_wdfsect]
    1.96 +KmdfLibraryVersion = 1.0
    1.97 +
    1.98 +[Strings]
    1.99 +JAMESHARPER = "James Harper"
   1.100 +ClassName = "Network Adapters"
   1.101 +XenNet.SVCDESC = "Xen Net Device Driver"
   1.102 +XenNet.DRVDESC = "Xen Net Device Driver"
   1.103 +DISK_NAME = "Xen Net Device Driver Install Disk"
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/xennet/makefile	Tue Nov 27 11:21:35 2007 -0800
     2.3 @@ -0,0 +1,1 @@
     2.4 +!INCLUDE $(NTMAKEENV)\makefile.def
     2.5 \ No newline at end of file
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/xennet/sources	Tue Nov 27 11:21:35 2007 -0800
     3.3 @@ -0,0 +1,14 @@
     3.4 +TARGETNAME=XENNET
     3.5 +TARGETTYPE=DRIVER
     3.6 +TARGETPATH=..\Target
     3.7 +
     3.8 +MSC_WARNING_LEVEL=/W4
     3.9 +
    3.10 +INCLUDES = ..\common\include;..\common\include\public
    3.11 +
    3.12 +NO_BINPLACE=1
    3.13 +KMDF_VERSION=1
    3.14 +TARGETLIBS=$(DDK_LIB_PATH)\ntstrsafe.lib \
    3.15 +  $(DDK_LIB_PATH)\ndis.lib
    3.16 +
    3.17 +SOURCES=xennet.c
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/xennet/xennet.c	Tue Nov 27 11:21:35 2007 -0800
     4.3 @@ -0,0 +1,580 @@
     4.4 +/*
     4.5 +PV Net Driver for Windows Xen HVM Domains
     4.6 +Copyright (C) 2007 James Harper
     4.7 +Copyright (C) 2007 Andrew Grover
     4.8 +
     4.9 +This program is free software; you can redistribute it and/or
    4.10 +modify it under the terms of the GNU General Public License
    4.11 +as published by the Free Software Foundation; either version 2
    4.12 +of the License, or (at your option) any later version.
    4.13 +
    4.14 +This program is distributed in the hope that it will be useful,
    4.15 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.17 +GNU General Public License for more details.
    4.18 +
    4.19 +You should have received a copy of the GNU General Public License
    4.20 +along with this program; if not, write to the Free Software
    4.21 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    4.22 +*/
    4.23 +
    4.24 +#include "xennet.h"
    4.25 +
    4.26 +#if !defined (NDIS51_MINIPORT)
    4.27 +#error requires NDIS 5.1 compilation environment
    4.28 +#endif
    4.29 +
    4.30 +#define GRANT_INVALID_REF	0
    4.31 +
    4.32 +#define NET_TX_RING_SIZE __RING_SIZE((struct netif_tx_sring *)0, PAGE_SIZE)
    4.33 +#define NET_RX_RING_SIZE __RING_SIZE((struct netif_rx_sring *)0, PAGE_SIZE)
    4.34 +
    4.35 +struct xennet_info
    4.36 +{
    4.37 +  PDEVICE_OBJECT pdo;
    4.38 +  PDEVICE_OBJECT fdo;
    4.39 +  PDEVICE_OBJECT lower_do;
    4.40 +  WDFDEVICE *wdf_device;
    4.41 +
    4.42 +  WCHAR name[NAME_SIZE];
    4.43 +  NDIS_HANDLE adapter_handle;
    4.44 +  ULONG packet_filter;
    4.45 +  UCHAR perm_mac_addr[ETH_ALEN];
    4.46 +  UCHAR curr_mac_addr[ETH_ALEN];
    4.47 +
    4.48 +  char Path[128];
    4.49 +  char BackendPath[128];
    4.50 +  XEN_IFACE_EVTCHN EvtChnInterface;
    4.51 +  XEN_IFACE_XENBUS XenBusInterface;
    4.52 +  XEN_IFACE_XEN XenInterface;
    4.53 +  XEN_IFACE_GNTTBL GntTblInterface;
    4.54 +
    4.55 +  struct netif_tx_front_ring tx;
    4.56 +  struct netif_rx_front_ring rx;
    4.57 +
    4.58 +  /* do we need to keep track of these? */
    4.59 +  struct netif_tx_sring *txs;
    4.60 +  struct netif_rx_sring *rxs;
    4.61 +
    4.62 +  UINT irq;
    4.63 +  SHORT event_channel;
    4.64 +
    4.65 +  grant_ref_t tx_ring_ref;
    4.66 +  grant_ref_t rx_ring_ref;
    4.67 +};
    4.68 +
    4.69 +/* need to do typedef so the DECLARE below works */
    4.70 +typedef struct _wdf_device_info
    4.71 +{
    4.72 +  struct xennet_info *xennet_info;
    4.73 +} wdf_device_info;
    4.74 +
    4.75 +WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(wdf_device_info, GetWdfDeviceInfo)
    4.76 +
    4.77 +static PMDL
    4.78 +AllocatePages(int Pages)
    4.79 +{
    4.80 +  PHYSICAL_ADDRESS Min;
    4.81 +  PHYSICAL_ADDRESS Max;
    4.82 +  PHYSICAL_ADDRESS Align;
    4.83 +  PMDL Mdl;
    4.84 +
    4.85 +  KdPrint((__DRIVER_NAME " --> Allocate Pages\n"));
    4.86 +
    4.87 +  Min.QuadPart = 0;
    4.88 +  Max.QuadPart = 0xFFFFFFFF;
    4.89 +  Align.QuadPart = PAGE_SIZE;
    4.90 +
    4.91 +  Mdl = MmAllocatePagesForMdl(Min, Max, Align, Pages * PAGE_SIZE);
    4.92 +
    4.93 +  KdPrint((__DRIVER_NAME " <-- Allocate Pages (mdl = %08x)\n", Mdl));
    4.94 +
    4.95 +  return Mdl;
    4.96 +}
    4.97 +  
    4.98 +static PMDL
    4.99 +AllocatePage()
   4.100 +{
   4.101 +  return AllocatePages(1);
   4.102 +}
   4.103 +
   4.104 +static BOOLEAN
   4.105 +XenNet_Interrupt(
   4.106 +  PKINTERRUPT Interrupt,
   4.107 +  PVOID ServiceContext
   4.108 +  )
   4.109 +{
   4.110 +  struct xennet_info *xennet_info = ServiceContext;
   4.111 +  KIRQL KIrql;
   4.112 +
   4.113 +  // KeAcquireSpinLock(&ChildDeviceData->Lock, &KIrql);
   4.114 +  // KdPrint((__DRIVER_NAME " --> Setting Dpc Event\n"));
   4.115 +  // KeSetEvent(&ChildDeviceData->DpcThreadEvent, 1, FALSE);
   4.116 +  // KeReleaseSpinLock(&ChildDeviceData->Lock, KIrql);
   4.117 +  // KdPrint((__DRIVER_NAME " --> Dpc Event Set\n"));
   4.118 +
   4.119 +  /* do something */
   4.120 +
   4.121 +  return TRUE;
   4.122 +}
   4.123 +
   4.124 +VOID
   4.125 +XenNet_Halt(
   4.126 +  IN NDIS_HANDLE MiniportAdapterContext
   4.127 +  )
   4.128 +{
   4.129 +}
   4.130 +
   4.131 +static NDIS_STATUS
   4.132 +XenNet_Init(
   4.133 +  OUT PNDIS_STATUS OpenErrorStatus,
   4.134 +  OUT PUINT SelectedMediumIndex,
   4.135 +  IN PNDIS_MEDIUM MediumArray,
   4.136 +  IN UINT MediumArraySize,
   4.137 +  IN NDIS_HANDLE MiniportAdapterHandle,
   4.138 +  IN NDIS_HANDLE WrapperConfigurationContext
   4.139 +  )
   4.140 +{
   4.141 +  NDIS_STATUS status;
   4.142 +  UINT i;
   4.143 +  BOOLEAN medium_found = FALSE;
   4.144 +  struct xennet_info *xi = NULL;
   4.145 +  UINT length;
   4.146 +  WDF_OBJECT_ATTRIBUTES wdf_attrs;
   4.147 +  PMDL mdl;
   4.148 +  ULONG pfn;
   4.149 +
   4.150 +  /* deal with medium stuff */
   4.151 +  for (i = 0; i < MediumArraySize; i++)
   4.152 +  {
   4.153 +    if (MediumArray[i] == NdisMedium802_3)
   4.154 +    {
   4.155 +      medium_found = TRUE;
   4.156 +      break;
   4.157 +    }
   4.158 +  }
   4.159 +  if (!medium_found)
   4.160 +  {
   4.161 +    KdPrint(("NIC_MEDIA_TYPE not in MediumArray\n"));
   4.162 +    return NDIS_STATUS_UNSUPPORTED_MEDIA;
   4.163 +  }
   4.164 +  *SelectedMediumIndex = i;
   4.165 +
   4.166 +  /* Alloc memory for adapter private info */
   4.167 +  status = NdisAllocateMemoryWithTag(&xi, sizeof(*xi), XENNET_POOL_TAG);
   4.168 +  if (!NT_SUCCESS(status))
   4.169 +  {
   4.170 +    KdPrint(("NdisAllocateMemoryWithTag failed with 0x%x\n", status));
   4.171 +    status = NDIS_STATUS_RESOURCES;
   4.172 +    goto err;
   4.173 +  }
   4.174 +  RtlZeroMemory(xi, sizeof(*xi));
   4.175 +
   4.176 +  /* init xennet_info */
   4.177 +  xi->adapter_handle = MiniportAdapterHandle;
   4.178 +  NdisMGetDeviceProperty(MiniportAdapterHandle, &xi->pdo, &xi->fdo,
   4.179 +    &xi->lower_do, NULL, NULL);
   4.180 +
   4.181 +  status = IoGetDeviceProperty(xi->pdo, DevicePropertyDeviceDescription,
   4.182 +    NAME_SIZE, xi->name, &length);
   4.183 +  if (!NT_SUCCESS(status))
   4.184 +  {
   4.185 +    KdPrint(("IoGetDeviceProperty failed with 0x%x\n", status));
   4.186 +    status = NDIS_STATUS_FAILURE;
   4.187 +    goto err;
   4.188 +  }
   4.189 +
   4.190 +  NdisMSetAttributesEx(xi->adapter_handle, (NDIS_HANDLE) xi,
   4.191 +      0, NDIS_ATTRIBUTE_DESERIALIZE, NdisInterfaceInternal);
   4.192 +
   4.193 +  WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&wdf_attrs, wdf_device_info);
   4.194 +
   4.195 +  status = WdfDeviceMiniportCreate(WdfGetDriver(), &wdf_attrs, xi->fdo,
   4.196 +    xi->lower_do, xi->pdo, &xi->wdf_device);
   4.197 +  if (!NT_SUCCESS(status))
   4.198 +  {
   4.199 +    KdPrint(("WdfDeviceMiniportCreate failed with 0x%x\n", status));
   4.200 +    status = NDIS_STATUS_FAILURE;
   4.201 +    goto err;
   4.202 +  }
   4.203 +  
   4.204 +  GetWdfDeviceInfo(xi->wdf_device)->xennet_info = xi;
   4.205 +
   4.206 +  /* get lower (Xen) interfaces */
   4.207 +
   4.208 +  status = WdfFdoQueryForInterface(xi->wdf_device, &GUID_XEN_IFACE_EVTCHN,
   4.209 +    (PINTERFACE) &xi->EvtChnInterface, sizeof(XEN_IFACE_EVTCHN), 1, NULL);
   4.210 +  if(!NT_SUCCESS(status))
   4.211 +  {
   4.212 +    KdPrint(("WdfFdoQueryForInterface (EvtChn) failed with status 0x%08x\n", status));
   4.213 +    status = NDIS_STATUS_FAILURE;
   4.214 +    goto err;
   4.215 +  }
   4.216 +
   4.217 +  status = WdfFdoQueryForInterface(xi->wdf_device, &GUID_XEN_IFACE_XENBUS,
   4.218 +    (PINTERFACE) &xi->XenBusInterface, sizeof(XEN_IFACE_XENBUS), 1, NULL);
   4.219 +  if(!NT_SUCCESS(status))
   4.220 +  {
   4.221 +    KdPrint(("WdfFdoQueryForInterface (XenBus) failed with status 0x%08x\n", status));
   4.222 +    status = NDIS_STATUS_FAILURE;
   4.223 +    goto err;
   4.224 +  }
   4.225 +
   4.226 +  status = WdfFdoQueryForInterface(xi->wdf_device, &GUID_XEN_IFACE_XEN,
   4.227 +    (PINTERFACE) &xi->XenInterface, sizeof(XEN_IFACE_XEN), 1, NULL);
   4.228 +  if(!NT_SUCCESS(status))
   4.229 +  {
   4.230 +    KdPrint(("WdfFdoQueryForInterface (Xen) failed with status 0x%08x\n", status));
   4.231 +    status = NDIS_STATUS_FAILURE;
   4.232 +    goto err;
   4.233 +  }
   4.234 +
   4.235 +  status = WdfFdoQueryForInterface(xi->wdf_device, &GUID_XEN_IFACE_GNTTBL,
   4.236 +    (PINTERFACE) &xi->GntTblInterface, sizeof(XEN_IFACE_GNTTBL), 1, NULL);
   4.237 +  if(!NT_SUCCESS(status))
   4.238 +  {
   4.239 +    KdPrint(("WdfFdoQueryForInterface (GntTbl) failed with status 0x%08x\n", status));
   4.240 +    status = NDIS_STATUS_FAILURE;
   4.241 +    goto err;
   4.242 +  }
   4.243 +
   4.244 +  xi->event_channel = xi->EvtChnInterface.AllocUnbound(0);  
   4.245 +  xi->EvtChnInterface.Bind(xi->event_channel, XenNet_Interrupt, xi);
   4.246 +
   4.247 +  /* TODO: must free pages in MDL as well as MDL using MmFreePagesFromMdl and ExFreePool */
   4.248 +  // or, allocate mem and then get mdl, then free mdl
   4.249 +  mdl = AllocatePage();
   4.250 +  pfn = *MmGetMdlPfnArray(mdl);
   4.251 +  xi->txs = MmMapLockedPages(mdl, KernelMode);
   4.252 +  SHARED_RING_INIT(xi->txs);
   4.253 +  FRONT_RING_INIT(&xi->tx, xi->txs, PAGE_SIZE);
   4.254 +  xi->tx_ring_ref = xi->GntTblInterface.GrantAccess(0, pfn, FALSE);
   4.255 +
   4.256 +  mdl = AllocatePage();
   4.257 +  pfn = *MmGetMdlPfnArray(mdl);
   4.258 +  xi->rxs = MmMapLockedPages(mdl, KernelMode);
   4.259 +  SHARED_RING_INIT(xi->rxs);
   4.260 +  FRONT_RING_INIT(&xi->rx, xi->rxs, PAGE_SIZE);
   4.261 +  xi->rx_ring_ref = xi->GntTblInterface.GrantAccess(0, pfn, FALSE);
   4.262 +
   4.263 +  {
   4.264 +  char *msg;
   4.265 +  char **vif_devs;
   4.266 +  char buffer[128];
   4.267 +  // get mac addr
   4.268 +  msg = xi->XenBusInterface.List(XBT_NIL, "device/vif", &vif_devs);
   4.269 +  if (!msg)
   4.270 +  {
   4.271 +    for (i = 0; vif_devs[i]; i++)
   4.272 +    {
   4.273 +      RtlStringCbPrintfA(buffer, ARRAY_SIZE(buffer),
   4.274 +        "device/vif/%s/state", vif_devs[i]);
   4.275 +      KdPrint(("%s\n", buffer));
   4.276 +      //XenVbd_HotPlugHandler(buffer, NULL);
   4.277 +      //ExFreePoolWithTag(bdDevices[i], XENPCI_POOL_TAG);
   4.278 +    }
   4.279 +  }
   4.280 +  }
   4.281 +
   4.282 +  return NDIS_STATUS_SUCCESS;
   4.283 +
   4.284 +err:
   4.285 +  NdisFreeMemory(xi, 0, 0);
   4.286 +  return status;
   4.287 +}
   4.288 +
   4.289 +NDIS_OID supported_oids[] =
   4.290 +{
   4.291 +  OID_GEN_SUPPORTED_LIST,
   4.292 +  OID_GEN_HARDWARE_STATUS,
   4.293 +  OID_GEN_MEDIA_SUPPORTED,
   4.294 +  OID_GEN_MEDIA_IN_USE,
   4.295 +  OID_GEN_MAXIMUM_LOOKAHEAD,
   4.296 +  OID_GEN_MAXIMUM_FRAME_SIZE,
   4.297 +  OID_GEN_LINK_SPEED,
   4.298 +  OID_GEN_TRANSMIT_BUFFER_SPACE,
   4.299 +  OID_GEN_RECEIVE_BUFFER_SPACE,
   4.300 +  OID_GEN_TRANSMIT_BLOCK_SIZE,
   4.301 +  OID_GEN_RECEIVE_BLOCK_SIZE,
   4.302 +  OID_GEN_VENDOR_ID,
   4.303 +  OID_GEN_VENDOR_DESCRIPTION,
   4.304 +  OID_GEN_CURRENT_PACKET_FILTER,
   4.305 +  OID_GEN_CURRENT_LOOKAHEAD,
   4.306 +  OID_GEN_DRIVER_VERSION,
   4.307 +  OID_GEN_MAXIMUM_TOTAL_SIZE,
   4.308 +  OID_GEN_MAC_OPTIONS,
   4.309 +  OID_GEN_MEDIA_CONNECT_STATUS,
   4.310 +  OID_GEN_MAXIMUM_SEND_PACKETS,
   4.311 +  OID_802_3_PERMANENT_ADDRESS,
   4.312 +  OID_802_3_CURRENT_ADDRESS,
   4.313 +  OID_802_3_MULTICAST_LIST,
   4.314 +  OID_802_3_MAXIMUM_LIST_SIZE,
   4.315 +};
   4.316 +
   4.317 +NDIS_STATUS 
   4.318 +XenNet_QueryInformation(
   4.319 +  IN NDIS_HANDLE MiniportAdapterContext,
   4.320 +  IN NDIS_OID Oid,
   4.321 +  IN PVOID InformationBuffer,
   4.322 +  IN ULONG InformationBufferLength,
   4.323 +  OUT PULONG BytesWritten,
   4.324 +  OUT PULONG BytesNeeded)
   4.325 +{
   4.326 +  struct xennet_info *xi = MiniportAdapterContext;
   4.327 +  UCHAR vendor_desc[] = XN_VENDOR_DESC;
   4.328 +  ULONG temp_data;
   4.329 +  PVOID data = &temp_data;
   4.330 +  UINT len = sizeof(temp_data);
   4.331 +  NDIS_STATUS status = NDIS_STATUS_SUCCESS;
   4.332 +
   4.333 +  switch(Oid)
   4.334 +  {
   4.335 +    case OID_GEN_SUPPORTED_LIST:
   4.336 +      data = supported_oids;
   4.337 +      len = sizeof(supported_oids);
   4.338 +      break;
   4.339 +    case OID_GEN_HARDWARE_STATUS:
   4.340 +      temp_data = NdisHardwareStatusReady;
   4.341 +      break;
   4.342 +    case OID_GEN_MEDIA_SUPPORTED:
   4.343 +      temp_data = NdisMedium802_3;
   4.344 +      break;
   4.345 +    case OID_GEN_MEDIA_IN_USE:
   4.346 +      temp_data = NdisMedium802_3;
   4.347 +      break;
   4.348 +    case OID_GEN_MAXIMUM_LOOKAHEAD:
   4.349 +      temp_data = XN_DATA_SIZE;
   4.350 +      break;
   4.351 +    case OID_GEN_MAXIMUM_FRAME_SIZE:
   4.352 +      temp_data = XN_MAX_PKT_SIZE;
   4.353 +      break;
   4.354 +    case OID_GEN_LINK_SPEED:
   4.355 +      temp_data = 10000000; /* 1Gb */
   4.356 +      break;
   4.357 +    case OID_GEN_TRANSMIT_BUFFER_SPACE:
   4.358 +      /* pkts times sizeof ring, maybe? */
   4.359 +      temp_data = XN_MAX_PKT_SIZE * NET_TX_RING_SIZE;
   4.360 +      break;
   4.361 +    case OID_GEN_RECEIVE_BUFFER_SPACE:
   4.362 +      /* pkts times sizeof ring, maybe? */
   4.363 +      temp_data = XN_MAX_PKT_SIZE * NET_TX_RING_SIZE;
   4.364 +      break;
   4.365 +    case OID_GEN_TRANSMIT_BLOCK_SIZE:
   4.366 +      temp_data = XN_MAX_PKT_SIZE;
   4.367 +      break;
   4.368 +    case OID_GEN_RECEIVE_BLOCK_SIZE:
   4.369 +      temp_data = XN_MAX_PKT_SIZE;
   4.370 +      break;
   4.371 +    case OID_GEN_VENDOR_ID:
   4.372 +      temp_data = XENSOURCE_MAC_HDR;
   4.373 +      break;
   4.374 +    case OID_GEN_VENDOR_DESCRIPTION:
   4.375 +      data = vendor_desc;
   4.376 +      len = sizeof(vendor_desc);
   4.377 +      break;
   4.378 +    case OID_GEN_CURRENT_PACKET_FILTER:
   4.379 +      temp_data = xi->packet_filter;
   4.380 +      break;
   4.381 +    case OID_GEN_CURRENT_LOOKAHEAD:
   4.382 +      temp_data = XN_MAX_PKT_SIZE;
   4.383 +      break;
   4.384 +    case OID_GEN_DRIVER_VERSION:
   4.385 +      temp_data = (NDIS_MAJOR_VER << 8) | NDIS_MINOR_VER;
   4.386 +      len = 2;
   4.387 +      break;
   4.388 +    case OID_GEN_MAXIMUM_TOTAL_SIZE:
   4.389 +      temp_data = XN_MAX_PKT_SIZE;
   4.390 +      break;
   4.391 +    case OID_GEN_MAC_OPTIONS:
   4.392 +      temp_data = NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA | 
   4.393 +        NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |
   4.394 +        NDIS_MAC_OPTION_NO_LOOPBACK;
   4.395 +      break;
   4.396 +    case OID_GEN_MEDIA_CONNECT_STATUS:
   4.397 +      /* how can we not be connected?? */
   4.398 +      temp_data = NdisMediaStateConnected;
   4.399 +      break;
   4.400 +    case OID_GEN_MAXIMUM_SEND_PACKETS:
   4.401 +      temp_data = XN_MAX_SEND_PKTS;
   4.402 +      break;
   4.403 +    case OID_802_3_PERMANENT_ADDRESS:
   4.404 +      data = xi->perm_mac_addr;
   4.405 +      len = ETH_ALEN;
   4.406 +      break;
   4.407 +    case OID_802_3_CURRENT_ADDRESS:
   4.408 +      data = xi->curr_mac_addr;
   4.409 +      len = ETH_ALEN;
   4.410 +      break;
   4.411 +    case OID_802_3_MULTICAST_LIST:
   4.412 +      data = NULL;
   4.413 +      len = 0;
   4.414 +    case OID_802_3_MAXIMUM_LIST_SIZE:
   4.415 +      temp_data = 0; /* no mcast support */
   4.416 +      break;
   4.417 +    default:
   4.418 +      KdPrint(("Unknown OID 0x%x\n", Oid));
   4.419 +      status = NDIS_STATUS_NOT_SUPPORTED;
   4.420 +  }
   4.421 +
   4.422 +  if (!NT_SUCCESS(status))
   4.423 +  {
   4.424 +    return status;
   4.425 +  }
   4.426 +
   4.427 +  if (len > InformationBufferLength)
   4.428 +  {
   4.429 +    *BytesNeeded = len;
   4.430 +    return NDIS_STATUS_BUFFER_TOO_SHORT;
   4.431 +  }
   4.432 +
   4.433 +  *BytesWritten = len;
   4.434 +  if (len)
   4.435 +  {
   4.436 +    NdisMoveMemory(InformationBuffer, data, len);
   4.437 +  }
   4.438 +
   4.439 +  KdPrint(("Got OID 0x%x\n", Oid));
   4.440 +
   4.441 +  return status;
   4.442 +}
   4.443 +
   4.444 +NDIS_STATUS 
   4.445 +XenNet_SetInformation(
   4.446 +  IN NDIS_HANDLE MiniportAdapterContext,
   4.447 +  IN NDIS_OID Oid,
   4.448 +  IN PVOID InformationBuffer,
   4.449 +  IN ULONG InformationBufferLength,
   4.450 +  OUT PULONG BytesRead,
   4.451 +  OUT PULONG BytesNeeded
   4.452 +  )
   4.453 +{
   4.454 +  KdPrint((__FUNCTION__ " called\n"));
   4.455 +  return NDIS_STATUS_SUCCESS;
   4.456 +}
   4.457 +
   4.458 +VOID
   4.459 +XenNet_ReturnPacket(
   4.460 +  IN NDIS_HANDLE MiniportAdapterContext,
   4.461 +  IN PNDIS_PACKET Packet
   4.462 +  )
   4.463 +{
   4.464 +  KdPrint((__FUNCTION__ " called\n"));
   4.465 +}
   4.466 +
   4.467 +VOID
   4.468 +XenNet_SendPackets(
   4.469 +  IN NDIS_HANDLE MiniportAdapterContext,
   4.470 +  IN PPNDIS_PACKET PacketArray,
   4.471 +  IN UINT NumberOfPackets
   4.472 +  )
   4.473 +{
   4.474 +  /* for each packet:
   4.475 +    req_prod_pvt is the next entry in the cmd ring to use
   4.476 +    add pkt to array of saved packets
   4.477 +    fill out tx request for the first part of skb
   4.478 +    add to grant table
   4.479 +    do flags for csum etc
   4.480 +    gso (later)
   4.481 +    inc req_prod_pvt
   4.482 +    frags
   4.483 +    possibly notify
   4.484 +    network_tx)buf_gc
   4.485 +    stop netif if no more room
   4.486 +    */
   4.487 +  struct xennet_info *xi = MiniportAdapterContext;
   4.488 +  PNDIS_PACKET curr_packet;
   4.489 +  UINT i;
   4.490 +  UINT table_entry;
   4.491 +
   4.492 +  KdPrint((__FUNCTION__ " called\n"));
   4.493 +
   4.494 +  for (i = 0; i < NumberOfPackets; i++)
   4.495 +  {
   4.496 +    curr_packet = PacketArray[i];
   4.497 +    ASSERT(curr_packet);
   4.498 +
   4.499 +    table_entry = xi->tx.req_prod_pvt;
   4.500 +  }
   4.501 +
   4.502 +}
   4.503 +
   4.504 +VOID
   4.505 +XenNet_PnPEventNotify(
   4.506 +  IN NDIS_HANDLE MiniportAdapterContext,
   4.507 +  IN NDIS_DEVICE_PNP_EVENT PnPEvent,
   4.508 +  IN PVOID InformationBuffer,
   4.509 +  IN ULONG InformationBufferLength
   4.510 +  )
   4.511 +{
   4.512 +  KdPrint((__FUNCTION__ " called\n"));
   4.513 +}
   4.514 +
   4.515 +VOID
   4.516 +XenNet_Shutdown(
   4.517 +  IN NDIS_HANDLE MiniportAdapterContext
   4.518 +  )
   4.519 +{
   4.520 +  KdPrint((__FUNCTION__ " called\n"));
   4.521 +}
   4.522 +
   4.523 +NTSTATUS
   4.524 +DriverEntry(
   4.525 +  PDRIVER_OBJECT DriverObject,
   4.526 +  PUNICODE_STRING RegistryPath
   4.527 +  )
   4.528 +{
   4.529 +  NTSTATUS status;
   4.530 +  WDF_DRIVER_CONFIG config;
   4.531 +  NDIS_HANDLE ndis_wrapper_handle;
   4.532 +  NDIS_MINIPORT_CHARACTERISTICS mini_chars;
   4.533 +
   4.534 +  RtlZeroMemory(&mini_chars, sizeof(mini_chars));
   4.535 +
   4.536 +  WDF_DRIVER_CONFIG_INIT(&config, WDF_NO_EVENT_CALLBACK);
   4.537 +  config.DriverInitFlags |= WdfDriverInitNoDispatchOverride;
   4.538 +
   4.539 +  status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES,
   4.540 +    &config, WDF_NO_HANDLE);
   4.541 +  if (!NT_SUCCESS(status))
   4.542 +  {
   4.543 +    KdPrint(("WdfDriverCreate failed err = 0x%x\n", status));
   4.544 +    return status;
   4.545 +  }
   4.546 +
   4.547 +  NdisMInitializeWrapper(&ndis_wrapper_handle, DriverObject, RegistryPath, NULL);
   4.548 +  if (!ndis_wrapper_handle)
   4.549 +  {
   4.550 +    KdPrint(("NdisMInitializeWrapper failed\n"));
   4.551 +    return NDIS_STATUS_FAILURE;
   4.552 +  }
   4.553 +
   4.554 +  /* NDIS 5.1 driver */
   4.555 +  mini_chars.MajorNdisVersion = 5;
   4.556 +  mini_chars.MinorNdisVersion = 1;
   4.557 +
   4.558 +  mini_chars.HaltHandler = XenNet_Halt;
   4.559 +  mini_chars.InitializeHandler = XenNet_Init;
   4.560 +  mini_chars.ISRHandler = NULL; // needed if we register interrupt?
   4.561 +  mini_chars.QueryInformationHandler = XenNet_QueryInformation;
   4.562 +  mini_chars.ResetHandler = NULL; //TODO: fill in
   4.563 +  mini_chars.SetInformationHandler = XenNet_SetInformation;
   4.564 +  /* added in v.4 -- use multiple pkts interface */
   4.565 +  mini_chars.ReturnPacketHandler = XenNet_ReturnPacket;
   4.566 +  mini_chars.SendPacketsHandler = XenNet_SendPackets;
   4.567 +  /* added in v.5.1 */
   4.568 +  mini_chars.PnPEventNotifyHandler = XenNet_PnPEventNotify;
   4.569 +  mini_chars.AdapterShutdownHandler = XenNet_Shutdown;
   4.570 +
   4.571 +  /* TODO: we don't have hardware, but we have "resources", so do we need to implement fns to handle this? */
   4.572 +
   4.573 +  /* set up upper-edge interface */
   4.574 +  status = NdisMRegisterMiniport(ndis_wrapper_handle, &mini_chars, sizeof(mini_chars));
   4.575 +  if (!NT_SUCCESS(status))
   4.576 +  {
   4.577 +    KdPrint(("NdisMRegisterMiniport failed, status = 0x%x\n", status));
   4.578 +    NdisTerminateWrapper(ndis_wrapper_handle, NULL);
   4.579 +    return status;
   4.580 +  }
   4.581 +
   4.582 +  return status;
   4.583 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/xennet/xennet.h	Tue Nov 27 11:21:35 2007 -0800
     5.3 @@ -0,0 +1,65 @@
     5.4 +/*
     5.5 +PV Drivers for Windows Xen HVM Domains
     5.6 +Copyright (C) 2007 James Harper
     5.7 +Copyright (C) 2007 Andrew Grover
     5.8 +
     5.9 +This program is free software; you can redistribute it and/or
    5.10 +modify it under the terms of the GNU General Public License
    5.11 +as published by the Free Software Foundation; either version 2
    5.12 +of the License, or (at your option) any later version.
    5.13 +
    5.14 +This program is distributed in the hope that it will be useful,
    5.15 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.17 +GNU General Public License for more details.
    5.18 +
    5.19 +You should have received a copy of the GNU General Public License
    5.20 +along with this program; if not, write to the Free Software
    5.21 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    5.22 +*/
    5.23 +
    5.24 +#pragma warning(disable: 4201)
    5.25 +#pragma warning(disable: 4214)
    5.26 +
    5.27 +#include <wdm.h>
    5.28 +#include <wdf.h>
    5.29 +#include <wdfminiport.h>
    5.30 +#include <initguid.h>
    5.31 +#define NDIS_MINIPORT_DRIVER
    5.32 +#define NDIS51_MINIPORT 1
    5.33 +#include <ndis.h>
    5.34 +#define NDIS_MAJOR_VER 5
    5.35 +#define NDIS_MINOR_VER 1
    5.36 +
    5.37 +#define NTSTRSAFE_LIB
    5.38 +#include <ntstrsafe.h>
    5.39 +
    5.40 +#include <xen_windows.h>
    5.41 +#include <memory.h>
    5.42 +#include <grant_table.h>
    5.43 +#include <event_channel.h>
    5.44 +#include <hvm/params.h>
    5.45 +#include <hvm/hvm_op.h>
    5.46 +#include <evtchn_public.h>
    5.47 +#include <xenbus_public.h>
    5.48 +#include <xen_public.h>
    5.49 +#include <gnttbl_public.h>
    5.50 +#include <io/ring.h>
    5.51 +#include <io/netif.h>
    5.52 +#define __DRIVER_NAME "XenNet"
    5.53 +#define XENNET_POOL_TAG (ULONG) 'XenN'
    5.54 +
    5.55 +#define NAME_SIZE 64
    5.56 +
    5.57 +#define ETH_ALEN 6
    5.58 +
    5.59 +/* TODO: crank this up if we support higher mtus? */
    5.60 +#define XN_DATA_SIZE 1500
    5.61 +#define XN_HDR_SIZE 14
    5.62 +#define XN_MIN_PKT_SIZE 60
    5.63 +#define XN_MAX_PKT_SIZE (XN_HDR_SIZE + XN_DATA_SIZE)
    5.64 +
    5.65 +#define XN_MAX_SEND_PKTS 16
    5.66 +
    5.67 +#define XENSOURCE_MAC_HDR 0x00163E
    5.68 +#define XN_VENDOR_DESC "Xensource"
    5.69 \ No newline at end of file