[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [win-pv-devel] [PATCH 1/2] Use the miniport source module for what it was intended
The miniport registration code and entry points should not be in driver.c Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx> --- src/xennet/adapter.c | 10 +- src/xennet/driver.c | 254 +---------------------- src/xennet/driver.h | 40 ++++ src/xennet/miniport.c | 479 +++++++++++++++++++++++++++---------------- src/xennet/miniport.h | 42 ++++ vs2012/xennet/xennet.vcxproj | 1 + vs2013/xennet/xennet.vcxproj | 1 + 7 files changed, 405 insertions(+), 422 deletions(-) create mode 100644 src/xennet/driver.h create mode 100644 src/xennet/miniport.h diff --git a/src/xennet/adapter.c b/src/xennet/adapter.c index 69a9c44..af958b6 100644 --- a/src/xennet/adapter.c +++ b/src/xennet/adapter.c @@ -29,14 +29,18 @@ * SUCH DAMAGE. */ +#define INITGUID 1 + #include <ndis.h> #include <stdlib.h> +#include <version.h> + +#include <vif_interface.h> +#include <cache_interface.h> + #include "adapter.h" #include "transmitter.h" #include "receiver.h" -#include <vif_interface.h> -#include <cache_interface.h> -#include <version.h> #include "dbg_print.h" #include "assert.h" diff --git a/src/xennet/driver.c b/src/xennet/driver.c index c6a4896..85efd1d 100644 --- a/src/xennet/driver.c +++ b/src/xennet/driver.c @@ -29,228 +29,22 @@ * SUCH DAMAGE. */ -#define INITGUID 1 - #include <ndis.h> -#include "adapter.h" #include <version.h> + +#include "driver.h" +#include "miniport.h" #include "dbg_print.h" #include "assert.h" typedef struct _XENNET_DRIVER { - NDIS_HANDLE MiniportHandle; + NDIS_HANDLE MiniportHandle; } XENNET_DRIVER; static XENNET_DRIVER Driver; extern PULONG InitSafeBootMode; -MINIPORT_CANCEL_OID_REQUEST __AdapterCancelOidRequest; -VOID -__AdapterCancelOidRequest( - IN NDIS_HANDLE Handle, - IN PVOID Request - ) -{ - UNREFERENCED_PARAMETER(Handle); - UNREFERENCED_PARAMETER(Request); -} - -MINIPORT_CANCEL_SEND __AdapterCancelSendNetBufferLists; -VOID -__AdapterCancelSendNetBufferLists( - IN NDIS_HANDLE Handle, - IN PVOID Cancel - ) -{ - UNREFERENCED_PARAMETER(Handle); - UNREFERENCED_PARAMETER(Cancel); -} - -MINIPORT_CHECK_FOR_HANG __AdapterCheckForHang; -BOOLEAN -__AdapterCheckForHang( - IN NDIS_HANDLE Handle - ) -{ - UNREFERENCED_PARAMETER(Handle); - return FALSE; -} - -MINIPORT_INITIALIZE __AdapterInitialize; -NDIS_STATUS -__AdapterInitialize( - IN NDIS_HANDLE Handle, - IN NDIS_HANDLE DriverContext, - IN PNDIS_MINIPORT_INIT_PARAMETERS Params - ) -{ - PXENNET_ADAPTER Adapter; - NDIS_STATUS ndisStatus; - - UNREFERENCED_PARAMETER(DriverContext); - UNREFERENCED_PARAMETER(Params); - - ndisStatus = AdapterInitialize(Handle, &Adapter); - if (ndisStatus != NDIS_STATUS_SUCCESS) - goto fail1; - - return ndisStatus; - -fail1: - Error("fail1\n"); - return ndisStatus; -} - -MINIPORT_HALT __AdapterHalt; -VOID -__AdapterHalt( - IN NDIS_HANDLE Handle, - IN NDIS_HALT_ACTION Action - ) -{ - PXENNET_ADAPTER Adapter = (PXENNET_ADAPTER)Handle; - - UNREFERENCED_PARAMETER(Action); - - if (Adapter == NULL) - return; - - (VOID) AdapterDisable(Adapter); - - AdapterTeardown(Adapter); -} - -MINIPORT_OID_REQUEST __AdapterOidRequest; -NDIS_STATUS -__AdapterOidRequest( - IN NDIS_HANDLE Handle, - IN PNDIS_OID_REQUEST Request - ) -{ - PXENNET_ADAPTER Adapter = (PXENNET_ADAPTER)Handle; - NDIS_STATUS ndisStatus; - - switch (Request->RequestType) { - case NdisRequestSetInformation: - ndisStatus = AdapterSetInformation(Adapter, Request); - break; - - case NdisRequestQueryInformation: - case NdisRequestQueryStatistics: - ndisStatus = AdapterQueryInformation(Adapter, Request); - break; - - default: - ndisStatus = NDIS_STATUS_NOT_SUPPORTED; - break; - }; - - return ndisStatus; -} - -MINIPORT_PAUSE __AdapterPause; -NDIS_STATUS -__AdapterPause( - IN NDIS_HANDLE Handle, - IN PNDIS_MINIPORT_PAUSE_PARAMETERS Params - ) -{ - PXENNET_ADAPTER Adapter = (PXENNET_ADAPTER)Handle; - - UNREFERENCED_PARAMETER(Params); - - if (AdapterDisable(Adapter)) - AdapterMediaStateChange(Adapter); - - return NDIS_STATUS_SUCCESS; -} - -MINIPORT_DEVICE_PNP_EVENT_NOTIFY __AdapterPnPEventHandler; -VOID -__AdapterPnPEventHandler( - IN NDIS_HANDLE Handle, - IN PNET_DEVICE_PNP_EVENT Event - ) -{ - UNREFERENCED_PARAMETER(Handle); - UNREFERENCED_PARAMETER(Event); -} - -MINIPORT_RESET __AdapterReset; -NDIS_STATUS -__AdapterReset( - IN NDIS_HANDLE Handle, - OUT PBOOLEAN AddressingReset - ) -{ - UNREFERENCED_PARAMETER(Handle); - - *AddressingReset = FALSE; - return NDIS_STATUS_SUCCESS; -} - -MINIPORT_RESTART __AdapterRestart; -NDIS_STATUS -__AdapterRestart( - IN NDIS_HANDLE Handle, - IN PNDIS_MINIPORT_RESTART_PARAMETERS Params - ) -{ - PXENNET_ADAPTER Adapter = (PXENNET_ADAPTER)Handle; - - UNREFERENCED_PARAMETER(Params); - - return AdapterEnable(Adapter); -} - -MINIPORT_RETURN_NET_BUFFER_LISTS __AdapterReturnNetBufferLists; -VOID -__AdapterReturnNetBufferLists( - IN NDIS_HANDLE Handle, - IN PNET_BUFFER_LIST NetBufferLists, - IN ULONG ReturnFlags - ) -{ - PXENNET_ADAPTER Adapter = (PXENNET_ADAPTER)Handle; - PXENNET_RECEIVER Receiver = AdapterGetReceiver(Adapter); - - ReceiverReturnNetBufferLists(Receiver, - NetBufferLists, - ReturnFlags); -} - -MINIPORT_SEND_NET_BUFFER_LISTS __AdapterSendNetBufferLists; -VOID -__AdapterSendNetBufferLists( - IN NDIS_HANDLE Handle, - IN PNET_BUFFER_LIST NetBufferList, - IN NDIS_PORT_NUMBER PortNumber, - IN ULONG SendFlags - ) -{ - PXENNET_ADAPTER Adapter = (PXENNET_ADAPTER)Handle; - PXENNET_TRANSMITTER Transmitter = AdapterGetTransmitter(Adapter); - - TransmitterSendNetBufferLists(Transmitter, - NetBufferList, - PortNumber, - SendFlags); -} - -MINIPORT_SHUTDOWN __AdapterShutdown; -VOID -__AdapterShutdown( - IN NDIS_HANDLE Handle, - IN NDIS_SHUTDOWN_ACTION Action - ) -{ - PXENNET_ADAPTER Adapter = (PXENNET_ADAPTER)Handle; - - if (Action != NdisShutdownBugCheck) - AdapterDisable(Adapter); -} - typedef struct _XENNET_CONTEXT { PDEVICE_CAPABILITIES Capabilities; PIO_COMPLETION_ROUTINE CompletionRoutine; @@ -363,7 +157,6 @@ DispatchFail( return STATUS_UNSUCCESSFUL; } -MINIPORT_UNLOAD DriverUnload; VOID DriverUnload( IN PDRIVER_OBJECT DriverObject @@ -402,7 +195,6 @@ DriverEntry ( ) { NDIS_STATUS ndisStatus; - NDIS_MINIPORT_DRIVER_CHARACTERISTICS mpChars; NDIS_CONFIGURATION_OBJECT ConfigurationObject; NDIS_HANDLE ConfigurationHandle; NDIS_STRING ParameterName; @@ -426,41 +218,9 @@ DriverEntry ( MONTH, YEAR); - // - // Register miniport with NDIS. - // - - NdisZeroMemory(&mpChars, sizeof(mpChars)); - mpChars.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_DRIVER_CHARACTERISTICS, - mpChars.Header.Size = sizeof(NDIS_MINIPORT_DRIVER_CHARACTERISTICS); - mpChars.Header.Revision = NDIS_MINIPORT_DRIVER_CHARACTERISTICS_REVISION_1; - - mpChars.MajorNdisVersion = 6; - mpChars.MinorNdisVersion = 0; - mpChars.MajorDriverVersion = MAJOR_VERSION; - mpChars.MinorDriverVersion = MINOR_VERSION; - - mpChars.CancelOidRequestHandler = __AdapterCancelOidRequest; - mpChars.CancelSendHandler = __AdapterCancelSendNetBufferLists; - mpChars.CheckForHangHandlerEx = __AdapterCheckForHang; - mpChars.InitializeHandlerEx = __AdapterInitialize; - mpChars.HaltHandlerEx = __AdapterHalt; - mpChars.OidRequestHandler = __AdapterOidRequest; - mpChars.PauseHandler = __AdapterPause; - mpChars.DevicePnPEventNotifyHandler = __AdapterPnPEventHandler; - mpChars.ResetHandlerEx = __AdapterReset; - mpChars.RestartHandler = __AdapterRestart; - mpChars.ReturnNetBufferListsHandler = __AdapterReturnNetBufferLists; - mpChars.SendNetBufferListsHandler = __AdapterSendNetBufferLists; - mpChars.ShutdownHandlerEx = __AdapterShutdown; - mpChars.UnloadHandler = DriverUnload; - - Driver.MiniportHandle = NULL; - ndisStatus = NdisMRegisterMiniportDriver(DriverObject, - RegistryPath, - NULL, - &mpChars, - &Driver.MiniportHandle); + ndisStatus = MiniportRegister(DriverObject, + RegistryPath, + &Driver.MiniportHandle); if (ndisStatus != NDIS_STATUS_SUCCESS) { Error("Failed (0x%08X) to register miniport.\n", ndisStatus); goto fail; diff --git a/src/xennet/driver.h b/src/xennet/driver.h new file mode 100644 index 0000000..2c5bb58 --- /dev/null +++ b/src/xennet/driver.h @@ -0,0 +1,40 @@ +/* Copyright (c) Citrix Systems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _XENNET_DRIVER_H +#define _XENNET_DRIVER_H + +extern VOID +DriverUnload( + IN PDRIVER_OBJECT DriverObject + ); + +#endif // _XENNET_DRIVER_H diff --git a/src/xennet/miniport.c b/src/xennet/miniport.c index 12d332f..9b686cb 100644 --- a/src/xennet/miniport.c +++ b/src/xennet/miniport.c @@ -1,223 +1,358 @@ /* Copyright (c) Citrix Systems Inc. * All rights reserved. - * - * Redistribution and use in source and binary forms, - * with or without modification, are permitted provided + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided * that the following conditions are met: - * - * * Redistributions of source code must retain the above - * copyright notice, this list of conditions and the + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the * following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other * materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#define INITGUID 1 +#include <ndis.h> +#include <version.h> + +#include "driver.h" +#include "miniport.h" +#include "adapter.h" +#include "dbg_print.h" +#include "assert.h" + +static +_Function_class_(MINIPORT_INITIALIZE) +NDIS_STATUS +MiniportInitializeEx( + IN NDIS_HANDLE NdisMiniportHandle, + IN NDIS_HANDLE MiniportDriverContext, + IN PNDIS_MINIPORT_INIT_PARAMETERS MiniportInitParameters + ) +{ + PXENNET_ADAPTER Adapter; + NDIS_STATUS NdisStatus; + + Trace("====>\n"); + + UNREFERENCED_PARAMETER(MiniportDriverContext); + UNREFERENCED_PARAMETER(MiniportInitParameters); + + NdisStatus = AdapterInitialize(NdisMiniportHandle, &Adapter); + if (NdisStatus != NDIS_STATUS_SUCCESS) + goto fail1; -#include "common.h" + Trace("<====\n"); -#pragma warning( disable : 4098 ) + return NDIS_STATUS_SUCCESS; -extern NTSTATUS AllocAdapter(PADAPTER *Adapter); +fail1: + Error("fail1 (%08x)\n", NdisStatus); -static FORCEINLINE NTSTATUS -__QueryInterface( - IN PDEVICE_OBJECT DeviceObject, - IN const GUID *Guid, - IN ULONG Version, - OUT PINTERFACE Interface, - IN ULONG Size, - IN BOOLEAN Optional + return NdisStatus; +} + +static +_Function_class_(MINIPORT_HALT) +VOID +MiniportHaltEx( + IN NDIS_HANDLE MiniportAdapterContext, + IN NDIS_HALT_ACTION HaltAction ) { - KEVENT Event; - IO_STATUS_BLOCK StatusBlock; - PIRP Irp; - PIO_STACK_LOCATION StackLocation; - NTSTATUS status; - - ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL); - - KeInitializeEvent(&Event, NotificationEvent, FALSE); - RtlZeroMemory(&StatusBlock, sizeof(IO_STATUS_BLOCK)); - - Irp = IoBuildSynchronousFsdRequest(IRP_MJ_PNP, - DeviceObject, - NULL, - 0, - NULL, - &Event, - &StatusBlock); - - status = STATUS_UNSUCCESSFUL; - if (Irp == NULL) - goto fail1; + PXENNET_ADAPTER Adapter = (PXENNET_ADAPTER)MiniportAdapterContext; + + UNREFERENCED_PARAMETER(HaltAction); - StackLocation = IoGetNextIrpStackLocation(Irp); - StackLocation->MinorFunction = IRP_MN_QUERY_INTERFACE; + Trace("====>\n"); - StackLocation->Parameters.QueryInterface.InterfaceType = Guid; - StackLocation->Parameters.QueryInterface.Size = (USHORT)Size; - StackLocation->Parameters.QueryInterface.Version = (USHORT)Version; - StackLocation->Parameters.QueryInterface.Interface = Interface; - - Irp->IoStatus.Status = STATUS_NOT_SUPPORTED; + if (Adapter == NULL) + return; + + (VOID) AdapterDisable(Adapter); + + AdapterTeardown(Adapter); + + Trace("<====\n"); +} - status = IoCallDriver(DeviceObject, Irp); - if (status == STATUS_PENDING) { - (VOID) KeWaitForSingleObject(&Event, - Executive, - KernelMode, - FALSE, - NULL); - status = StatusBlock.Status; - } +static +_Function_class_(MINIPORT_UNLOAD) +VOID +MiniportDriverUnload( + IN PDRIVER_OBJECT DriverObject + ) +{ + DriverUnload(DriverObject); +} - if (!NT_SUCCESS(status)) { - if (status == STATUS_NOT_SUPPORTED && Optional) - goto done; +static +_Function_class_(MINIPORT_PAUSE) +NDIS_STATUS +MiniportPause( + IN NDIS_HANDLE MiniportAdapterContext, + IN PNDIS_MINIPORT_PAUSE_PARAMETERS MiniportPauseParameters + ) +{ + PXENNET_ADAPTER Adapter = (PXENNET_ADAPTER)MiniportAdapterContext; - goto fail2; - } + UNREFERENCED_PARAMETER(MiniportPauseParameters); -done: - return STATUS_SUCCESS; + Trace("====>\n"); -fail2: - Error("fail2\n"); + if (AdapterDisable(Adapter)) + AdapterMediaStateChange(Adapter); -fail1: - Error("fail1 (%08x)\n", status); + Trace("<====\n"); - return status; + return NDIS_STATUS_SUCCESS; } -#define QUERY_INTERFACE( \ - _DeviceObject, \ - _ProviderName, \ - _InterfaceName, \ - _Version, \ - _Interface, \ - _Size, \ - _Optional) \ - __QueryInterface((_DeviceObject), \ - &GUID_ ## _ProviderName ## _ ## _InterfaceName ## _INTERFACE, \ - (_Version), \ - (_Interface), \ - (_Size), \ - (_Optional)) - -NDIS_STATUS -MiniportInitialize ( - IN NDIS_HANDLE MiniportAdapterHandle, - IN NDIS_HANDLE MiniportDriverContext, - IN PNDIS_MINIPORT_INIT_PARAMETERS MiniportInitParameters +static +_Function_class_(MINIORT_RESTART) +NDIS_STATUS +MiniportRestart( + IN NDIS_HANDLE MiniportAdapterContext, + IN PNDIS_MINIPORT_RESTART_PARAMETERS MiniportRestartParameters ) { - PADAPTER Adapter = NULL; - NDIS_STATUS ndisStatus; - PDEVICE_OBJECT DeviceObject; - NTSTATUS status; + PXENNET_ADAPTER Adapter = (PXENNET_ADAPTER)MiniportAdapterContext; + NDIS_STATUS NdisStatus; - UNREFERENCED_PARAMETER(MiniportDriverContext); - UNREFERENCED_PARAMETER(MiniportInitParameters); + UNREFERENCED_PARAMETER(MiniportRestartParameters); Trace("====>\n"); - status = AllocAdapter(&Adapter); - - if (!NT_SUCCESS(status) || Adapter == NULL) { - ndisStatus = NDIS_STATUS_RESOURCES; - goto fail1; - } - - RtlZeroMemory(Adapter, sizeof (ADAPTER)); - - DeviceObject = NULL; - NdisMGetDeviceProperty(MiniportAdapterHandle, - &DeviceObject, - NULL, - NULL, - NULL, - NULL); - - status = QUERY_INTERFACE(DeviceObject, - XENVIF, - VIF, - XENVIF_VIF_INTERFACE_VERSION_MAX, - (PINTERFACE)&Adapter->VifInterface, - sizeof (Adapter->VifInterface), - FALSE); - - if (!NT_SUCCESS(status)) { - ndisStatus = NDIS_STATUS_ADAPTER_NOT_FOUND; - goto fail2; - } - - ndisStatus = AdapterInitialize(Adapter, MiniportAdapterHandle); - if (ndisStatus != NDIS_STATUS_SUCCESS) { - goto fail3; - } + NdisStatus = AdapterEnable(Adapter); Trace("<====\n"); - return ndisStatus; -fail3: - Error("fail3\n"); + return NdisStatus; +} - RtlZeroMemory(&Adapter->VifInterface, - sizeof (XENVIF_VIF_INTERFACE)); +static +_Function_class_(MINIPORT_OID_REQUEST) +NDIS_STATUS +MiniportOidRequest( + IN NDIS_HANDLE MiniportAdapterContext, + IN PNDIS_OID_REQUEST OidRequest + ) +{ + PXENNET_ADAPTER Adapter = (PXENNET_ADAPTER)MiniportAdapterContext; + NDIS_STATUS NdisStatus; -fail2: - Error("fail2\n"); + switch (OidRequest->RequestType) { + case NdisRequestSetInformation: + NdisStatus = AdapterSetInformation(Adapter, OidRequest); + break; - ExFreePool(Adapter); + case NdisRequestQueryInformation: + case NdisRequestQueryStatistics: + NdisStatus = AdapterQueryInformation(Adapter, OidRequest); + break; -fail1: - Error("fail1\n"); + default: + NdisStatus = NDIS_STATUS_NOT_SUPPORTED; + break; + }; - return ndisStatus; + return NdisStatus; } -// -// Stops adapter and frees all resources. -// -VOID -MiniportHalt ( - IN NDIS_HANDLE MiniportAdapterHandle, - IN NDIS_HALT_ACTION HaltAction +static +_Function_class_(MINIPORT_SEND_NET_BUFFER_LISTS) +VOID +MiniportSendNetBufferLists( + IN NDIS_HANDLE MiniportAdapterContext, + IN PNET_BUFFER_LIST NetBufferList, + IN NDIS_PORT_NUMBER PortNumber, + IN ULONG SendFlags ) { - PADAPTER Adapter = (PADAPTER)MiniportAdapterHandle; + PXENNET_ADAPTER Adapter = (PXENNET_ADAPTER)MiniportAdapterContext; + PXENNET_TRANSMITTER Transmitter = AdapterGetTransmitter(Adapter); - UNREFERENCED_PARAMETER(HaltAction); + TransmitterSendNetBufferLists(Transmitter, + NetBufferList, + PortNumber, + SendFlags); +} - if (Adapter == NULL) +static +_Function_class_(MINIPORT_RETURN_NET_BUFFER_LISTS) +VOID +MiniportReturnNetBufferLists( + IN NDIS_HANDLE MiniportAdapterContext, + IN PNET_BUFFER_LIST NetBufferLists, + IN ULONG ReturnFlags + ) +{ + PXENNET_ADAPTER Adapter = (PXENNET_ADAPTER)MiniportAdapterContext; + PXENNET_RECEIVER Receiver = AdapterGetReceiver(Adapter); + + ReceiverReturnNetBufferLists(Receiver, + NetBufferLists, + ReturnFlags); +} + +static +_Function_class_(MINIPORT_CANCEL_SEND) +VOID +MiniportCancelSend( + IN NDIS_HANDLE MiniportAdapterContext, + IN PVOID CancelId + ) +{ + UNREFERENCED_PARAMETER(MiniportAdapterContext); + UNREFERENCED_PARAMETER(CancelId); +} + +static +_Function_class_(MINIPORT_CHECK_FOR_HANG) +BOOLEAN +MiniportCheckForHangEx( + IN NDIS_HANDLE MiniportAdapterContext + ) +{ + UNREFERENCED_PARAMETER(MiniportAdapterContext); + + return FALSE; +} + +static +_Function_class_(MINIPORT_RESET) +NDIS_STATUS +MiniportResetEx( + IN NDIS_HANDLE MiniportAdapterContext, + OUT PBOOLEAN AddressingReset + ) +{ + UNREFERENCED_PARAMETER(MiniportAdapterContext); + + Trace("<===>\n"); + + *AddressingReset = FALSE; + + return NDIS_STATUS_SUCCESS; +} + +static +_Function_class_(MINIPORT_DEVICE_PNP_EVENT_NOTIFY) +VOID +MiniportDevicePnPEventNotify( + IN NDIS_HANDLE MiniportAdapterContext, + IN PNET_DEVICE_PNP_EVENT NetDevicePnPEvent + ) +{ + UNREFERENCED_PARAMETER(MiniportAdapterContext); + UNREFERENCED_PARAMETER(NetDevicePnPEvent); + + Trace("<===>\n"); +} + +static +_Function_class_(MINIPORT_SHUTDOWN) +VOID +MiniportShutdownEx( + IN NDIS_HANDLE MiniportAdapterContext, + IN NDIS_SHUTDOWN_ACTION ShutdownAction + ) +{ + PXENNET_ADAPTER Adapter = (PXENNET_ADAPTER)MiniportAdapterContext; + + if (ShutdownAction == NdisShutdownBugCheck) return; - (VOID) AdapterStop(Adapter); + Trace("====>\n"); + + AdapterDisable(Adapter); + + Trace("<====\n"); +} + +static +_Function_class_(MINIPORT_CANCEL_OID_REQUEST) +VOID +MiniportCancelOidRequest( + IN NDIS_HANDLE MiniportAdapterContext, + IN PVOID RequestId + ) +{ + UNREFERENCED_PARAMETER(MiniportAdapterContext); + UNREFERENCED_PARAMETER(RequestId); - AdapterCleanup(Adapter); + Trace("<===>\n"); +} - RtlZeroMemory(&Adapter->VifInterface, - sizeof (XENVIF_VIF_INTERFACE)); +NDIS_STATUS +MiniportRegister( + IN PDRIVER_OBJECT DriverObject, + IN PUNICODE_STRING RegistryPath, + OUT PNDIS_HANDLE NdisMiniportDriverHandle + ) +{ + NDIS_STATUS NdisStatus; + NDIS_MINIPORT_DRIVER_CHARACTERISTICS MiniportDriverCharacteristics; + + Trace("====>\n"); + + NdisZeroMemory(&MiniportDriverCharacteristics, sizeof (MiniportDriverCharacteristics)); + + MiniportDriverCharacteristics.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_DRIVER_CHARACTERISTICS, + MiniportDriverCharacteristics.Header.Size = NDIS_SIZEOF_MINIPORT_DRIVER_CHARACTERISTICS_REVISION_1; + MiniportDriverCharacteristics.Header.Revision = NDIS_MINIPORT_DRIVER_CHARACTERISTICS_REVISION_1; + + MiniportDriverCharacteristics.MajorNdisVersion = 6; + MiniportDriverCharacteristics.MinorNdisVersion = 0; + MiniportDriverCharacteristics.MajorDriverVersion = MAJOR_VERSION; + MiniportDriverCharacteristics.MinorDriverVersion = MINOR_VERSION; + + MiniportDriverCharacteristics.CancelOidRequestHandler = MiniportCancelOidRequest; + MiniportDriverCharacteristics.CancelSendHandler = MiniportCancelSend; + MiniportDriverCharacteristics.CheckForHangHandlerEx = MiniportCheckForHangEx; + MiniportDriverCharacteristics.InitializeHandlerEx = MiniportInitializeEx; + MiniportDriverCharacteristics.HaltHandlerEx = MiniportHaltEx; + MiniportDriverCharacteristics.OidRequestHandler = MiniportOidRequest; + MiniportDriverCharacteristics.PauseHandler = MiniportPause; + MiniportDriverCharacteristics.DevicePnPEventNotifyHandler = MiniportDevicePnPEventNotify; + MiniportDriverCharacteristics.ResetHandlerEx = MiniportResetEx; + MiniportDriverCharacteristics.RestartHandler = MiniportRestart; + MiniportDriverCharacteristics.ReturnNetBufferListsHandler = MiniportReturnNetBufferLists; + MiniportDriverCharacteristics.SendNetBufferListsHandler = MiniportSendNetBufferLists; + MiniportDriverCharacteristics.ShutdownHandlerEx = MiniportShutdownEx; + MiniportDriverCharacteristics.UnloadHandler = MiniportDriverUnload; + + NdisStatus = NdisMRegisterMiniportDriver(DriverObject, + RegistryPath, + NULL, + &MiniportDriverCharacteristics, + NdisMiniportDriverHandle); + if (NdisStatus != NDIS_STATUS_SUCCESS) + goto fail1; + + Trace("<====\n"); + + return NDIS_STATUS_SUCCESS; + +fail1: + Error("fail1 (%08x)\n", NdisStatus); - ExFreePool(Adapter); + return NdisStatus; } diff --git a/src/xennet/miniport.h b/src/xennet/miniport.h new file mode 100644 index 0000000..15d4455 --- /dev/null +++ b/src/xennet/miniport.h @@ -0,0 +1,42 @@ +/* Copyright (c) Citrix Systems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _XENNET_MINIPORT_H +#define _XENNET_MINIPORT_H + +extern NDIS_STATUS +MiniportRegister( + IN PDRIVER_OBJECT DriverObject, + IN PUNICODE_STRING RegistryPath, + OUT PNDIS_HANDLE NdisMiniportDriverHandle + ); + +#endif // _XENNET_MINIPORT_H diff --git a/vs2012/xennet/xennet.vcxproj b/vs2012/xennet/xennet.vcxproj index 03ddf91..b006832 100644 --- a/vs2012/xennet/xennet.vcxproj +++ b/vs2012/xennet/xennet.vcxproj @@ -85,6 +85,7 @@ <ItemGroup> <ClCompile Include="../../src/xennet/adapter.c" /> <ClCompile Include="../../src/xennet/driver.c" /> + <ClCompile Include="../../src/xennet/miniport.c" /> <ClCompile Include="../../src/xennet/receiver.c" /> <ClCompile Include="../../src/xennet/transmitter.c" /> </ItemGroup> diff --git a/vs2013/xennet/xennet.vcxproj b/vs2013/xennet/xennet.vcxproj index 6cb09d2..5c877a4 100644 --- a/vs2013/xennet/xennet.vcxproj +++ b/vs2013/xennet/xennet.vcxproj @@ -116,6 +116,7 @@ <ItemGroup> <ClCompile Include="../../src/xennet/adapter.c" /> <ClCompile Include="../../src/xennet/driver.c" /> + <ClCompile Include="../../src/xennet/miniport.c" /> <ClCompile Include="../../src/xennet/receiver.c" /> <ClCompile Include="../../src/xennet/transmitter.c" /> </ItemGroup> -- 2.1.1 _______________________________________________ win-pv-devel mailing list win-pv-devel@xxxxxxxxxxxxxxxxxxxx http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |