[MLX4] MLX4_HCA is returned to its original WDF form. [mlnx: 4103]
authorleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Sun, 29 Mar 2009 15:31:57 +0000 (15:31 +0000)
committerleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Sun, 29 Mar 2009 15:31:57 +0000 (15:31 +0000)
The old WDM version is kept for now under a preprocessor flag.

git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2063 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

hw/mlx4/kernel/hca/SOURCES
hw/mlx4/kernel/hca/drv.c
hw/mlx4/kernel/hca/drv.h
hw/mlx4/kernel/hca/mlx4_hca.inx

index 4a25791..cb3caf7 100644 (file)
@@ -42,7 +42,8 @@ NTTARGETFILE0=mofcomp
 \r
 KMDF_VERSION=1\r
 \r
-C_DEFINES=$(C_DEFINES) -DDRIVER -DDEPRECATE_DDK_FUNCTIONS -D__LITTLE_ENDIAN -DUSE_WDM_FRAMEWORK -DUSE_WDM_INTERRUPTS\r
+C_DEFINES=$(C_DEFINES) -DDRIVER -DDEPRECATE_DDK_FUNCTIONS -D__LITTLE_ENDIAN \r
+#-DUSE_WDM_FRAMEWORK \r
 \r
 TARGETLIBS= \\r
        $(TARGETPATH)\*\complib.lib     \\r
index baf318c..cb4d757 100644 (file)
@@ -42,9 +42,6 @@
 #include "drv.tmh"\r
 #endif \r
 \r
-#define DRV_VERSION    "1.0"\r
-#define DRV_RELDATE    "02/01/2008"\r
-\r
 GLOBALS g;\r
 \r
 /*\r
@@ -53,16 +50,6 @@ GLOBALS g;
  */\r
 char                   mlnx_uvp_lib_name[MAX_LIB_NAME] = {"mlx4u"};\r
 \r
