[ipoib,ibbus] Add support for partitioning (winib 2416,2417,2418)
authortzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 12 May 2008 13:01:47 +0000 (13:01 +0000)
committertzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 12 May 2008 13:01:47 +0000 (13:01 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@1160 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

19 files changed:
core/al/al_dev.h
core/al/kernel/al_proxy.c
core/bus/kernel/bus_driver.c
core/bus/kernel/bus_pnp.h
core/bus/kernel/bus_port_mgr.c
core/bus/kernel/ib_bus.inf
inc/kernel/iba/ipoib_ifc.h
tools/dirs
tools/part_man/dirs [new file with mode: 0644]
tools/part_man/user/SOURCES [new file with mode: 0644]
tools/part_man/user/makefile [new file with mode: 0644]
tools/part_man/user/part_man.c [new file with mode: 0644]
tools/part_man/user/part_man.rc [new file with mode: 0644]
ulp/ipoib/kernel/ipoib_adapter.c
ulp/ipoib/kernel/ipoib_driver.c
ulp/ipoib/kernel/ipoib_endpoint.c
ulp/ipoib/kernel/ipoib_ibat.c
ulp/ipoib/kernel/ipoib_port.c
ulp/ipoib/kernel/ipoib_port.h

index cca9874..0cf9d00 100644 (file)
 \r
 #define AL_IOCTL_VERSION                       (4)\r
 \r
+/* max number of devices with non-default pkey */\r
+#define        MAX_NUM_PKEY    16\r
 \r
+typedef struct _pkey_array\r
+{\r
+       ib_net16_t         pkey_num;\r
+       ib_net16_t     pkey_array[MAX_NUM_PKEY];\r
+}pkey_array_t;\r
 #ifdef CL_KERNEL\r
 \r
 /* Function prototypes for al device framework */\r
@@ -82,6 +89,9 @@ al_dev_cancel_io(
        IN                              DEVICE_OBJECT                           *p_dev_obj,\r
        IN                              IRP                                                     *p_irp );\r
 \r
+cl_status_t\r
+bus_add_pkey(\r
+       IN                              cl_ioctl_handle_t                       h_ioctl );\r
 \r
 /* Define data structures for user-mode proxy */\r
 #else          /* CL_KERNEL */\r
@@ -132,7 +142,7 @@ typedef enum al_proxy_ops
        ual_bind_cq,\r
        ual_bind_destroy,\r
        ual_bind_nd,\r
-\r
+       ual_req_create_pdo,\r
        al_proxy_maxops\r
 \r
 }      al_proxy_ops_t;\r
@@ -156,6 +166,7 @@ typedef enum al_proxy_ops
 #define UAL_BIND_CQ                    IOCTL_CODE(ALDEV_KEY, ual_bind_cq)\r
 #define UAL_BIND_DESTROY       IOCTL_CODE(ALDEV_KEY, ual_bind_destroy)\r
 #define UAL_BIND_ND                    IOCTL_CODE(ALDEV_KEY, ual_bind_nd)\r
+#define UAL_REQ_CREATE_PDO  IOCTL_CODE(ALDEV_KEY, ual_req_create_pdo)\r
 \r
 #define AL_PROXY_OPS_START     IOCTL_CODE(ALDEV_KEY, al_proxy_ops_start)\r
 #define AL_PROXY_MAXOPS                IOCTL_CODE(ALDEV_KEY, al_proxy_maxops)\r
index b381127..8f702b1 100644 (file)
@@ -706,6 +706,9 @@ proxy_ioctl(
        case UAL_BIND_ND: //check_done, used only in kernel\r
                cl_status = proxy_bind_file( h_ioctl, AL_OBJ_TYPE_NDI );\r
                break;\r
+       case UAL_REQ_CREATE_PDO:\r
+               cl_status = bus_add_pkey( h_ioctl);\r
+               break;\r
        default:\r
                cl_status = CL_INVALID_PARAMETER;\r
                break;\r
index 1c5d9b5..b1f1a41 100644 (file)
@@ -42,7 +42,7 @@
 #include "al_dev.h"\r
 #include "al_debug.h"\r
 #include <complib/cl_init.h>\r
-\r
+#include "iba/ipoib_ifc.h"\r
 \r
 #if defined(EVENT_TRACING)\r
 #ifdef offsetof\r
@@ -56,7 +56,8 @@
 #else\r
 #define DEFAULT_NODE_DESC      "OpenIB Windows® Host"\r
 #endif\r
-\r
+/* pkey array to be read */\r
+pkey_array_t  g_pkeys;\r
 \r
 char   node_desc[IB_NODE_DESCRIPTION_SIZE];\r
 \r
@@ -181,24 +182,160 @@ __read_machine_name( void )
                RtlStringCbCopyNA( node_desc, sizeof(node_desc),\r
                        DEFAULT_NODE_DESC, sizeof(DEFAULT_NODE_DESC) );\r
        }\r
-\r
-       BUS_ENTER( BUS_DBG_DRV );\r
 }\r
