[Openib-windows] [PATCH] MTHCA: Fix bus interface usage

Fab Tillier ftillier at silverstorm.com
Mon Apr 3 11:55:40 PDT 2006


Hi Leo,

The recent changes to how bus interfaces get used could cause the bus interface
to be overwritten.  When a user calls fw_access_ctrl for FW_OPEN_IF, the
function overwrites the bus interface stored in the device extension.  This
patch replaces the fw_get_pci_bus_interface function with __open_fw_access,
which simply takes an extra reference on the pre-existing interface, ensuring
that the pre-existing interface doesn't get overwritten.

Also shouldn't there be synchronization on these calls, to prevent a user-mode
app from issuing multiple potentially conflicting FW commands simultaneously?

- Fab

Index: hw/mthca/kernel/hca_driver.c
===================================================================
--- hw/mthca/kernel/hca_driver.c	(revision 274)
+++ hw/mthca/kernel/hca_driver.c	(working copy)
@@ -110,11 +110,6 @@
 		IN		ULONG POINTER_ALIGNMENT			length
);
 
 static NTSTATUS
-fw_get_pci_bus_interface(
-	IN		DEVICE_OBJECT				*p_dev_obj,
-	OUT		BUS_INTERFACE_STANDARD		*p_BusInterface );
-
-static NTSTATUS
 fw_flash_write_data (
 		IN		BUS_INTERFACE_STANDARD
*p_BusInterface,
 		IN		PVOID
p_buffer,
@@ -388,56 +383,7 @@
 	return status;
 }
 
-static NTSTATUS
-fw_get_pci_bus_interface(
-	IN		DEVICE_OBJECT				*p_dev_obj,
-	OUT		BUS_INTERFACE_STANDARD		*p_BusInterface )
-{
-	KEVENT event;
-	NTSTATUS status;
-	PIRP p_irp;
-	IO_STATUS_BLOCK ioStatus;
-	PIO_STACK_LOCATION p_irpStack;
-	PDEVICE_OBJECT p_target_obj;
 
-	KeInitializeEvent( &event, NotificationEvent, FALSE );
-
-	p_target_obj = IoGetAttachedDeviceReference( p_dev_obj );
-
-	p_irp = IoBuildSynchronousFsdRequest( IRP_MJ_PNP,
-
p_target_obj,
-
NULL,
-
0,
-
NULL,
-
&event,
-
&ioStatus );
-	if (p_irp == NULL) {
-		status = STATUS_INSUFFICIENT_RESOURCES;
-		goto End;
-	}
-	p_irpStack = IoGetNextIrpStackLocation( p_irp );
-	p_irpStack->MinorFunction = IRP_MN_QUERY_INTERFACE;
-	p_irpStack->Parameters.QueryInterface.InterfaceType = (LPGUID)
&GUID_BUS_INTERFACE_STANDARD;
-	p_irpStack->Parameters.QueryInterface.Size =
sizeof(BUS_INTERFACE_STANDARD);
-	p_irpStack->Parameters.QueryInterface.Version = 1;
-	p_irpStack->Parameters.QueryInterface.Interface = (PINTERFACE)
p_BusInterface;
-	p_irpStack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
-
-	p_irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
-	
-	status = IoCallDriver( p_target_obj, p_irp );
-
-	if ( status == STATUS_PENDING )
-	{
-		KeWaitForSingleObject( &event, Executive, KernelMode, FALSE,
NULL );
-		status = ioStatus.Status;
-	}
-End:
-	// Done with reference
-	ObDereferenceObject( p_target_obj );
-	return status;
-}
-
 static NTSTATUS
 __map_crspace(
 	IN		struct ib_ucontext *			p_context,
@@ -542,6 +488,20 @@
 	HCA_EXIT( HCA_DBG_PNP );
 }
 
+
+static void
+__open_fw_access(
+	IN				struct ib_ucontext*
p_context,
+	IN				PBUS_INTERFACE_STANDARD
p_bus_interface )
+{
+	if( !p_context->fw_if_open )
+	{
+		p_bus_interface->InterfaceReference( p_bus_interface->Context );
+		p_context->fw_if_open = TRUE;
+	}
+}
+
+
 static void 
 __close_fw_access(
 	IN		struct ib_ucontext *	p_context,
@@ -554,6 +514,7 @@
 	}
 }
 
+
 void
 unmap_crspace_for_all( struct ib_ucontext *p_context )
 {
@@ -580,7 +541,7 @@
 	IN	OUT			ci_umv_buf_t
*p_umv_buf )
 {
 	DEVICE_OBJECT				*p_dev_obj;
-	PBUS_INTERFACE_STANDARD    p_bus_interface;
+	PBUS_INTERFACE_STANDARD		p_bus_interface;
 	NTSTATUS					status = STATUS_SUCCESS;
 	PVOID						p_data;
 	ULONG						offset;
@@ -621,14 +582,7 @@
 		break;
 				
 	case FW_OPEN_IF: // open BusInterface
-		if ( !p_context->fw_if_open ) {
-			status = fw_get_pci_bus_interface(p_dev_obj,
p_bus_interface);
-			if ( NT_SUCCESS( status ) ) {
-				p_context->fw_if_open = TRUE;
-				// status can be positive, but != STATUS_SUCCESS
-				status = STATUS_SUCCESS;
-			}
-		}
+		__open_fw_access( p_context, p_bus_interface );
 		break;
 
 	case FW_READ: // read data from flash
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mthca_bus_ifc.patch
Type: application/octet-stream
Size: 3308 bytes
Desc: not available
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20060403/f7657c2f/attachment.obj>


More information about the ofw mailing list