-\r
-static void\r
-__put_ifc(\r
-               IN      PINTERFACE              p_ifc )\r
-{\r
-       HCA_ENTER( HCA_DBG_PNP );\r
-       p_ifc->InterfaceDereference( p_ifc->Context );\r
-       HCA_EXIT( HCA_DBG_PNP );\r
-}\r
-\r
 static int __get_dev_info(PFDO_DEVICE_DATA p_fdo, __be64 *node_guid, u32 *hw_id)\r
 {\r
        struct ib_device_attr device_attr;\r
@@ -94,173 +81,6 @@ static int __get_dev_info(PFDO_DEVICE_DATA p_fdo, __be64 *node_guid, u32 *hw_id)
 //\r
 \r
 \r
-static NTSTATUS\r
-__get_ci_interface(\r
-       IN                                      PFDO_DEVICE_DATA                                p_fdo )\r
-{\r
-       NTSTATUS                        status;\r
-       IRP                                     *p_irp;\r
-       IO_STATUS_BLOCK         ioStatus;\r
-       IO_STACK_LOCATION       *pIoStack;\r
-       KEVENT                          event;\r
-\r
-       HCA_ENTER( HCA_DBG_PNP );\r
-\r
-       KeInitializeEvent( &event, NotificationEvent, FALSE );\r
-\r
-       /* Query for the verbs interface. */\r
-       p_irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP, p_fdo->p_al_dev,\r
-               NULL, 0, NULL, &event, &ioStatus );\r
-       if( !p_irp )\r
-       {\r
-               HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_PNP, \r
-                       ("IoBuildSynchronousFsdRequest failed.\n"));\r
-               return STATUS_INSUFFICIENT_RESOURCES;\r
-       }\r
-\r
-       /* Format the IRP. */\r
-       pIoStack = IoGetNextIrpStackLocation( p_irp );\r
-       pIoStack->MinorFunction = IRP_MN_QUERY_INTERFACE;\r
-       pIoStack->Parameters.QueryInterface.Version = IB_CI_INTERFACE_VERSION;\r
-       pIoStack->Parameters.QueryInterface.Size = sizeof(ib_ci_ifc_t);\r
-       pIoStack->Parameters.QueryInterface.Interface = \r
-               (INTERFACE*)&p_fdo->ci_ifc;\r
-       pIoStack->Parameters.QueryInterface.InterfaceSpecificData = NULL;\r
-       pIoStack->Parameters.QueryInterface.InterfaceType = \r
-               &GUID_IB_CI_INTERFACE;\r
-       p_irp->IoStatus.Status = STATUS_NOT_SUPPORTED;\r
-\r
-       /* Send the IRP. */\r
-       status = IoCallDriver( p_fdo->p_al_dev, p_irp );\r
-       if( status == STATUS_PENDING )\r
-       {\r
-               KeWaitForSingleObject( &event, Executive, KernelMode, \r
-                       FALSE, NULL );\r
-\r
-               status = ioStatus.Status;\r
-       }\r
-\r
-       if( !NT_SUCCESS( status ) )\r
-       {\r
-               HCA_PRINT( TRACE_LEVEL_ERROR,HCA_DBG_PNP, \r
-                       ("Query interface for verbs returned %08x.\n", status));\r
-               return status;\r
-       }\r
-\r
-       HCA_EXIT( HCA_DBG_PNP );\r
-       return status;\r
-}\r
-\r
-\r
-static NTSTATUS\r
-__pnp_notify_target(\r
-       IN                              void                                            *pNotifyStruct,\r
-       IN                              void                                            *context )\r
-{\r
-       NTSTATUS                                                        status = STATUS_SUCCESS;\r
-       PFDO_DEVICE_DATA                                                p_fdo = context;\r
-       PDEVICE_OBJECT p_dev_obj = WdfDeviceWdmGetDeviceObject(p_fdo->FdoDevice);\r
-       TARGET_DEVICE_REMOVAL_NOTIFICATION      *pNotify;\r
-\r
-       HCA_ENTER( HCA_DBG_PNP );\r
-\r
-       pNotify = (TARGET_DEVICE_REMOVAL_NOTIFICATION*)pNotifyStruct;\r
-\r
-       if( IsEqualGUID( &pNotify->Event, &GUID_TARGET_DEVICE_QUERY_REMOVE ) )\r
-       {\r
-               if ( p_fdo->state == HCA_REGISTERED) {\r
-                       /* Release AL's CI interface. */\r
-                       p_fdo->ci_ifc.wdm.InterfaceDereference( p_fdo->ci_ifc.wdm.Context );\r
-                       p_fdo->state = HCA_IFC_DEREFERENCED;\r
-               }\r
-\r
-               /* Release AL's file object so that it can unload. */\r
-               CL_ASSERT( p_fdo->p_al_dev );\r
-               CL_ASSERT( p_fdo->p_al_file_obj );\r
-               CL_ASSERT( p_fdo->p_al_file_obj == pNotify->FileObject );\r
-               if( p_fdo->p_al_file_obj ) {\r
-                       ObDereferenceObject( p_fdo->p_al_file_obj );\r
-                       p_fdo->p_al_file_obj = NULL;\r
-                       p_fdo->p_al_dev = NULL;\r
-               }\r
-       }\r
-       else if( IsEqualGUID( &pNotify->Event, \r
-               &GUID_TARGET_DEVICE_REMOVE_COMPLETE ) )\r
-       {\r
-               if (p_fdo->ci_ifc.deregister_ca) {\r
-                       /* Notify AL that the CA is being removed. */\r
-                       p_fdo->ci_ifc.deregister_ca( p_fdo->hca.guid );\r
-                       p_fdo->ci_ifc.deregister_ca = NULL;\r
-               }\r
-\r
-               if ( p_fdo->state == HCA_REGISTERED) {\r
-                       /* Release AL's CI interface. */\r
-                       p_fdo->ci_ifc.wdm.InterfaceDereference( p_fdo->ci_ifc.wdm.Context );\r
-               }\r
-               p_fdo->state = HCA_STARTED;\r
-\r
-               /* Release AL's file object so that it can unload. */\r
-               if( p_fdo->p_al_file_obj )\r
-               {\r
-                       ObDereferenceObject( p_fdo->p_al_file_obj );\r
-                       p_fdo->p_al_file_obj = NULL;\r
-                       p_fdo->p_al_dev = NULL;\r
-               }\r
-\r
-               /* Cancel our target device change registration. */\r
-               if (p_fdo->pnp_target_entry) {\r
-                       IoUnregisterPlugPlayNotification( p_fdo->pnp_target_entry );\r
-                       p_fdo->pnp_target_entry = NULL;\r
-               }\r
-\r
-       }\r
-       else if( IsEqualGUID( &pNotify->Event, \r
-               &GUID_TARGET_DEVICE_REMOVE_CANCELLED ) )\r
-       {\r
-               /* Cancel our target device change registration. */\r
-               if (p_fdo->pnp_target_entry) {\r
-                       IoUnregisterPlugPlayNotification( p_fdo->pnp_target_entry );\r
-                       p_fdo->pnp_target_entry = NULL;\r
-               }\r
-\r
-               /* Get the device object pointer for the AL. */\r
-               CL_ASSERT( !p_fdo->p_al_file_obj );\r
-               CL_ASSERT( !p_fdo->p_al_dev );\r
-               /* Get the AL device object. */\r
-               HCA_PRINT( TRACE_LEVEL_INFORMATION      ,HCA_DBG_SHIM  ,("Calling IoGetDeviceObjectPointer.\n"));\r
-               status = IoGetDeviceObjectPointer( &p_fdo->al_sym_name,\r
-                       FILE_ALL_ACCESS, &p_fdo->p_al_file_obj, &p_fdo->p_al_dev );\r
-               if( !NT_SUCCESS( status ) )\r
-               {\r
-                       HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_SHIM, \r
-                               ("IoGetDeviceObjectPointer returned %08x.\n", status ));\r
-                       return STATUS_SUCCESS;\r
-               }\r
-\r
-               /* Register for removal notification of the IB Fabric root device. */\r
-               status = IoRegisterPlugPlayNotification( \r
-                       EventCategoryTargetDeviceChange, 0, p_fdo->p_al_file_obj, \r
-                       p_dev_obj->DriverObject, __pnp_notify_target, p_fdo, \r
-                       &p_fdo->pnp_target_entry );\r
-               if( !NT_SUCCESS( status ) )\r
-               {\r
-                       HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_PNP, \r
-                               ("IoRegisterPlugPlayNotification returned %08x.\n", status));\r
-                       return status;\r
-               }\r
-\r
-               CL_ASSERT( p_fdo->state == HCA_IFC_DEREFERENCED );\r
-               if ( p_fdo->state == HCA_IFC_DEREFERENCED) {\r
-                       /* Release AL's CI interface. */\r
-                       p_fdo->ci_ifc.wdm.InterfaceReference( p_fdo->ci_ifc.wdm.Context );\r
-                       p_fdo->state = HCA_REGISTERED;\r
-               }\r
-       }\r
-\r
-       HCA_EXIT( HCA_DBG_PNP );\r
-       return status;\r
-}\r
-\r
 \r
 static ci_interface_t*\r
 __alloc_hca_ifc(\r
@@ -282,8 +102,7 @@ __alloc_hca_ifc(
 \r
        setup_ci_interface( p_fdo->hca.guid, !!hca_is_livefish(p_fdo), pIfc );\r
 \r
-       pIfc->p_hca_dev = WdfDeviceWdmGetPhysicalDevice(p_fdo->FdoDevice);\r
-       ASSERT(pIfc->p_hca_dev);\r
+       pIfc->p_hca_obj = &p_fdo->hca;\r
        pIfc->vend_id = (uint32_t)p_fdo->bus_ib_ifc.pdev->ven_id;\r
        pIfc->dev_id = (uint16_t)p_fdo->bus_ib_ifc.pdev->dev_id;\r
        pIfc->dev_revision = (uint16_t)p_fdo->hca.hw_ver;\r
@@ -292,191 +111,6 @@ __alloc_hca_ifc(
        return pIfc;\r
 }\r
 \r
-static void\r
-__hca_deregister(\r
-       IN                              PFDO_DEVICE_DATA                                p_fdo )\r
-{\r
-       HCA_ENTER( HCA_DBG_PNP );\r
-       \r
-       if ( p_fdo->state == HCA_REGISTERED) {\r
-               if (p_fdo->ci_ifc.deregister_ca) {\r
-                       /* Notify AL that the CA is being removed. */\r
-                       p_fdo->ci_ifc.deregister_ca( p_fdo->hca.guid );\r
-                       p_fdo->ci_ifc.deregister_ca = NULL;\r
-                       /* Release AL's CI interface. */\r
-                       p_fdo->ci_ifc.wdm.InterfaceDereference( p_fdo->ci_ifc.wdm.Context );\r
-                       p_fdo->state = HCA_STARTED;\r
-                       HCA_PRINT( TRACE_LEVEL_INFORMATION      ,HCA_DBG_PNP,\r
-                               ("***** HCA deregistered \n"));\r
-               }\r
-       }\r
-\r
-       HCA_EXIT( HCA_DBG_PNP );\r
-}\r
-\r
-static NTSTATUS\r
-__hca_register(\r
-       IN                              PFDO_DEVICE_DATA                                p_fdo )\r
-{\r
-       NTSTATUS                                status;\r
-       ib_api_status_t                 ib_status;\r
-       ci_interface_t                  *p_hca_ifc;\r
-\r
-       HCA_ENTER( HCA_DBG_PNP );\r
-       \r
-       ASSERT( p_fdo->state == HCA_STARTED );\r
-       ASSERT( p_fdo->p_al_dev );\r
-\r
-       /* Get the AL's lower interface. */\r
-       status = __get_ci_interface( p_fdo );\r
-       if( !NT_SUCCESS( status ) )\r
-       {\r
-               HCA_PRINT( TRACE_LEVEL_ERROR,HCA_DBG_PNP, \r
-                       ("__get_ci_interface returned %08x.\n", status));\r
-               goto exit;\r
-       }\r
-\r
-       /* Allocate and populate our HCA interface structure. */\r
-       p_hca_ifc = __alloc_hca_ifc( p_fdo );\r
-       if( !p_hca_ifc )\r
-       {\r
-               HCA_PRINT( TRACE_LEVEL_ERROR  ,HCA_DBG_PNP  ,("__alloc_hca_ifc failed.\n"));\r
-               status = STATUS_NO_MEMORY;\r
-               goto exit;\r
-       }\r
-\r
-       /* Notify AL that we're available... */\r
-       ib_status = p_fdo->ci_ifc.register_ca( p_hca_ifc );\r
-       ExFreePool( p_hca_ifc );\r
-       if( ib_status != IB_SUCCESS )\r
-       {\r
-               p_fdo->ci_ifc.wdm.InterfaceDereference( p_fdo->ci_ifc.wdm.Context );\r
-               status = STATUS_INSUFFICIENT_RESOURCES;\r
-               goto exit;\r
-       }\r
-\r
-       p_fdo->state = HCA_REGISTERED;\r
-       HCA_PRINT( TRACE_LEVEL_INFORMATION  ,HCA_DBG_PNP,\r
-               ("***** HCA registered \n"));\r
-exit:\r
-       HCA_EXIT( HCA_DBG_PNP );\r
-       return status;\r
-}\r
-\r
-static NTSTATUS\r
-__pnp_notify_ifc(\r
-       IN                              void                                            *pNotifyStruct,\r
-       IN                              void                                            *context )\r
-{\r
-       NTSTATUS                                                                status = STATUS_SUCCESS;\r
-       DEVICE_INTERFACE_CHANGE_NOTIFICATION    *pNotify;\r
-       PFDO_DEVICE_DATA                                                p_fdo = context;\r
-       PDEVICE_OBJECT p_dev_obj = WdfDeviceWdmGetDeviceObject(p_fdo->FdoDevice);\r
-\r
-       HCA_ENTER( HCA_DBG_PNP );\r
-\r
-       pNotify = (DEVICE_INTERFACE_CHANGE_NOTIFICATION*)pNotifyStruct;\r
-\r
-       if( !IsEqualGUID( &pNotify->Event, &GUID_DEVICE_INTERFACE_ARRIVAL ) )\r
-               goto done;\r
-\r
-       /*\r
-        * Sanity check.  We should only be getting notifications of the \r
-        * CI interface exported by AL.\r
-        */\r
-       ASSERT( \r
-               IsEqualGUID( &pNotify->InterfaceClassGuid, &GUID_IB_CI_INTERFACE ) );\r
-\r
-       if( p_fdo->state != HCA_STARTED )\r
-       {\r
-               HCA_PRINT( TRACE_LEVEL_ERROR  ,HCA_DBG_PNP  ,("Invalid state: %d\n", p_fdo->state));\r
-               goto done;\r
-       }\r
-\r
-       /* save symbolic name of IBAL for a case of cancelled IBAL removal */\r
-       if (!p_fdo->al_sym_name.Buffer) {\r
-               p_fdo->al_sym_name.Length = pNotify->SymbolicLinkName->Length;\r
-               p_fdo->al_sym_name.MaximumLength = pNotify->SymbolicLinkName->MaximumLength;\r
-               p_fdo->al_sym_name.Buffer = ExAllocatePoolWithTag( NonPagedPool, \r
-                       p_fdo->al_sym_name.MaximumLength * sizeof(wchar_t), MT_TAG_KERNEL );\r
-               if (!p_fdo->al_sym_name.Buffer)\r
-               {\r
-                       HCA_PRINT( TRACE_LEVEL_ERROR  ,HCA_DBG_PNP  ,("allocation of sym IBAL name failed.\n"));\r
-                       goto done;\r
-               }\r
-               RtlCopyUnicodeString( &p_fdo->al_sym_name, pNotify->SymbolicLinkName );\r
-       }\r
-\r
-       ASSERT( !p_fdo->p_al_dev );\r
-       ASSERT( !p_fdo->p_al_file_obj );\r
-\r
-       /* Get the AL device object. */\r
-       HCA_PRINT( TRACE_LEVEL_INFORMATION  ,HCA_DBG_PNP  ,("Calling IoGetDeviceObjectPointer.\n"));\r
-       status = IoGetDeviceObjectPointer( pNotify->SymbolicLinkName,\r
-               FILE_ALL_ACCESS, &p_fdo->p_al_file_obj, &p_fdo->p_al_dev );\r
-       if( !NT_SUCCESS( status ) )\r
-       {\r
-               HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_PNP, \r
-                       ("IoGetDeviceObjectPointer returned %08x.\n", status ));\r
-               goto done;\r
-       }\r
-\r
-       /* Register for removal notification of the IB Fabric root device. */\r
-       HCA_PRINT( TRACE_LEVEL_INFORMATION, HCA_DBG_PNP, \r
-               ("Registering for target notifications.\n"));\r
-       status = IoRegisterPlugPlayNotification( \r
-               EventCategoryTargetDeviceChange, 0, p_fdo->p_al_file_obj, \r
-               p_dev_obj->DriverObject, __pnp_notify_target, p_fdo, \r
-               &p_fdo->pnp_target_entry );\r
-       if( !NT_SUCCESS( status ) )\r
-       {\r
-               HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_PNP, \r
-                       ("IoRegisterPlugPlayNotification returned %08x.\n", status));\r
-               goto err_reg_notify;\r
-       }\r
-\r
-       status = __hca_register( p_fdo );\r
-       if( !NT_SUCCESS( status ) )\r
-       {\r
-               HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_PNP, \r
-                       ("__get_ci_interface returned %08x.\n", status));\r
-               goto err_reg_hca;\r
-       }\r
-       goto done;\r
-       \r
-err_reg_hca:\r
-       IoUnregisterPlugPlayNotification( p_fdo->pnp_target_entry );\r
-       p_fdo->pnp_target_entry = NULL;\r
-err_reg_notify:\r
-       ObDereferenceObject( p_fdo->p_al_file_obj );\r
-       p_fdo->p_al_file_obj = NULL;\r
-       p_fdo->p_al_dev = NULL;\r
-done:\r
-       HCA_EXIT( HCA_DBG_PNP );\r
-       return status;\r
-}\r
-\r
-/* Forwards the request to the HCA's PDO. */\r
-static NTSTATUS\r
-__get_ifc(\r
-       IN                              WDFDEVICE const                 FdoDevice,\r
-       IN              const   GUID* const                             p_guid,\r
-       IN                              USHORT                                  size,\r
-       IN                              USHORT                                  Version,\r
-       IN OUT                  PVOID                                   InterfaceSpecificData,\r
-       OUT                             PINTERFACE                              p_ifc )\r
-{\r
-       NTSTATUS status;\r
-\r
-       HCA_ENTER( HCA_DBG_PNP );\r
-       \r
-       status = WdfFdoQueryForInterface( FdoDevice, p_guid, p_ifc,\r
-               size, Version, InterfaceSpecificData );\r
-\r
-       HCA_EXIT( HCA_DBG_PNP );\r
-       return status;\r
-}\r
-\r
 static void\r
 __unmap_hca_memory(\r
        IN                              PFDO_DEVICE_DATA const p_fdo )\r
