[MLX4] return different MLX4 bus locations for several cards in multi-homed machine...
authorleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 17 Jun 2009 13:47:59 +0000 (13:47 +0000)
committerleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 17 Jun 2009 13:47:59 +0000 (13:47 +0000)
One can see on multi-homed computers, that mlx4_bus creates all its children (mlx4_hca, IPoIB et al) with built-in location string "MLX4 Bus 0" which complicates differentiation between them.
This patch makes mlx4_bus to return a location string of the structure "MLX4 bus x, device y, function z", where x,y,z is HCA card's PCI bus location.

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

hw/mlx4/kernel/bus/drv/drv.c
hw/mlx4/kernel/bus/drv/drv.h
hw/mlx4/kernel/bus/drv/pdo.c
hw/mlx4/kernel/bus/net/mlx4.h
hw/mlx4/kernel/inc/l2w.h

index 568685b..f88b2d1 100644 (file)
@@ -185,7 +185,7 @@ Routine Description:
                // the list locked for enumeration.  The enumeration lock applies only\r
                // to enumeration, not addition or removal.\r
                //\r
-               status = create_pdo(Device, HardwareIds, DeviceDescription, SerialNo);\r
+               status = create_pdo(Device, HardwareIds, DeviceDescription, SerialNo, p_fdo->pci_dev.location);\r
        }\r
 \r
        WdfFdoUnlockStaticChildListFromIteration(Device);\r
