mthca/pnp: respond to query interface
authorshefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 23 Jul 2008 20:34:43 +0000 (20:34 +0000)
committershefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 23 Jul 2008 20:34:43 +0000 (20:34 +0000)
Add infrastructure to respond to query calls for the
RDMA_INTERFACE_VERB interface.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@1439 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

hw/mthca/kernel/hca_pnp.c
inc/kernel/rdma/verbs.h [new file with mode: 0644]

index 576b1c3..0e01505 100644 (file)
@@ -12,6 +12,7 @@
 \r
 #include "hca_driver.h"\r
 #include "mthca_dev.h"\r
+#include <rdma\verbs.h>\r
 \r
 #if defined(EVENT_TRACING)\r
 #ifdef offsetof\r
@@ -23,6 +24,9 @@
 #include <initguid.h>\r
 #include <wdmguid.h>\r
 \r
+#define MTHCA_VERBS_MIN_VERSION                2\r
+#define MTHCA_VERBS_MAX_VERSION                2\r
+\r
 extern const char *mthca_version;\r
 \r
 static NTSTATUS\r
@@ -111,6 +115,12 @@ static ci_interface_t*
 __alloc_hca_ifc(\r
        IN                              hca_dev_ext_t* const            p_ext );\r
 \r
+static NTSTATUS\r
+hca_query_interface(\r
+       IN                              DEVICE_OBJECT* const            p_dev_obj,\r
+       IN                              IRP* const                                      p_irp, \r
+               OUT                     cl_irp_action_t* const          p_action );\r
+\r
 static NTSTATUS\r
 __get_ci_interface(\r
        IN                              DEVICE_OBJECT* const            p_dev_obj );\r