@@ -507,71 +141,66 @@ __hca_release_resources(
 \r
        switch( p_fdo->state )\r
        {\r
-       case HCA_REGISTERED:\r
-               __hca_deregister( p_fdo );\r
-\r
-               /* Fall through. */\r
        case HCA_STARTED:\r
                /* dequeue HCA  */\r
                mlnx_hca_remove( &p_fdo->hca );\r
        }\r
-\r
-       if (p_fdo->al_sym_name.Buffer) {\r
-               ExFreePool( p_fdo->al_sym_name.Buffer );\r
-               p_fdo->al_sym_name.Buffer = NULL;\r
-       }\r
        \r
-       if( p_fdo->pnp_target_entry )\r
-       {\r
-               ASSERT( p_fdo->pnp_ifc_entry );\r
-               IoUnregisterPlugPlayNotification( p_fdo->pnp_target_entry );\r
-               p_fdo->pnp_target_entry = NULL;\r
-       }\r
+       __unmap_hca_memory( p_fdo );\r
 \r
-       if( p_fdo->pnp_ifc_entry ) {\r
-               IoUnregisterPlugPlayNotification( p_fdo->pnp_ifc_entry );\r
-               p_fdo->pnp_ifc_entry = NULL;\r
-       }\r
+       p_fdo->state = HCA_ADDED;\r
 \r
-       if( p_fdo->p_al_file_obj ) {\r
-               ObDereferenceObject( p_fdo->p_al_file_obj );\r
-               p_fdo->p_al_file_obj = NULL;\r
-       }\r
+       HCA_EXIT( HCA_DBG_PNP );\r
+}\r
 \r