@@ -749,6 +749,9 @@ EvtPrepareHardware(
        NTSTATUS status;\r
        PFDO_DEVICE_DATA p_fdo  = FdoGetData(Device);\r
        struct pci_dev *pdev = &p_fdo->pci_dev;\r
+       struct mlx4_dev *mdev;\r
+       WDFMEMORY  memory;\r
+       WDF_OBJECT_ATTRIBUTES  attributes;\r
 \r
        MLX4_ENTER(MLX4_DBG_DRV);\r
 \r
@@ -761,19 +764,43 @@ EvtPrepareHardware(
 \r
        // start the card\r
        status = __start_card(Device, p_fdo );\r
+       if( !NT_SUCCESS( status ) ) \r
+               goto err;\r
+       mdev = pdev->dev;\r
 \r
        // get VPD \r
-       \r
+       status = pci_get_vpd( &pdev->bus_pci_ifc, \r
+               &pdev->pci_cfg_space, &pdev->vpd, &pdev->vpd_size );\r
+       if( !NT_SUCCESS( status ) )\r
+       {\r
+               MLX4_PRINT_EV(TRACE_LEVEL_ERROR, MLX4_DBG_DRV, \r
+                       ("pci_get_vpd failed,  status=0x%x\n", status));\r
+               goto err;\r
+       }\r
+\r
+       // get card location\r
+       WDF_OBJECT_ATTRIBUTES_INIT(&attributes);\r
+       attributes.ParentObject = Device;\r
+       status = WdfDeviceAllocAndQueryProperty( Device,\r
+               DevicePropertyLocationInformation, NonPagedPool,\r
+               &attributes, &memory );\r
        if( NT_SUCCESS( status ) ) {\r
-               status = pci_get_vpd( &pdev->bus_pci_ifc, \r
-                       &pdev->pci_cfg_space, &pdev->vpd, &pdev->vpd_size );\r
-               if( !NT_SUCCESS( status ) )\r
-               {\r
-                       MLX4_PRINT(TRACE_LEVEL_ERROR, MLX4_DBG_DRV, \r
-                               ("pci_get_vpd failed,  status=0x%x\n", status));\r
-                       goto err;\r
+               UCHAR *ptr;\r
+\r
+               // get location\r
+               ptr = WdfMemoryGetBuffer(memory, NULL);\r
+               status = RtlStringCbCopyW( (LPWSTR)p_fdo->pci_dev.location, \r
+                       sizeof(p_fdo->pci_dev.location), (LPCWSTR)ptr );\r
+               WdfObjectDelete(memory);\r
+               if( !NT_SUCCESS( status ) ) {\r
+                       MLX4_PRINT_EV(TRACE_LEVEL_ERROR, MLX4_DBG_DRV, \r
+                               ("Failed to move location string '%S',  status=0x%x\n", ptr, status));\r
                }\r
        }\r
+       else {\r
+               MLX4_PRINT_EV(TRACE_LEVEL_ERROR, MLX4_DBG_DRV, \r
+                       ("WdfDeviceAllocAndQueryProperty failed,  status=0x%x\n", status));\r
+       }\r
        \r
 err:\r
        MLX4_EXIT( MLX4_DBG_DRV );\r
@@ -798,6 +825,7 @@ EvtReleaseHardware(
 {\r
        PFDO_DEVICE_DATA p_fdo  = FdoGetData(Device);\r
        struct pci_dev *pdev = &p_fdo->pci_dev;\r
+       int i;\r
 \r
        UNUSED_PARAM(ResourcesTranslated);\r
 \r
@@ -810,6 +838,12 @@ EvtReleaseHardware(
        }\r
        __stop_card( p_fdo );\r
        __put_resources( p_fdo );\r
+       for (i=0; i<MAX_HCA_CARDS; ++i) {\r
+               if ( g.p_fdo[i] == p_fdo) {\r
+                       g.p_fdo[i] = NULL;\r
+                       break;\r
+               }\r
+       }\r
 \r
        MLX4_EXIT( MLX4_DBG_DRV );\r
        return STATUS_SUCCESS;\r
@@ -902,6 +936,7 @@ Return Value:
        PFDO_DEVICE_DATA                                p_fdo;\r
        PNP_BUS_INFORMATION                             busInfo;\r
        WDF_PNPPOWER_EVENT_CALLBACKS    Callbacks;\r
+       int i;\r
 \r
        UNREFERENCED_PARAMETER(Driver);\r
 \r
@@ -950,9 +985,13 @@ Return Value:
        //\r
        p_fdo = FdoGetData(device);\r
        RtlZeroMemory(p_fdo, sizeof(FDO_DEVICE_DATA));\r
-       p_fdo->FdoDevice = device;\r
-       if (!g.p_fdo)\r
-               g.p_fdo = p_fdo;\r
+       p_fdo->FdoDevice = device; \r
+       for (i=0; i<MAX_HCA_CARDS; ++i) {\r
+               if (!g.p_fdo[i]) {\r
+                       g.p_fdo[i] = p_fdo;\r
+                       break;\r
+               }\r
+       }\r
 \r
        //\r
        // Init the BusIsr data\r
index 3a425cc..1b63fb7 100644 (file)
@@ -234,7 +234,8 @@ create_pdo(
        __in WDFDEVICE  Device,\r
        __in PWCHAR     HardwareIds,\r
        __in PWCHAR     DeviceDescription,\r
-       __in ULONG      SerialNo\r
+       __in ULONG      SerialNo,\r
+       __in PWCHAR     Location\r
 );\r
 \r
 \r
index 48ec280..2144404 100644 (file)
@@ -46,7 +46,8 @@ create_pdo(
        __in WDFDEVICE  Device,\r
        __in PWCHAR     HardwareIds,\r
        __in PWCHAR     DeviceDescription,\r
-       __in ULONG      SerialNo\r
+       __in ULONG      SerialNo,\r
+       __in PWCHAR     Location\r
 )\r
 /*++\r
 \r
@@ -71,9 +72,9 @@ Return Value:
        WDF_DEVICE_PNP_CAPABILITIES pnpCaps;\r
        WDF_DEVICE_POWER_CAPABILITIES powerCaps;\r
        UNICODE_STRING compatId;\r
-       DECLARE_CONST_UNICODE_STRING(deviceLocation, L"MLX4 Bus 0");\r
        UNICODE_STRING deviceId;\r
        DECLARE_UNICODE_STRING_SIZE(buffer, MAX_ID_LEN);\r
+       DECLARE_UNICODE_STRING_SIZE(deviceLocation, MAX_ID_LEN);\r
 \r
        MLX4_PRINT(TRACE_LEVEL_INFORMATION, MLX4_DBG_DRV, ("Entered CreatePdo\n"));\r
 \r
@@ -152,6 +153,11 @@ Return Value:
        // The driver can specify the driver's default locale by calling\r
        // WdfPdoInitSetDefaultLocale.\r
        //\r
+       status =  RtlUnicodeStringPrintf(&deviceLocation, L"MLX4 %s", Location+4);\r
+       if (!NT_SUCCESS(status)) {\r
+               goto Cleanup;\r
+       }\r
+\r
        status = WdfPdoInitAddDeviceText(pDeviceInit,\r
                &buffer, &deviceLocation, 0x409);\r
        if (!NT_SUCCESS(status)) {\r
index 0409ba0..d3f74cb 100644 (file)
@@ -65,6 +65,7 @@ enum mlx4_port_type {
        MLX4_PORT_TYPE_ETH      = 1 << 1,
 };
 
+#define MAX_HCA_CARDS          8
 
 #pragma warning(disable:4201) // nameless struct/union
 typedef struct _GLOBALS {
@@ -86,7 +87,7 @@ typedef struct _GLOBALS {
        int mod_interrupt_from_first;
 
        int mod_affinity;
-       PFDO_DEVICE_DATA p_fdo; // for debug purposes
+       PFDO_DEVICE_DATA p_fdo[MAX_HCA_CARDS];  // for debug purposes
 } GLOBALS;
 #pragma warning(default:4201) // nameless struct/union
 
index b1c2e40..57f8b34 100644 (file)
@@ -182,6 +182,7 @@ struct pci_dev
        volatile long                                   dpc_lock;
        PUCHAR                                                  vpd;
        int                                                             vpd_size;
+       WCHAR                                                   location[36];           /* bus+func+dev */
 #ifdef USE_WDM_INTERRUPTS
        PKINTERRUPT                                             int_obj;                /* HCA interrupt object */
        KSPIN_LOCK                                              isr_lock;               /* lock for the ISR */