@@ -145,6 +155,7 @@ __pnp_notify_ifc(
 #pragma alloc_text (PAGE, hca_cancel_remove)\r
 #pragma alloc_text (PAGE, hca_surprise_remove)\r
 #pragma alloc_text (PAGE, hca_query_capabilities)\r
+#pragma alloc_text (PAGE, hca_query_interface)\r
 #pragma alloc_text (PAGE, hca_query_pnp_state)\r
 #pragma alloc_text (PAGE, hca_query_bus_relations)\r
 #pragma alloc_text (PAGE, hca_query_removal_relations)\r
@@ -185,7 +196,7 @@ hca_init_vfptr( void )
        vfptrHcaPnp.pfn_query_resources = cl_irp_ignore;\r
        vfptrHcaPnp.pfn_query_res_req = cl_irp_ignore;\r
        vfptrHcaPnp.pfn_query_bus_info = cl_irp_ignore;\r
-       vfptrHcaPnp.pfn_query_interface = cl_irp_ignore;\r
+       vfptrHcaPnp.pfn_query_interface = hca_query_interface;\r
        vfptrHcaPnp.pfn_read_config = cl_irp_ignore;\r
        vfptrHcaPnp.pfn_write_config = cl_irp_ignore;\r
        vfptrHcaPnp.pfn_eject = cl_irp_ignore;\r
@@ -1272,6 +1283,101 @@ hca_query_capabilities(
 }\r
 \r
 \r
+static VOID\r
+__hca_noop( VOID *context )\r
+{\r
+       UNREFERENCED_PARAMETER(context);\r
+}\r
+\r
+\r
+static NTSTATUS\r
+__query_ci_ifc(\r
+       IN                                      DEVICE_OBJECT* const            p_dev_obj,\r
+       IN                                      IO_STACK_LOCATION* const        p_io_stack )\r
+{\r
+       RDMA_INTERFACE_VERBS    *p_ifc;\r
+       hca_dev_ext_t                   *p_ext;\r
+       ci_interface_t                  *p_hca_ifc;\r
+       NTSTATUS                                status;\r
+       UINT8                                   version;\r
+\r
+       HCA_ENTER( HCA_DBG_PNP );\r
+\r
+       version = VerbsVersionMajor(p_io_stack->Parameters.QueryInterface.Version);\r
+       if( version < MTHCA_VERBS_MIN_VERSION || version > MTHCA_VERBS_MAX_VERSION )\r
+       {\r
+               status = STATUS_NOT_SUPPORTED;\r
+               goto exit;\r
+       }\r
+\r
+       if( p_io_stack->Parameters.QueryInterface.Size < sizeof(RDMA_INTERFACE_VERBS) )\r
+       {\r
+               status = STATUS_BUFFER_TOO_SMALL;\r
+               goto exit;\r
+       }\r
+\r
+       p_ext = (hca_dev_ext_t*)p_dev_obj->DeviceExtension;\r
+       p_hca_ifc = __alloc_hca_ifc( p_ext );\r
+       if( !p_hca_ifc )\r
+       {\r
+               status = STATUS_NO_MEMORY;\r
+               goto exit;\r
+       }\r
+\r
+       p_ifc = (RDMA_INTERFACE_VERBS *) p_io_stack->Parameters.QueryInterface.Interface;\r
+\r
+       p_ifc->InterfaceHeader.Size = sizeof(RDMA_INTERFACE_VERBS);\r
+       p_ifc->InterfaceHeader.Version = VerbsVersion(version, 0);\r
+       p_ifc->InterfaceHeader.Context = p_dev_obj;\r
+       p_ifc->InterfaceHeader.InterfaceReference = __hca_noop;\r
+       p_ifc->InterfaceHeader.InterfaceDereference = __hca_noop;\r
+       p_ifc->Verbs = *p_hca_ifc;\r
+       p_ifc->Verbs.p_hca_dev = &p_ext->hca.hob;\r
+\r
+       ExFreePool( p_hca_ifc );\r
+       status = STATUS_SUCCESS;\r
+\r
+exit:\r
+       HCA_EXIT( HCA_DBG_PNP );\r
+       return status;\r
+}\r
+\r
+\r
+static NTSTATUS\r
+hca_query_interface(\r
+       IN                              DEVICE_OBJECT* const            p_dev_obj,\r
+       IN                              IRP* const                                      p_irp, \r
+               OUT                     cl_irp_action_t* const          p_action )\r
+{\r
+       NTSTATUS                        status;\r
+       IO_STACK_LOCATION       *p_io_stack;\r
+\r
+       HCA_ENTER( HCA_DBG_PNP );\r
+\r
+#pragma warning( push, 3 )\r
+       PAGED_CODE();\r
+#pragma warning( pop )\r
+\r
+       p_io_stack = IoGetCurrentIrpStackLocation( p_irp );\r
+       \r
+       /* Compare requested GUID with our supported interface GUIDs. */\r
+       if( IsEqualGUID( p_io_stack->Parameters.QueryInterface.InterfaceType,\r
+               &GUID_RDMA_INTERFACE_VERBS ) )\r
+       {\r
+               status = __query_ci_ifc( p_dev_obj, p_io_stack );\r
+               *p_action = IrpComplete;\r
+       }\r
+       else\r
+       {\r
+               status = p_irp->IoStatus.Status;\r
+               *p_action = IrpSkip;\r
+       }\r
+\r
+       HCA_EXIT( HCA_DBG_PNP );\r
+       return status;\r
+}\r
+\r
+\r
 static NTSTATUS\r
 hca_query_pnp_state(\r
        IN                              DEVICE_OBJECT* const            p_dev_obj,\r
diff --git a/inc/kernel/rdma/verbs.h b/inc/kernel/rdma/verbs.h
new file mode 100644 (file)
index 0000000..67f5eac
--- /dev/null
@@ -0,0 +1,63 @@
+/*\r
+ * Copyright (c) 1996-2008 Intel Corporation. All rights reserved.\r
+ *\r
+ * This software is available to you under the OpenIB.org BSD license\r
+ * below:\r
+ *\r
+ *     Redistribution and use in source and binary forms, with or\r
+ *     without modification, are permitted provided that the following\r
+ *     conditions are met:\r
+ *\r
+ *      - Redistributions of source code must retain the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer.\r
+ *\r
+ *      - Redistributions in binary form must reproduce the above\r
+ *        copyright notice, this list of conditions and the following\r
+ *        disclaimer in the documentation and/or other materials\r
+ *        provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#pragma once\r
+\r
+#ifndef _VERBS_H_\r
+#define _VERBS_H_\r
+\r
+#include <initguid.h>\r
+#include <iba/ib_ci.h>\r
+\r
+static inline USHORT VerbsVersion(UINT8 Major, UINT8 Minor)\r
+{\r
+       return ((USHORT) Major << 8) | ((USHORT) Minor);\r
+}\r
+\r
+static inline UINT8 VerbsVersionMajor(USHORT Version)\r
+{\r
+       return (UINT8) (Version >> 8);\r
+}\r
+\r
+static inline UINT8 VerbsVersionMinor(USHORT Version)\r
+{\r
+       return (UINT8) Version;\r
+}\r
+\r
+DEFINE_GUID(GUID_RDMA_INTERFACE_VERBS, 0xf0ebae86, 0xedb5, 0x4b40,\r
+                       0xa1, 0xa, 0x44, 0xd5, 0xdb, 0x3b, 0x96, 0x4e);\r
+\r
+typedef struct _RDMA_INTERFACE_VERBS\r
+{\r
+       INTERFACE               InterfaceHeader;\r
+       ci_interface_t  Verbs;\r
+\r
+}      RDMA_INTERFACE_VERBS;\r
+\r
+#endif // _VERBS_H_\r