-       __unmap_hca_memory( p_fdo );\r
+static void\r
+__ref_ifc(\r
+       IN                              DEVICE_OBJECT*                          p_dev_obj )\r
+{\r
+       PFDO_DEVICE_DATA p_fdo = (PFDO_DEVICE_DATA)p_dev_obj->DeviceExtension;\r
 \r
-       p_fdo->state = HCA_ADDED;\r
+       HCA_ENTER( HCA_DBG_PNP );\r
+\r
+       cl_atomic_inc( &p_fdo->n_hca_ifc_ref );\r
+       ObReferenceObject( p_dev_obj );\r
+\r
+       HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_PNP, \r
+               ("MLX4_HCA: CA_guid %I64x, hca_ifc_ref %d\n",\r
+               p_fdo->hca.guid, p_fdo->n_hca_ifc_ref) );\r
 \r
        HCA_EXIT( HCA_DBG_PNP );\r
 }\r
 \r
+static void\r
+__deref_ifc(\r
+       IN                              DEVICE_OBJECT*                          p_dev_obj )\r
+{\r
+       PFDO_DEVICE_DATA p_fdo = (PFDO_DEVICE_DATA)p_dev_obj->DeviceExtension;\r
+\r
+       HCA_ENTER( HCA_DBG_PNP );\r
+\r
+       cl_atomic_dec( &p_fdo->n_hca_ifc_ref );\r
+       ObDereferenceObject( p_dev_obj );\r
+\r
+       HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_PNP, \r
+               ("MLX4_HCA: CA_guid %I64x, hca_ifc_ref %d\n",\r
+               p_fdo->hca.guid, p_fdo->n_hca_ifc_ref) );\r
+\r
+       HCA_EXIT( HCA_DBG_PNP );\r
+}\r
+\r
+\r
+\r
 NTSTATUS\r
 EvtDeviceD0Entry(\r
        IN WDFDEVICE  Device,\r
        IN WDF_POWER_DEVICE_STATE  PreviousState\r
        )\r
 {\r
-       PFDO_DEVICE_DATA p_fdo = FdoGetData(Device);\r
-       NTSTATUS status = STATUS_SUCCESS;\r
-\r
+       UNUSED_PARAM(Device);\r
        UNUSED_PARAM(PreviousState);\r
        HCA_ENTER( HCA_DBG_PNP );\r
-\r
        HCA_PRINT(TRACE_LEVEL_INFORMATION, HCA_DBG_PNP, ("EvtDeviceD0Entry: PreviousState 0x%x\n", PreviousState));\r
-\r
-       /* Connect to IBAL */\r
-       HCA_PRINT( TRACE_LEVEL_INFORMATION, HCA_DBG_PO, \r
-               ("***** Connect to IBAL, IRQL %d\n", KeGetCurrentIrql()));\r
-\r
-       if( p_fdo->p_al_dev && p_fdo->state == HCA_STARTED) {\r
-               status = __hca_register( p_fdo );\r
-               if( !NT_SUCCESS( status ) ) {\r
-                       HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_PO, \r
-                               ("!!! __hca_register failed (%#x) \n", status));\r
-                       status = STATUS_UNSUCCESSFUL;\r
-               }\r
-       }\r
-\r
        HCA_EXIT( HCA_DBG_PNP );\r
        return STATUS_SUCCESS;\r
 }\r