+/************************************************************************************\r
+* name :       __prepare_pKey_array\r
+*           parses registry string and exrtacts pkey value(s) from it.\r
+*                      pkey pattern is 0xABCD\r
+* input        :       UNICODE_STRING *str\r
+* output:      pkey_array\r
+* return:      uint16_t number of pkey(s) found\r
+*************************************************************************************/\r
+static uint16_t __prepare_pKey_array(IN const UNICODE_STRING *str, OUT uint16_t *pkey_array)\r
+{\r
+       uint16_t i, num_pKeys, cur_pkey_length;\r
+       NTSTATUS status;\r
+       ANSI_STRING ansi_str;\r
+       static const uint16_t PATTERN_LENGTH = 6;\r
+       BUS_ENTER( BUS_DBG_DRV );\r
+\r
+       CL_ASSERT(pkey_array);\r
+       CL_ASSERT(str);\r
 \r
+       num_pKeys = 0;\r
+    cur_pkey_length = 0;\r
 \r
+       status = RtlUnicodeStringToAnsiString(&ansi_str,str,TRUE);\r
+       if(! NT_SUCCESS(status))\r
+       {\r
+               BUS_TRACE(BUS_DBG_ERROR ,\r
+               ("RtlUnicodeStringToAnsiString returned 0x%.8x\n", status) );\r
+               return 0;\r
+       }\r
+       \r
+       for (i = 0; (i < ansi_str.MaximumLength) && (num_pKeys < MAX_NUM_PKEY) ; i++)\r
+    {\r
+               switch(ansi_str.Buffer[i])\r
+               {\r
+               case '0':\r
+                       cur_pkey_length++;\r
+                       if (((i+1) < ansi_str.Length) && ( ( ansi_str.Buffer[i+1] == 'x') || ( ansi_str.Buffer[i+1] == 'X')))\r
+                               break;\r
+                       else\r
+                       {\r
+                               pkey_array[num_pKeys] = \\r
+                               (pkey_array[num_pKeys] << 4)| 0;\r
+                               break;\r
+                       }\r
+\r
+               case 'x':\r
+               case 'X':\r
+                       cur_pkey_length++;\r
+                       break;\r
+\r
+               case ',':\r
+                       if(cur_pkey_length == PATTERN_LENGTH)\r
+                       {\r
+                               cur_pkey_length = 0;\r
+                               num_pKeys++;\r
+                       }\r
+                       break;\r
+\r
+               case 'A':\r
+               case 'a':\r
+                       pkey_array[num_pKeys] = \\r
+                       (pkey_array[num_pKeys] << 4)| 0xA;\r
+                       cur_pkey_length++;\r
+                       break;\r
+\r
+               case 'B':\r
+               case 'b':\r
+                       pkey_array[num_pKeys] = \\r
+                       (pkey_array[num_pKeys] << 4)| 0xB;\r
+                       cur_pkey_length++;\r
+                       break;\r
+\r
+               case 'C':\r
+               case 'c':\r
+                       pkey_array[num_pKeys] = \\r
+                       (pkey_array[num_pKeys] << 4)| 0xC;\r
+                       cur_pkey_length++;\r
+                       break;\r
+\r
+               case 'D':\r
+               case 'd':\r
+                       pkey_array[num_pKeys] = \\r
+                       (pkey_array[num_pKeys] << 4)| 0xD;\r
+                       cur_pkey_length++;\r
+                       break;\r
+\r
+               case 'E':\r
+               case 'e':\r
+                       pkey_array[num_pKeys] = \\r
+                       (pkey_array[num_pKeys] << 4)| 0xE;\r
+                       cur_pkey_length++;\r
+                       break;\r
+\r
+               case 'F':\r
+               case 'f':\r
+                       pkey_array[num_pKeys] = \\r
+                       (pkey_array[num_pKeys] << 4)| 0xF;\r
+                       cur_pkey_length++;\r
+                       break;\r
+\r
+               case '1':\r
+               case '2':\r
+               case '3':\r
+               case '4':\r
+               case '5':\r
+               case '6':\r
+               case '7':\r
+               case '8':\r
+               case '9':\r
+                       pkey_array[num_pKeys] = \\r
+                       (pkey_array[num_pKeys] << 4)| (ansi_str.Buffer[i] - '0');\r
+                       cur_pkey_length++;\r
+                       break;\r
+                       \r
+               case '\0':\r
+                       if(cur_pkey_length == PATTERN_LENGTH)\r
+                       {\r
+                               cur_pkey_length = 0;\r
+                               num_pKeys++;\r
+                       }\r
+                       else\r
+                       {\r
+                               RtlFreeAnsiString(&ansi_str);\r
+                               return num_pKeys;\r
+                       }\r
+                       break;\r
+\r
+               default:\r
+                       break;\r
+\r
+               }\r
+       }\r
+\r
+    RtlFreeAnsiString(&ansi_str);\r
+       BUS_EXIT( BUS_DBG_DRV );\r
+       return num_pKeys;\r
+}\r
 static NTSTATUS\r
 __read_registry(\r
        IN                              UNICODE_STRING* const           p_registry_path )\r
 {\r
        NTSTATUS                                        status;\r
        /* Remember the terminating entry in the table below. */\r
-       RTL_QUERY_REGISTRY_TABLE        table[9];\r
+       RTL_QUERY_REGISTRY_TABLE        table[10];\r
        UNICODE_STRING                          param_path;\r
+       UNICODE_STRING                          pkeyString;\r
+       UNICODE_STRING                          empy_string;\r
 \r
        BUS_ENTER( BUS_DBG_DRV );\r
 \r
        __read_machine_name();\r
 \r
+       RtlInitUnicodeString( &empy_string,NULL);\r
        RtlInitUnicodeString( &param_path, NULL );\r
        param_path.MaximumLength = p_registry_path->Length + \r
                sizeof(L"\\Parameters");\r
@@ -212,6 +349,18 @@ __read_registry(
 \r
        RtlAppendUnicodeStringToString( &param_path, p_registry_path );\r
        RtlAppendUnicodeToString( &param_path, L"\\Parameters" );\r
+       RtlInitUnicodeString( &pkeyString, NULL );\r
+    pkeyString.MaximumLength = 1024*sizeof(WCHAR);\r
+    pkeyString.Buffer = cl_zalloc( pkeyString.MaximumLength );\r
+    if( !pkeyString.Buffer )\r
+       {\r
+               cl_free(param_path.Buffer);\r
+               BUS_TRACE_EXIT( BUS_DBG_ERROR,\r
+                      ("Failed to allocate parameters path pkeyString.\n") );\r
+        return STATUS_INSUFFICIENT_RESOURCES;\r
+    }\r
+\r
+       cl_memclr(&g_pkeys,sizeof(pkey_array_t));\r
 \r
        /*\r
         * Clear the table.  This clears all the query callback pointers,\r
@@ -277,10 +426,17 @@ __read_registry(
        table[7].DefaultData = &g_ioc_poll_interval;\r
        table[7].DefaultLength = sizeof(ULONG);\r
 \r
+       table[8].Flags = RTL_QUERY_REGISTRY_DIRECT;\r
+       table[8].Name = L"PartitionKey";\r
+       table[8].EntryContext = &pkeyString;\r
+       table[8].DefaultType  = REG_SZ;\r
+       table[8].DefaultData  = &empy_string;\r
+       table[8].DefaultLength = 1024*sizeof(WCHAR);\r
        /* Have at it! */\r
        status = RtlQueryRegistryValues( RTL_REGISTRY_ABSOLUTE, \r
                param_path.Buffer, table, NULL, NULL );\r
-\r
+       if (NT_SUCCESS(status))\r
+                       g_pkeys.pkey_num = __prepare_pKey_array(&pkeyString, (uint16_t*)g_pkeys.pkey_array);\r
 #if DBG\r
        if( g_al_dbg_flags & AL_DBG_ERR )\r
                g_al_dbg_flags |= CL_DBG_ERROR;\r
@@ -291,6 +447,7 @@ __read_registry(
                        g_al_dbg_level,\r
                        g_al_dbg_flags));\r
 \r
+       cl_free( pkeyString.Buffer );\r
        cl_free( param_path.Buffer );\r
        BUS_EXIT( BUS_DBG_DRV );\r
        return status;\r
@@ -419,6 +576,37 @@ bus_drv_ioctl(
        return status;\r
 }\r
 \r
+cl_status_t\r
+bus_add_pkey(cl_ioctl_handle_t                 h_ioctl)\r
+{\r
+       cl_status_t                             status;\r
+       pkey_array_t                            *pkeys;\r
+       PIO_STACK_LOCATION                      pIoStack;\r
+\r
+       BUS_ENTER( BUS_DBG_DRV );\r
+\r
+       pIoStack = IoGetCurrentIrpStackLocation(h_ioctl);\r
+       if ( (! h_ioctl->AssociatedIrp.SystemBuffer) || \r
+                pIoStack->Parameters.DeviceIoControl.InputBufferLength < sizeof (pkey_array_t))\r
+    {\r
+               BUS_TRACE_EXIT( BUS_DBG_ERROR, \r
+                       ("Invalid parameters.\n") );\r
+               return CL_INVALID_PARAMETER;\r
+       }\r
+\r
+       pkeys =  (pkey_array_t*)h_ioctl->AssociatedIrp.SystemBuffer;\r
+\r
+       /* create additional pdo */\r
+       status = port_mgr_pkey_add(pkeys);\r
+       if (! NT_SUCCESS(status))\r
+       {\r
+               BUS_TRACE_EXIT( BUS_DBG_ERROR, \r
+                       ("port_mgr_pkey_add returned %08x.\n", status) );\r
+       }\r
+\r
+       BUS_EXIT( BUS_DBG_DRV );\r
+       return status;\r
+}\r
 \r
 static NTSTATUS\r
 bus_drv_sysctl(\r
index a5c2041..83fd743 100644 (file)
@@ -86,4 +86,5 @@ bus_get_relations(
        IN              const   net64_t                                         ca_guid,\r
        IN                              IRP* const                                      p_irp );\r
 \r
+NTSTATUS port_mgr_pkey_add();\r
 #endif // !defined _BUS_DRV_PNP_H_\r
index f74bab3..8d79576 100644 (file)
@@ -42,7 +42,7 @@
 #include <initguid.h>\r
 #include <wdmguid.h>\r
 #include "iba/ipoib_ifc.h"\r
-\r
+#include "al_dev.h"\r
 \r
 #define IPOIB_DEVICE_ID                        L"IBA\\IPoIB"\r
 #define IPOIB_COMPAT_ID                        L"IBA\\SID_1000066a00020000\0\0"\r
@@ -62,7 +62,7 @@ typedef struct _bus_port_ext
 {\r
        bus_pdo_ext_t                   pdo;\r
 \r
-       net64_t                                 port_guid;\r
+       port_guid_pkey                  port_guid;\r
        uint32_t                                n_port;\r
 \r
        /* Number of references on the upper interface. */\r
@@ -73,7 +73,9 @@ typedef struct _bus_port_ext
 \r
 port_mgr_t*                                            gp_port_mgr = NULL;\r
 \r
+extern pkey_array_t  g_pkeys;\r
 \r
+static boolean_t pkeys_enumerated = FALSE;\r
 /*\r
  * Function prototypes.\r
  */\r
@@ -513,7 +515,7 @@ __port_was_hibernated(
                p_port_ext = (bus_port_ext_t*)p_pdo_ext;\r
        \r
                if( p_pdo_ext->b_present && p_pdo_ext->b_hibernating &&\r
-                       (p_port_ext->port_guid == p_pnp_rec->p_port_attr->port_guid) )\r
+                       (p_port_ext->port_guid.guid == p_pnp_rec->p_port_attr->port_guid) )\r
                {\r
                        n_devs++;\r
                        break;\r
@@ -523,7 +525,7 @@ __port_was_hibernated(
                        ("Skipped PDO for %s: PDO %p, ext %p, present %d, missing %d, hibernating %d, port_guid %I64x.\n",\r
                        p_pdo_ext->cl_ext.vfptr_pnp_po->identity, p_pdo_ext->cl_ext.p_self_do, \r
                        p_pdo_ext, p_pdo_ext->b_present, p_pdo_ext->b_reported_missing, \r
-                       p_pdo_ext->b_hibernating, p_port_ext->port_guid ) );\r
+                       p_pdo_ext->b_hibernating, p_port_ext->port_guid.guid  ) );\r
        }\r
 \r
        if (n_devs)\r
@@ -546,7 +548,7 @@ __port_was_hibernated(
                                ("Found PDO for %s: PDO %p, ext %p, present %d, missing %d, hibernating %d, port_guid %I64x.\n",\r
                                p_pdo_ext->cl_ext.vfptr_pnp_po->identity, p_pdo_ext->cl_ext.p_self_do, \r
                                p_pdo_ext, p_pdo_ext->b_present, p_pdo_ext->b_reported_missing, \r
-                               p_pdo_ext->b_hibernating, p_port_ext->port_guid ) );\r
+                               p_pdo_ext->b_hibernating, p_port_ext->port_guid.guid ) );\r
                }\r
        }\r
        else \r
