From c9082b172188c3f3740da91647ec8196f0ca60f5 Mon Sep 17 00:00:00 2001 From: stansmith Date: Wed, 12 Mar 2008 17:17:19 +0000 Subject: [PATCH] [mthca-kmdf] rever to original mthca file structure so other will not be confused by KMDF additions and know where to find functions [DriverEntry] for instance is still in hca_driver.c git-svn-id: svn://openib.tc.cornell.edu/gen1@989 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- branches/IBFD/hw/mthca/kmdf/SOURCES | 3 +- branches/IBFD/hw/mthca/kmdf/hca_driver.c | 1186 ++++++++++++- branches/IBFD/hw/mthca/kmdf/hca_driver.h | 23 - branches/IBFD/hw/mthca/kmdf/hca_pnp.c | 812 ++++++++- branches/IBFD/hw/mthca/kmdf/hca_pnp.h | 49 +- branches/IBFD/hw/mthca/kmdf/mthca_kmdf.c | 2005 ---------------------- branches/IBFD/hw/mthca/kmdf/pcidrv.h | 120 -- 7 files changed, 2016 insertions(+), 2182 deletions(-) delete mode 100644 branches/IBFD/hw/mthca/kmdf/mthca_kmdf.c delete mode 100644 branches/IBFD/hw/mthca/kmdf/pcidrv.h diff --git a/branches/IBFD/hw/mthca/kmdf/SOURCES b/branches/IBFD/hw/mthca/kmdf/SOURCES index 5d6266bd..4d97c63c 100644 --- a/branches/IBFD/hw/mthca/kmdf/SOURCES +++ b/branches/IBFD/hw/mthca/kmdf/SOURCES @@ -16,7 +16,6 @@ INF_NAME=mthca SOURCES= \ mthca_log.mc \ hca.rc \ - mthca_kmdf.c \ wmi.c \ mthca_log.c \ \ @@ -95,4 +94,4 @@ RUN_WPP= $(SOURCES) -km -ext: .c .h .C .H \ MSC_OPTIMIZATION=/Oi # ignore volatile ignored warning @ line 318 in mt_atmoic.h -MSC_WARNING_LEVEL= /W4 /wd4197 /wd4324 /wd4201 +MSC_WARNING_LEVEL= /W4 /wd4197 /wd4201 /wd4324 diff --git a/branches/IBFD/hw/mthca/kmdf/hca_driver.c b/branches/IBFD/hw/mthca/kmdf/hca_driver.c index b05a4661..d0a1b413 100644 --- a/branches/IBFD/hw/mthca/kmdf/hca_driver.c +++ b/branches/IBFD/hw/mthca/kmdf/hca_driver.c @@ -1,4 +1,5 @@ /* + * Copyright (c) 2008 Intel corporation. All rights reserved. * Copyright (c) 2005 SilverStorm Technologies. All rights reserved. * * This software is available to you under the OpenIB.org BSD license @@ -26,18 +27,24 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * - * $Id: hca_driver.c 931 2008-01-31 09:20:41Z leonidk $ + * $Id$ */ /* - * Provides the driver entry points for the Tavor VPD. + * Provides KMDF driver entry points for the Tavor VPD. + * Driver: load/unload, start/stop. */ #include #include "hca_driver.h" #include "hca_debug.h" +#include "hca_pnp.h" +#include +#include + +#include "mthca_public.h" #include "mthca_log.h" #if defined(EVENT_TRACING) #ifdef offsetof @@ -45,6 +52,35 @@ #endif #include "hca_driver.tmh" #endif + + + +DRIVER_INITIALIZE DriverEntry; +DRIVER_UNLOAD hca_drv_unload; + +NTSTATUS +DriverEntry ( + IN PDRIVER_OBJECT DriverObject, + IN PUNICODE_STRING RegistryPath ); + +NTSTATUS +HcaWmiRegistration( WDFDEVICE Device ); + +NTSTATUS +HcaAllocSWResources(PFDO_DATA fdoData); + +NTSTATUS +HcaFreeSWResources(PFDO_DATA fdoData); + +VOID +HcaEvtDeviceSelfManagedIoCleanup( IN WDFDEVICE Device ); + +NTSTATUS +HcaEvtDeviceSelfManagedIoSuspend( IN WDFDEVICE Device ); + + +#define PARAMATER_NAME_LEN 80 + #include "mthca_dev.h" #include #include @@ -86,7 +122,7 @@ char mlnx_uvp_lib_name[MAX_LIB_NAME] = {"mthcau"}; void reregister_hca( hca_dev_ext_t *p_ext ); -NTSTATUS +static NTSTATUS HcaEntry( IN PDRIVER_OBJECT p_driver_obj, IN PUNICODE_STRING p_registry_path ); @@ -95,7 +131,7 @@ static NTSTATUS __read_registry( IN UNICODE_STRING* const p_Param_Path ); -static void +void hca_drv_unload( IN PDRIVER_OBJECT p_driver_obj ); @@ -161,14 +197,23 @@ static NTSTATUS fw_flash_deinit( IN BUS_INTERFACE_STANDARD *p_BusInterface ); + #ifdef ALLOC_PRAGMA -#pragma alloc_text (INIT, HcaEntry) -#pragma alloc_text (INIT, __read_registry) +#pragma alloc_text (INIT, DriverEntry) +#pragma alloc_text (PAGE, HcaEvtDeviceAdd) +#pragma alloc_text (PAGE, HcaEvtDeviceContextCleanup) +#pragma alloc_text (PAGE, HcaReadRegistryValue) +#pragma alloc_text (PAGE, HcaWriteRegistryValue) +#pragma alloc_text (PAGE, HcaEvtDriverContextCleanup) +#pragma alloc_text (PAGE, HcaEvtDeviceSelfManagedIoCleanup) +#pragma alloc_text (PAGE, HcaEvtDeviceSelfManagedIoSuspend) +#pragma alloc_text (PAGE, HcaReadFdoRegistryKeyValue) #pragma alloc_text (PAGE, hca_drv_unload) #pragma alloc_text (PAGE, hca_sysctl) #endif -NTSTATUS + +static NTSTATUS HcaEntry( IN PDRIVER_OBJECT p_driver_obj, IN PUNICODE_STRING p_registry_path ) @@ -176,6 +221,8 @@ HcaEntry( NTSTATUS status; cl_status_t cl_status; + UNREFERENCED_PARAMETER( p_driver_obj ); // XXX + HCA_ENTER( HCA_DBG_DEV ); /* init common mechanisms */ @@ -220,16 +267,19 @@ HcaEntry( #endif /* init core */ if (ib_core_init()) { - HCA_PRINT( TRACE_LEVEL_ERROR ,HCA_DBG_INIT ,("Failed to init core, aborting.\n")); + HCA_PRINT( TRACE_LEVEL_ERROR ,HCA_DBG_INIT, + ("Failed to init core, aborting.\n")); return STATUS_UNSUCCESSFUL; } /* init uverbs module */ if (ib_uverbs_init()) { - HCA_PRINT( TRACE_LEVEL_ERROR ,HCA_DBG_INIT ,("Failed ib_uverbs_init, aborting.\n")); + HCA_PRINT( TRACE_LEVEL_ERROR ,HCA_DBG_INIT, + ("Failed ib_uverbs_init, aborting.\n")); return STATUS_UNSUCCESSFUL; } HCA_EXIT( HCA_DBG_DEV ); + return STATUS_SUCCESS; } @@ -396,7 +446,6 @@ hca_drv_unload( IN PDRIVER_OBJECT p_driver_obj ) #if defined(EVENT_TRACING) WPP_CLEANUP(p_driver_obj); #endif - } @@ -1034,3 +1083,1120 @@ fw_set_bank( } return status; } + + +/*++ + +Routine Description: + + Installable driver initialization entry point. + This entry point is called directly by the I/O system. + +Arguments: + + DriverObject - pointer to the driver object + + RegistryPath - pointer to a unicode string representing the path, + to driver-specific key in the registry. + +Return Value: + + STATUS_SUCCESS if successful, + STATUS_UNSUCCESSFUL otherwise. + +--*/ + +NTSTATUS +DriverEntry ( + IN PDRIVER_OBJECT DriverObject, + IN PUNICODE_STRING RegistryPath ) +{ + NTSTATUS status = STATUS_SUCCESS; + WDF_DRIVER_CONFIG config; + WDF_OBJECT_ATTRIBUTES attrib; + WDFDRIVER driver; + PDRIVER_CONTEXT driverContext; + + // + // Initialize WPP Tracing + // +#if defined(EVENT_TRACING) + WPP_INIT_TRACING( DriverObject, RegistryPath ); +#endif + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, + "mthca - KM Driver Framework Edition \n"); + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, + "Built %s %s\n", __DATE__, __TIME__); + +// WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attrib, DRIVER_CONTEXT); + + // + // Register a cleanup callback so that we can call WPP_CLEANUP when + // the framework driver object is deleted during driver unload. + // + attrib.EvtCleanupCallback = HcaEvtDriverContextCleanup; + + // + // Initialize the Driver Config structure.. + // + WDF_DRIVER_CONFIG_INIT(&config, HcaEvtDeviceAdd); + + // + // Create a WDFDRIVER object. + // + status = WdfDriverCreate(DriverObject, + RegistryPath, + &attrib, + &config, + &driver); + + if (!NT_SUCCESS(status)) { + TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, + "WdfDriverCreate failed with status %!STATUS!\n", status); + // + // Cleanup tracing here because DriverContextCleanup will not be called + // as we have failed to create WDFDRIVER object itself. + // Please note that if your return failure from DriverEntry after the + // WDFDRIVER object is created successfully, you don't have to + // call WPP cleanup because in those cases DriverContextCleanup + // will be executed when the framework deletes the DriverObject. + // +#if defined(EVENT_TRACING) + WPP_CLEANUP(DriverObject); +#endif + return status; + } + + driverContext = GetDriverContext(driver); + driverContext->DrvObj = DriverObject; // for DeviceAdd +#if 0 + // + // Create a driver wide lookside list used for allocating memory for the + // MP_RFD structure for all device instances (if there are multiple present). + // + status = WdfLookasideListCreate(WDF_NO_OBJECT_ATTRIBUTES, // LookAsideAttributes + sizeof(MP_RFD), + NonPagedPool, + WDF_NO_OBJECT_ATTRIBUTES, // MemoryAttributes + PCIDRV_POOL_TAG, + &driverContext->RecvLookaside ); + if (!NT_SUCCESS(status)) + { + TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, + "Couldn't allocate lookaside list status %!STATUS!\n", status); + return status; + } + if (!NT_SUCCESS(status)) + return status; +#endif + + return HcaEntry( DriverObject, RegistryPath ); +} + + +/*++ +Routine Description: + + EvtDeviceAdd is called by the framework in response to AddDevice + call from the PnP manager. + +Arguments: + + Driver - Handle to a framework driver object created in DriverEntry + + DeviceInit - Pointer to a framework-allocated WDFDEVICE_INIT structure. + +Return Value: + + NTSTATUS + +--*/ + +NTSTATUS +HcaEvtDeviceAdd ( + IN WDFDRIVER Driver, + IN PWDFDEVICE_INIT DeviceInit ) +{ + NTSTATUS status = STATUS_SUCCESS; + WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks; + WDF_POWER_POLICY_EVENT_CALLBACKS powerPolicyCallbacks; + WDF_OBJECT_ATTRIBUTES fdoAttributes; + WDFDEVICE device; + PFDO_DATA fdoData = NULL; + + UNREFERENCED_PARAMETER( Driver ); + + PAGED_CODE(); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s()\n", __FUNCTION__); + + // + // I/O type is Buffered by default. If required to use something else, + // call WdfDeviceInitSetIoType with the appropriate type. + // + WdfDeviceInitSetIoType(DeviceInit, WdfDeviceIoDirect); + + // + // Zero out the PnpPowerCallbacks structure. + // + WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks); + + // + // Set Callbacks for any of the functions we are interested in. + // If no callback is set, Framework will take the default action + // by itself. This sample provides many of the possible callbacks, + // mostly because it's a fairly complex sample that drives full-featured + // hardware. Drivers derived from this sample will often be able to + // provide only some of these. + // + + // + // These callback is invoked to tear down all the driver-managed state + // that is set up in this function. Many times, this callback won't do + // much of anything, since many of the things that are set up here will + // have their lifetimes automatically managed by the Framework. + // + + // + // These two callbacks set up and tear down hardware state, + // specifically that which only has to be done once. + // + + pnpPowerCallbacks.EvtDevicePrepareHardware = HcaEvtDevicePrepareHardware; + pnpPowerCallbacks.EvtDeviceReleaseHardware = HcaEvtDeviceReleaseHardware; + + // + // These two callbacks set up and tear down hardware state that must be + // done every time the device moves in and out of the D0-working state. + // + + pnpPowerCallbacks.EvtDeviceD0Entry = HcaEvtDeviceD0Entry; + pnpPowerCallbacks.EvtDeviceD0Exit = HcaEvtDeviceD0Exit; + + // + // These next two callbacks are for doing work at PASSIVE_LEVEL (low IRQL) + // after all the interrupts are connected and before they are disconnected. + // + // Some drivers need to do device initialization and tear-down while the + // interrupt is connected. (This is a problem for these devices, since + // it opens them up to taking interrupts before they are actually ready + // to handle them, or to taking them after they have torn down too much + // to be able to handle them.) While this hardware design pattern is to + // be discouraged, it is possible to handle it by doing device init and + // tear down in these routines rather than in EvtDeviceD0Entry and + // EvtDeviceD0Exit. + // + // In this sample these callbacks don't do anything. + // + + pnpPowerCallbacks.EvtDeviceD0EntryPostInterruptsEnabled = + HcaEvtDeviceD0EntryPostInterruptsEnabled; + pnpPowerCallbacks.EvtDeviceD0ExitPreInterruptsDisabled = + HcaEvtDeviceD0ExitPreInterruptsDisabled; + + // + // This next group of five callbacks allow a driver to become involved in + // starting and stopping operations within a driver as the driver moves + // through various PnP/Power states. These functions are not necessary + // if the Framework is managing all the device's queues and there is no + // activity going on that isn't queue-based. This sample provides these + // callbacks because it uses watchdog timer to monitor whether the device + // is working or not and it needs to start and stop the timer when the + // device is started or removed. It cannot start and stop the timers in the + // D0Entry and D0Exit callbacks because if the device is surprise-removed, + // D0Exit will not be called. + // + pnpPowerCallbacks.EvtDeviceSelfManagedIoInit = + HcaEvtDeviceSelfManagedIoInit; + pnpPowerCallbacks.EvtDeviceSelfManagedIoCleanup = + HcaEvtDeviceSelfManagedIoCleanup; + pnpPowerCallbacks.EvtDeviceSelfManagedIoSuspend = + HcaEvtDeviceSelfManagedIoSuspend; + pnpPowerCallbacks.EvtDeviceSelfManagedIoRestart = + HcaEvtDeviceSelfManagedIoRestart; + + // + // Register the PnP and power callbacks. Power policy related callbacks will + // be registered later. + // + WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks); + + // + // Init the power policy callbacks + // + WDF_POWER_POLICY_EVENT_CALLBACKS_INIT(&powerPolicyCallbacks); + + // + // This group of three callbacks allows this sample driver to manage + // arming the device for wake from the S0 state. Networking devices can + // optionally be put into a low-power state when there is no networking + // cable plugged into them. This sample implements this feature. + // + powerPolicyCallbacks.EvtDeviceArmWakeFromS0 = HcaEvtDeviceWakeArmS0; + powerPolicyCallbacks.EvtDeviceDisarmWakeFromS0 = HcaEvtDeviceWakeDisarmS0; + powerPolicyCallbacks.EvtDeviceWakeFromS0Triggered = + HcaEvtDeviceWakeTriggeredS0; + + // + // This group of three callbacks allows the device to be armed for wake + // from Sx (S1, S2, S3 or S4.) Networking devices can optionally be put + // into a state where a packet sent to them will cause the device's wake + // signal to be triggered, which causes the machine to wake, moving back + // into the S0 state. + // + + powerPolicyCallbacks.EvtDeviceArmWakeFromSx = HcaEvtDeviceWakeArmSx; + powerPolicyCallbacks.EvtDeviceDisarmWakeFromSx = HcaEvtDeviceWakeDisarmSx; + powerPolicyCallbacks.EvtDeviceWakeFromSxTriggered = + HcaEvtDeviceWakeTriggeredSx; + + WdfDeviceInitSetDeviceType( DeviceInit, + FILE_DEVICE_INFINIBAND|FILE_DEVICE_SECURE_OPEN ); + + WdfDeviceInitSetExclusive(DeviceInit, TRUE); + // + // Register the power policy callbacks. + // + WdfDeviceInitSetPowerPolicyEventCallbacks(DeviceInit,&powerPolicyCallbacks); + + // Since we are the function driver, we are now the power policy owner + // for the device according to the default framework rule. We will register + // our power policy callbacks after finding the wakeup capability of the + // device. + + + // Specify the context type and size for the device we are about to create. + + WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&fdoAttributes, FDO_DATA); + + + // ContextCleanup will be called by the framework when it deletes the + // device. So you can defer freeing any resources allocated to Cleanup + // callback in the event AddDevice returns any error after the device is + // created. + + fdoAttributes.EvtCleanupCallback = HcaEvtDeviceContextCleanup; + + status = WdfDeviceCreate(&DeviceInit, &fdoAttributes, &device); + + if ( !NT_SUCCESS(status)) { + TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, + "WdfDeviceInitialize failed %!STATUS!\n", status); + return status; + } + + // + // Device creation is complete. + // Get the DeviceExtension and initialize it. + // + fdoData = FdoGetData(device); + RtlZeroMemory( (VOID*)fdoData, sizeof(*fdoData) ); + + fdoData->WdfDevice = device; // for pre-KMDF routines. + + // from deprecated hca_add_device() + cl_spinlock_init( &fdoData->uctx_lock ); + cl_qlist_init( &fdoData->uctx_list ); + atomic_set( &fdoData->usecnt, 0 ); + fdoData->state = HCA_ADDED; + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "PDO(0x%p) FDO(0x%p), Lower(0x%p) DevExt (0x%p)\n", + WdfDeviceWdmGetPhysicalDevice (device), + WdfDeviceWdmGetDeviceObject (device), + WdfDeviceWdmGetAttachedDevice(device), + fdoData); + + // Initialize the device extension and allocate all the software resources + + status = HcaAllocSWResources(fdoData); + if (!NT_SUCCESS (status)){ + TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, + "HcaAllocSWResources failed: %!STATUS!\n", + status); + return status; + } + + // + // If we own the power policy and if our device supports wait-wake then we + // will set our power-policy and update S0-Idle policy. + // + if(IsPoMgmtSupported(fdoData) ) + { + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "Device has wait-wake capability\n"); + status = HcaSetPowerPolicy(fdoData); + if (!NT_SUCCESS (status)) { + TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, + "HcaSetPowerPolicy failed %!STATUS!\n", status); + return status; + } + } + + // + // Tell the Framework that this device will need an interface so that + // application can interact with it. + // + status = WdfDeviceCreateDeviceInterface( device, + (LPGUID)&GUID_DEVINTERFACE_RDMA_IO, + NULL ); + if (!NT_SUCCESS (status)) + { + TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, + "WdfDeviceCreateDeviceInterface failed %!STATUS!\n",status); + return status; + } + + status = HcaWmiRegistration(device); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "<-- %s() ret %x\n",__FUNCTION__, status); + return status; +} + + +/*++ + +Routine Description: + + EvtDeviceContextCleanup event callback cleans up anything done in + EvtDeviceAdd, except those things that are automatically cleaned + up by the Framework. + + In the case of this sample, everything is automatically handled. In a + driver derived from this sample, it's quite likely that this function could + be deleted. + +Arguments: + + Device - Handle to a framework device object. + +Return Value: + + VOID + +--*/ + +VOID +HcaEvtDeviceContextCleanup ( WDFDEVICE Device ) +{ + PFDO_DATA fdoData; + NTSTATUS status; + + PAGED_CODE(); + + fdoData = FdoGetData(Device); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s()\n", __FUNCTION__); + + status = HcaFreeSWResources(fdoData); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s()\n", __FUNCTION__); +} + + +/*++ + +Routine Description: + + HcaEvtDeviceSelfManagedIoInit is called by the Framework when the device + enters the D0 state. Its job is to start any I/O-related actions that the + Framework isn't managing. This might include releasing queues that are not + power-managed, that is, the Framework is not automatically holding and + releasing them across PnP/Power transitions. (The default behavior for + WDFQUEUE is auto-managed, so most queues don't need to be dealt with here.) + This might also include setting up non-queue-based actions. + + If you allow the Framework to manage most or all of your queues, then when + you build a driver from this sample, you can probably delete this function. + + In this driver, the SelfManagedIo callbacks are used to implement a + watchdog timer. + + This function is not marked pagable because this function is in the + device power up path. When a function is marked pagable and the code + section is paged out, it will generate a page fault which could impact + the fast resume behavior because the client driver will have to wait + until the system drivers can service this page fault. + +Arguments: + + Device - Handle to a framework device object. + +Return Value: + + NTSTATUS - Failures will result in the device stack being torn down. + +--*/ + +NTSTATUS +HcaEvtDeviceSelfManagedIoInit( IN WDFDEVICE Device ) +{ + PFDO_DATA fdoData = NULL; + NTSTATUS status=STATUS_SUCCESS; +// WDF_TIMER_CONFIG wdfTimerConfig; +// WDF_OBJECT_ATTRIBUTES timerAttributes; + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s()\n", __FUNCTION__); + + fdoData = FdoGetData(Device); + +#if 0 + // To minimize init-time, create a timer DPC to do link detection. + // This DPC will also be used to check for hardware hang. + // + WDF_TIMER_CONFIG_INIT(&wdfTimerConfig, NICWatchDogEvtTimerFunc); + + WDF_OBJECT_ATTRIBUTES_INIT(&timerAttributes); + timerAttributes.ParentObject = fdoData->WdfDevice; + + status = WdfTimerCreate( + &wdfTimerConfig, + &timerAttributes, + &fdoData->WatchDogTimer + ); + + if(!NT_SUCCESS(status) ) { + TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, + "Error: WdfTimerCreate create failed 0x%x\n", status); + return status; + } + + NICStartWatchDogTimer(fdoData); +#endif + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "<-- %s() ret %x\n", __FUNCTION__, status); + + return status; +} + + +/*++ + +Routine Description: + + EvtDeviceSelfManagedIoSuspend is called by the Framework before the device + leaves the D0 state. Its job is to stop any I/O-related actions that the + Framework isn't managing, and which cannot be handled when the device + hardware isn't available. In general, this means reversing anything that + was done in EvtDeviceSelfManagedIoStart. + + If you allow the Framework to manage most or all of your queues, then when + you build a driver from this sample, you can probably delete this function. + +Arguments: + + Device - Handle to a framework device object. + +Return Value: + + NTSTATUS - Failures will result in the device stack being torn down. + +--*/ + +NTSTATUS +HcaEvtDeviceSelfManagedIoSuspend( IN WDFDEVICE Device ) +{ + PFDO_DATA fdoData = NULL; + + PAGED_CODE(); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "--> HcaEvtDeviceSelfManagedIoSuspend\n"); + + fdoData = FdoGetData(Device); + +#if 0 + // + // Stop the watchdog timer and wait for DPC to run to completion if + // it's already fired. + // + WdfTimerStop(fdoData->WatchDogTimer, TRUE); +#endif + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "<-- HcaEvtDeviceSelfManagedIoSuspend\n"); + + return STATUS_SUCCESS; +} + +NTSTATUS +HcaEvtDeviceSelfManagedIoRestart( + IN WDFDEVICE Device + ) +/*++ + +Routine Description: + + EvtDeviceSelfManagedIoRestart is called by the Framework before the device + is restarted for one of the following reasons: + a) the PnP resources were rebalanced (framework received + query-stop and stop IRPS ) + b) the device resumed from a low power state to D0. + + This function is not marked pagable because this function is in the + device power up path. When a function is marked pagable and the code + section is paged out, it will generate a page fault which could impact + the fast resume behavior because the client driver will have to wait + until the system drivers can service this page fault. + +Arguments: + + Device - Handle to a framework device object. + +Return Value: + + NTSTATUS - Failure will cause the device stack to be torn down. + +--*/ +{ + PFDO_DATA fdoData; + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "--> HcaEvtDeviceSelfManagedIoRestart\n"); + + fdoData = FdoGetData(Device); + + // + // Restart the watchdog timer. + // +#if 0 + NICStartWatchDogTimer(fdoData); +#endif + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "<-- HcaEvtDeviceSelfManagedIoRestart\n"); + + return STATUS_SUCCESS; +} + + +/*++ + +Routine Description: + + EvtDeviceSelfManagedIoCleanup is called by the Framework when the device is + being torn down, either in response to the WDM IRP_MN_REMOVE_DEVICE + It will be called only once. Its job is to stop all outstanding I/O in the driver + that the Framework is not managing. + +Arguments: + + Device - Handle to a framework device object. + +Return Value: + + None + +--*/ + +VOID +HcaEvtDeviceSelfManagedIoCleanup( IN WDFDEVICE Device ) +{ + PFDO_DATA fdoData = NULL; + + PAGED_CODE(); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "--> HcaEvtDeviceSelfManagedIoCleanup\n"); + + fdoData = FdoGetData(Device); + +#if 0 + if(fdoData->WatchDogTimer) { + WdfObjectDelete(fdoData->WatchDogTimer); + } +#endif + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "<-- HcaEvtDeviceSelfManagedIoCleanup\n"); +} + + +/*++ + +Routine Description: + + This event is called when the framework receives IRP_MJ_DEVICE_CONTROL + requests from the system. + +Arguments: + + Queue - Handle to the framework queue object that is associated + with the I/O request. + Request - Handle to a framework request object. + + OutputBufferLength - length of the request's output buffer, + if an output buffer is available. + InputBufferLength - length of the request's input buffer, + if an input buffer is available. + + IoControlCode - the driver-defined or system-defined I/O control code + (IOCTL) that is associated with the request. +Return Value: + + VOID + +--*/ + +VOID +HcaEvtIoDeviceControl( + IN WDFQUEUE Queue, + IN WDFREQUEST Request, + IN size_t OutputBufferLength, + IN size_t InputBufferLength, + IN ULONG IoControlCode ) +{ + //NTSTATUS status= STATUS_SUCCESS; + PFDO_DATA fdoData = NULL; + WDFDEVICE hDevice; + WDF_REQUEST_PARAMETERS params; + + UNREFERENCED_PARAMETER(OutputBufferLength); + UNREFERENCED_PARAMETER(InputBufferLength); + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_IOCTLS, + "HcaEvtIoDeviceControl called %p\n", Request); + + hDevice = WdfIoQueueGetDevice(Queue); + fdoData = FdoGetData(hDevice); + + WDF_REQUEST_PARAMETERS_INIT(¶ms); + + WdfRequestGetParameters( + Request, + ¶ms + ); + + switch (IoControlCode) + { +#if 0 + case IOCTL_NDISPROT_QUERY_OID_VALUE: + + ASSERT((IoControlCode & 0x3) == METHOD_BUFFERED); + + NICHandleQueryOidRequest( + Queue, + Request, + ¶ms + ); + break; + + case IOCTL_NDISPROT_SET_OID_VALUE: + + ASSERT((IoControlCode & 0x3) == METHOD_BUFFERED); + + NICHandleSetOidRequest( + Queue, + Request, + ¶ms + ); + + break; + + case IOCTL_NDISPROT_INDICATE_STATUS: + + status = WdfRequestForwardToIoQueue(Request, + fdoData->PendingIoctlQueue); + if(!NT_SUCCESS(status)){ + TraceEvents(TRACE_LEVEL_ERROR, DBG_IOCTLS, + "WdfRequestForwardToIoQueue failed 0x%x\n", status); + WdfRequestComplete(Request, status); + break; + } + + break; +#endif + default: + ASSERTMSG(FALSE, "Invalid IOCTL request\n"); + WdfRequestComplete(Request, STATUS_INVALID_DEVICE_REQUEST); + break; + } +} + + +/*++ + +Routine Description: + + This routine is used to queue workitems so that the callback + functions can be executed at PASSIVE_LEVEL in the conext of + a system thread. + +Arguments: + + FdoData - pointer to a device extenion. + + CallbackFunction - Function to invoke when at PASSIVE_LEVEL. + + Context1 & 2 - Meaning of the context values depends on the + callback function. + +Return Value: + +--*/ + +NTSTATUS +HcaQueuePassiveLevelCallback( + IN PFDO_DATA FdoData, + IN PFN_WDF_WORKITEM CallbackFunction, + IN PVOID Context1, + IN PVOID Context2 ) +{ + NTSTATUS status = STATUS_SUCCESS; + PWORKER_ITEM_CONTEXT context; + WDF_OBJECT_ATTRIBUTES attributes; + WDF_WORKITEM_CONFIG workitemConfig; + WDFWORKITEM hWorkItem; + + WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, WORKER_ITEM_CONTEXT); + + attributes.ParentObject = FdoData->WdfDevice; + + WDF_WORKITEM_CONFIG_INIT(&workitemConfig, CallbackFunction); + + status = WdfWorkItemCreate( &workitemConfig, + &attributes, + &hWorkItem); + + if (!NT_SUCCESS(status)) { + return status; + } + + context = GetWorkItemContext(hWorkItem); + + context->FdoData = FdoData; + context->Argument1 = Context1; + context->Argument2 = Context2; + + // + // Execute this work item. + // + WdfWorkItemEnqueue(hWorkItem); + + return STATUS_SUCCESS; +} + + +/*++ + +Routine Description: + + Can be used to read any REG_DWORD registry value stored + under Device Parameter. + +Arguments: + + FdoData - pointer to the device extension + Name - Name of the registry value + Value - + + +Return Value: + + TRUE if successful + FALSE if not present/error in reading registry + +--*/ + +BOOLEAN +HcaReadRegistryValue( + __in PFDO_DATA FdoData, + __in PWCHAR Name, + __out PULONG Value ) +{ + WDFKEY hKey = NULL; + NTSTATUS status; + BOOLEAN retValue = FALSE; + UNICODE_STRING valueName; + + PAGED_CODE(); + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_INIT, "--> %s()\n", __FUNCTION__); + + *Value = 0; + + status = WdfDeviceOpenRegistryKey(FdoData->WdfDevice, + PLUGPLAY_REGKEY_DEVICE, + STANDARD_RIGHTS_ALL, + WDF_NO_OBJECT_ATTRIBUTES, + &hKey); + + if (NT_SUCCESS (status)) { + + RtlInitUnicodeString(&valueName,Name); + + status = WdfRegistryQueryULong( hKey, + &valueName, + Value ); + + if (NT_SUCCESS (status)) { + retValue = TRUE; + } + + WdfRegistryClose(hKey); + } + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_INIT, + "<-- %s() %ws %d \n", __FUNCTION__, Name, *Value); + + return retValue; +} + + +/*++ + +Routine Description: + + Can be used to write any REG_DWORD registry value stored + under Device Parameter. + +Arguments: + + +Return Value: + + TRUE - if write is successful + FALSE - otherwise + +--*/ + +BOOLEAN +HcaWriteRegistryValue( + __in PFDO_DATA FdoData, + __in PWCHAR Name, + __in ULONG Value ) +{ + WDFKEY hKey = NULL; + NTSTATUS status; + BOOLEAN retValue = FALSE; + UNICODE_STRING valueName; + + + PAGED_CODE(); + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_INIT, "--> %s()\n", __FUNCTION__); + + // + // write the value out to the registry + // + status = WdfDeviceOpenRegistryKey(FdoData->WdfDevice, + PLUGPLAY_REGKEY_DEVICE, + STANDARD_RIGHTS_ALL, + WDF_NO_OBJECT_ATTRIBUTES, + &hKey); + + if (NT_SUCCESS (status)) { + + RtlInitUnicodeString(&valueName,Name); + + status = WdfRegistryAssignULong (hKey, + &valueName, + Value ); + + if (NT_SUCCESS (status)) { + retValue = TRUE; + } + + WdfRegistryClose(hKey); + } + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_INIT, + "<-- ret %s() %s\n", __FUNCTION__, (retValue ? "True":"False")); + + return retValue; +} + + +/*++ + +Routine Description: + + Can be used to read any REG_DWORD registry value stored + under Device Parameter. + +Arguments: + + FdoData - pointer to the device extension + Name - Name of the registry value + Value - + + +Return Value: + + TRUE if successful + FALSE if not present/error in reading registry + +--*/ + +BOOLEAN +HcaReadFdoRegistryKeyValue( + __in PWDFDEVICE_INIT DeviceInit, + __in PWCHAR Name, + __out PULONG Value ) +{ + WDFKEY hKey = NULL; + NTSTATUS status; + BOOLEAN retValue = FALSE; + UNICODE_STRING valueName; + + PAGED_CODE(); + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, "--> %s()\n", __FUNCTION__); + + *Value = 0; + + status = WdfFdoInitOpenRegistryKey(DeviceInit, + PLUGPLAY_REGKEY_DEVICE, + STANDARD_RIGHTS_ALL, + WDF_NO_OBJECT_ATTRIBUTES, + &hKey); + + if (NT_SUCCESS (status)) { + + RtlInitUnicodeString(&valueName,Name); + + status = WdfRegistryQueryULong (hKey, + &valueName, + Value); + + if (NT_SUCCESS (status)) { + retValue = TRUE; + } + + WdfRegistryClose(hKey); + } + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, + "<-- %s() %ws %d \n", __FUNCTION__, Name, *Value); + + return retValue; +} + + +/*++ +Routine Description: + + Free all the resources allocated in DriverEntry. + +Arguments: + + Driver - handle to a WDF Driver object. + +Return Value: + + VOID. + +--*/ + +VOID +HcaEvtDriverContextCleanup( IN WDFDRIVER Driver ) +{ + UNREFERENCED_PARAMETER( Driver ); + + PAGED_CODE (); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "--> %s()\n",__FUNCTION__); + + // Stop WPP Tracing + // + WPP_CLEANUP( WdfDriverWdmGetDriverObject( Driver ) ); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "<-- %s()\n",__FUNCTION__); +} + + +#if !defined(EVENT_TRACING) + + +/*++ + +Routine Description: + + Debug print for the sample driver. + +Arguments: + + TraceEventsLevel - print level between 0 and 3, with 3 the most verbose + +Return Value: + + None. + + --*/ + +VOID +TraceEvents ( + IN ULONG TraceEventsLevel, + IN ULONG TraceEventsFlag, + IN PCCHAR DebugMessage, + ... ) + { +#if 1 // always for starters... DBG + +#define TEMP_BUFFER_SIZE 512 + va_list list; + CHAR debugMessageBuffer[TEMP_BUFFER_SIZE]; + NTSTATUS status; + + va_start(list, DebugMessage); + + if (DebugMessage) { + + // + // Using new safe string functions instead of _vsnprintf. + // This function takes care of NULL terminating if the message + // is longer than the buffer. + // + status = RtlStringCbVPrintfA( debugMessageBuffer, + sizeof(debugMessageBuffer), + DebugMessage, + list ); + if(!NT_SUCCESS(status)) { + + DbgPrint (_DRIVER_NAME_": RtlStringCbVPrintfA failed %x\n", + status); + return; + } + if (TraceEventsLevel <= TRACE_LEVEL_INFORMATION || + (TraceEventsLevel <= g_mthca_dbg_level && + ((TraceEventsFlag & g_mthca_dbg_flags) == TraceEventsFlag))) { + DbgPrint(debugMessageBuffer); + } + } + va_end(list); + + return; +#else + UNREFERENCED_PARAMETER(TraceEventsLevel); + UNREFERENCED_PARAMETER(TraceEventsFlag); + UNREFERENCED_PARAMETER(DebugMessage); +#endif +} + +#endif + + +NTSTATUS +HcaAllocSWResources(PFDO_DATA fdoData) +{ + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, + "--> %s() fdoData %p\n", __FUNCTION__, fdoData); + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, "<-- %s()\n", __FUNCTION__); + + return STATUS_SUCCESS; +} + +NTSTATUS +HcaFreeSWResources(PFDO_DATA fdoData) +{ + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, + "--> %s() fdoData %p\n", __FUNCTION__, fdoData); + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, "<-- %s()\n", __FUNCTION__); + + return STATUS_SUCCESS; +} + diff --git a/branches/IBFD/hw/mthca/kmdf/hca_driver.h b/branches/IBFD/hw/mthca/kmdf/hca_driver.h index 91bbe8b5..d4a96a8c 100644 --- a/branches/IBFD/hw/mthca/kmdf/hca_driver.h +++ b/branches/IBFD/hw/mthca/kmdf/hca_driver.h @@ -47,7 +47,6 @@ #include "trace.h" -#include "hca_pnp.h" #include "hca_pci.h" #if !defined(FILE_DEVICE_INFINIBAND) // Not defined in WXP DDK @@ -292,27 +291,10 @@ EVT_WDF_DRIVER_DEVICE_ADD HcaEvtDeviceAdd; EVT_WDF_OBJECT_CONTEXT_CLEANUP HcaEvtDriverContextCleanup; EVT_WDF_DEVICE_CONTEXT_CLEANUP HcaEvtDeviceContextCleanup; -EVT_WDF_DEVICE_D0_ENTRY HcaEvtDeviceD0Entry; -EVT_WDF_DEVICE_D0_EXIT HcaEvtDeviceD0Exit; -EVT_WDF_DEVICE_PREPARE_HARDWARE HcaEvtDevicePrepareHardware; -EVT_WDF_DEVICE_RELEASE_HARDWARE HcaEvtDeviceReleaseHardware; - EVT_WDF_DEVICE_SELF_MANAGED_IO_CLEANUP HcaEvtDeviceSelfManagedIoCleanup; EVT_WDF_DEVICE_SELF_MANAGED_IO_INIT HcaEvtDeviceSelfManagedIoInit; EVT_WDF_DEVICE_SELF_MANAGED_IO_SUSPEND HcaEvtDeviceSelfManagedIoSuspend; EVT_WDF_DEVICE_SELF_MANAGED_IO_RESTART HcaEvtDeviceSelfManagedIoRestart; - -EVT_WDF_DEVICE_SURPRISE_REMOVAL HcaEvtDeviceSurpriseRemoval; - -EVT_WDF_DEVICE_ARM_WAKE_FROM_S0 HcaEvtDeviceWakeArmS0; -EVT_WDF_DEVICE_ARM_WAKE_FROM_SX HcaEvtDeviceWakeArmSx; -EVT_WDF_DEVICE_DISARM_WAKE_FROM_S0 HcaEvtDeviceWakeDisarmS0; -EVT_WDF_DEVICE_DISARM_WAKE_FROM_SX HcaEvtDeviceWakeDisarmSx; -EVT_WDF_DEVICE_WAKE_FROM_S0_TRIGGERED HcaEvtDeviceWakeTriggeredS0; -EVT_WDF_DEVICE_WAKE_FROM_SX_TRIGGERED HcaEvtDeviceWakeTriggeredSx; -EVT_WDF_DEVICE_D0_ENTRY_POST_INTERRUPTS_ENABLED HcaEvtDeviceD0EntryPostInterruptsEnabled; -EVT_WDF_DEVICE_D0_EXIT_PRE_INTERRUPTS_DISABLED HcaEvtDeviceD0ExitPreInterruptsDisabled; - EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL HcaEvtIoDeviceControl; NTSTATUS @@ -353,11 +335,6 @@ HcaWmiRegistration( WDFDEVICE hDevice ); -PCHAR -DbgDevicePowerString( - IN WDF_POWER_DEVICE_STATE Type - ); - BOOLEAN HcaReadFdoRegistryKeyValue( diff --git a/branches/IBFD/hw/mthca/kmdf/hca_pnp.c b/branches/IBFD/hw/mthca/kmdf/hca_pnp.c index bec49210..d95e14f7 100644 --- a/branches/IBFD/hw/mthca/kmdf/hca_pnp.c +++ b/branches/IBFD/hw/mthca/kmdf/hca_pnp.c @@ -1,16 +1,44 @@ /* BEGIN_ICS_COPYRIGHT **************************************** ** END_ICS_COPYRIGHT ****************************************/ - /* - $Revision: 1.1 $ -*/ - + * Copyright (c) 2008 Intel corporation. All rights reserved. + * Copyright (c) 2005 SilverStorm Technologies. All rights reserved. + * + * This software is available to you under the OpenIB.org BSD license + * below: + * + * 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * + * $Id$ + */ /* - * Provides the driver entry points for the Tavor VPD. + * Provides driver entry points for Plug-n-Play power management. */ #include "hca_driver.h" +#include "hca_pnp.h" #include "mthca_dev.h" #if defined(EVENT_TRACING) @@ -141,6 +169,14 @@ __pnp_notify_ifc( #ifdef ALLOC_PRAGMA +#pragma alloc_text (PAGE, HcaEvtDevicePrepareHardware) +#pragma alloc_text (PAGE, HcaEvtDeviceReleaseHardware) +#pragma alloc_text (PAGE, HcaEvtDeviceWakeArmS0) +#pragma alloc_text (PAGE, HcaEvtDeviceWakeDisarmS0) +#pragma alloc_text (PAGE, HcaEvtDeviceWakeTriggeredS0) +#pragma alloc_text (PAGE, HcaEvtDeviceWakeArmSx) +#pragma alloc_text (PAGE, HcaSetPowerPolicy) + #pragma alloc_text (PAGE, hca_add_device) #pragma alloc_text (PAGE, hca_start) #pragma alloc_text (PAGE, hca_query_stop) @@ -160,6 +196,10 @@ __pnp_notify_ifc( #pragma alloc_text (PAGE, __hca_register) #pragma alloc_text (PAGE, __pnp_notify_target) #pragma alloc_text (PAGE, __pnp_notify_ifc) + +#pragma alloc_text (PAGE, HcaEvtDeviceD0ExitPreInterruptsDisabled) +#pragma alloc_text (PAGE, HcaEvtDeviceD0EntryPostInterruptsEnabled) + #endif @@ -203,6 +243,8 @@ hca_init_vfptr( void ) } +#ifdef NOT_USED_XXX + NTSTATUS hca_add_device( IN PDRIVER_OBJECT pDriverObj, @@ -216,7 +258,7 @@ hca_add_device( UNREFERENCED_PARAMETER(pDriverObj); HCA_ENTER(HCA_DBG_PNP); -#if 0 + /* * Create the device so that we have a device extension to store stuff in. */ @@ -229,7 +271,6 @@ hca_add_device( ("IoCreateDevice returned 0x%08X.\n", status)); return status; } -#endif p_ext = (hca_dev_ext_t*)p_dev_obj->DeviceExtension; cl_memclr( p_ext, sizeof(hca_dev_ext_t) ); @@ -237,7 +278,6 @@ hca_add_device( cl_qlist_init( &p_ext->uctx_list ); atomic_set(&p_ext->usecnt, 0); -#if 0 /* Attach to the device stack. */ pNextDevObj = IoAttachDeviceToDeviceStack( p_dev_obj, pPdo ); if( !pNextDevObj ) @@ -248,10 +288,6 @@ hca_add_device( ("IoAttachDeviceToDeviceStack failed.\n")); return STATUS_NO_SUCH_DEVICE; } -#endif - -// XXX fixup pNextDevObj... STAN - pNextDevObj = NULL; /* Inititalize the complib extension. */ cl_init_pnp_po_ext( p_dev_obj, pNextDevObj, pPdo, 0, &vfptrHcaPnp, NULL ); @@ -262,7 +298,7 @@ hca_add_device( return status; } - +#endif static NTSTATUS __get_ci_interface( @@ -402,7 +438,8 @@ __pnp_notify_target( CL_ASSERT( !p_ext->p_al_file_obj ); CL_ASSERT( !p_ext->p_al_dev ); /* Get the AL device object. */ - HCA_PRINT( TRACE_LEVEL_INFORMATION ,HCA_DBG_SHIM ,("Calling IoGetDeviceObjectPointer.\n")); + HCA_PRINT( TRACE_LEVEL_INFORMATION ,HCA_DBG_SHIM, + ("Calling IoGetDeviceObjectPointer.\n")); status = IoGetDeviceObjectPointer( &p_ext->al_sym_name, FILE_ALL_ACCESS, &p_ext->p_al_file_obj, &p_ext->p_al_dev ); if( !NT_SUCCESS( status ) ) @@ -912,7 +949,8 @@ hca_start( /* We get started fully powered. */ p_ext->DevicePowerState = PowerDeviceD0; powerState.DeviceState = PowerDeviceD0; - powerState = PoSetPowerState ( p_ext->cl_ext.p_self_do, DevicePowerState, powerState ); + powerState = PoSetPowerState ( p_ext->cl_ext.p_self_do, + DevicePowerState, powerState ); HCA_PRINT( TRACE_LEVEL_INFORMATION, HCA_DBG_PNP, ("PoSetPowerState: old state %d, new state to %d\n", powerState.DeviceState, p_ext->DevicePowerState )); @@ -946,8 +984,7 @@ hca_start( /* release the resources, allocated in hca_start */ static void -__hca_release_resources( - IN DEVICE_OBJECT* const p_dev_obj ) +__hca_release_resources( IN DEVICE_OBJECT* const p_dev_obj ) { hca_dev_ext_t *p_ext = (hca_dev_ext_t*)p_dev_obj->DeviceExtension; @@ -1021,7 +1058,8 @@ hca_release_resources( /* Notify the power manager that the device is powered down. */ p_ext->DevicePowerState = PowerDeviceD3; powerState.DeviceState = PowerDeviceD3; - powerState = PoSetPowerState ( p_ext->cl_ext.p_self_do, DevicePowerState, powerState ); + powerState = PoSetPowerState ( p_ext->cl_ext.p_self_do, + DevicePowerState, powerState ); HCA_PRINT( TRACE_LEVEL_INFORMATION, HCA_DBG_PNP, ("PoSetPowerState: old state %d, new state to %d\n", @@ -1782,3 +1820,741 @@ void reregister_hca( hca_dev_ext_t *p_ext ) } + + +/*++ + +Routine Description: + + EvtDeviceStart event callback performs operations that are necessary + to make the driver's device operational. The framework calls the driver's + EvtDeviceStart callback when the PnP manager sends an IRP_MN_START_DEVICE + request to the driver stack. + +Arguments: + + Device - Handle to a framework device object. + + Resources - Handle to a collection of framework resource objects. + This collection identifies the raw (bus-relative) hardware + resources that have been assigned to the device. + + ResourcesTranslated - Handle to a collection of framework resource objects. + This collection identifies the translated (system-physical) + hardware resources that have been assigned to the device. + The resources appear from the CPU's point of view. + Use this list of resources to map I/O space and + device-accessible memory into virtual address space + +Return Value: + + WDF status code + +--*/ + +NTSTATUS +HcaEvtDevicePrepareHardware ( + WDFDEVICE Device, + WDFCMRESLIST Resources, + WDFCMRESLIST ResourcesTranslated ) +{ + NTSTATUS status = STATUS_SUCCESS; + PFDO_DATA fdoData = NULL; + DEVICE_OBJECT* p_dev_obj; + + UNREFERENCED_PARAMETER(Resources); + UNREFERENCED_PARAMETER(ResourcesTranslated); + + PAGED_CODE(); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s()\n", __FUNCTION__); + + fdoData = FdoGetData(Device); + p_dev_obj = WdfDeviceWdmGetAttachedDevice(Device), + +#if 0 + status = NICMapHWResources(fdoData, ResourcesTranslated); + if (!NT_SUCCESS (status)){ + TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, + "NICMapHWResources failed: %!STATUS!\n", status); + return status; + } +#endif + + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "<-- %s() ret %x\n", __FUNCTION__, status); + + return status; + +} + + +/*++ + +Routine Description: + + EvtDeviceReleaseHardware is called by the framework whenever the PnP manager + is revoking ownership of our resources. This may be in response to either + IRP_MN_STOP_DEVICE or IRP_MN_REMOVE_DEVICE. The callback is made before + passing down the IRP to the lower driver. + + In this callback, do anything necessary to free those resources. + +Arguments: + + Device - Handle to a framework device object. + + ResourcesTranslated - Handle to a collection of framework resource objects. + This collection identifies the translated (system-physical) + hardware resources that have been assigned to the device. + The resources appear from the CPU's point of view. + Use this list of resources to map I/O space and + device-accessible memory into virtual address space + +Return Value: + + NTSTATUS - Failures will be logged, but not acted on. + +--*/ + +NTSTATUS +HcaEvtDeviceReleaseHardware( + IN WDFDEVICE Device, + IN WDFCMRESLIST ResourcesTranslated ) +{ + PFDO_DATA fdoData; + PDEVICE_OBJECT p_dev_obj; + + UNREFERENCED_PARAMETER(ResourcesTranslated); + + PAGED_CODE(); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s()\n", __FUNCTION__); + + fdoData = FdoGetData(Device); + p_dev_obj = WdfDeviceWdmGetAttachedDevice(Device), + +#if 0 + // + // Unmap any I/O ports. Disconnecting from the interrupt will be done + // automatically by the framework. + // + NICUnmapHWResources(fdoData); +#endif + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s()\n", __FUNCTION__); + + return STATUS_SUCCESS; +} + + + +/*++ + +Updated Routine Description: + DbgDevicePowerString does not change in this stage of the function driver. + +--*/ + +static PCHAR +DbgDevicePowerString( IN WDF_POWER_DEVICE_STATE Type ) +{ + switch (Type) + { + case WdfPowerDeviceInvalid: + return "WdfPowerDeviceInvalid"; + case WdfPowerDeviceD0: + return "WdfPowerDeviceD0"; + case PowerDeviceD1: + return "WdfPowerDeviceD1"; + case WdfPowerDeviceD2: + return "WdfPowerDeviceD2"; + case WdfPowerDeviceD3: + return "WdfPowerDeviceD3"; + case WdfPowerDeviceD3Final: + return "WdfPowerDeviceD3Final"; + case WdfPowerDevicePrepareForHibernation: + return "WdfPowerDevicePrepareForHibernation"; + case WdfPowerDeviceMaximum: + return "PowerDeviceMaximum"; + default: + return "UnKnown Device Power State"; + } +} + + +/*++ + +Routine Description: + + EvtDeviceD0Entry event callback must perform any operations that are + necessary before the specified device is used. It will be called every + time the hardware needs to be (re-)initialized. This includes after + IRP_MN_START_DEVICE, IRP_MN_CANCEL_STOP_DEVICE, IRP_MN_CANCEL_REMOVE_DEVICE, + IRP_MN_SET_POWER-D0. + + This function is not marked pageable because this function is in the + device power up path. When a function is marked pagable and the code + section is paged out, it will generate a page fault which could impact + the fast resume behavior because the client driver will have to wait + until the system drivers can service this page fault. + + This function runs at PASSIVE_LEVEL, even though it is not paged. A + driver can optionally make this function pageable if DO_POWER_PAGABLE + is set. Even if DO_POWER_PAGABLE isn't set, this function still runs + at PASSIVE_LEVEL. In this case, though, the function absolutely must + not do anything that will cause a page fault. + +Arguments: + + Device - Handle to a framework device object. + + PreviousState - Device power state which the device was in most recently. + If the device is being newly started, this will be + PowerDeviceUnspecified. + +Return Value: + + NTSTATUS + +--*/ + +NTSTATUS +HcaEvtDeviceD0Entry( + IN WDFDEVICE Device, + IN WDF_POWER_DEVICE_STATE PreviousState ) +{ + PFDO_DATA fdoData; + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_POWER, + "-->HcaEvtDeviceD0Entry - coming from %s\n", + DbgDevicePowerString(PreviousState)); + + fdoData = FdoGetData(Device); + + ASSERT(PowerDeviceD0 != PreviousState); + + fdoData->DevicePowerState = PowerDeviceD0; + + if(IsPoMgmtSupported(fdoData)){ + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_POWER, + "Entering fully on state\n"); +#ifdef XXX + MPSetPowerD0 (fdoData); +#endif + } + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_POWER, "<--HcaEvtDeviceD0Entry\n"); + + return STATUS_SUCCESS; +} + + +NTSTATUS +HcaEvtDeviceD0Exit( + IN WDFDEVICE Device, + IN WDF_POWER_DEVICE_STATE TargetState + ) +/*++ + +Routine Description: + + This routine undoes anything done in EvtDeviceD0Entry. It is called + whenever the device leaves the D0 state, which happens when the device is + stopped, when it is removed, and when it is powered off. + + The device is still in D0 when this callback is invoked, which means that + the driver can still touch hardware in this routine. + + Note that interrupts have already been disabled by the time that this + callback is invoked. + + EvtDeviceD0Exit event callback must perform any operations that are + necessary before the specified device is moved out of the D0 state. If the + driver needs to save hardware state before the device is powered down, then + that should be done here. + + This function runs at PASSIVE_LEVEL, though it is generally not paged. A + driver can optionally make this function pageable if DO_POWER_PAGABLE is set. + + Even if DO_POWER_PAGABLE isn't set, this function still runs at + PASSIVE_LEVEL. In this case, though, the function absolutely must not do + anything that will cause a page fault. + +Arguments: + + Device - Handle to a framework device object. + + TargetState - Device power state which the device will be put in once this + callback is complete. + +Return Value: + + Success implies that the device can be used. Failure will result in the + device stack being torn down. + +--*/ +{ + PFDO_DATA fdoData; + + UNREFERENCED_PARAMETER(Device); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_POWER, + "-->HcaEvtDeviceD0Exit - moving to %s\n", + DbgDevicePowerString(TargetState)); + + fdoData = FdoGetData(Device); + + fdoData->DevicePowerState = TargetState; + + switch (TargetState) { + case WdfPowerDeviceD1: + case WdfPowerDeviceD2: + case WdfPowerDeviceD3: + + if(IsPoMgmtSupported(fdoData)){ + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_POWER, + "Entering a deeper sleep state\n"); +#ifdef XXX + MPSetPowerLow (fdoData, TargetState); +#endif + } + break; + + case WdfPowerDevicePrepareForHibernation: + + // + // Fill in any code to save hardware state here. Do not put in any + // code to shut the device off. If this device cannot support being + // in the paging path (or being a parent or grandparent of a paging + // path device) then this whole case can be deleted. + // + ASSERT(FALSE); // This driver shouldn't get this. + break; + + case WdfPowerDeviceD3Final: + // + // Reset and put the device into a known initial state we're shutting + // down for the last time. + // +#if 0 + NICShutdown(fdoData); +#endif + break; + + default: + break; + } + + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_POWER, "<--HcaEvtDeviceD0Exit\n"); + + return STATUS_SUCCESS; +} + + + +/*++ + +Routine Description: + + EvtDeviceWakeArmS0 is called when the Framework arms the device for + wake in the S0 state. If there is any device-specific initialization + that needs to be done to arm internal wake signals, or to route internal + interrupt signals to the wake logic, it should be done here. The device + will be moved out of the D0 state soon after this callback is invoked. + + In this sample, wake from S0 involves waking on packet arrival, as does + wake from Sx. A more common NIC implementation might wake on cable + insertion. + + This function is pageable and it will run at PASSIVE_LEVEL. + +Arguments: + + Device - Handle to a Framework device object. + +Return Value: + + NTSTATUS - Failure will result in the device remaining in the D0 state. + +--*/ + +NTSTATUS +HcaEvtDeviceWakeArmS0( IN WDFDEVICE Device ) +{ + NTSTATUS status=STATUS_SUCCESS; + PFDO_DATA fdoData; + + PAGED_CODE(); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s()\n", __FUNCTION__); + + fdoData = FdoGetData(Device); + + // + // Add pattern before sending wait-wake + // +#if 0 + status = NICConfigureForWakeUp(fdoData, TRUE); +#endif + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "<-- %s() %x\n", __FUNCTION__, status); + + return status; +} + + +/*++ + +Routine Description: + + EvtDeviceWakeArmSx is called when the Framework arms the device for + wake from the S1, S2, S3 or S4 states. If there is any device-specific + initialization that needs to be done to arm internal wake signals, or to + route internal interrupt signals to the wake logic, it should be done here. + The device will be moved out of the D0 state soon after this callback is + invoked. + + In this sample, wake from Sx involves arming for wake on packet arrival. + Cable insertion should not be enabled, as nobody would want their machine + to wake up simply because they plugged the cable in. + + This function runs at PASSIVE_LEVEL. Whether it is pageable or not depends + on whether the device has set DO_POWER_PAGABLE. + +Arguments: + + Device - Handle to a Framework device object. + +Return Value: + + NTSTATUS - Failure will result in the device not being armed for wake + while the system is in Sx. + +--*/ + +NTSTATUS +HcaEvtDeviceWakeArmSx( IN WDFDEVICE Device ) +{ + NTSTATUS status=STATUS_SUCCESS; + PFDO_DATA fdoData; + + PAGED_CODE(); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s()\n", __FUNCTION__); + + fdoData = FdoGetData(Device); + // + // Add pattern before sending wait-wake + // +#if 0 + status = NICConfigureForWakeUp(fdoData, TRUE); +#endif + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "<-- %s() ret %x\n", __FUNCTION__, status); + + return status; +} + + +/*++ + +Routine Description: + + EvtDeviceWakeDisarmS0 reverses anything done in EvtDeviceWakeArmS0. + + This function is pageable and it will run at PASSIVE_LEVEL. + +Arguments: + + Device - Handle to a Framework device object. + +Return Value: + + VOID. + +--*/ + +VOID +HcaEvtDeviceWakeDisarmS0( IN WDFDEVICE Device ) +{ + NTSTATUS status=STATUS_SUCCESS; + PFDO_DATA fdoData; + + PAGED_CODE(); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s\n", __FUNCTION__); + + fdoData = FdoGetData(Device); +#if 0 + status = NICConfigureForWakeUp(fdoData, FALSE); +#endif + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "<-- %s %x\n", __FUNCTION__, status); +} + + +/*++ + +Routine Description: + + EvtDeviceWakeDisarmSx reverses anything done in EvtDeviceWakeArmSx. + + This function is not marked pageable because this function is in the + device power up path. When a function is marked pagable and the code + section is paged out, it will generate a page fault which could impact + the fast resume behavior because the client driver will have to wait + until the system drivers can service this page fault. + + This function runs at PASSIVE_LEVEL, even though it is not paged. A + driver can optionally make this function pageable if DO_POWER_PAGABLE + is set. Even if DO_POWER_PAGABLE isn't set, this function still runs + at PASSIVE_LEVEL. In this case, though, the function absolutely must + not do anything that will cause a page fault. + +Arguments: + + Device - Handle to a Framework device object. + +Return Value: + + VOID + +--*/ + +VOID +HcaEvtDeviceWakeDisarmSx( IN WDFDEVICE Device ) +{ + NTSTATUS status=STATUS_SUCCESS; + PFDO_DATA fdoData; + + UNREFERENCED_PARAMETER(Device); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s\n", __FUNCTION__); + + fdoData = FdoGetData(Device); +#if 0 + status = NICConfigureForWakeUp(fdoData, FALSE); +#endif + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, + "<-- %s %x\n", __FUNCTION__, status); +} + + +/*++ + +Routine Description: + + EvtDeviceWakeTriggeredS0 will be called whenever the device triggers its + wake signal after being armed for wake from S0. + + This function is pageable and runs at PASSIVE_LEVEL. + +Arguments: + + Device - Handle to a Framework device object. + +Return Value: + + VOID + +--*/ + +VOID +HcaEvtDeviceWakeTriggeredS0( IN WDFDEVICE Device ) +{ + UNREFERENCED_PARAMETER(Device); + + PAGED_CODE(); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s\n", __FUNCTION__); + + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s\n", __FUNCTION__); +} + + +/*++ + +Routine Description: + + EvtDeviceWakeTriggeredSx will be called whenever the device triggers its + wake signal after being armed for wake from Sx. + + This function is not marked pageable because this function is in the + device power up path. When a function is marked pagable and the code + section is paged out, it will generate a page fault which could impact + the fast resume behavior because the client driver will have to wait + until the system drivers can service this page fault. + + This function runs at PASSIVE_LEVEL, even though it is not paged. A + driver can optionally make this function pageable if DO_POWER_PAGABLE + is set. Even if DO_POWER_PAGABLE isn't set, this function still runs + at PASSIVE_LEVEL. In this case, though, the function absolutely must + not do anything that will cause a page fault. + +Arguments: + + Device - Handle to a Framework device object. + +Return Value: + + VOID + +--*/ + +VOID +HcaEvtDeviceWakeTriggeredSx( IN WDFDEVICE Device ) +{ + UNREFERENCED_PARAMETER(Device); + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s", __FUNCTION__); + + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s", __FUNCTION__); + + return; +} + + + +NTSTATUS +HcaSetPowerPolicy( + IN PFDO_DATA FdoData + ) +{ + WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS idleSettings; + WDF_DEVICE_POWER_POLICY_WAKE_SETTINGS wakeSettings; + NTSTATUS status = STATUS_SUCCESS; + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s()\n", __FUNCTION__); + + PAGED_CODE(); + + // + // Init the idle policy structure. + // + WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT(&idleSettings, IdleCanWakeFromS0); + idleSettings.IdleTimeout = 10000; // 10-sec + + status = WdfDeviceAssignS0IdleSettings(FdoData->WdfDevice, &idleSettings); + if ( !NT_SUCCESS(status)) { + TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, + "WdfDeviceSetPowerPolicyS0IdlePolicy failed %x\n", status); + return status; + } + + // + // Init wait-wake policy structure. + // + WDF_DEVICE_POWER_POLICY_WAKE_SETTINGS_INIT(&wakeSettings); + + status = WdfDeviceAssignSxWakeSettings(FdoData->WdfDevice, &wakeSettings); + if (!NT_SUCCESS(status)) { + TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, + "WdfDeviceAssignSxWakeSettings failed %x\n", status); + return status; + } + + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s()\n", __FUNCTION__); + + return status; +} + + + +/*++ + +Routine Description: + + This event is called so that driver can do PASSIVE_LEVEL work before + the interrupt is disconnected and disabled. + +Arguments: + + Interrupt - Handle to a Framework interrupt object. + + AssociatedDevice - Handle to a Framework device object. + +Return Value: + + STATUS_SUCCESS - indicates success. + +--*/ + +NTSTATUS +HcaEvtDeviceD0ExitPreInterruptsDisabled( + IN WDFDEVICE Device, + IN WDF_POWER_DEVICE_STATE TargetState ) +{ + PFDO_DATA fdoData; + + UNREFERENCED_PARAMETER(TargetState); + + PAGED_CODE(); + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, "--> %s()\n", __FUNCTION__); + + fdoData = FdoGetData(Device); + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, "<-- %s()\n", __FUNCTION__); + + return STATUS_SUCCESS; + +} + + +/*++ + +Routine Description: + + This event is called so that driver can do PASSIVE_LEVEL work after + the interrupt is connected and enabled. Here we start the watchdog timer. + Watch dog timer is used to do the initial link detection during + start and then used to make sure the device is not stuck for any reason. + + This function is not marked pageable because this function is in the + device power up path. When a function is marked pagable and the code + section is paged out, it will generate a page fault which could impact + the fast resume behavior because the client driver will have to wait + until the system drivers can service this page fault. + +Arguments: + + Interrupt - Handle to a Framework interrupt object. + + AssociatedDevice - Handle to a Framework device object. + +Return Value: + + STATUS_SUCCESS - indicates success. + +--*/ + +NTSTATUS +HcaEvtDeviceD0EntryPostInterruptsEnabled( + IN WDFDEVICE Device, + IN WDF_POWER_DEVICE_STATE PreviousState ) +{ + PFDO_DATA fdoData; + + UNREFERENCED_PARAMETER( PreviousState ); + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, "--> %s()\n", __FUNCTION__); + + fdoData = FdoGetData(Device); + + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, "<-- %s()\n", __FUNCTION__); + + return STATUS_SUCCESS; + +} + diff --git a/branches/IBFD/hw/mthca/kmdf/hca_pnp.h b/branches/IBFD/hw/mthca/kmdf/hca_pnp.h index 3c121eae..ff06505a 100644 --- a/branches/IBFD/hw/mthca/kmdf/hca_pnp.h +++ b/branches/IBFD/hw/mthca/kmdf/hca_pnp.h @@ -35,13 +35,54 @@ void hca_init_vfptr( void ); + +EVT_WDF_DEVICE_D0_ENTRY HcaEvtDeviceD0Entry; +EVT_WDF_DEVICE_D0_EXIT HcaEvtDeviceD0Exit; +EVT_WDF_DEVICE_PREPARE_HARDWARE HcaEvtDevicePrepareHardware; +EVT_WDF_DEVICE_RELEASE_HARDWARE HcaEvtDeviceReleaseHardware; + +EVT_WDF_DEVICE_SURPRISE_REMOVAL HcaEvtDeviceSurpriseRemoval; + +EVT_WDF_DEVICE_ARM_WAKE_FROM_S0 HcaEvtDeviceWakeArmS0; +EVT_WDF_DEVICE_ARM_WAKE_FROM_SX HcaEvtDeviceWakeArmSx; +EVT_WDF_DEVICE_DISARM_WAKE_FROM_S0 HcaEvtDeviceWakeDisarmS0; +EVT_WDF_DEVICE_DISARM_WAKE_FROM_SX HcaEvtDeviceWakeDisarmSx; +EVT_WDF_DEVICE_WAKE_FROM_S0_TRIGGERED HcaEvtDeviceWakeTriggeredS0; +EVT_WDF_DEVICE_WAKE_FROM_SX_TRIGGERED HcaEvtDeviceWakeTriggeredSx; +EVT_WDF_DEVICE_D0_ENTRY_POST_INTERRUPTS_ENABLED HcaEvtDeviceD0EntryPostInterruptsEnabled; +EVT_WDF_DEVICE_D0_EXIT_PRE_INTERRUPTS_DISABLED HcaEvtDeviceD0ExitPreInterruptsDisabled; + NTSTATUS -hca_add_device( - IN PDRIVER_OBJECT pDriverObj, - IN PDEVICE_OBJECT pPdo, - IN PDEVICE_OBJECT p_dev_obj ); +HcaEvtDeviceD0ExitPreInterruptsDisabled( + IN WDFDEVICE Device, + IN WDF_POWER_DEVICE_STATE TargetState ); + +NTSTATUS +HcaEvtDeviceD0EntryPostInterruptsEnabled( + IN WDFDEVICE Device, + IN WDF_POWER_DEVICE_STATE PreviousState ); +static __inline BOOLEAN +IsPoMgmtSupported( IN PFDO_DATA FdoData ) +{ +#if 1 + UNREFERENCED_PARAMETER(FdoData); + return TRUE; +#else + if (FdoData->RevsionID >= E100_82559_A_STEP + /*&& FdoData->RevsionID <= E100_82559_C_STEP*/) + { + return TRUE; + } + else + { + return FALSE; + } #endif +} + + +#endif /* _HCA_PNP_H_ */ diff --git a/branches/IBFD/hw/mthca/kmdf/mthca_kmdf.c b/branches/IBFD/hw/mthca/kmdf/mthca_kmdf.c deleted file mode 100644 index 39b35c73..00000000 --- a/branches/IBFD/hw/mthca/kmdf/mthca_kmdf.c +++ /dev/null @@ -1,2005 +0,0 @@ -/* - * Copyright (c) 2008 Intel Corporation. All rights reserved. - * Copyright (c) 2005 SilverStorm Technologies. All rights reserved. - * - * This software is available to you under the OpenIB.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * $Id$ - */ - -/*++ -Copyright (c) Microsoft Corporation. All rights reserved. - - THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY - KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR - PURPOSE. - -Module Name: - - mthca_kmdf.c - -Abstract: - - The WDM interfaces in this sample are derrived from the PciDrv KMDF samples - function driver (e100 NIC). mthca interfaces have been merged. - Goal is to provide a skeleton KMDF wrapper around the existing mthca driver - as a starting point in the migrate to a full KMDF driver enviroment. - -Environment: - - Kernel mode - ---*/ - -#include "hca_driver.h" -#include -#include - -#include "mthca_public.h" - -DRIVER_INITIALIZE DriverEntry; -DRIVER_UNLOAD hca_drv_unload; - -// hca_driver.c - previous DriverEntry() -NTSTATUS -HcaEntry ( - IN PDRIVER_OBJECT p_driver_obj, - IN PUNICODE_STRING p_registry_path ); - -void -hca_drv_unload( IN PDRIVER_OBJECT p_driver_obj ); - -NTSTATUS -HcaWmiRegistration( WDFDEVICE Device ); - -NTSTATUS -HcaAllocSWResources(PFDO_DATA fdoData); - -NTSTATUS -HcaFreeSWResources(PFDO_DATA fdoData); - -VOID -HcaEvtDeviceSelfManagedIoCleanup( IN WDFDEVICE Device ); - -NTSTATUS -HcaEvtDeviceSelfManagedIoSuspend( IN WDFDEVICE Device ); - -NTSTATUS -HcaEvtDeviceD0ExitPreInterruptsDisabled( - IN WDFDEVICE Device, - IN WDF_POWER_DEVICE_STATE TargetState ); - -NTSTATUS -HcaEvtDeviceD0EntryPostInterruptsEnabled( - IN WDFDEVICE Device, - IN WDF_POWER_DEVICE_STATE PreviousState ); - - -#if defined(EVENT_TRACING) -// -// The trace message header (.tmh) file must be included in a source file -// before any WPP macro calls and after defining a WPP_CONTROL_GUIDS -// macro (defined in toaster.h). During the compilation, WPP scans the source -// files for DoTraceMessage() calls and builds a .tmh file which stores a unique -// data GUID for each message, the text resource string for each message, -// and the data types of the variables passed in for each message. This file -// is automatically generated and used during post-processing. -// -#include "pcidrv.tmh" -#endif - -#ifdef ALLOC_PRAGMA -#pragma alloc_text (INIT, DriverEntry) -#pragma alloc_text (PAGE, HcaEvtDeviceAdd) -#pragma alloc_text (PAGE, HcaEvtDeviceContextCleanup) -#pragma alloc_text (PAGE, HcaEvtDevicePrepareHardware) -#pragma alloc_text (PAGE, HcaEvtDeviceReleaseHardware) -#pragma alloc_text (PAGE, HcaReadRegistryValue) -#pragma alloc_text (PAGE, HcaWriteRegistryValue) -#pragma alloc_text (PAGE, HcaEvtDriverContextCleanup) -#pragma alloc_text (PAGE, HcaEvtDeviceSelfManagedIoCleanup) -#pragma alloc_text (PAGE, HcaEvtDeviceSelfManagedIoSuspend) -#pragma alloc_text (PAGE, HcaEvtDeviceWakeArmS0) -#pragma alloc_text (PAGE, HcaEvtDeviceWakeDisarmS0) -#pragma alloc_text (PAGE, HcaEvtDeviceWakeTriggeredS0) -#pragma alloc_text (PAGE, HcaEvtDeviceWakeArmSx) -#pragma alloc_text (PAGE, HcaSetPowerPolicy) -#pragma alloc_text (PAGE, HcaReadFdoRegistryKeyValue) -#pragma alloc_text (PAGE, HcaEvtDeviceD0ExitPreInterruptsDisabled) -#pragma alloc_text (PAGE, HcaEvtDeviceD0EntryPostInterruptsEnabled) -#endif - -#define PARAMATER_NAME_LEN 80 - -__inline -BOOLEAN -IsPoMgmtSupported( - IN PFDO_DATA FdoData - ) -{ -#if 1 - UNREFERENCED_PARAMETER(FdoData); - return TRUE; -#else - if (FdoData->RevsionID >= E100_82559_A_STEP - /*&& FdoData->RevsionID <= E100_82559_C_STEP*/) - { - return TRUE; - } - else - { - return FALSE; - } -#endif -} - - -/*++ - -Routine Description: - - Installable driver initialization entry point. - This entry point is called directly by the I/O system. - -Arguments: - - DriverObject - pointer to the driver object - - RegistryPath - pointer to a unicode string representing the path, - to driver-specific key in the registry. - -Return Value: - - STATUS_SUCCESS if successful, - STATUS_UNSUCCESSFUL otherwise. - ---*/ - -NTSTATUS -DriverEntry ( - IN PDRIVER_OBJECT DriverObject, - IN PUNICODE_STRING RegistryPath ) -{ - NTSTATUS status = STATUS_SUCCESS; - WDF_DRIVER_CONFIG config; - WDF_OBJECT_ATTRIBUTES attrib; - WDFDRIVER driver; - PDRIVER_CONTEXT driverContext; - - // - // Initialize WPP Tracing - // -#if defined(EVENT_TRACING) - WPP_INIT_TRACING( DriverObject, RegistryPath ); -#endif - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, - "mthca - KM Driver Framework Edition \n"); - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, - "Built %s %s\n", __DATE__, __TIME__); - -// WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attrib, DRIVER_CONTEXT); - - // - // Register a cleanup callback so that we can call WPP_CLEANUP when - // the framework driver object is deleted during driver unload. - // - attrib.EvtCleanupCallback = HcaEvtDriverContextCleanup; - - // - // Initialize the Driver Config structure.. - // - WDF_DRIVER_CONFIG_INIT(&config, HcaEvtDeviceAdd); - - // - // Create a WDFDRIVER object. - // - status = WdfDriverCreate(DriverObject, - RegistryPath, - &attrib, - &config, - &driver); - - if (!NT_SUCCESS(status)) { - TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, - "WdfDriverCreate failed with status %!STATUS!\n", status); - // - // Cleanup tracing here because DriverContextCleanup will not be called - // as we have failed to create WDFDRIVER object itself. - // Please note that if your return failure from DriverEntry after the - // WDFDRIVER object is created successfully, you don't have to - // call WPP cleanup because in those cases DriverContextCleanup - // will be executed when the framework deletes the DriverObject. - // -#if defined(EVENT_TRACING) - WPP_CLEANUP(DriverObject); -#endif - return status; - } - - driverContext = GetDriverContext(driver); - driverContext->DrvObj = DriverObject; // for DeviceAdd -#if 0 - // - // Create a driver wide lookside list used for allocating memory for the - // MP_RFD structure for all device instances (if there are multiple present). - // - status = WdfLookasideListCreate(WDF_NO_OBJECT_ATTRIBUTES, // LookAsideAttributes - sizeof(MP_RFD), - NonPagedPool, - WDF_NO_OBJECT_ATTRIBUTES, // MemoryAttributes - PCIDRV_POOL_TAG, - &driverContext->RecvLookaside - ); - if (!NT_SUCCESS(status)) { - TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT, - "Couldn't allocate lookaside list status %!STATUS!\n", status); - return status; - } -#endif - if (!NT_SUCCESS(status)) - return status; - - return HcaEntry( DriverObject, RegistryPath ); -} - - -/*++ -Routine Description: - - EvtDeviceAdd is called by the framework in response to AddDevice - call from the PnP manager. - -Arguments: - - Driver - Handle to a framework driver object created in DriverEntry - - DeviceInit - Pointer to a framework-allocated WDFDEVICE_INIT structure. - -Return Value: - - NTSTATUS - ---*/ - -NTSTATUS -HcaEvtDeviceAdd( - IN WDFDRIVER Driver, - IN PWDFDEVICE_INIT DeviceInit ) -{ - NTSTATUS status = STATUS_SUCCESS; - WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks; - WDF_POWER_POLICY_EVENT_CALLBACKS powerPolicyCallbacks; - WDF_OBJECT_ATTRIBUTES fdoAttributes; - WDFDEVICE device; - PFDO_DATA fdoData = NULL; - PDRIVER_CONTEXT DriverContext; - - PAGED_CODE(); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "-->%s() Driver: 0x%p\n", __FUNCTION__, Driver); - - // - // I/O type is Buffered by default. If required to use something else, - // call WdfDeviceInitSetIoType with the appropriate type. - // - WdfDeviceInitSetIoType(DeviceInit, WdfDeviceIoDirect); - - // - // Zero out the PnpPowerCallbacks structure. - // - WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks); - - // - // Set Callbacks for any of the functions we are interested in. - // If no callback is set, Framework will take the default action - // by itself. This sample provides many of the possible callbacks, - // mostly because it's a fairly complex sample that drives full-featured - // hardware. Drivers derived from this sample will often be able to - // provide only some of these. - // - - // - // These callback is invoked to tear down all the driver-managed state - // that is set up in this function. Many times, this callback won't do - // much of anything, since many of the things that are set up here will - // have their lifetimes automatically managed by the Framework. - // - - // - // These two callbacks set up and tear down hardware state, - // specifically that which only has to be done once. - // - - pnpPowerCallbacks.EvtDevicePrepareHardware = HcaEvtDevicePrepareHardware; - pnpPowerCallbacks.EvtDeviceReleaseHardware = HcaEvtDeviceReleaseHardware; - - // - // These two callbacks set up and tear down hardware state that must be - // done every time the device moves in and out of the D0-working state. - // - - pnpPowerCallbacks.EvtDeviceD0Entry = HcaEvtDeviceD0Entry; - pnpPowerCallbacks.EvtDeviceD0Exit = HcaEvtDeviceD0Exit; - - // - // These next two callbacks are for doing work at PASSIVE_LEVEL (low IRQL) - // after all the interrupts are connected and before they are disconnected. - // - // Some drivers need to do device initialization and tear-down while the - // interrupt is connected. (This is a problem for these devices, since - // it opens them up to taking interrupts before they are actually ready - // to handle them, or to taking them after they have torn down too much - // to be able to handle them.) While this hardware design pattern is to - // be discouraged, it is possible to handle it by doing device init and - // tear down in these routines rather than in EvtDeviceD0Entry and - // EvtDeviceD0Exit. - // - // In this sample these callbacks don't do anything. - // - - pnpPowerCallbacks.EvtDeviceD0EntryPostInterruptsEnabled = - HcaEvtDeviceD0EntryPostInterruptsEnabled; - pnpPowerCallbacks.EvtDeviceD0ExitPreInterruptsDisabled = - HcaEvtDeviceD0ExitPreInterruptsDisabled; - - // - // This next group of five callbacks allow a driver to become involved in - // starting and stopping operations within a driver as the driver moves - // through various PnP/Power states. These functions are not necessary - // if the Framework is managing all the device's queues and there is no - // activity going on that isn't queue-based. This sample provides these - // callbacks because it uses watchdog timer to monitor whether the device - // is working or not and it needs to start and stop the timer when the - // device is started or removed. It cannot start and stop the timers in the - // D0Entry and D0Exit callbacks because if the device is surprise-removed, - // D0Exit will not be called. - // - pnpPowerCallbacks.EvtDeviceSelfManagedIoInit = - HcaEvtDeviceSelfManagedIoInit; - pnpPowerCallbacks.EvtDeviceSelfManagedIoCleanup = - HcaEvtDeviceSelfManagedIoCleanup; - pnpPowerCallbacks.EvtDeviceSelfManagedIoSuspend = - HcaEvtDeviceSelfManagedIoSuspend; - pnpPowerCallbacks.EvtDeviceSelfManagedIoRestart = - HcaEvtDeviceSelfManagedIoRestart; - - // - // Register the PnP and power callbacks. Power policy related callbacks will - // be registered later. - // - WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks); - - // - // Init the power policy callbacks - // - WDF_POWER_POLICY_EVENT_CALLBACKS_INIT(&powerPolicyCallbacks); - - // - // This group of three callbacks allows this sample driver to manage - // arming the device for wake from the S0 state. Networking devices can - // optionally be put into a low-power state when there is no networking - // cable plugged into them. This sample implements this feature. - // - powerPolicyCallbacks.EvtDeviceArmWakeFromS0 = HcaEvtDeviceWakeArmS0; - powerPolicyCallbacks.EvtDeviceDisarmWakeFromS0 = HcaEvtDeviceWakeDisarmS0; - powerPolicyCallbacks.EvtDeviceWakeFromS0Triggered = - HcaEvtDeviceWakeTriggeredS0; - - // - // This group of three callbacks allows the device to be armed for wake - // from Sx (S1, S2, S3 or S4.) Networking devices can optionally be put - // into a state where a packet sent to them will cause the device's wake - // signal to be triggered, which causes the machine to wake, moving back - // into the S0 state. - // - - powerPolicyCallbacks.EvtDeviceArmWakeFromSx = HcaEvtDeviceWakeArmSx; - powerPolicyCallbacks.EvtDeviceDisarmWakeFromSx = HcaEvtDeviceWakeDisarmSx; - powerPolicyCallbacks.EvtDeviceWakeFromSxTriggered = - HcaEvtDeviceWakeTriggeredSx; - - WdfDeviceInitSetDeviceType( DeviceInit, - FILE_DEVICE_INFINIBAND|FILE_DEVICE_SECURE_OPEN ); - - WdfDeviceInitSetExclusive(DeviceInit, TRUE); - // - // Register the power policy callbacks. - // - WdfDeviceInitSetPowerPolicyEventCallbacks(DeviceInit,&powerPolicyCallbacks); - - // Since we are the function driver, we are now the power policy owner - // for the device according to the default framework rule. We will register - // our power policy callbacks after finding the wakeup capability of the - // device. - - - // Specify the context type and size for the device we are about to create. - - WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&fdoAttributes, FDO_DATA); - - - // ContextCleanup will be called by the framework when it deletes the - // device. So you can defer freeing any resources allocated to Cleanup - // callback in the event AddDevice returns any error after the device is - // created. - - fdoAttributes.EvtCleanupCallback = HcaEvtDeviceContextCleanup; - - status = WdfDeviceCreate(&DeviceInit, &fdoAttributes, &device); - - if ( !NT_SUCCESS(status)) { - TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, - "WdfDeviceInitialize failed %!STATUS!\n", status); - return status; - } - - // - // Device creation is complete. - // Get the DeviceExtension and initialize it. - // - fdoData = FdoGetData(device); - fdoData->WdfDevice = device; - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "PDO(0x%p) FDO(0x%p), Lower(0x%p) DevExt (0x%p)\n", - WdfDeviceWdmGetPhysicalDevice (device), - WdfDeviceWdmGetDeviceObject (device), - WdfDeviceWdmGetAttachedDevice(device), - fdoData); - - DriverContext = GetDriverContext(Driver); - - status = hca_add_device( DriverContext->DrvObj, - WdfDeviceWdmGetPhysicalDevice(device), - WdfDeviceWdmGetAttachedDevice(device) ); - // - // Initialize the device extension and allocate all the software resources - // - status = HcaAllocSWResources(fdoData); - if (!NT_SUCCESS (status)){ - TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, - "HcaAllocSWResources failed: %!STATUS!\n", - status); - return status; - } - - // - // If we own the power policy and if our device supports wait-wake then we - // will set our power-policy and update S0-Idle policy. - // - if(IsPoMgmtSupported(fdoData) ) - { - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "Device has wait-wake capability\n"); - status = HcaSetPowerPolicy(fdoData); - if (!NT_SUCCESS (status)) { - TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, - "HcaSetPowerPolicy failed %!STATUS!\n", status); - return status; - } - } - - // - // Tell the Framework that this device will need an interface so that - // application can interact with it. - // - status = WdfDeviceCreateDeviceInterface( - device, - (LPGUID) &GUID_DEVINTERFACE_RDMA_IO, - NULL ); - - if (!NT_SUCCESS (status)) { - TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, - "WdfDeviceCreateDeviceInterface failed %!STATUS!\n",status); - return status; - } - - status = HcaWmiRegistration(device); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s \n",__FUNCTION__); - - return status; -} - -VOID -HcaEvtDeviceContextCleanup ( - WDFDEVICE Device - ) -/*++ - -Routine Description: - - EvtDeviceContextCleanup event callback cleans up anything done in - EvtDeviceAdd, except those things that are automatically cleaned - up by the Framework. - - In the case of this sample, everything is automatically handled. In a - driver derived from this sample, it's quite likely that this function could - be deleted. - -Arguments: - - Device - Handle to a framework device object. - -Return Value: - - VOID - ---*/ -{ - PFDO_DATA fdoData = NULL; - NTSTATUS status; - - PAGED_CODE(); - - fdoData = FdoGetData(Device); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "--> HcaEvtDeviceContextCleanup\n"); - - status = HcaFreeSWResources(fdoData); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "<-- HcaEvtDeviceContextCleanup\n"); - -} - - -/*++ - -Routine Description: - - EvtDeviceStart event callback performs operations that are necessary - to make the driver's device operational. The framework calls the driver's - EvtDeviceStart callback when the PnP manager sends an IRP_MN_START_DEVICE - request to the driver stack. - -Arguments: - - Device - Handle to a framework device object. - - Resources - Handle to a collection of framework resource objects. - This collection identifies the raw (bus-relative) hardware - resources that have been assigned to the device. - - ResourcesTranslated - Handle to a collection of framework resource objects. - This collection identifies the translated (system-physical) - hardware resources that have been assigned to the device. - The resources appear from the CPU's point of view. - Use this list of resources to map I/O space and - device-accessible memory into virtual address space - -Return Value: - - WDF status code - ---*/ - -NTSTATUS -HcaEvtDevicePrepareHardware ( - WDFDEVICE Device, - WDFCMRESLIST Resources, - WDFCMRESLIST ResourcesTranslated ) -{ - NTSTATUS status = STATUS_SUCCESS; - PFDO_DATA fdoData = NULL; - - UNREFERENCED_PARAMETER(Resources); - UNREFERENCED_PARAMETER(ResourcesTranslated); - - PAGED_CODE(); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "--> HcaEvtDevicePrepareHardware\n"); - - fdoData = FdoGetData(Device); - -#if 0 - status = NICMapHWResources(fdoData, ResourcesTranslated); - if (!NT_SUCCESS (status)){ - TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, - "NICMapHWResources failed: %!STATUS!\n", status); - return status; - } -#endif - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "<-- HcaEvtDevicePrepareHardware\n"); - - return status; - -} - - -/*++ - -Routine Description: - - EvtDeviceReleaseHardware is called by the framework whenever the PnP manager - is revoking ownership of our resources. This may be in response to either - IRP_MN_STOP_DEVICE or IRP_MN_REMOVE_DEVICE. The callback is made before - passing down the IRP to the lower driver. - - In this callback, do anything necessary to free those resources. - -Arguments: - - Device - Handle to a framework device object. - - ResourcesTranslated - Handle to a collection of framework resource objects. - This collection identifies the translated (system-physical) - hardware resources that have been assigned to the device. - The resources appear from the CPU's point of view. - Use this list of resources to map I/O space and - device-accessible memory into virtual address space - -Return Value: - - NTSTATUS - Failures will be logged, but not acted on. - ---*/ - -NTSTATUS -HcaEvtDeviceReleaseHardware( - IN WDFDEVICE Device, - IN WDFCMRESLIST ResourcesTranslated ) -{ - PFDO_DATA fdoData = NULL; - - UNREFERENCED_PARAMETER(ResourcesTranslated); - - PAGED_CODE(); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "--> HcaEvtDeviceReleaseHardware\n"); - - fdoData = FdoGetData(Device); - -#if 0 - // - // Unmap any I/O ports. Disconnecting from the interrupt will be done - // automatically by the framework. - // - NICUnmapHWResources(fdoData); -#endif - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "<-- HcaEvtDeviceReleaseHardware\n"); - - return STATUS_SUCCESS; -} - - -/*++ - -Routine Description: - - EvtDeviceD0Entry event callback must perform any operations that are - necessary before the specified device is used. It will be called every - time the hardware needs to be (re-)initialized. This includes after - IRP_MN_START_DEVICE, IRP_MN_CANCEL_STOP_DEVICE, IRP_MN_CANCEL_REMOVE_DEVICE, - IRP_MN_SET_POWER-D0. - - This function is not marked pageable because this function is in the - device power up path. When a function is marked pagable and the code - section is paged out, it will generate a page fault which could impact - the fast resume behavior because the client driver will have to wait - until the system drivers can service this page fault. - - This function runs at PASSIVE_LEVEL, even though it is not paged. A - driver can optionally make this function pageable if DO_POWER_PAGABLE - is set. Even if DO_POWER_PAGABLE isn't set, this function still runs - at PASSIVE_LEVEL. In this case, though, the function absolutely must - not do anything that will cause a page fault. - -Arguments: - - Device - Handle to a framework device object. - - PreviousState - Device power state which the device was in most recently. - If the device is being newly started, this will be - PowerDeviceUnspecified. - -Return Value: - - NTSTATUS - ---*/ - -NTSTATUS -HcaEvtDeviceD0Entry( - IN WDFDEVICE Device, - IN WDF_POWER_DEVICE_STATE PreviousState ) -{ - PFDO_DATA fdoData; - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_POWER, - "-->HcaEvtDeviceD0Entry - coming from %s\n", - DbgDevicePowerString(PreviousState)); - - fdoData = FdoGetData(Device); - - ASSERT(PowerDeviceD0 != PreviousState); - - fdoData->DevicePowerState = PowerDeviceD0; - - if(IsPoMgmtSupported(fdoData)){ - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_POWER, - "Entering fully on state\n"); -#ifdef XXX - MPSetPowerD0 (fdoData); -#endif - } - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_POWER, "<--HcaEvtDeviceD0Entry\n"); - - return STATUS_SUCCESS; -} - - -NTSTATUS -HcaEvtDeviceD0Exit( - IN WDFDEVICE Device, - IN WDF_POWER_DEVICE_STATE TargetState - ) -/*++ - -Routine Description: - - This routine undoes anything done in EvtDeviceD0Entry. It is called - whenever the device leaves the D0 state, which happens when the device is - stopped, when it is removed, and when it is powered off. - - The device is still in D0 when this callback is invoked, which means that - the driver can still touch hardware in this routine. - - Note that interrupts have already been disabled by the time that this - callback is invoked. - - EvtDeviceD0Exit event callback must perform any operations that are - necessary before the specified device is moved out of the D0 state. If the - driver needs to save hardware state before the device is powered down, then - that should be done here. - - This function runs at PASSIVE_LEVEL, though it is generally not paged. A - driver can optionally make this function pageable if DO_POWER_PAGABLE is set. - - Even if DO_POWER_PAGABLE isn't set, this function still runs at - PASSIVE_LEVEL. In this case, though, the function absolutely must not do - anything that will cause a page fault. - -Arguments: - - Device - Handle to a framework device object. - - TargetState - Device power state which the device will be put in once this - callback is complete. - -Return Value: - - Success implies that the device can be used. Failure will result in the - device stack being torn down. - ---*/ -{ - PFDO_DATA fdoData; - - UNREFERENCED_PARAMETER(Device); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_POWER, - "-->HcaEvtDeviceD0Exit - moving to %s\n", - DbgDevicePowerString(TargetState)); - - fdoData = FdoGetData(Device); - - fdoData->DevicePowerState = TargetState; - - switch (TargetState) { - case WdfPowerDeviceD1: - case WdfPowerDeviceD2: - case WdfPowerDeviceD3: - - if(IsPoMgmtSupported(fdoData)){ - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_POWER, - "Entering a deeper sleep state\n"); -#ifdef XXX - MPSetPowerLow (fdoData, TargetState); -#endif - } - break; - - case WdfPowerDevicePrepareForHibernation: - - // - // Fill in any code to save hardware state here. Do not put in any - // code to shut the device off. If this device cannot support being - // in the paging path (or being a parent or grandparent of a paging - // path device) then this whole case can be deleted. - // - ASSERT(FALSE); // This driver shouldn't get this. - break; - - case WdfPowerDeviceD3Final: - // - // Reset and put the device into a known initial state we're shutting - // down for the last time. - // -#if 0 - NICShutdown(fdoData); -#endif - break; - - default: - break; - } - - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_POWER, "<--HcaEvtDeviceD0Exit\n"); - - return STATUS_SUCCESS; -} - - -/*++ - -Routine Description: - - HcaEvtDeviceSelfManagedIoInit is called by the Framework when the device - enters the D0 state. Its job is to start any I/O-related actions that the - Framework isn't managing. This might include releasing queues that are not - power-managed, that is, the Framework is not automatically holding and - releasing them across PnP/Power transitions. (The default behavior for - WDFQUEUE is auto-managed, so most queues don't need to be dealt with here.) - This might also include setting up non-queue-based actions. - - If you allow the Framework to manage most or all of your queues, then when - you build a driver from this sample, you can probably delete this function. - - In this driver, the SelfManagedIo callbacks are used to implement a - watchdog timer. - - This function is not marked pagable because this function is in the - device power up path. When a function is marked pagable and the code - section is paged out, it will generate a page fault which could impact - the fast resume behavior because the client driver will have to wait - until the system drivers can service this page fault. - -Arguments: - - Device - Handle to a framework device object. - -Return Value: - - NTSTATUS - Failures will result in the device stack being torn down. - ---*/ - -NTSTATUS -HcaEvtDeviceSelfManagedIoInit( IN WDFDEVICE Device ) -{ - PFDO_DATA fdoData = NULL; - NTSTATUS status=STATUS_SUCCESS; -// WDF_TIMER_CONFIG wdfTimerConfig; -// WDF_OBJECT_ATTRIBUTES timerAttributes; - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s()\n", __FUNCTION__); - - fdoData = FdoGetData(Device); - -#if 0 - // To minimize init-time, create a timer DPC to do link detection. - // This DPC will also be used to check for hardware hang. - // - WDF_TIMER_CONFIG_INIT(&wdfTimerConfig, NICWatchDogEvtTimerFunc); - - WDF_OBJECT_ATTRIBUTES_INIT(&timerAttributes); - timerAttributes.ParentObject = fdoData->WdfDevice; - - status = WdfTimerCreate( - &wdfTimerConfig, - &timerAttributes, - &fdoData->WatchDogTimer - ); - - if(!NT_SUCCESS(status) ) { - TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, - "Error: WdfTimerCreate create failed 0x%x\n", status); - return status; - } - - NICStartWatchDogTimer(fdoData); -#endif - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "<-- %s() ret %x\n", __FUNCTION__, status); - - return status; -} - - -/*++ - -Routine Description: - - EvtDeviceSelfManagedIoSuspend is called by the Framework before the device - leaves the D0 state. Its job is to stop any I/O-related actions that the - Framework isn't managing, and which cannot be handled when the device - hardware isn't available. In general, this means reversing anything that - was done in EvtDeviceSelfManagedIoStart. - - If you allow the Framework to manage most or all of your queues, then when - you build a driver from this sample, you can probably delete this function. - -Arguments: - - Device - Handle to a framework device object. - -Return Value: - - NTSTATUS - Failures will result in the device stack being torn down. - ---*/ - -NTSTATUS -HcaEvtDeviceSelfManagedIoSuspend( IN WDFDEVICE Device ) -{ - PFDO_DATA fdoData = NULL; - - PAGED_CODE(); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "--> HcaEvtDeviceSelfManagedIoSuspend\n"); - - fdoData = FdoGetData(Device); - -#if 0 - // - // Stop the watchdog timer and wait for DPC to run to completion if - // it's already fired. - // - WdfTimerStop(fdoData->WatchDogTimer, TRUE); -#endif - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "<-- HcaEvtDeviceSelfManagedIoSuspend\n"); - - return STATUS_SUCCESS; -} - -NTSTATUS -HcaEvtDeviceSelfManagedIoRestart( - IN WDFDEVICE Device - ) -/*++ - -Routine Description: - - EvtDeviceSelfManagedIoRestart is called by the Framework before the device - is restarted for one of the following reasons: - a) the PnP resources were rebalanced (framework received - query-stop and stop IRPS ) - b) the device resumed from a low power state to D0. - - This function is not marked pagable because this function is in the - device power up path. When a function is marked pagable and the code - section is paged out, it will generate a page fault which could impact - the fast resume behavior because the client driver will have to wait - until the system drivers can service this page fault. - -Arguments: - - Device - Handle to a framework device object. - -Return Value: - - NTSTATUS - Failure will cause the device stack to be torn down. - ---*/ -{ - PFDO_DATA fdoData; - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "--> HcaEvtDeviceSelfManagedIoRestart\n"); - - fdoData = FdoGetData(Device); - - // - // Restart the watchdog timer. - // -#if 0 - NICStartWatchDogTimer(fdoData); -#endif - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "<-- HcaEvtDeviceSelfManagedIoRestart\n"); - - return STATUS_SUCCESS; -} - - -/*++ - -Routine Description: - - EvtDeviceSelfManagedIoCleanup is called by the Framework when the device is - being torn down, either in response to the WDM IRP_MN_REMOVE_DEVICE - It will be called only once. Its job is to stop all outstanding I/O in the driver - that the Framework is not managing. - -Arguments: - - Device - Handle to a framework device object. - -Return Value: - - None - ---*/ - -VOID -HcaEvtDeviceSelfManagedIoCleanup( IN WDFDEVICE Device ) -{ - PFDO_DATA fdoData = NULL; - - PAGED_CODE(); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "--> HcaEvtDeviceSelfManagedIoCleanup\n"); - - fdoData = FdoGetData(Device); - -#if 0 - if(fdoData->WatchDogTimer) { - WdfObjectDelete(fdoData->WatchDogTimer); - } -#endif - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "<-- HcaEvtDeviceSelfManagedIoCleanup\n"); -} - - -/*++ - -Routine Description: - - This event is called when the framework receives IRP_MJ_DEVICE_CONTROL - requests from the system. - -Arguments: - - Queue - Handle to the framework queue object that is associated - with the I/O request. - Request - Handle to a framework request object. - - OutputBufferLength - length of the request's output buffer, - if an output buffer is available. - InputBufferLength - length of the request's input buffer, - if an input buffer is available. - - IoControlCode - the driver-defined or system-defined I/O control code - (IOCTL) that is associated with the request. -Return Value: - - VOID - ---*/ - -VOID -HcaEvtIoDeviceControl( - IN WDFQUEUE Queue, - IN WDFREQUEST Request, - IN size_t OutputBufferLength, - IN size_t InputBufferLength, - IN ULONG IoControlCode ) -{ - //NTSTATUS status= STATUS_SUCCESS; - PFDO_DATA fdoData = NULL; - WDFDEVICE hDevice; - WDF_REQUEST_PARAMETERS params; - - UNREFERENCED_PARAMETER(OutputBufferLength); - UNREFERENCED_PARAMETER(InputBufferLength); - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_IOCTLS, - "HcaEvtIoDeviceControl called %p\n", Request); - - hDevice = WdfIoQueueGetDevice(Queue); - fdoData = FdoGetData(hDevice); - - WDF_REQUEST_PARAMETERS_INIT(¶ms); - - WdfRequestGetParameters( - Request, - ¶ms - ); - - switch (IoControlCode) - { -#if 0 - case IOCTL_NDISPROT_QUERY_OID_VALUE: - - ASSERT((IoControlCode & 0x3) == METHOD_BUFFERED); - - NICHandleQueryOidRequest( - Queue, - Request, - ¶ms - ); - break; - - case IOCTL_NDISPROT_SET_OID_VALUE: - - ASSERT((IoControlCode & 0x3) == METHOD_BUFFERED); - - NICHandleSetOidRequest( - Queue, - Request, - ¶ms - ); - - break; - - case IOCTL_NDISPROT_INDICATE_STATUS: - - status = WdfRequestForwardToIoQueue(Request, - fdoData->PendingIoctlQueue); - if(!NT_SUCCESS(status)){ - TraceEvents(TRACE_LEVEL_ERROR, DBG_IOCTLS, - "WdfRequestForwardToIoQueue failed 0x%x\n", status); - WdfRequestComplete(Request, status); - break; - } - - break; -#endif - default: - ASSERTMSG(FALSE, "Invalid IOCTL request\n"); - WdfRequestComplete(Request, STATUS_INVALID_DEVICE_REQUEST); - break; - } -} - - -/*++ - -Routine Description: - - EvtDeviceWakeArmS0 is called when the Framework arms the device for - wake in the S0 state. If there is any device-specific initialization - that needs to be done to arm internal wake signals, or to route internal - interrupt signals to the wake logic, it should be done here. The device - will be moved out of the D0 state soon after this callback is invoked. - - In this sample, wake from S0 involves waking on packet arrival, as does - wake from Sx. A more common NIC implementation might wake on cable - insertion. - - This function is pageable and it will run at PASSIVE_LEVEL. - -Arguments: - - Device - Handle to a Framework device object. - -Return Value: - - NTSTATUS - Failure will result in the device remaining in the D0 state. - ---*/ - -NTSTATUS -HcaEvtDeviceWakeArmS0( IN WDFDEVICE Device ) -{ - NTSTATUS status=STATUS_SUCCESS; - PFDO_DATA fdoData; - - PAGED_CODE(); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s()\n", __FUNCTION__); - - fdoData = FdoGetData(Device); - - // - // Add pattern before sending wait-wake - // -#if 0 - status = NICConfigureForWakeUp(fdoData, TRUE); -#endif - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "<-- %s() %x\n", __FUNCTION__, status); - - return status; -} - - -/*++ - -Routine Description: - - EvtDeviceWakeArmSx is called when the Framework arms the device for - wake from the S1, S2, S3 or S4 states. If there is any device-specific - initialization that needs to be done to arm internal wake signals, or to - route internal interrupt signals to the wake logic, it should be done here. - The device will be moved out of the D0 state soon after this callback is - invoked. - - In this sample, wake from Sx involves arming for wake on packet arrival. - Cable insertion should not be enabled, as nobody would want their machine - to wake up simply because they plugged the cable in. - - This function runs at PASSIVE_LEVEL. Whether it is pageable or not depends - on whether the device has set DO_POWER_PAGABLE. - -Arguments: - - Device - Handle to a Framework device object. - -Return Value: - - NTSTATUS - Failure will result in the device not being armed for wake - while the system is in Sx. - ---*/ - -NTSTATUS -HcaEvtDeviceWakeArmSx( IN WDFDEVICE Device ) -{ - NTSTATUS status=STATUS_SUCCESS; - PFDO_DATA fdoData; - - PAGED_CODE(); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s()\n", __FUNCTION__); - - fdoData = FdoGetData(Device); - // - // Add pattern before sending wait-wake - // -#if 0 - status = NICConfigureForWakeUp(fdoData, TRUE); -#endif - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "<-- %s() ret %x\n", __FUNCTION__, status); - - return status; -} - - -/*++ - -Routine Description: - - EvtDeviceWakeDisarmS0 reverses anything done in EvtDeviceWakeArmS0. - - This function is pageable and it will run at PASSIVE_LEVEL. - -Arguments: - - Device - Handle to a Framework device object. - -Return Value: - - VOID. - ---*/ - -VOID -HcaEvtDeviceWakeDisarmS0( IN WDFDEVICE Device ) -{ - NTSTATUS status=STATUS_SUCCESS; - PFDO_DATA fdoData; - - PAGED_CODE(); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s\n", __FUNCTION__); - - fdoData = FdoGetData(Device); -#if 0 - status = NICConfigureForWakeUp(fdoData, FALSE); -#endif - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "<-- %s %x\n", __FUNCTION__, status); -} - - -/*++ - -Routine Description: - - EvtDeviceWakeDisarmSx reverses anything done in EvtDeviceWakeArmSx. - - This function is not marked pageable because this function is in the - device power up path. When a function is marked pagable and the code - section is paged out, it will generate a page fault which could impact - the fast resume behavior because the client driver will have to wait - until the system drivers can service this page fault. - - This function runs at PASSIVE_LEVEL, even though it is not paged. A - driver can optionally make this function pageable if DO_POWER_PAGABLE - is set. Even if DO_POWER_PAGABLE isn't set, this function still runs - at PASSIVE_LEVEL. In this case, though, the function absolutely must - not do anything that will cause a page fault. - -Arguments: - - Device - Handle to a Framework device object. - -Return Value: - - VOID - ---*/ - -VOID -HcaEvtDeviceWakeDisarmSx( IN WDFDEVICE Device ) -{ - NTSTATUS status=STATUS_SUCCESS; - PFDO_DATA fdoData; - - UNREFERENCED_PARAMETER(Device); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s\n", __FUNCTION__); - - fdoData = FdoGetData(Device); -#if 0 - status = NICConfigureForWakeUp(fdoData, FALSE); -#endif - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, - "<-- %s %x\n", __FUNCTION__, status); -} - - -/*++ - -Routine Description: - - EvtDeviceWakeTriggeredS0 will be called whenever the device triggers its - wake signal after being armed for wake from S0. - - This function is pageable and runs at PASSIVE_LEVEL. - -Arguments: - - Device - Handle to a Framework device object. - -Return Value: - - VOID - ---*/ - -VOID -HcaEvtDeviceWakeTriggeredS0( IN WDFDEVICE Device ) -{ - UNREFERENCED_PARAMETER(Device); - - PAGED_CODE(); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s\n", __FUNCTION__); - - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s\n", __FUNCTION__); -} - - -/*++ - -Routine Description: - - EvtDeviceWakeTriggeredSx will be called whenever the device triggers its - wake signal after being armed for wake from Sx. - - This function is not marked pageable because this function is in the - device power up path. When a function is marked pagable and the code - section is paged out, it will generate a page fault which could impact - the fast resume behavior because the client driver will have to wait - until the system drivers can service this page fault. - - This function runs at PASSIVE_LEVEL, even though it is not paged. A - driver can optionally make this function pageable if DO_POWER_PAGABLE - is set. Even if DO_POWER_PAGABLE isn't set, this function still runs - at PASSIVE_LEVEL. In this case, though, the function absolutely must - not do anything that will cause a page fault. - -Arguments: - - Device - Handle to a Framework device object. - -Return Value: - - VOID - ---*/ - -VOID -HcaEvtDeviceWakeTriggeredSx( IN WDFDEVICE Device ) -{ - UNREFERENCED_PARAMETER(Device); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s", __FUNCTION__); - - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s", __FUNCTION__); - - return; -} - - -/*++ - -Routine Description: - - This routine is used to queue workitems so that the callback - functions can be executed at PASSIVE_LEVEL in the conext of - a system thread. - -Arguments: - - FdoData - pointer to a device extenion. - - CallbackFunction - Function to invoke when at PASSIVE_LEVEL. - - Context1 & 2 - Meaning of the context values depends on the - callback function. - -Return Value: - ---*/ - -NTSTATUS -HcaQueuePassiveLevelCallback( - IN PFDO_DATA FdoData, - IN PFN_WDF_WORKITEM CallbackFunction, - IN PVOID Context1, - IN PVOID Context2 ) -{ - NTSTATUS status = STATUS_SUCCESS; - PWORKER_ITEM_CONTEXT context; - WDF_OBJECT_ATTRIBUTES attributes; - WDF_WORKITEM_CONFIG workitemConfig; - WDFWORKITEM hWorkItem; - - WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, WORKER_ITEM_CONTEXT); - - attributes.ParentObject = FdoData->WdfDevice; - - WDF_WORKITEM_CONFIG_INIT(&workitemConfig, CallbackFunction); - - status = WdfWorkItemCreate( &workitemConfig, - &attributes, - &hWorkItem); - - if (!NT_SUCCESS(status)) { - return status; - } - - context = GetWorkItemContext(hWorkItem); - - context->FdoData = FdoData; - context->Argument1 = Context1; - context->Argument2 = Context2; - - // - // Execute this work item. - // - WdfWorkItemEnqueue(hWorkItem); - - return STATUS_SUCCESS; -} - - -/*++ - -Routine Description: - - Can be used to read any REG_DWORD registry value stored - under Device Parameter. - -Arguments: - - FdoData - pointer to the device extension - Name - Name of the registry value - Value - - - -Return Value: - - TRUE if successful - FALSE if not present/error in reading registry - ---*/ - -BOOLEAN -HcaReadRegistryValue( - __in PFDO_DATA FdoData, - __in PWCHAR Name, - __out PULONG Value ) -{ - WDFKEY hKey = NULL; - NTSTATUS status; - BOOLEAN retValue = FALSE; - UNICODE_STRING valueName; - - PAGED_CODE(); - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_INIT, "--> %s()\n", __FUNCTION__); - - *Value = 0; - - status = WdfDeviceOpenRegistryKey(FdoData->WdfDevice, - PLUGPLAY_REGKEY_DEVICE, - STANDARD_RIGHTS_ALL, - WDF_NO_OBJECT_ATTRIBUTES, - &hKey); - - if (NT_SUCCESS (status)) { - - RtlInitUnicodeString(&valueName,Name); - - status = WdfRegistryQueryULong( hKey, - &valueName, - Value ); - - if (NT_SUCCESS (status)) { - retValue = TRUE; - } - - WdfRegistryClose(hKey); - } - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_INIT, - "<-- %s() %ws %d \n", __FUNCTION__, Name, *Value); - - return retValue; -} - - -/*++ - -Routine Description: - - Can be used to write any REG_DWORD registry value stored - under Device Parameter. - -Arguments: - - -Return Value: - - TRUE - if write is successful - FALSE - otherwise - ---*/ - -BOOLEAN -HcaWriteRegistryValue( - __in PFDO_DATA FdoData, - __in PWCHAR Name, - __in ULONG Value ) -{ - WDFKEY hKey = NULL; - NTSTATUS status; - BOOLEAN retValue = FALSE; - UNICODE_STRING valueName; - - - PAGED_CODE(); - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_INIT, "--> %s()\n", __FUNCTION__); - - // - // write the value out to the registry - // - status = WdfDeviceOpenRegistryKey(FdoData->WdfDevice, - PLUGPLAY_REGKEY_DEVICE, - STANDARD_RIGHTS_ALL, - WDF_NO_OBJECT_ATTRIBUTES, - &hKey); - - if (NT_SUCCESS (status)) { - - RtlInitUnicodeString(&valueName,Name); - - status = WdfRegistryAssignULong (hKey, - &valueName, - Value ); - - if (NT_SUCCESS (status)) { - retValue = TRUE; - } - - WdfRegistryClose(hKey); - } - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_INIT, - "<-- ret %s() %s\n", __FUNCTION__, (retValue ? "True":"False")); - - return retValue; -} - - -/*++ - -Routine Description: - - Can be used to read any REG_DWORD registry value stored - under Device Parameter. - -Arguments: - - FdoData - pointer to the device extension - Name - Name of the registry value - Value - - - -Return Value: - - TRUE if successful - FALSE if not present/error in reading registry - ---*/ - -BOOLEAN -HcaReadFdoRegistryKeyValue( - __in PWDFDEVICE_INIT DeviceInit, - __in PWCHAR Name, - __out PULONG Value ) -{ - WDFKEY hKey = NULL; - NTSTATUS status; - BOOLEAN retValue = FALSE; - UNICODE_STRING valueName; - - PAGED_CODE(); - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, "--> %s()\n", __FUNCTION__); - - *Value = 0; - - status = WdfFdoInitOpenRegistryKey(DeviceInit, - PLUGPLAY_REGKEY_DEVICE, - STANDARD_RIGHTS_ALL, - WDF_NO_OBJECT_ATTRIBUTES, - &hKey); - - if (NT_SUCCESS (status)) { - - RtlInitUnicodeString(&valueName,Name); - - status = WdfRegistryQueryULong (hKey, - &valueName, - Value); - - if (NT_SUCCESS (status)) { - retValue = TRUE; - } - - WdfRegistryClose(hKey); - } - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, - "<-- %s() %ws %d \n", __FUNCTION__, Name, *Value); - - return retValue; -} - - -/*++ -Routine Description: - - Free all the resources allocated in DriverEntry. - -Arguments: - - Driver - handle to a WDF Driver object. - -Return Value: - - VOID. - ---*/ - -VOID -HcaEvtDriverContextCleanup( IN WDFDRIVER Driver ) -{ - UNREFERENCED_PARAMETER( Driver ); - - PAGED_CODE (); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "--> %s()\n",__FUNCTION__); - - // Stop WPP Tracing - // - WPP_CLEANUP( WdfDriverWdmGetDriverObject( Driver ) ); - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT, "<-- %s()\n",__FUNCTION__); -} - - -NTSTATUS -HcaSetPowerPolicy( - IN PFDO_DATA FdoData - ) -{ - WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS idleSettings; - WDF_DEVICE_POWER_POLICY_WAKE_SETTINGS wakeSettings; - NTSTATUS status = STATUS_SUCCESS; - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s()\n", __FUNCTION__); - - PAGED_CODE(); - - // - // Init the idle policy structure. - // - WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT(&idleSettings, IdleCanWakeFromS0); - idleSettings.IdleTimeout = 10000; // 10-sec - - status = WdfDeviceAssignS0IdleSettings(FdoData->WdfDevice, &idleSettings); - if ( !NT_SUCCESS(status)) { - TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, - "WdfDeviceSetPowerPolicyS0IdlePolicy failed %x\n", status); - return status; - } - - // - // Init wait-wake policy structure. - // - WDF_DEVICE_POWER_POLICY_WAKE_SETTINGS_INIT(&wakeSettings); - - status = WdfDeviceAssignSxWakeSettings(FdoData->WdfDevice, &wakeSettings); - if (!NT_SUCCESS(status)) { - TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, - "WdfDeviceAssignSxWakeSettings failed %x\n", status); - return status; - } - - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s()\n", __FUNCTION__); - - return status; -} - - -/*++ - -Updated Routine Description: - DbgDevicePowerString does not change in this stage of the function driver. - ---*/ - -PCHAR -DbgDevicePowerString( IN WDF_POWER_DEVICE_STATE Type ) -{ - switch (Type) - { - case WdfPowerDeviceInvalid: - return "WdfPowerDeviceInvalid"; - case WdfPowerDeviceD0: - return "WdfPowerDeviceD0"; - case PowerDeviceD1: - return "WdfPowerDeviceD1"; - case WdfPowerDeviceD2: - return "WdfPowerDeviceD2"; - case WdfPowerDeviceD3: - return "WdfPowerDeviceD3"; - case WdfPowerDeviceD3Final: - return "WdfPowerDeviceD3Final"; - case WdfPowerDevicePrepareForHibernation: - return "WdfPowerDevicePrepareForHibernation"; - case WdfPowerDeviceMaximum: - return "PowerDeviceMaximum"; - default: - return "UnKnown Device Power State"; - } -} - - -#if !defined(EVENT_TRACING) - - -/*++ - -Routine Description: - - Debug print for the sample driver. - -Arguments: - - TraceEventsLevel - print level between 0 and 3, with 3 the most verbose - -Return Value: - - None. - - --*/ - -VOID -TraceEvents ( - IN ULONG TraceEventsLevel, - IN ULONG TraceEventsFlag, - IN PCCHAR DebugMessage, - ... ) - { -#if 1 // always for starters... DBG - -#define TEMP_BUFFER_SIZE 512 - va_list list; - CHAR debugMessageBuffer[TEMP_BUFFER_SIZE]; - NTSTATUS status; - - va_start(list, DebugMessage); - - if (DebugMessage) { - - // - // Using new safe string functions instead of _vsnprintf. - // This function takes care of NULL terminating if the message - // is longer than the buffer. - // - status = RtlStringCbVPrintfA( debugMessageBuffer, - sizeof(debugMessageBuffer), - DebugMessage, - list ); - if(!NT_SUCCESS(status)) { - - DbgPrint (_DRIVER_NAME_": RtlStringCbVPrintfA failed %x\n", - status); - return; - } - if (TraceEventsLevel <= TRACE_LEVEL_INFORMATION || - (TraceEventsLevel <= g_mthca_dbg_level && - ((TraceEventsFlag & g_mthca_dbg_flags) == TraceEventsFlag))) { - DbgPrint(debugMessageBuffer); - } - } - va_end(list); - - return; -#else - UNREFERENCED_PARAMETER(TraceEventsLevel); - UNREFERENCED_PARAMETER(TraceEventsFlag); - UNREFERENCED_PARAMETER(DebugMessage); -#endif -} - -#endif - - -/*++ - -Routine Description: - - This event is called so that driver can do PASSIVE_LEVEL work before - the interrupt is disconnected and disabled. - -Arguments: - - Interrupt - Handle to a Framework interrupt object. - - AssociatedDevice - Handle to a Framework device object. - -Return Value: - - STATUS_SUCCESS - indicates success. - ---*/ - -NTSTATUS -HcaEvtDeviceD0ExitPreInterruptsDisabled( - IN WDFDEVICE Device, - IN WDF_POWER_DEVICE_STATE TargetState ) -{ - PFDO_DATA fdoData; - - UNREFERENCED_PARAMETER(TargetState); - - PAGED_CODE(); - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, "--> %s()\n", __FUNCTION__); - - fdoData = FdoGetData(Device); - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, "<-- %s()\n", __FUNCTION__); - - return STATUS_SUCCESS; - -} - - -/*++ - -Routine Description: - - This event is called so that driver can do PASSIVE_LEVEL work after - the interrupt is connected and enabled. Here we start the watchdog timer. - Watch dog timer is used to do the initial link detection during - start and then used to make sure the device is not stuck for any reason. - - This function is not marked pageable because this function is in the - device power up path. When a function is marked pagable and the code - section is paged out, it will generate a page fault which could impact - the fast resume behavior because the client driver will have to wait - until the system drivers can service this page fault. - -Arguments: - - Interrupt - Handle to a Framework interrupt object. - - AssociatedDevice - Handle to a Framework device object. - -Return Value: - - STATUS_SUCCESS - indicates success. - ---*/ - -NTSTATUS -HcaEvtDeviceD0EntryPostInterruptsEnabled( - IN WDFDEVICE Device, - IN WDF_POWER_DEVICE_STATE PreviousState ) -{ - PFDO_DATA fdoData; - - UNREFERENCED_PARAMETER( PreviousState ); - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, "--> %s()\n", __FUNCTION__); - - fdoData = FdoGetData(Device); - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, "<-- %s()\n", __FUNCTION__); - - return STATUS_SUCCESS; - -} - -NTSTATUS -HcaAllocSWResources(PFDO_DATA fdoData) -{ - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, - "--> %s() fdoData %p\n", __FUNCTION__, fdoData); - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, "<-- %s()\n", __FUNCTION__); - - return STATUS_SUCCESS; -} - -NTSTATUS -HcaFreeSWResources(PFDO_DATA fdoData) -{ - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, - "--> %s() fdoData %p\n", __FUNCTION__, fdoData); - - TraceEvents(TRACE_LEVEL_VERBOSE, DBG_PNP, "<-- %s()\n", __FUNCTION__); - - return STATUS_SUCCESS; -} - diff --git a/branches/IBFD/hw/mthca/kmdf/pcidrv.h b/branches/IBFD/hw/mthca/kmdf/pcidrv.h deleted file mode 100644 index 55893f3c..00000000 --- a/branches/IBFD/hw/mthca/kmdf/pcidrv.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2008 Intel Corporation. All rights reserved. - * Copyright (c) 2005 SilverStorm Technologies. All rights reserved. - * - * This software is available to you under the OpenIB.org BSD license - * below: - * - * 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. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * $Id$ - */ - -#ifndef _PCIDRV_H_ -#define _PCIDRV_H_ - -// -// PciDrv/KMDF Function prototypes -// - -EVT_WDF_DRIVER_DEVICE_ADD HcaEvtDeviceAdd; - -EVT_WDF_OBJECT_CONTEXT_CLEANUP HcaEvtDriverContextCleanup; -EVT_WDF_DEVICE_CONTEXT_CLEANUP HcaEvtDeviceContextCleanup; - -EVT_WDF_DEVICE_D0_ENTRY HcaEvtDeviceD0Entry; -EVT_WDF_DEVICE_D0_EXIT HcaEvtDeviceD0Exit; -EVT_WDF_DEVICE_PREPARE_HARDWARE HcaEvtDevicePrepareHardware; -EVT_WDF_DEVICE_RELEASE_HARDWARE HcaEvtDeviceReleaseHardware; - -EVT_WDF_DEVICE_SELF_MANAGED_IO_CLEANUP HcaEvtDeviceSelfManagedIoCleanup; -EVT_WDF_DEVICE_SELF_MANAGED_IO_INIT HcaEvtDeviceSelfManagedIoInit; -EVT_WDF_DEVICE_SELF_MANAGED_IO_SUSPEND HcaEvtDeviceSelfManagedIoSuspend; -EVT_WDF_DEVICE_SELF_MANAGED_IO_RESTART HcaEvtDeviceSelfManagedIoRestart; - -EVT_WDF_DEVICE_SURPRISE_REMOVAL HcaEvtDeviceSurpriseRemoval; - -EVT_WDF_DEVICE_ARM_WAKE_FROM_S0 HcaEvtDeviceWakeArmS0; -EVT_WDF_DEVICE_ARM_WAKE_FROM_SX HcaEvtDeviceWakeArmSx; -EVT_WDF_DEVICE_DISARM_WAKE_FROM_S0 HcaEvtDeviceWakeDisarmS0; -EVT_WDF_DEVICE_DISARM_WAKE_FROM_SX HcaEvtDeviceWakeDisarmSx; -EVT_WDF_DEVICE_WAKE_FROM_S0_TRIGGERED HcaEvtDeviceWakeTriggeredS0; -EVT_WDF_DEVICE_WAKE_FROM_SX_TRIGGERED HcaEvtDeviceWakeTriggeredSx; -EVT_WDF_DEVICE_D0_ENTRY_POST_INTERRUPTS_ENABLED HcaEvtDeviceD0EntryPostInterruptsEnabled; -EVT_WDF_DEVICE_D0_EXIT_PRE_INTERRUPTS_DISABLED HcaEvtDeviceD0ExitPreInterruptsDisabled; - -EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL HcaEvtIoDeviceControl; - -NTSTATUS -HcaReturnResources ( - IN OUT PFDO_DATA FdoData - ); - -NTSTATUS -HcaSetPowerPolicy( - IN PFDO_DATA FdoData - ); - -NTSTATUS -HcaQueuePassiveLevelCallback( - IN PFDO_DATA FdoData, - IN PFN_WDF_WORKITEM CallbackFunction, - IN PVOID Context1, - IN PVOID Context2 - ); - -BOOLEAN -HcaReadRegistryValue( - __in PFDO_DATA FdoData, - __in PWCHAR Name, - __out PULONG Value - ); - -BOOLEAN -HcaWriteRegistryValue( - __in PFDO_DATA FdoData, - __in PWCHAR Name, - __in ULONG Value - ); - - -NTSTATUS -HcaWmiRegistration( - WDFDEVICE hDevice -); - -PCHAR -DbgDevicePowerString( - IN WDF_POWER_DEVICE_STATE Type - ); - - -BOOLEAN -HcaReadFdoRegistryKeyValue( - __in PWDFDEVICE_INIT DeviceInit, - __in PWCHAR Name, - __out PULONG Value - ); - - -#endif // _PCIDRV_H_ -- 2.41.0