@@ -598,7 +227,6 @@ EvtDeviceD0Exit(
                }\r
                /* Fall through. */\r
        default:\r
-               __hca_deregister( p_fdo );\r
                status = STATUS_SUCCESS;\r
                break;\r
        }\r
@@ -617,8 +245,10 @@ EvtDevicePrepareHardware(
        int err;\r
        NTSTATUS status;\r
        PFDO_DEVICE_DATA p_fdo  = FdoGetData(Device);\r
-       PDEVICE_OBJECT p_dev_obj = WdfDeviceWdmGetDeviceObject(Device);\r
        BUS_INTERFACE_STANDARD  bus_pci_ifc;\r
+       ci_interface_t *p_hca_ifc;\r
+       RDMA_INTERFACE_VERBS rdma_ifc, *p_ifc = &rdma_ifc;\r
+       WDF_QUERY_INTERFACE_CONFIG qiConfig;\r
                \r
        UNUSED_PARAM(ResourcesRaw);\r
        UNUSED_PARAM(ResourcesTranslated);\r
@@ -627,11 +257,9 @@ EvtDevicePrepareHardware(
        \r
        HCA_PRINT(TRACE_LEVEL_INFORMATION, HCA_DBG_PNP, ("EvtPrepareHardware: \n"));\r
 \r
-       ASSERT(p_dev_obj);\r
-\r
        /* get PCI BUS interface */\r
-       status = __get_ifc( Device, &GUID_BUS_INTERFACE_STANDARD,\r
-               sizeof(BUS_INTERFACE_STANDARD), 1, NULL, (PINTERFACE)&bus_pci_ifc);\r
+       status = WdfFdoQueryForInterface( Device, &GUID_BUS_INTERFACE_STANDARD,\r
+               (PINTERFACE)&bus_pci_ifc, sizeof(BUS_INTERFACE_STANDARD), 1, NULL );\r
        if( !NT_SUCCESS( status ) ) {\r
                HCA_PRINT(TRACE_LEVEL_ERROR, HCA_DBG_PNP, ("Getting PCI BUS interface failed: status=0x%x\n", status));\r
                return status;\r
@@ -640,8 +268,8 @@ EvtDevicePrepareHardware(
        p_fdo->bus_pci_ifc_taken = TRUE;\r
        \r
        /* get MLX4_BUS IB interface */\r
-       status = __get_ifc( Device, &MLX4_BUS_IB_INTERFACE_GUID,\r
-               sizeof(MLX4_BUS_IB_INTERFACE), MLX4_BUS_IB_INTERFACE_VERSION, NULL, (PINTERFACE)&p_fdo->bus_ib_ifc);\r
+       status = WdfFdoQueryForInterface( Device, &MLX4_BUS_IB_INTERFACE_GUID,\r
+               (PINTERFACE)&p_fdo->bus_ib_ifc, sizeof(MLX4_BUS_IB_INTERFACE), MLX4_BUS_IB_INTERFACE_VERSION, NULL );\r
        if( !NT_SUCCESS( status ) ) {\r
                HCA_PRINT(TRACE_LEVEL_ERROR, HCA_DBG_PNP, ("Getting MLX4 BUS interface failed: status=0x%x\n", status));\r
                return status;\r
@@ -665,27 +293,40 @@ EvtDevicePrepareHardware(
        /* queue HCA  */\r
        mlnx_hca_insert( &p_fdo->hca );\r
 \r
+       /* Allocate and populate our HCA interface structure. */\r
+       p_hca_ifc = __alloc_hca_ifc( p_fdo );\r
+       if( !p_hca_ifc ) {\r
+               HCA_PRINT( TRACE_LEVEL_ERROR  ,HCA_DBG_PNP  ,("__alloc_hca_ifc failed.\n"));\r
+               return STATUS_NO_MEMORY;\r
+       }\r
+\r
+       /* fill interface fields */\r
+       p_ifc->InterfaceHeader.Size = sizeof(RDMA_INTERFACE_VERBS);\r
+       p_ifc->InterfaceHeader.Version = VerbsVersion(VERBS_MAJOR_VER, VERBS_MINOR_VER);\r
+       p_ifc->InterfaceHeader.Context = p_fdo->p_dev_obj;\r
+       p_ifc->InterfaceHeader.InterfaceReference = __ref_ifc;\r
+       p_ifc->InterfaceHeader.InterfaceDereference = __deref_ifc;\r
+       p_ifc->Verbs = *p_hca_ifc;\r
+       ExFreePool( p_hca_ifc );\r
+\r
+       /* create an upper interface */\r
+       WDF_QUERY_INTERFACE_CONFIG_INIT( &qiConfig, (PINTERFACE)p_ifc,\r
+               &GUID_RDMA_INTERFACE_VERBS, NULL);\r
+\r
+       status = WdfDeviceAddQueryInterface( Device, &qiConfig );\r
+       if (!NT_SUCCESS(status)) {\r
+               HCA_PRINT( TRACE_LEVEL_ERROR  ,HCA_DBG_PNP  ,("WdfDeviceAddQueryInterface failed %#x\n", status));\r
+               return status;\r
+       }\r
+\r
        /*\r
         * Change the state since the PnP callback can happen\r
         * before the callback returns.\r
         */\r
        p_fdo->state = HCA_STARTED;\r
        \r
-       /* Register for interface arrival of the IB_AL device. */\r
-       status = IoRegisterPlugPlayNotification(\r
-               EventCategoryDeviceInterfaceChange,\r
-               PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES,\r
-               (void*)&GUID_IB_CI_INTERFACE, p_dev_obj->DriverObject,\r
-               __pnp_notify_ifc, p_fdo, &p_fdo->pnp_ifc_entry );\r
-       if( !NT_SUCCESS( status ) )\r
-       {\r
-               p_fdo->state = HCA_ADDED;\r
-               HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_PNP,\r
-                       ("IoRegisterPlugPlayNotification returned %08x.\n", status));\r
-       }\r
-\r
        HCA_EXIT( HCA_DBG_PNP );\r
-       return status;\r
+       return STATUS_SUCCESS;\r
 }\r
 \r
 \r
@@ -708,14 +349,16 @@ EvtDeviceReleaseHardware(
 \r
        // release MLX4_BUS resources\r
        if(p_fdo->bus_ib_ifc_taken) {\r
+               PINTERFACE p_ifc = (PINTERFACE)&p_fdo->bus_ib_ifc;\r
+               p_ifc->InterfaceDereference( p_ifc->Context );\r
                p_fdo->bus_ib_ifc_taken = FALSE;\r
-               __put_ifc( (PINTERFACE)&p_fdo->bus_ib_ifc );\r
        }\r
 \r
        // release PCI BUS resources\r
        if(p_fdo->bus_pci_ifc_taken) {\r
+               PINTERFACE p_ifc = (PINTERFACE)&p_fdo->bus_pci_ifc;\r
+               p_ifc->InterfaceDereference( p_ifc->Context );\r
                p_fdo->bus_pci_ifc_taken = FALSE;\r
-               __put_ifc( (PINTERFACE)&p_fdo->bus_pci_ifc );\r
        }\r
 \r
        HCA_EXIT( HCA_DBG_PNP );\r
@@ -730,7 +373,7 @@ EvtDeviceQueryRemove(
        PFDO_DEVICE_DATA p_fdo = FdoGetData(Device);\r
        HCA_ENTER( HCA_DBG_PNP );\r
        if (atomic_read(&p_fdo->usecnt)) {\r
-               cl_dbg_out( "MLX4: Can't get unloaded. %d applications are still in work\n", p_fdo->usecnt);\r
+               cl_dbg_out( "MLX4_HCA: Can't get unloaded. %d applications are still in work\n", p_fdo->usecnt);\r
                return STATUS_UNSUCCESSFUL;\r
        }\r
        HCA_EXIT( HCA_DBG_PNP );\r
@@ -739,14 +382,14 @@ EvtDeviceQueryRemove(
 \r
 \r
 NTSTATUS\r
-EvtDeviceAdd(\r
+EvtDriverDeviceAdd(\r
        IN WDFDRIVER        Driver,\r
        IN PWDFDEVICE_INIT  DeviceInit\r
        )\r
 /*++\r
 Routine Description:\r
 \r
-       EvtDeviceAdd is called by the framework in response to AddDevice\r
+       EvtDriverDeviceAdd is called by the framework in response to AddDevice\r
        call from the PnP manager. We create and initialize a device object to\r
        represent a new instance of mxe bus.\r
 \r
@@ -772,7 +415,7 @@ Return Value:
 \r
        PAGED_CODE ();\r
        \r
-       HCA_PRINT(TRACE_LEVEL_INFORMATION, HCA_DBG_PNP, ("EvtDeviceAdd: 0x%p\n", Driver));\r
+       HCA_PRINT(TRACE_LEVEL_INFORMATION, HCA_DBG_PNP, ("EvtDriverDeviceAdd: 0x%p\n", Driver));\r
        //\r
        // register PnP & Power stuff\r
        //\r
@@ -806,7 +449,7 @@ Return Value:
        //\r
        status = WdfDeviceCreate(&DeviceInit, &attributes, &device);\r
        if (!NT_SUCCESS(status)) {\r
-               HCA_PRINT(TRACE_LEVEL_VERBOSE, HCA_DBG_PNP, ("EvtDeviceAdd: WdfDeviceCreate failed with 0x%x\n", status));\r
+               HCA_PRINT(TRACE_LEVEL_VERBOSE, HCA_DBG_PNP, ("EvtDriverDeviceAdd: WdfDeviceCreate failed with 0x%x\n", status));\r
                goto end;\r
        }\r
 \r
@@ -816,6 +459,7 @@ Return Value:
        p_fdo = FdoGetData(device);\r
        RtlZeroMemory(p_fdo, sizeof(FDO_DEVICE_DATA));\r
        p_fdo->FdoDevice = device;\r
+       p_fdo->p_dev_obj = WdfDeviceWdmGetDeviceObject( device );\r
        spin_lock_init( &p_fdo->uctx_lock );\r
        cl_qlist_init( &p_fdo->uctx_list );\r
        atomic_set(&p_fdo->usecnt, 0);\r
@@ -887,9 +531,7 @@ Return Value:
        g.DebugPrintLevel = TRACE_LEVEL_VERBOSE;\r
        g.DebugPrintFlags = 0xffff;\r
        HCA_ENTER( HCA_DBG_PNP );\r
-       HCA_PRINT(TRACE_LEVEL_INFORMATION, HCA_DBG_PNP, \r
-               ("Built %s %s, Version %s, RelDate %s\n", \r
-               __DATE__, __TIME__, DRV_VERSION, DRV_RELDATE));\r
+\r
        status = mlnx_hcas_init();\r
        if( status  != STATUS_SUCCESS ) {\r
                HCA_PRINT( TRACE_LEVEL_ERROR ,HCA_DBG_PNP ,\r
@@ -906,7 +548,7 @@ Return Value:
        //\r
 \r
        WDF_DRIVER_CONFIG_INIT(\r
-               &config, EvtDeviceAdd );\r
+               &config, EvtDriverDeviceAdd );\r
        config.EvtDriverUnload = EvtDriverUnload;\r
 \r
        //\r
@@ -949,6 +591,8 @@ Return Value:
        }\r
 \r
 end:\r
+       HCA_PRINT( TRACE_LEVEL_ERROR ,HCA_DBG_PNP ,\r
+               ("exit status %#x.\n", status));\r
        HCA_EXIT( HCA_DBG_PNP );\r
        return status;\r
 \r
@@ -1133,6 +777,15 @@ hca_add_device(
        return status;\r
 }\r
 \r
+static void\r
+__put_ifc(\r
+               IN      PINTERFACE              p_ifc )\r
+{\r
+       HCA_ENTER( HCA_DBG_PNP );\r
+       p_ifc->InterfaceDereference( p_ifc->Context );\r
+       HCA_EXIT( HCA_DBG_PNP );\r
+}\r
+\r
 /* Forwards the request to the HCA's PDO. */\r
 static NTSTATUS\r
 __get_ifc(\r
@@ -1215,8 +868,7 @@ __alloc_hca_ifc(
 \r
        setup_ci_interface( p_fdo->hca.guid, !!hca_is_livefish(p_fdo), pIfc );\r
 \r
-       pIfc->p_hca_dev = p_fdo->cl_ext.p_pdo;\r
-       ASSERT(pIfc->p_hca_dev);    \r
+       pIfc->p_hca_obj = &p_fdo->hca;\r
        pIfc->vend_id = (uint32_t)p_fdo->bus_ib_ifc.pdev->ven_id;\r
        pIfc->dev_id = (uint16_t)p_fdo->bus_ib_ifc.pdev->dev_id;\r
        pIfc->dev_revision = (uint16_t)p_fdo->hca.hw_ver;\r
@@ -1641,7 +1293,6 @@ __query_ci_ifc(
        p_ifc->InterfaceHeader.InterfaceReference = __ref_ifc;\r
        p_ifc->InterfaceHeader.InterfaceDereference = __deref_ifc;\r
        p_ifc->Verbs = *p_hca_ifc;\r
-       p_ifc->p_hca_obj = &p_fdo->hca;\r
 \r
        /* take the reference before returning. */\r
        __ref_ifc( p_dev_obj );\r
@@ -2301,9 +1952,6 @@ DriverEntry(
        g.DebugPrintFlags = 0xffff;\r
 \r
        HCA_ENTER( HCA_DBG_PNP );\r
-       HCA_PRINT(TRACE_LEVEL_INFORMATION, HCA_DBG_PNP, \r
-               ("Built %s %s, Version %s, RelDate %s\n", \r
-               __DATE__, __TIME__, DRV_VERSION, DRV_RELDATE));\r
 \r
        status = mlnx_hcas_init();\r
        if( status  != STATUS_SUCCESS ) {\r
index 0b42e6a..732d9fd 100644 (file)
@@ -150,16 +150,19 @@ typedef struct _FDO_DEVICE_DATA
        *               WDF DATA         \r
        * ------------------------------------------------ */\r
        WDFDEVICE                                       FdoDevice;\r
+       DEVICE_OBJECT                   *       p_dev_obj;              /* WDM dev object */\r
 #endif\r
 \r
        HCA_WMI_STD_DATA                        WmiData;\r
 \r
+#ifdef USE_WDM_FRAMEWORK\r
        /* -------------------------------------------------\r
        *               PNP DATA         \r
        * ------------------------------------------------ */\r
        void                                    *       pnp_ifc_entry;                  /* Notification entry for PnP interface events. */\r
        void                                    *       pnp_target_entry;       /* Notification entry for PnP target events. */\r
        PNP_DEVICE_STATE                        pnpState; /* state for PnP Manager */\r
+#endif \r
 \r
        /* -------------------------------------------------\r
        *               IBAL DATA        \r
@@ -167,9 +170,11 @@ typedef struct _FDO_DEVICE_DATA
        /* Number of references on the upper interface. */\r
        atomic32_t                                      n_hca_ifc_ref;\r
        hca_reg_state_t                         state;                          /* State for tracking registration with AL */\r
+#ifdef USE_WDM_FRAMEWORK\r
        DEVICE_OBJECT                   *       p_al_dev;               /* IB_AL FDO */\r
        FILE_OBJECT                             *       p_al_file_obj;  /* IB_AL file object */\r
        UNICODE_STRING                          al_sym_name;    /* IB_AL symbolic name */\r
+#endif \r
 \r
        /* -------------------------------------------------\r
        *               SHIM DATA        \r
@@ -300,7 +305,7 @@ EvtDriverUnload(
        );\r
 \r
 NTSTATUS\r
-EvtDeviceAdd(\r
+EvtDriverDeviceAdd(\r
        IN WDFDRIVER Driver,\r
        IN PWDFDEVICE_INIT Device\r
        );\r
index e3d7ece..046a70c 100644 (file)
@@ -391,12 +391,6 @@ DelService = WinVerbs,%SPSVCINST_STOPSERVICE%
 DelService = Ibbus,%SPSVCINST_STOPSERVICE%\r
 DelService = mlx4_hca,%SPSVCINST_STOPSERVICE%\r
 \r
-\r
-;\r
-; It should be uncommented after returning MLX4_HCA to WDF model.\r
-; WinVerbs is a WDF, KMDF driver.\r
-;\r
-\r
 ;*****************************************\r
 ; WDF Coinstaller installation section\r
 ;*****************************************\r
@@ -420,14 +414,17 @@ HKR,,CoInstallers32,0x00010000, "WdfCoInstaller01007.dll,WdfCoInstaller"
 WdfCoInstaller01007.dll\r
 \r
 [MLX4HCA.DDInstall.ntx86.Wdf]\r
+KmdfService = mlx4_hca,WvWdfSect\r
 KmdfService = WinVerbs,WvWdfSect\r
 KmdfService = WinMad,WvWdfSect\r
 \r
 [MLX4HCA.DDInstall.ntamd64.Wdf]\r
+KmdfService = mlx4_hca,WvWdfSect\r
 KmdfService = WinVerbs,WvWdfSect\r
 KmdfService = WinMad,WvWdfSect\r
 \r
 [MLX4HCA.DDInstall.ntia64.Wdf]\r
+KmdfService = mlx4_hca,WvWdfSect\r
 KmdfService = WinVerbs,WvWdfSect\r
 KmdfService = WinMad,WvWdfSect\r
 \r