@@ -567,9 +569,10 @@ port_mgr_port_add(
        IN                              ib_pnp_port_rec_t*                      p_pnp_rec )\r
 {\r
        NTSTATUS                status;\r
-       DEVICE_OBJECT   *p_pdo;\r
+    DEVICE_OBJECT   *p_pdo[MAX_NUM_PKEY + 1];\r
+    uint8_t         num_pdo;\r
        bus_port_ext_t  *p_port_ext;\r
-\r
+       ib_net16_t      pdo_cnt;\r
        BUS_ENTER( BUS_DBG_PNP );\r
 \r
        if( !bus_globals.b_report_port_nic )\r
@@ -588,11 +591,20 @@ port_mgr_port_add(
                return status;\r
        }\r
 \r
+    p_port_ext = NULL;\r
+\r
+       if( pkeys_enumerated)\r
+               pdo_cnt = 1;\r
+       else\r
+               pdo_cnt = g_pkeys.pkey_num + 1;\r
+\r
+    for (num_pdo = 0; num_pdo < pdo_cnt; num_pdo++)\r
+    {\r
        /* Create the PDO for the new port device. */\r
        status = IoCreateDevice( bus_globals.p_driver_obj, sizeof(bus_port_ext_t),\r
                NULL, FILE_DEVICE_CONTROLLER,\r
                FILE_DEVICE_SECURE_OPEN | FILE_AUTOGENERATED_DEVICE_NAME,\r
-               FALSE, &p_pdo );\r
+                       FALSE, &p_pdo[num_pdo] );\r
        if( !NT_SUCCESS( status ) )\r
        {\r
                BUS_TRACE_EXIT( BUS_DBG_ERROR,\r
@@ -601,13 +613,13 @@ port_mgr_port_add(
        }\r
 \r
        /* Initialize the device extension. */\r
-       cl_init_pnp_po_ext( p_pdo, NULL, p_pdo, bus_globals.dbg_lvl,\r
+               cl_init_pnp_po_ext( p_pdo[num_pdo], NULL, p_pdo[num_pdo], bus_globals.dbg_lvl,\r
                &vfptr_port_pnp, &vfptr_port_query_txt );\r
 \r
        /* Set the DO_BUS_ENUMERATED_DEVICE flag to mark it as a PDO. */\r
-       p_pdo->Flags |= DO_BUS_ENUMERATED_DEVICE;\r
+               p_pdo[num_pdo]->Flags |= DO_BUS_ENUMERATED_DEVICE;\r
 \r
-       p_port_ext = p_pdo->DeviceExtension;\r
+               p_port_ext = p_pdo[num_pdo]->DeviceExtension;\r
        p_port_ext->pdo.dev_po_state.DeviceState = PowerDeviceD0;\r
        p_port_ext->pdo.p_parent_ext = bus_globals.p_bus_ext;\r
        p_port_ext->pdo.b_present = TRUE;\r
@@ -615,24 +627,34 @@ port_mgr_port_add(
        p_port_ext->pdo.b_hibernating = FALSE;\r
        p_port_ext->pdo.p_po_work_item = NULL;\r
        BUS_TRACE( BUS_DBG_PNP, ("Created device for %s: PDO %p,ext %p, present %d, missing %d .\n",\r
-               p_port_ext->pdo.cl_ext.vfptr_pnp_po->identity, p_pdo, p_port_ext, p_port_ext->pdo.b_present, \r
+                       p_port_ext->pdo.cl_ext.vfptr_pnp_po->identity, p_pdo[num_pdo], p_port_ext, p_port_ext->pdo.b_present, \r
                p_port_ext->pdo.b_reported_missing ) );\r
 \r
        /* Cache the CA GUID. */\r
        p_port_ext->pdo.ca_guid = p_pnp_rec->p_ca_attr->ca_guid;\r
 \r
        /* Take a reference on the parent HCA. */\r
+               if(num_pdo > 0)\r
+               {\r
+                       p_port_ext->pdo.h_ca = ((bus_port_ext_t*)p_pdo[0]->DeviceExtension)->pdo.h_ca;\r
+               }\r
+               else\r
        p_port_ext->pdo.h_ca = acquire_ca( p_pnp_rec->p_ca_attr->ca_guid );\r
        if( !p_port_ext->pdo.h_ca )\r
        {\r
-               BUS_TRACE( BUS_DBG_PNP, ("Deleted device: PDO %p\n", p_pdo ));\r
-               IoDeleteDevice( p_pdo );\r
+                       BUS_TRACE( BUS_DBG_PNP, ("Deleted device: PDO %p\n", p_pdo[num_pdo]));\r
+                       IoDeleteDevice( p_pdo[num_pdo]);\r
                BUS_TRACE_EXIT( BUS_DBG_ERROR, ("acquire_ca failed to find CA.\n") );\r
                return IB_INVALID_GUID;\r
        }\r
-       p_port_ext->port_guid = p_pnp_rec->p_port_attr->port_guid;\r
+               p_port_ext->port_guid.guid = p_pnp_rec->p_port_attr->port_guid;\r
        p_port_ext->n_port = p_pnp_rec->p_port_attr->port_num;\r
+               p_port_ext->port_guid.pkey = IB_DEFAULT_PKEY;\r
 \r
+               if(num_pdo > 0)\r
+               {\r
+                 p_port_ext->port_guid.pkey = g_pkeys.pkey_array[num_pdo -1];\r
+               }\r
        /* Store the device extension in the port vector for future queries. */\r
        cl_mutex_acquire( &gp_port_mgr->pdo_mutex );\r
        cl_qlist_insert_tail( &gp_port_mgr->port_list,\r
@@ -643,7 +665,10 @@ port_mgr_port_add(
         * Set the context of the PNP event.  The context is passed in for future\r
         * events on the same port.\r
         */\r
-       p_pnp_rec->pnp_rec.context = p_port_ext;\r
+               if(num_pdo == 0)\r
+                       p_pnp_rec->pnp_rec.context = p_port_ext;\r
+       }\r
+       pkeys_enumerated = TRUE;\r
 \r
        /* Tell the PnP Manager to rescan for the HCA's bus relations. */\r
        IoInvalidateDeviceRelations(\r
@@ -657,6 +682,106 @@ port_mgr_port_add(
        return IB_SUCCESS;\r
 }\r
 \r
+/************************************************************************************\r
+* name :       port_mgr_pkey_add\r
+*           creates pdo for each pkey value in pkey_array \r
+* input        :       g_pkeys\r
+* output:      none\r
+* return:      cl_status\r
+*************************************************************************************/\r
+cl_status_t port_mgr_pkey_add(pkey_array_t *pkeys)\r
+{\r
+       uint16_t                        cnt;\r
+       NTSTATUS            status;\r
+       cl_list_item_t          *p_list_item;\r
+       bus_port_ext_t          *p_port_ext, *pkey_port_ext;\r
+       DEVICE_OBJECT       *p_pdo[MAX_NUM_PKEY];\r
+       bus_pdo_ext_t           *p_pdo_ext = NULL;\r
+       cl_qlist_t*                     p_pdo_list = &gp_port_mgr->port_list;\r
+\r
+       BUS_ENTER( BUS_DBG_PNP );\r
+\r
+       p_port_ext = NULL;\r
+       cl_mutex_acquire( &gp_port_mgr->pdo_mutex );\r
+       \r
+       /* Count the number of child devices. */\r
+       for( p_list_item = cl_qlist_head( p_pdo_list );\r
+               p_list_item != cl_qlist_end( p_pdo_list );\r
+               p_list_item = cl_qlist_next( p_list_item ) )\r
+       {\r
+               p_pdo_ext = PARENT_STRUCT( p_list_item, bus_pdo_ext_t, list_item );\r
+               p_port_ext = (bus_port_ext_t*)p_pdo_ext;\r
+\r
+               if(p_port_ext->port_guid.pkey != IB_DEFAULT_PKEY)\r
+                       break;\r
+       }\r
+       cl_mutex_release( &gp_port_mgr->pdo_mutex );\r
+\r
+       if (!p_port_ext)\r
+       {\r
+               BUS_TRACE_EXIT( BUS_DBG_ERROR,\r
+                       ("No existed pdo found.\n") );\r
+               return CL_ERROR;\r
+       }\r
+\r
+    for (cnt = 0; cnt < pkeys->pkey_num; cnt++)\r
+    {\r
+\r
+               /* Create the PDO for the new port device. */\r
+               status = IoCreateDevice( bus_globals.p_driver_obj, sizeof(bus_port_ext_t),\r
+                       NULL, FILE_DEVICE_CONTROLLER,\r
+                       FILE_DEVICE_SECURE_OPEN | FILE_AUTOGENERATED_DEVICE_NAME,\r
+                       FALSE, &p_pdo[cnt] );\r
+               if( !NT_SUCCESS( status ) )\r
+               {\r
+                       BUS_TRACE_EXIT( BUS_DBG_ERROR,\r
+                               ("IoCreateDevice returned %08x.\n", status) );\r
+                       return CL_ERROR;\r
+               }\r
+       \r
+               /* Initialize the device extension. */\r
+               cl_init_pnp_po_ext( p_pdo[cnt], NULL, p_pdo[cnt], bus_globals.dbg_lvl,\r
+                       &vfptr_port_pnp, &vfptr_port_query_txt );\r
+       \r
+               /* Set the DO_BUS_ENUMERATED_DEVICE flag to mark it as a PDO. */\r
+               p_pdo[cnt]->Flags |= DO_BUS_ENUMERATED_DEVICE;\r
+       \r
+               pkey_port_ext = p_pdo[cnt]->DeviceExtension;\r
+               pkey_port_ext->pdo.dev_po_state.DeviceState = PowerDeviceD0;\r
+               pkey_port_ext->pdo.p_parent_ext = bus_globals.p_bus_ext;\r
+               pkey_port_ext->pdo.b_present = TRUE;\r
+               pkey_port_ext->pdo.b_reported_missing = FALSE;\r
+               pkey_port_ext->pdo.b_hibernating = FALSE;\r
+               pkey_port_ext->pdo.p_po_work_item = NULL;\r
+               BUS_TRACE( BUS_DBG_PNP, ("Created device for %s: PDO %p,ext %p, present %d, missing %d .\n",\r
+                       pkey_port_ext->pdo.cl_ext.vfptr_pnp_po->identity, p_pdo[cnt], pkey_port_ext, pkey_port_ext->pdo.b_present, \r
+                       pkey_port_ext->pdo.b_reported_missing ) );\r
+       \r
+               /* Cache the CA GUID. */\r
+               pkey_port_ext->pdo.ca_guid = p_port_ext->pdo.ca_guid;\r
+               pkey_port_ext->pdo.h_ca = p_port_ext->pdo.h_ca;\r
+               pkey_port_ext->port_guid.guid = p_port_ext->port_guid.guid;\r
+               pkey_port_ext->n_port = p_port_ext->n_port;\r
+               pkey_port_ext->port_guid.pkey = pkeys->pkey_array[cnt];\r
+\r
+               /* Store the device extension in the port vector for future queries. */\r
+               cl_mutex_acquire( &gp_port_mgr->pdo_mutex );\r
+               cl_qlist_insert_tail( &gp_port_mgr->port_list,\r
+                       &pkey_port_ext->pdo.list_item );\r
+               cl_mutex_release( &gp_port_mgr->pdo_mutex );\r
+       }\r
+\r
+       /* Tell the PnP Manager to rescan for the HCA's bus relations. */\r
+       IoInvalidateDeviceRelations(\r
+               p_port_ext->pdo.h_ca->obj.p_ci_ca->verbs.p_hca_dev, BusRelations );\r
+\r
+       /* Invalidate removal relations for the bus driver. */\r
+       IoInvalidateDeviceRelations(\r
+               bus_globals.p_bus_ext->cl_ext.p_pdo, RemovalRelations );\r
+\r
+       BUS_EXIT( BUS_DBG_PNP );\r
+       return CL_SUCCESS;\r
+}\r
 \r
 void\r
 port_mgr_port_remove(\r
@@ -1063,16 +1188,16 @@ port_query_unique_id(
        }\r
 \r
        /* The instance ID is the port GUID. */\r
-       p_string = ExAllocatePoolWithTag( PagedPool, sizeof(WCHAR) * 17, 'iuqp' );\r
+       p_string = ExAllocatePoolWithTag( PagedPool, sizeof(WCHAR) * 21, 'iuqp' );\r
        if( !p_string )\r
        {\r
                BUS_TRACE_EXIT( BUS_DBG_ERROR,\r
                        ("Failed to allocate instance ID buffer (%d bytes).\n",\r
-                       sizeof(WCHAR) * 17) );\r
+                       sizeof(WCHAR) * 21) );\r
                return STATUS_NO_MEMORY;\r
        }\r
 \r
-       status = RtlStringCchPrintfW( p_string, 17, L"%016I64x", p_ext->port_guid );\r
+       status = RtlStringCchPrintfW( p_string, 21, L"%016I64x%04x",p_ext->port_guid.guid,p_ext->port_guid.pkey );\r
        if( !NT_SUCCESS( status ) )\r
        {\r
                CL_ASSERT( NT_SUCCESS( status ) );\r
index 0de3c61..09a30c0 100644 (file)
@@ -183,6 +183,7 @@ HKR,"Parameters","SmiPollInterval",%REG_DWORD_NO_CLOBBER%,20000
 HKR,"Parameters","IocQueryTimeout",%REG_DWORD_NO_CLOBBER%,250\r
 HKR,"Parameters","IocQueryRetries",%REG_DWORD_NO_CLOBBER%,4\r
 HKR,"Parameters","IocPollInterval",%REG_DWORD_NO_CLOBBER%,30000\r
+HKR,"Parameters","PartitionKey",%REG_SZ%,""\r
 \r
 [Iou.ParamsReg]\r
 HKR,"Parameters","DebugLevel",%REG_DWORD%,2\r
index c7ab015..7fd53f6 100644 (file)
 * DESCRIPTION\r
 *      IPoIB interface datat.\r
 *\r
+*      The port guid combined from guid + PKEY \r
+*/\r
+typedef struct _port_guid_pkey\r
+{\r
+       net64_t         guid;\r
+       ib_net16_t      pkey;\r
+} port_guid_pkey;\r
+\r
+\r
+/*\r
 *      The ipoib_ifc_data_t structure \r
 *\r
 * SYNOPSIS\r
@@ -69,7 +79,7 @@
 typedef struct _ipoib_ifc_data\r
 {\r
        net64_t                                         ca_guid;\r
-       net64_t                                         port_guid;\r
+       port_guid_pkey                          port_guid;\r
        uint8_t                                         port_num;\r
 \r
 }      ipoib_ifc_data_t;\r
index e6432ec..34cba9a 100644 (file)
@@ -6,7 +6,8 @@ DIRS=\
        flint           \\r
        mread           \\r
        mwrite          \\r
-       mst                     \\r
+       mst             \\r
        spark           \\r
-       nsc                     \\r
-       perftests\r
+       nsc             \\r
+       perftests       \\r
+        part_man        \r
diff --git a/tools/part_man/dirs b/tools/part_man/dirs
new file mode 100644 (file)
index 0000000..389156f
--- /dev/null
@@ -0,0 +1,2 @@
+DIRS=\\r
+       user\r
diff --git a/tools/part_man/user/SOURCES b/tools/part_man/user/SOURCES
new file mode 100644 (file)
index 0000000..1c2a3bc
--- /dev/null
@@ -0,0 +1,23 @@
+TARGETNAME=part_man\r
+TARGETPATH=..\..\..\bin\user\obj$(BUILD_ALT_DIR)\r
+TARGETTYPE=PROGRAM\r
+UMTYPE=console\r
+USE_MSVCRT=1\r
+\r
+SOURCES=part_man.c \\r
+       part_man.rc\r
+       \r
+INCLUDES=..\..\..\inc;..\..\..\inc\user;..\..\..\core\al\r
+\r
+RCOPTIONS=/I..\..\win\include\r
+\r
+TARGETLIBS= \\r
+!if $(FREEBUILD)\r
+                       $(TARGETPATH)\*\complib.lib \\r
+                       $(TARGETPATH)\*\ibal.lib\r
+!else\r
+                       $(TARGETPATH)\*\complibd.lib \\r
+                       $(TARGETPATH)\*\ibald.lib\r
+!endif\r
+\r
+MSC_WARNING_LEVEL= /W3\r
diff --git a/tools/part_man/user/makefile b/tools/part_man/user/makefile
new file mode 100644 (file)
index 0000000..bffacaa
--- /dev/null
@@ -0,0 +1,7 @@
+#\r
+# DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source\r
+# file to this component.  This file merely indirects to the real make file\r
+# that is shared by all the driver components of the OpenIB Windows project.\r
+#\r
+\r
+!INCLUDE ..\..\..\inc\openib.def\r
diff --git a/tools/part_man/user/part_man.c b/tools/part_man/user/part_man.c
new file mode 100644 (file)
index 0000000..194f625
--- /dev/null
@@ -0,0 +1,384 @@
+#include "stdio.h"\r
+#include "string.h"\r
+#include "stdlib.h"\r
+#include <windows.h>\r
+\r
+#include <iba/ib_types.h>\r
+#include <iba/ib_al.h>\r
+#include "al_dev.h"\r
+\r
+typedef enum\r
+{\r
+       pkey_show = 0,\r
+       pkey_add,\r
+       pkey_rem\r
+}Pkey_action;\r
+\r
+/* common query parameters */\r
+typedef struct _REQUEST_IN\r
+{\r
+       union\r
+       {\r
+               struct\r
+               {\r
+                       unsigned short     pkey_num;\r
+                       unsigned __int16   pkeys[MAX_NUM_PKEY];\r
+                       Pkey_action                action;\r
+               }guid_pkey;\r
+               }u;\r
+}REQUEST_IN;\r
+\r
+#define        DEFAULT_BUFER_SIZE      1024\r
+static const char IBBUS_SERV_KEY[] = {"SYSTEM\\CurrentControlSet\\Services\\ibbus\\Parameters"};\r
+\r
+void show_help()\r
+{\r
+       printf("Usage : part_man.exe <show|add|rem> <pkey1 pkey2 ...>\n");\r
+}\r
+\r
+/********************************************************************\r
+* name :       reg_ibbus_pkey_show\r
+*                      read registry pkey and optionally prints it\r
+* input        :       show - whether to print\r
+* output:      partKey - contains read pkeys, reg_handle\r
+* return:   number of characters read\r
+********************************************************************/\r
+static int reg_ibbus_pkey_show(IN BOOLEAN show,OUT char *partKey, OUT HKEY *reg_handle)\r
+{\r
+       LONG   ret;\r
+       int retval;\r
+       DWORD  read_length = DEFAULT_BUFER_SIZE;\r
+\r
+       ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,IBBUS_SERV_KEY,0,KEY_SET_VALUE | KEY_QUERY_VALUE ,reg_handle);\r
+       if (ERROR_SUCCESS != ret)\r
+       {\r
+               printf("reg_ibbus_pkey_show error = %d\n",GetLastError());\r
+               return 0;\r
+       }       \r
+\r
+       do\r
+       {\r
+               ret = RegQueryValueEx(*reg_handle,"PartitionKey",NULL,NULL,(LPBYTE)partKey,&read_length);\r
+               if (ERROR_MORE_DATA == ret)\r
+               {\r
+                       printf("reg_ibbus_pkey_show : more buffer space required\n");\r
+                       retval = 0;\r
+                       break;\r
+               }\r
+\r
+               if (ERROR_SUCCESS != ret)\r
+               {\r
+                       printf("RegQueryValueEx : Error %d\n",ret);\r
+                       retval = 0;\r
+                       break;\r
+               }\r
+               retval = (int)read_length;\r
+               if(retval > 4)\r
+               {\r
+                       if(show)\r
+                               printf("Existing Pkey(s): %s\n",partKey);\r
+               }\r
+               else\r
+                       retval = 0;\r
+       }\r
+       while(FALSE);\r
+       return retval;\r
+}\r
+\r
+static boolean_t reg_ibbus_print_pkey()\r
+{\r
+       int result;\r
+       char pkeyBuf[DEFAULT_BUFER_SIZE];\r
+       HKEY hreg = NULL;\r
+\r
+       result = reg_ibbus_pkey_show(TRUE,(char*)pkeyBuf,&hreg);\r
+       if(hreg)\r
+               RegCloseKey( hreg );\r
+\r
+       if (result < 4)\r
+       {\r
+               printf("No configured pkey found\n");\r
+               return FALSE;\r
+       }\r
+       return TRUE;\r
+}\r
+\r
+static int reg_ibbus_pkey_add(const uint16_t *pkeys, uint16_t pkey_num,OUT pkey_array_t *pkey)\r
+{\r
+       char partKey[DEFAULT_BUFER_SIZE];\r
+       char tmp[10];\r
+       HKEY reg_handle;\r
+       LONG   ret;\r
+       int cnt;\r
+       int retval = 0;\r
+       uint16_t i = 0;\r
+       DWORD  read_length;\r
+\r
+       read_length = reg_ibbus_pkey_show(FALSE,(char*)partKey,&reg_handle);\r
+\r
+       if (read_length < 4)\r
+       {\r
+               /* empty string read, simply write to registry */\r
+               cnt = sprintf(partKey,"0x%04X",pkeys[0]);\r
+               pkey->pkey_array[pkey->pkey_num] = pkeys[0];\r
+               pkey->pkey_num++;\r
+               i = 1;\r
+       }\r
+       else\r
+       {\r
+               /* update the existed registry list */\r
+               cnt = (int)strlen(partKey);\r
+               i = 0;\r
+       }       \r
+\r
+       for ( ;i < pkey_num; i++)\r
+       {\r
+               sprintf(tmp,"0x%04X",pkeys[i]);\r
+               if (strstr(partKey,tmp))\r
+               {\r
+                       continue;\r
+               }\r
+               pkey->pkey_array[pkey->pkey_num] = pkeys[i];\r
+               pkey->pkey_num++;\r
+               cnt += sprintf(partKey + cnt,",0x%04X",pkeys[i]);\r
+       }\r
+       cnt += sprintf(partKey + cnt,"\0");\r
+\r
+       if(pkey->pkey_num)\r
+       {\r
+               ret = RegSetValueEx(reg_handle,"PartitionKey",0,REG_SZ,(BYTE*)partKey, (DWORD)cnt);\r
+               if (ERROR_SUCCESS != ret)\r
+               {\r
+                       printf("reg_ibbus_pkey_add RegSetValueEx error = %d\n",GetLastError());\r
+                       retval = 1;\r
+               }\r
+       }\r
+       else\r
+               printf("No pkey to add\n");\r
+       RegCloseKey( reg_handle );\r
+       return retval;\r
+}\r
+\r
+static int reg_ibbus_pkey_rem(const unsigned __int16 *pkeys, unsigned short pkey_num,OUT pkey_array_t *pkey)\r
+{\r
+       char partKey[DEFAULT_BUFER_SIZE];\r
+       char newKey[DEFAULT_BUFER_SIZE] = {'\0'};\r
+\r
+       HKEY reg_handle;\r
+       LONG   ret;\r
+       DWORD  read_length;\r
+       int converted,cnt;\r
+       unsigned __int16 cur_pkey;\r
+       int retval = 0;\r
+       unsigned short i = 0;\r
+       char seps[] = ",";\r
+       char *token;\r
+       boolean_t found2remove;\r
+\r
+       read_length = reg_ibbus_pkey_show(FALSE,(char*)partKey,&reg_handle);\r
+       do\r
+       {\r
+               if (read_length < 4)\r
+               {\r
+                       /* empty string read, nothing to delete */\r
+                       printf("No pkey configured - nothing to remove\n");\r
+                       retval = 1;\r
+                       break;\r
+               }\r
+\r
+               token = strtok(partKey,seps);\r
+               cnt = 0;\r
+               while(token)\r
+               {\r
+                       found2remove = FALSE;\r
+                       converted = sscanf(token,"0x%X",&cur_pkey);\r
+                       if(! converted || (converted == EOF))\r
+                       {\r
+                               printf("invalid registry format\n");\r
+                               retval = 1;\r
+                               break;\r
+                       }\r
+                       for (i = 0; i < pkey_num; i++)\r
+                       {\r
+                               found2remove = (boolean_t)(cur_pkey == pkeys[i]);\r
+                               if(found2remove)\r
+                                       break;\r
+                       }\r
+                       \r
+                       if(found2remove)\r
+                       {\r
+                               pkey->pkey_num++;\r
+                       }\r
+                       else\r
+                       {\r
+                               if(!cnt)\r
+                                       cnt += sprintf(newKey + cnt,"0x%04X",cur_pkey);\r
+                               else\r
+                                       cnt += sprintf(newKey + cnt,",0x%04X",cur_pkey);\r
+                       }\r
+                       token = strtok(NULL,seps);\r
+               }\r
+\r
+               if(! pkey->pkey_num)\r
+               {\r
+                       /* nothing to delete */\r
+                       printf("No pkey found to remove\n");\r
+                       retval = 1;\r
+                       break;\r
+               }\r
+\r
+               ret = RegSetValueEx(reg_handle,"PartitionKey",0,REG_SZ,(BYTE*)newKey, (DWORD)strlen(newKey));\r
+               if (ERROR_SUCCESS != ret)\r
+               {\r
+                       printf("reg_ibbus_pkey_add RegSetValueEx error = %d\n",GetLastError());\r
+                       retval = 1;\r
+                       break;\r
+               }\r
+       }\r
+       while(FALSE);\r
+\r
+       RegCloseKey( reg_handle );\r
+       return retval;\r
+}\r
+\r
+int send_create_pdo_req(pkey_array_t *pkeys)\r
+{\r
+       HANDLE hKernelLib;\r
+       DWORD           bytesReturned;\r
+\r
+       hKernelLib =\r
+               CreateFile(\r
+               "\\\\.\\ibal",\r
+               GENERIC_READ | GENERIC_WRITE,\r
+               FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode none\r
+               NULL,                               // no security\r
+               OPEN_EXISTING,\r
+               FILE_ATTRIBUTE_NORMAL,\r
+               NULL                                // no template\r
+               );\r
+\r
+       if (hKernelLib == INVALID_HANDLE_VALUE)\r
+       {\r
+               printf("failed to open the kernel device : error = %d\n",GetLastError());\r
+               return 1;\r
+       }\r
+\r
+       if (! DeviceIoControl(hKernelLib,\r
+                                                 UAL_REQ_CREATE_PDO,\r
+                                                 pkeys,sizeof(pkey_array_t),\r
+                                                 NULL,0,\r
+                                                 &bytesReturned,\r
+                                                 NULL))\r
+       {\r
+               printf("send_create_pdo_req failed error %d\n",GetLastError());\r
+               CloseHandle(hKernelLib);\r
+               return 1;\r
+       }\r
+       CloseHandle(hKernelLib);\r
+       return 0;\r
+}\r
+\r
+boolean_t reg_pkey_operation(const REQUEST_IN *input)\r
+{\r
+       pkey_array_t pkeys;\r
+       int result;\r
+       int i;\r
+       if(!input)\r
+       {\r
+               printf("create_ipoib_pdo : invalid input parameter\n");\r
+               return FALSE;\r
+       }\r
+\r
+       RtlZeroMemory(&pkeys,sizeof(pkeys));\r
+       if(input->u.guid_pkey.action == pkey_add)\r
+               result = reg_ibbus_pkey_add((unsigned __int16*)input->u.guid_pkey.pkeys, input->u.guid_pkey.pkey_num, &pkeys);\r
+       else if(input->u.guid_pkey.action == pkey_rem)\r
+       {\r
+               result = reg_ibbus_pkey_rem((unsigned __int16*)input->u.guid_pkey.pkeys, input->u.guid_pkey.pkey_num, &pkeys);\r
+               return (boolean_t)(result == 0);\r
+       }\r
+       else if(input->u.guid_pkey.action == pkey_show)\r
+               return reg_ibbus_print_pkey();\r
+\r
+       if(0 == result)\r
+       {\r
+               if(pkeys.pkey_num)\r
+                       return (boolean_t)( 0 == send_create_pdo_req(&pkeys));\r
+       }\r
+       return FALSE;\r
+}\r
+\r
+int prepare_reg_pkey_input(OUT REQUEST_IN *input,char* cmd[],int num)\r
+{\r
+       int i;\r
+       input->u.guid_pkey.pkey_num = 0;\r
+\r
+       if(strstr(cmd[1],"add"))\r
+               input->u.guid_pkey.action = pkey_add;\r
+       else if(strstr(cmd[1],"rem"))\r
+               input->u.guid_pkey.action = pkey_rem;\r
+       else if(strstr(cmd[1],"show"))\r
+       {\r
+               input->u.guid_pkey.action = pkey_show;\r
+               return 1;\r
+       }\r
+       else\r
+       {\r
+               printf("invalid command %s\n",cmd[1]);\r
+               return 0;\r
+       }\r
+\r
+       if(num < 3)\r
+       {\r
+               printf("invalid command %s\n",cmd[1]);\r
+               return 0;\r
+       }\r
+       for( i = 2; i < num; i++)\r
+       {\r
+               if (strstr(cmd[i],"0x"))\r
+                       sscanf(cmd[i],"0x%x",&input->u.guid_pkey.pkeys[input->u.guid_pkey.pkey_num]);\r
+               else\r
+                       sscanf(cmd[i],"%x",&input->u.guid_pkey.pkeys[input->u.guid_pkey.pkey_num]);\r
+\r
+               input->u.guid_pkey.pkey_num++;\r
+       }\r
+       return 1;\r
+}\r
+\r
+void partition_operation(char* cmd[],int num)\r
+{\r
+       REQUEST_IN input;\r
+\r
+       if (! prepare_reg_pkey_input(&input, cmd, num))\r
+               return;\r
+\r
+       if(! reg_pkey_operation(&input))\r
+               printf("Pkey operation failed\n");      \r
+       else\r
+               printf("Done...\n");\r
+}\r
+\r
+int32_t __cdecl\r
+main(\r
+       int32_t argc,\r
+       char* argv[])\r
+{\r
+       BOOLEAN showHelp = FALSE;\r
+       if (argc < 2)\r
+       {\r
+               showHelp = TRUE;\r
+       }\r
+       else\r
+       {\r
+               if(!_stricmp(argv[1], "-h") || !_stricmp(argv[1], "-help"))\r
+               {\r
+                       showHelp = TRUE;\r
+               }\r
+               else\r
+                       partition_operation(argv,argc);\r
+       }\r
+       if (showHelp)\r
+               show_help();\r
+}\r
+\r
+\r
diff --git a/tools/part_man/user/part_man.rc b/tools/part_man/user/part_man.rc
new file mode 100644 (file)
index 0000000..d095f33
--- /dev/null
@@ -0,0 +1,15 @@
+#include <oib_ver.h>\r
+\r
+#define VER_FILETYPE                           VFT_APP\r
+#define VER_FILESUBTYPE                                VFT2_UNKNOWN\r
+\r
+#ifdef _DEBUG_\r
+#define VER_FILEDESCRIPTION_STR                "Partition manager application(Debug)"\r
+#else\r
+#define VER_FILEDESCRIPTION_STR                "Partition manager application"\r
+#endif\r
+\r
+#define VER_INTERNALNAME_STR           "part_man.exe"\r
+#define VER_ORIGINALFILENAME_STR       "part_man.exe"\r
+\r
+#include <common.ver>
\ No newline at end of file
index 8c664e5..b5fa667 100644 (file)
@@ -171,7 +171,7 @@ ipoib_create_adapter(
 \r
        IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_INIT,\r
                        ("Port %016I64x (CA %016I64x port %d) initializing\n",\r
-                       p_adapter->guids.port_guid, p_adapter->guids.ca_guid,\r
+                       p_adapter->guids.port_guid.guid, p_adapter->guids.ca_guid,\r
                        p_adapter->guids.port_num) );\r
 \r
        cl_status = cl_obj_init( &p_adapter->obj, CL_DESTROY_SYNC,\r
@@ -343,7 +343,7 @@ adapter_init(
 \r
        /* Validate the port GUID and generate the MAC address. */\r
        status =\r
-               ipoib_mac_from_guid( p_adapter->guids.port_guid, &p_adapter->mac );\r
+               ipoib_mac_from_guid( p_adapter->guids.port_guid.guid, &p_adapter->mac );\r
        if( status != IB_SUCCESS )\r
        {\r
                IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
@@ -530,7 +530,7 @@ __ipoib_pnp_cb(
        case IB_PNP_PORT_ADD:\r
                CL_ASSERT( !p_pnp_rec->context );\r
                /* Only process our port GUID. */\r
-               if( p_pnp_rec->guid != p_adapter->guids.port_guid )\r
+               if( p_pnp_rec->guid != p_adapter->guids.port_guid.guid )\r
                {\r
                        status = IB_NOT_DONE;\r
                        break;\r
index c10dfdc..48dacbe 100644 (file)
@@ -767,7 +767,7 @@ ipoib_halt(
 \r
        IPOIB_PRINT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_INIT,\r
                        ("Port %016I64x (CA %016I64x port %d) halting\n",\r
-                       p_adapter->guids.port_guid, p_adapter->guids.ca_guid,\r
+                       p_adapter->guids.port_guid.guid, p_adapter->guids.ca_guid,\r
                        p_adapter->guids.port_num) );\r
 \r
        ipoib_destroy_adapter( p_adapter );\r
@@ -2330,13 +2330,19 @@ ipoib_reg_addrs(
 \r
        IPOIB_ENTER( IPOIB_DBG_OID );\r
 \r
+       if(p_adapter->guids.port_guid.pkey != IB_DEFAULT_PKEY)\r
+       {\r
+               IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR,IPOIB_DBG_ERROR,\r
+               ("ATS Service available for default pkey only\n"));      \r
+               return;\r
+       }\r
        port_num = p_adapter->guids.port_num;\r
 \r
        /* Setup our service call with things common to all calls */\r
        cl_memset( &ib_service, 0, sizeof(ib_service) );\r
 \r
        /* BUGBUG Only register local subnet GID prefix for now */\r
-       ib_gid_set_default( &port_gid, p_adapter->guids.port_guid );\r
+       ib_gid_set_default( &port_gid, p_adapter->guids.port_guid.guid );\r
        ib_service.svc_rec.service_gid          = port_gid;\r
 \r
        ib_service.svc_rec.service_pkey         = IB_DEFAULT_PKEY;\r
@@ -2347,7 +2353,7 @@ ipoib_reg_addrs(
        strcpy( (char *)ib_service.svc_rec.service_name, ATS_NAME );\r
 \r
        /* IP Address in question will be put in below */\r
-       ib_service.port_guid            = p_adapter->guids.port_guid;\r
+       ib_service.port_guid            = p_adapter->guids.port_guid.guid;\r
        ib_service.timeout_ms           = p_adapter->params.sa_timeout;\r
        ib_service.retry_cnt            = p_adapter->params.sa_retry_cnt;\r
 \r
index e60cf2d..465817d 100644 (file)
@@ -312,13 +312,13 @@ ipoib_endpt_queue(
 \r
        cl_memclr( &path, sizeof(ib_path_rec_t) );\r
        path.dgid = p_endpt->dgid;\r
-       ib_gid_set_default( &path.sgid, p_port->p_adapter->guids.port_guid );\r
+       ib_gid_set_default( &path.sgid, p_port->p_adapter->guids.port_guid.guid );\r
        path.num_path = 0x1;\r
 \r
        cl_memclr( &query, sizeof(ib_query_req_t) );\r
        query.query_type = IB_QUERY_USER_DEFINED;\r
        query.p_query_input = &info;\r
-       query.port_guid = p_port->p_adapter->guids.port_guid;\r
+       query.port_guid = p_port->p_adapter->guids.port_guid.guid;\r
        query.timeout_ms = p_port->p_adapter->params.sa_timeout;\r
        query.retry_cnt = p_port->p_adapter->params.sa_retry_cnt;\r
 \r
index 7994a5d..06c568a 100644 (file)
@@ -140,7 +140,7 @@ __ibat_get_ports(
        {\r
                pAdapter = CONTAINING_RECORD( pItem, ipoib_adapter_t, entry );\r
                pOut->Ports[pOut->NumPorts].CaGuid = pAdapter->guids.ca_guid;\r
-               pOut->Ports[pOut->NumPorts].PortGuid = pAdapter->guids.port_guid;\r
+               pOut->Ports[pOut->NumPorts].PortGuid = pAdapter->guids.port_guid.guid;\r
                pOut->Ports[pOut->NumPorts].PortNum = pAdapter->guids.port_num;\r
                pOut->NumPorts++;\r
 \r
@@ -210,7 +210,7 @@ __ibat_get_ips(
                pItem = cl_qlist_next( pItem ) )\r
        {\r
                pAdapter = CONTAINING_RECORD( pItem, ipoib_adapter_t, entry );\r
-               if( PortGuid && pAdapter->guids.port_guid != PortGuid )\r
+               if( PortGuid && pAdapter->guids.port_guid.guid != PortGuid )\r
                        continue;\r
 \r
                cl_obj_lock( &pAdapter->obj );\r
@@ -300,7 +300,7 @@ __ibat_mac_to_gid(
                pItem = cl_qlist_next( pItem ) )\r
        {\r
                pAdapter = CONTAINING_RECORD( pItem, ipoib_adapter_t, entry );\r
-               if( pIn->PortGuid != pAdapter->guids.port_guid )\r
+               if( pIn->PortGuid != pAdapter->guids.port_guid.guid )\r
                        continue;\r
 \r
                /* Found the port - lookup the MAC. */\r
@@ -394,7 +394,7 @@ __ibat_ip_to_port(
                        if (!memcmp( &pIn->Address.Address[12], pAddr->address.as_bytes, IPV4_ADDR_SIZE))\r
                        {\r
                                pOut->Port.CaGuid = pAdapter->guids.ca_guid;\r
-                               pOut->Port.PortGuid = pAdapter->guids.port_guid;\r
+                               pOut->Port.PortGuid = pAdapter->guids.port_guid.guid;\r
                                pOut->Port.PortNum = pAdapter->guids.port_num;\r
                                pIrp->IoStatus.Information = sizeof(IOCTL_IBAT_IP_TO_PORT_OUT);\r
                                status = STATUS_SUCCESS;\r
@@ -584,3 +584,4 @@ __ipoib_dispatch(
        return status;\r
 }\r
 \r
+\r
index 3599729..0b3efa6 100644 (file)
@@ -793,6 +793,8 @@ __ib_mgr_init(
        uint64_t                        vaddr;\r
        net32_t                         rkey;\r
        ib_qp_attr_t            qp_attr;\r
+       ib_ca_attr_t            *ca_attr;\r
+       uint32_t                        ca_size;\r
 \r
        IPOIB_ENTER( IPOIB_DBG_INIT );\r
 \r
@@ -810,6 +812,52 @@ __ib_mgr_init(
                return status;\r
        }\r
 \r
+       /* Query the CA for Pkey table */\r
+       status = p_port->p_adapter->p_ifc->query_ca(p_port->ib_mgr.h_ca, NULL, &ca_size);\r
+       if(status != IB_INSUFFICIENT_MEMORY)\r
+       {\r
+               IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
+                       ("ib_query_ca failed\n"));\r
+                       return status;\r
+       }\r
+\r
+       ca_attr = (ib_ca_attr_t*)cl_zalloc(ca_size);\r
+       if      (!ca_attr)\r
+       {\r
+               IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
+                       ("cl_zalloc can't allocate %d\n",ca_size));\r
+               return IB_INSUFFICIENT_RESOURCES;\r
+       }\r
+\r
+       status = p_port->p_adapter->p_ifc->query_ca(p_port->ib_mgr.h_ca, ca_attr,&ca_size);     \r
+       if( status != IB_SUCCESS )\r
+       {\r
+               cl_free(ca_attr);\r
+               IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
+                       ("ib_query_ca returned %s\n", \r
+                       p_port->p_adapter->p_ifc->get_err_str( status )) );\r
+               return status;\r
+       }\r
+       if( ca_attr->p_port_attr->link_state == IB_LINK_ACTIVE)\r
+       {\r
+               uint16_t index;\r
+               CL_ASSERT(ca_attr->p_port_attr->p_pkey_table[0] == IB_DEFAULT_PKEY);\r
+               for(index = 0; index < ca_attr->p_port_attr->num_pkeys; index++)\r
+               {\r
+                       if(p_port->p_adapter->guids.port_guid.pkey == ca_attr->p_port_attr->p_pkey_table[index])\r
+                               break;\r
+               }\r
+               if(index >= ca_attr->p_port_attr->num_pkeys)\r
+               {\r
+                       IPOIB_PRINT_EXIT( TRACE_LEVEL_ERROR, IPOIB_DBG_ERROR,\r
+                       ("Pkey table is invalid, index not found\n"));\r
+                   return IB_NOT_FOUND;\r
+               }\r
+               p_port->pkey_index = index;\r
+               IPOIB_PRINT_EXIT( TRACE_LEVEL_INFORMATION, IPOIB_DBG_IB,\r
+                       ("for PKEY = 0x%04X got index = %d\n",p_port->p_adapter->guids.port_guid.pkey,index));\r
+       }\r
+       cl_free(ca_attr);\r
        /* Allocate the PD. */\r
        status = p_port->p_adapter->p_ifc->alloc_pd(\r
                p_port->ib_mgr.h_ca, IB_PDT_UD, p_port, &p_port->ib_mgr.h_pd );\r
@@ -3309,7 +3357,7 @@ __send_mgr_filter_dhcp(
 \r
                CL_ASSERT( p_cid[1] == 21 );\r
                p_cid[23]= DHCP_OPT_END;\r
-               ib_gid_set_default( &gid, p_port->p_adapter->guids.port_guid );\r
+               ib_gid_set_default( &gid, p_port->p_adapter->guids.port_guid.guid );\r
                cl_memcpy( &p_cid[7], &gid, sizeof(ib_gid_t) );\r
                cl_memcpy( &p_cid[3], &p_port->ib_mgr.qpn, sizeof(p_port->ib_mgr.qpn) );                \r
                p_ib_dhcp->htype = DHCP_HW_TYPE_IB;\r
@@ -3409,7 +3457,7 @@ __send_mgr_filter_arp(
        p_ib_arp->op = p_arp->op;\r
        p_ib_arp->src_hw.flags_qpn = p_port->ib_mgr.qpn;\r
        ib_gid_set_default( &p_ib_arp->src_hw.gid,\r
-               p_port->p_adapter->guids.port_guid );\r
+               p_port->p_adapter->guids.port_guid.guid );\r
        p_ib_arp->src_ip = p_arp->src_ip;\r
        if( cl_memcmp( &p_arp->dst_hw, &null_hw, sizeof(mac_addr_t) ) )\r
        {\r
@@ -3584,7 +3632,7 @@ __build_send_desc(
        p_desc->wr.dgrm.ud.remote_qp = p_desc->p_endpt->qpn;\r
        p_desc->wr.dgrm.ud.remote_qkey = p_port->ib_mgr.bcast_rec.qkey;\r
        p_desc->wr.dgrm.ud.h_av = p_desc->p_endpt->h_av;\r
-       p_desc->wr.dgrm.ud.pkey_index = 0;\r
+       p_desc->wr.dgrm.ud.pkey_index = p_port->pkey_index;\r
        p_desc->wr.dgrm.ud.rsvd = NULL;\r
 \r
        /* Store context in our reserved area of the packet. */\r
@@ -4683,7 +4731,7 @@ ipoib_port_up(
        cl_memclr( &query, sizeof(ib_query_req_t) );\r
        query.query_type = IB_QUERY_USER_DEFINED;\r
        query.p_query_input = &info;\r
-       query.port_guid = p_port->p_adapter->guids.port_guid;\r
+       query.port_guid = p_port->p_adapter->guids.port_guid.guid;\r
        query.timeout_ms = p_port->p_adapter->params.sa_timeout;\r
        query.retry_cnt = p_port->p_adapter->params.sa_retry_cnt;\r
        query.query_context = p_port;\r
@@ -4721,7 +4769,7 @@ __endpt_mgr_add_local(
 \r
        IPOIB_ENTER( IPOIB_DBG_INIT );\r
 \r
-       ib_gid_set_default( &gid, p_port->p_adapter->guids.port_guid );\r
+       ib_gid_set_default( &gid, p_port->p_adapter->guids.port_guid.guid );\r
        p_endpt = ipoib_endpt_create(\r
                &gid, p_port_info->base_lid, p_port->ib_mgr.qpn );\r
        if( !p_endpt )\r
@@ -4894,10 +4942,13 @@ __port_get_bcast(
        cl_memclr( &member_rec, sizeof(ib_member_rec_t) );\r
        member_rec.mgid = bcast_mgid_template;\r
 \r
+    member_rec.mgid.raw[4] = (uint8_t) p_port->p_adapter->guids.port_guid.pkey ;\r
+       member_rec.mgid.raw[5] = (uint8_t) (p_port->p_adapter->guids.port_guid.pkey >> 8);\r
+       member_rec.pkey = p_port->p_adapter->guids.port_guid.pkey;\r
        cl_memclr( &query, sizeof(ib_query_req_t) );\r
        query.query_type = IB_QUERY_USER_DEFINED;\r
        query.p_query_input = &info;\r
-       query.port_guid = p_port->p_adapter->guids.port_guid;\r
+       query.port_guid = p_port->p_adapter->guids.port_guid.guid;\r
        query.timeout_ms = p_port->p_adapter->params.sa_timeout;\r
        query.retry_cnt = p_port->p_adapter->params.sa_retry_cnt;\r
        query.query_context = p_port;\r
@@ -5031,14 +5082,14 @@ __port_join_bcast(
        /* We specify our port GID for the join operation. */\r
        mcast_req.member_rec.port_gid.unicast.prefix = IB_DEFAULT_SUBNET_PREFIX;\r
        mcast_req.member_rec.port_gid.unicast.interface_id =\r
-               p_port->p_adapter->guids.port_guid;\r
+               p_port->p_adapter->guids.port_guid.guid;\r
 \r
        mcast_req.mcast_context = p_port;\r
        mcast_req.pfn_mcast_cb = __bcast_cb;\r
        mcast_req.timeout_ms = p_port->p_adapter->params.sa_timeout;\r
        mcast_req.retry_cnt = p_port->p_adapter->params.sa_retry_cnt;\r
-       mcast_req.port_guid = p_port->p_adapter->guids.port_guid;\r
-       mcast_req.pkey_index = 0;\r
+       mcast_req.port_guid = p_port->p_adapter->guids.port_guid.guid;\r
+       mcast_req.pkey_index = p_port->pkey_index;\r
 \r
        if( ib_member_get_state( mcast_req.member_rec.scope_state ) !=\r
                IB_MC_REC_STATE_FULL_MEMBER )\r
@@ -5085,8 +5136,10 @@ __port_create_bcast(
         * We specify the MGID since we don't want the SA to generate it for us.\r
         */\r
        mcast_req.member_rec.mgid = bcast_mgid_template;\r
+       mcast_req.member_rec.mgid.raw[4] = (uint8_t) p_port->p_adapter->guids.port_guid.pkey; \r
+       mcast_req.member_rec.mgid.raw[5] = (uint8_t) (p_port->p_adapter->guids.port_guid.pkey >> 8);\r
        ib_gid_set_default( &mcast_req.member_rec.port_gid,\r
-               p_port->p_adapter->guids.port_guid );\r
+               p_port->p_adapter->guids.port_guid.guid );\r
        /*\r
         * IPOIB spec requires that the QKEY have the MSb set so that the QKEY\r
         * from the QP is used rather than the QKEY in the send WR.\r
@@ -5096,7 +5149,7 @@ __port_create_bcast(
        mcast_req.member_rec.mtu =\r
                (IB_PATH_SELECTOR_EXACTLY << 6) | IB_MTU_LEN_2048;\r
 \r
-       mcast_req.member_rec.pkey = IB_DEFAULT_PKEY;\r
+       mcast_req.member_rec.pkey = p_port->p_adapter->guids.port_guid.pkey;\r
 \r
        mcast_req.member_rec.sl_flow_hop = ib_member_set_sl_flow_hop( 0, 0, 0 );\r
        mcast_req.member_rec.scope_state =\r
@@ -5106,8 +5159,8 @@ __port_create_bcast(
        mcast_req.pfn_mcast_cb = __bcast_cb;\r
        mcast_req.timeout_ms = p_port->p_adapter->params.sa_timeout;\r
        mcast_req.retry_cnt = p_port->p_adapter->params.sa_retry_cnt;\r
-       mcast_req.port_guid = p_port->p_adapter->guids.port_guid;\r
-       mcast_req.pkey_index = 0;\r
+       mcast_req.port_guid = p_port->p_adapter->guids.port_guid.guid;\r
+       mcast_req.pkey_index = p_port->pkey_index;\r
 \r
        /* reference the object for the multicast join request. */\r
        ipoib_port_ref( p_port, ref_join_bcast );\r
@@ -5362,9 +5415,9 @@ __ib_mgr_activate(
        }\r
 \r
        /* Move the QP to RTS. */\r
-       dgrm_info.port_guid = p_port->p_adapter->guids.port_guid;\r
+       dgrm_info.port_guid = p_port->p_adapter->guids.port_guid.guid;\r
        dgrm_info.qkey = p_port->ib_mgr.bcast_rec.qkey;\r
-       dgrm_info.pkey_index = 0;\r
+       dgrm_info.pkey_index = p_port->pkey_index;\r
        status = p_port->p_adapter->p_ifc->init_dgrm_svc( p_port->ib_mgr.h_qp, &dgrm_info );\r
        if( status != IB_SUCCESS )\r
        {\r
@@ -5464,9 +5517,9 @@ ipoib_port_join_mcast(
        mcast_req.pfn_mcast_cb = __mcast_cb;\r
        mcast_req.timeout_ms = p_port->p_adapter->params.sa_timeout;\r
        mcast_req.retry_cnt = p_port->p_adapter->params.sa_retry_cnt;\r
-       mcast_req.port_guid = p_port->p_adapter->guids.port_guid;\r
-       mcast_req.pkey_index = 0;\r
-\r
+       mcast_req.port_guid = p_port->p_adapter->guids.port_guid.guid;\r
+       mcast_req.pkey_index = p_port->pkey_index;\r
+       mcast_req.member_rec.pkey = p_port->p_adapter->guids.port_guid.pkey;\r
        /*\r
         * Create the endpoint and insert it in the port.  Since we don't wait for\r
         * the mcast SA operations to complete before returning from the multicast\r
@@ -5661,3 +5714,4 @@ __leave_error_mcast_cb(
 \r
 \r
 \r
+\r
index 4fbc5a2..0018d9b 100644 (file)
@@ -506,6 +506,7 @@ typedef struct _ipoib_port
        atomic32_t                              endpt_rdr;\r
 \r
        atomic32_t                              hdr_idx;\r
+       uint16_t                                pkey_index;\r
        ipoib_hdr_t                             hdr[1]; /* Must be last! */\r
 \r
 }      ipoib_port_t;\r