[IBBUS] added support to logging to System Event Log.
authorleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 2 Jun 2009 17:44:02 +0000 (17:44 +0000)
committerleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 2 Jun 2009 17:44:02 +0000 (17:44 +0000)
CL_PRINT_TO_EVENT_LOG(_obj_,_event_id_,_msg_)
   obj - FDO of IBBUS
   event_id - EVENT_IBBUS_ANY_ERROR, EVENT_IBBUS_ANY_WARN, EVENT_IBBUS_ANY_INFO
   msg - (<format_string>[,param_list])

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

14 files changed:
core/al/al_ca.h
core/al/kernel/SOURCES
core/al/kernel/al_ci_ca.c
core/al/kernel/al_mgr.c
core/al/user/SOURCES
core/bus/kernel/SOURCES
core/bus/kernel/bus_ev_log.mc [new file with mode: 0644]
core/bus/kernel/ibbus.rc
core/complib/kernel/cl_log.c
hw/mlx4/kernel/hca/mlx4_hca.inx
hw/mthca/kernel/mthca.inx
inc/complib/cl_log.h
inc/iba/ib_ci.h
inc/kernel/iba/ib_ci_ifc.h

index 5c01343..403a0a0 100644 (file)
@@ -51,6 +51,7 @@ typedef struct _ib_ca
 #if defined(CL_KERNEL)\r
        ib_ca_handle_t                  h_um_ca;\r
        PDEVICE_OBJECT                  p_hca_dev;\r
+       PDEVICE_OBJECT                  p_fdo;\r
 #endif\r
 \r
 }      ib_ca_t;\r
index 0a80f7e..23bfebc 100644 (file)
@@ -56,12 +56,13 @@ SOURCES= ibal.rc                    \
        ..\ib_common.c                  \\r
        ..\ib_statustext.c\r
 \r
-INCLUDES=..;..\..\..\inc;..\..\..\inc\kernel;\r
+INCLUDES=..;..\..\..\inc;..\..\..\inc\kernel;..\..\bus\kernel\$O;\r
 \r
 C_DEFINES=$(C_DEFINES) -DDRIVER -DDEPRECATE_DDK_FUNCTIONS \\r
        -DEXPORT_AL_SYMBOLS\r
 \r
 TARGETLIBS= \\r
+    $(DDK_LIB_PATH)\ntstrsafe.lib \\r
        $(TARGETPATH)\*\complib.lib\r
 \r
 !IFDEF ENABLE_EVENT_TRACING\r
index b24f583..8f62030 100644 (file)
@@ -85,7 +85,8 @@ ib_api_status_t
 create_ci_ca(\r
        IN                              al_obj_t                                        *p_parent_obj,\r
        IN              const   ci_interface_t*                         p_ci,\r
-       IN              const   PDEVICE_OBJECT                          p_hca_dev\r
+       IN              const   PDEVICE_OBJECT                          p_hca_dev,\r
+       IN              const   PDEVICE_OBJECT                          p_fdo\r
        )\r
 {\r
        ib_api_status_t                 status;\r
@@ -189,8 +190,10 @@ create_ci_ca(
                return status;\r
        }\r
 \r
+\r
        /* store HCA device object into CA object */\r
        p_ci_ca->h_ca->p_hca_dev = p_hca_dev;\r
+       p_ci_ca->h_ca->p_fdo = p_fdo;\r
        \r
        /* Get a list of the port GUIDs on this CI CA. */\r
        status = get_port_info( p_ci_ca );\r
index 707e334..313a840 100644 (file)
@@ -257,7 +257,8 @@ __free_al_mgr(
 ib_api_status_t\r
 ib_register_ca(\r
        IN              const   ci_interface_t*                         p_ci,\r
-       IN              const   PDEVICE_OBJECT                          p_hca_dev\r
+       IN              const   PDEVICE_OBJECT                          p_hca_dev,\r
+       IN              const   PDEVICE_OBJECT                          p_fdo\r
        )\r
 {\r
        ib_api_status_t         status;\r
@@ -285,7 +286,7 @@ ib_register_ca(
        }\r
 \r
        /* Construct and initialize the CA structure. */\r
-       status = create_ci_ca( &gp_al_mgr->obj, p_ci, p_hca_dev );\r
+       status = create_ci_ca( &gp_al_mgr->obj, p_ci, p_hca_dev, p_fdo );\r
        if( status != IB_SUCCESS )\r
        {\r
                AL_PRINT( TRACE_LEVEL_ERROR, AL_DBG_ERROR,\r
index 037ed31..bc294a5 100644 (file)
@@ -72,7 +72,7 @@ SOURCES=\
        ..\ib_common.c                  \\r
        ..\ib_statustext.c\r
 \r
-INCLUDES=..;..\..\..\inc;..\..\..\inc\user;\r
+INCLUDES=..;..\..\..\inc;..\..\..\inc\user;;..\..\bus\kernel\$O;\r
 \r
 USER_C_FLAGS=$(USER_C_FLAGS) -DEXPORT_AL_SYMBOLS -DCL_NO_TRACK_MEM -DWPP_OLDCC\r
 \r
index d10bd1f..09d90f2 100644 (file)
@@ -10,16 +10,18 @@ ENABLE_EVENT_TRACING=1
 \r
 \r
 SOURCES= ibbus.rc              \\r
+       bus_ev_log.mc           \\r
        bus_driver.c            \\r
        bus_pnp.c                       \\r
        bus_port_mgr.c          \\r
        bus_iou_mgr.c\r
 \r
-INCLUDES=..\..\..\inc;..\..\..\inc\kernel;..\..\al;..\..\al\kernel;\r
+INCLUDES=..\..\..\inc;..\..\..\inc\kernel;..\..\al;..\..\al\kernel;..\..\bus\kernel\$O;\r
 \r
 C_DEFINES=$(C_DEFINES) -DDRIVER -DDEPRECATE_DDK_FUNCTIONS -DNEED_CL_OBJ\r
 \r
 TARGETLIBS= \\r
+    $(DDK_LIB_PATH)\ntstrsafe.lib \\r
        $(TARGETPATH)\*\complib.lib \\r
        $(TARGETPATH)\*\ibal.lib\r
        \r
diff --git a/core/bus/kernel/bus_ev_log.mc b/core/bus/kernel/bus_ev_log.mc
new file mode 100644 (file)
index 0000000..e60869f
--- /dev/null
@@ -0,0 +1,56 @@
+;/*++\r
+;=============================================================================\r
+;Copyright (c) 2009 Mellanox Technologies\r
+;\r
+;Module Name:\r
+;\r
+;    bus_ev_log.mc\r
+;\r
+;Abstract:\r
+;\r
+;    IB Driver event log messages\r
+;\r
+;Authors:\r
+;\r
+;    Leonid Keller\r
+;\r
+;Environment:\r
+;\r
+;   Kernel Mode .\r
+;\r
+;=============================================================================\r
+;--*/\r
+;\r
+MessageIdTypedef = NTSTATUS\r
+\r
+SeverityNames = (\r
+       Success                 = 0x0:STATUS_SEVERITY_SUCCESS\r
+       Informational   = 0x1:STATUS_SEVERITY_INFORMATIONAL\r
+       Warning                 = 0x2:STATUS_SEVERITY_WARNING\r
+       Error                   = 0x3:STATUS_SEVERITY_ERROR\r
+       )\r
+\r
+FacilityNames = (\r
+       System                  = 0x0\r
+       RpcRuntime              = 0x2:FACILITY_RPC_RUNTIME\r
+       RpcStubs                = 0x3:FACILITY_RPC_STUBS\r
+       Io                              = 0x4:FACILITY_IO_ERROR_CODE\r
+       IBBUS                   = 0x9:FACILITY_IB_ERROR_CODE\r
+       )\r
+\r
+\r
+MessageId=0x0001 Facility=IBBUS Severity=Informational SymbolicName=EVENT_IBBUS_ANY_INFO\r
+Language=English\r
+%2\r
+.\r
+\r
+MessageId=0x0002 Facility=IBBUS Severity=Warning SymbolicName=EVENT_IBBUS_ANY_WARN\r
+Language=English\r
+%2\r
+.\r
+\r
+MessageId=0x0003 Facility=IBBUS Severity=Error SymbolicName=EVENT_IBBUS_ANY_ERROR\r
+Language=English\r
+%2\r
+.\r
+\r
index a6b3ffd..ba5e0b7 100644 (file)
@@ -44,4 +44,6 @@
 #define VER_INTERNALNAME_STR           "ibbus.sys"\r
 #define VER_ORIGINALFILENAME_STR       "ibbus.sys"\r
 \r
+#include "bus_ev_log.rc"\r
+\r
 #include <common.ver>\r
index 399f2d7..5aa2b0b 100644 (file)
  * $Id$\r
  */\r
 \r
-\r
+#include <stdarg.h>\r
 #include "complib/cl_log.h"\r
 \r
+WCHAR g_cl_wlog[ CL_LOG_BUF_LEN ]; \r
+UCHAR g_cl_slog[ CL_LOG_BUF_LEN ]; \r
+\r
+\r
+VOID\r
+cl_event_log_write(\r
+       PVOID   p_io_object,\r
+       ULONG   p_error_code,\r
+       ULONG   p_unique_error_code,\r
+       ULONG   p_final_status,\r
+       PWCHAR  p_insertion_string,\r
+       ULONG   p_n_data_items,\r
+       ...\r
+       )\r
+/*++\r
+\r
+Routine Description:\r
+    Writes an event log entry to the event log.\r
+\r
+Arguments:\r
+\r
+       p_io_object......... The IO object ( driver object or device object ).\r
+       p_error_code......... The error code.\r
+       p_unique_error_code... A specific error code.\r
+       p_final_status....... The final status.\r
+       p_n_data_items........ Number of data items.\r
+       .\r
+       . data items values\r
+       .\r
+\r
+Return Value:\r
+\r
+       None .\r
+\r
+--*/\r
+{ /* WriteEventLogEntryStr */\r
+\r
+       /* Variable argument list */    \r
+       va_list                                 l_Argptr;\r
+       /* Pointer to an error log entry */\r
+       PIO_ERROR_LOG_PACKET    l_pErrorLogEntry; \r
+       /* sizeof insertion string */\r
+       int     l_Size = (int)((p_insertion_string) ? ((wcslen(p_insertion_string) + 1) * sizeof( WCHAR )) : 0);\r
+       int l_PktSize =sizeof(IO_ERROR_LOG_PACKET)+p_n_data_items*sizeof(ULONG);\r
+       int l_TotalSize =l_PktSize +l_Size;\r
+\r
+       if (p_io_object == NULL) {\r
+               ASSERT(p_io_object != NULL);\r
+               return;\r
+       }\r
+\r
+       /* Init the variable argument list */   \r
+       va_start(l_Argptr, p_n_data_items);\r
+\r
+       /* Allocate an error log entry */ \r
+       if (l_TotalSize >= ERROR_LOG_MAXIMUM_SIZE - 2) \r
+               l_TotalSize = ERROR_LOG_MAXIMUM_SIZE - 2;\r
+       l_pErrorLogEntry = (PIO_ERROR_LOG_PACKET)IoAllocateErrorLogEntry(\r
+               p_io_object,  (UCHAR)l_TotalSize );\r
+\r
+       /* Check allocation */\r
+       if ( l_pErrorLogEntry != NULL) \r
+       { /* OK */\r
+\r
+               /* Data item index */\r
+               USHORT l_nDataItem ;\r
+\r
+               /* Set the error log entry header */\r
+               l_pErrorLogEntry->ErrorCode                     = p_error_code; \r
+               l_pErrorLogEntry->DumpDataSize          = (USHORT) (p_n_data_items*sizeof(ULONG)); \r
+               l_pErrorLogEntry->SequenceNumber        = 0; \r
+               l_pErrorLogEntry->MajorFunctionCode = 0; \r
+               l_pErrorLogEntry->IoControlCode         = 0; \r
+               l_pErrorLogEntry->RetryCount            = 0; \r
+               l_pErrorLogEntry->UniqueErrorValue      = p_unique_error_code; \r
+               l_pErrorLogEntry->FinalStatus           = p_final_status; \r
+\r
+               /* Insert the data items */\r
+               for (l_nDataItem = 0; l_nDataItem < p_n_data_items; l_nDataItem++) \r
+               { /* Inset a data item */\r
+\r
+                       /* Current data item */\r
+                       int l_CurDataItem ;\r
+                               \r
+                       /* Get next data item */\r
+                       l_CurDataItem = va_arg( l_Argptr, int);\r
+\r
+                       /* Put it into the data array */\r
+                       l_pErrorLogEntry->DumpData[l_nDataItem] = l_CurDataItem ;\r
+\r
+               } /* Inset a data item */\r
+\r
+               /* add insertion string */\r
+               if (p_insertion_string) {\r
+                       char *ptr; \r
+                       int sz = min( l_TotalSize - l_PktSize, l_Size );\r
+                       l_pErrorLogEntry->NumberOfStrings = 1;\r
+                       l_pErrorLogEntry->StringOffset = sizeof(IO_ERROR_LOG_PACKET) + l_pErrorLogEntry->DumpDataSize;\r
+                       ptr = (char*)l_pErrorLogEntry + l_pErrorLogEntry->StringOffset;\r
+                       memcpy( ptr, p_insertion_string, sz );\r
+                       *(WCHAR*)&ptr[sz - 2] = (WCHAR)0;\r
+               }\r
+               \r
+               /* Write the packet */\r
+               IoWriteErrorLogEntry(l_pErrorLogEntry);\r
+\r
+       } /* OK */\r
+\r
+       /* Term the variable argument list */   \r
+       va_end(l_Argptr);\r
+\r
+} /* WriteEventLogEntry */\r
+\r
 \r
 /*\r
  * The IO Object required to allocate an event log entry is passed in\r
index db7765d..6db1853 100644 (file)
@@ -177,19 +177,19 @@ CopyFiles = WinMad.CopyDllFiles
 \r
 [MLX4HCA.DDInstall.ntx86.Services]\r
 AddService = mlx4_hca,%SPSVCINST_ASSOCSERVICE%,MLX4HCA.ServiceInstall,MLX4HCA.EventLog\r
-AddService = ibbus,,Ibbus.ServiceInstall\r
+AddService = ibbus,,Ibbus.ServiceInstall,IBBUS.EventLog\r
 AddService = WinVerbs,,WinVerbs.ServiceInstall\r
 AddService = WinMad,,WinMad.ServiceInstall\r
 \r
 [MLX4HCA.DDInstall.ntamd64.Services]\r
 AddService = mlx4_hca,%SPSVCINST_ASSOCSERVICE%,MLX4HCA.ServiceInstall,MLX4HCA.EventLog\r
-AddService = ibbus,,Ibbus.ServiceInstall\r
+AddService = ibbus,,Ibbus.ServiceInstall,IBBUS.EventLog\r
 AddService = WinVerbs,,WinVerbs.ServiceInstall\r
 AddService = WinMad,,WinMad.ServiceInstall\r
 \r
 [MLX4HCA.DDInstall.ntia64.Services]\r
 AddService = mlx4_hca,%SPSVCINST_ASSOCSERVICE%,MLX4HCA.ServiceInstall,MLX4HCA.EventLog\r
-AddService = ibbus,,Ibbus.ServiceInstall\r
+AddService = ibbus,,Ibbus.ServiceInstall,IBBUS.EventLog\r
 AddService = WinVerbs,,WinVerbs.ServiceInstall\r
 AddService = WinMad,,WinMad.ServiceInstall\r
 \r
@@ -282,6 +282,14 @@ LoadOrderGroup  = PnP Filter
 AddReg          = Ibbus.ParamsReg\r
 Dependencies   = mlx4_hca\r
 \r
+[IBBUS.EventLog]\r
+AddReg = IBBUS.AddEventLogReg\r
+\r
+[IBBUS.AddEventLogReg]\r
+HKR, , EventMessageFile, 0x00020000, "%%SystemRoot%%\System32\IoLogMsg.dll;%%SystemRoot%%\System32\drivers\ibbus.sys"\r
+HKR, , TypesSupported,   0x00010001, 7\r
+\r
+\r
 [Ibbus.ParamsReg]\r
 HKR,"Parameters","IbalDebugLevel",%REG_DWORD%,2\r
 HKR,"Parameters","IbalDebugFlags",%REG_DWORD%,0x00ffffff\r
index 33224cf..ce14a7d 100644 (file)
@@ -192,19 +192,19 @@ CopyFiles = WinMad.CopyDllFiles
 \r
 [MTHCA.DDInstall.ntx86.Services]\r
 AddService = mthca,%SPSVCINST_ASSOCSERVICE%,MTHCA.ServiceInstall,MTHCA.EventLog\r
-AddService = ibbus,,Ibbus.ServiceInstall\r
+AddService = ibbus,,Ibbus.ServiceInstall,Ibbus.EventLog\r
 AddService = WinVerbs,,WinVerbs.ServiceInstall\r
 AddService = WinMad,,WinMad.ServiceInstall\r
 \r
 [MTHCA.DDInstall.ntamd64.Services]\r
 AddService = mthca,%SPSVCINST_ASSOCSERVICE%,MTHCA.ServiceInstall,MTHCA.EventLog\r
-AddService = ibbus,,Ibbus.ServiceInstall\r
+AddService = ibbus,,Ibbus.ServiceInstall,Ibbus.EventLog\r
 AddService = WinVerbs,,WinVerbs.ServiceInstall\r
 AddService = WinMad,,WinMad.ServiceInstall\r
 \r
 [MTHCA.DDInstall.ntia64.Services]\r
 AddService = mthca,%SPSVCINST_ASSOCSERVICE%,MTHCA.ServiceInstall,MTHCA.EventLog\r
-AddService = ibbus,,Ibbus.ServiceInstall\r
+AddService = ibbus,,Ibbus.ServiceInstall,Ibbus.EventLog\r
 AddService = WinVerbs,,WinVerbs.ServiceInstall\r
 AddService = WinMad,,WinMad.ServiceInstall\r
 \r
@@ -296,6 +296,13 @@ LoadOrderGroup  = PnP Filter
 AddReg          = Ibbus.ParamsReg\r
 Dependencies   = mthca\r
 \r
+[Ibbus.EventLog]\r
+AddReg = Ibbus.AddEventLogReg\r
+\r
+[Ibbus.AddEventLogReg]\r
+HKR, , EventMessageFile, 0x00020000, "%%SystemRoot%%\System32\IoLogMsg.dll;%%SystemRoot%%\System32\drivers\ibbus.sys"\r
+HKR, , TypesSupported,   0x00010001, 7\r
+\r
 [Ibbus.ParamsReg]\r
 HKR,"Parameters","IbalDebugLevel",%REG_DWORD%,2\r
 HKR,"Parameters","IbalDebugFlags",%REG_DWORD%,0x00ffffff\r
index 389c6c6..1563cbe 100644 (file)
@@ -43,7 +43,6 @@
 #ifndef _CL_LOG_H_\r
 #define _CL_LOG_H_\r
 \r
-\r
 #include <complib/cl_types.h>\r
 \r
 \r
@@ -147,9 +146,100 @@ cl_log_event(
 *********/\r
 \r
 \r
+/****f* Component Library: Debug Output/cl_msg_out\r
+* NAME\r
+*      cl_event_log_write\r
+*\r
+* DESCRIPTION\r
+*      The cl_event_log_write function sends a message to System Event Logger.\r
+*\r
+* SYNOPSIS\r
+*/\r
+CL_EXPORT void\r
+cl_event_log_write(\r
+       PVOID   p_io_object,\r
+       ULONG   p_error_code,\r
+       ULONG   p_unique_error_code,\r
+       ULONG   p_final_status,\r
+       PWCHAR  p_insertion_string,\r
+       ULONG   p_n_data_items,\r
+               ...\r
+               );\r
+/*\r
+* PARAMETERS\r
+*      p_io_object\r
+*              [in] The IO object ( driver object or device object ).\r
+*      \r
+*      p_error_code\r
+*              [in] The error code.\r
+*\r
+*      p_unique_error_code\r
+*              [in] A specific error code.\r
+*\r
+*      p_final_status\r
+*              [in] The final status.\r
+*\r
+*      p_insertion_string\r
+*              [in] String to print.\r
+*\r
+*      p_n_data_items\r
+*              [in] Number of data items\r
+*\r
+*      ...\r
+*              [in] data items values\r
+*\r
+* RETURN VALUE\r
+*      This function does not return a value.\r
+*\r
+* NOTES\r
+*      cl_event_log_write is available in both debug and release builds.\r
+*\r
+*      The function uses IoAllocateErrorLogEntry and IoWriteErrorLogEntry\r
+*      functions to send data to System Event Log.\r
+*\r
+* SEE ALSO\r
+*      \r
+*********/\r
+\r
 #ifdef __cplusplus\r
 }\r
 #endif\r
 \r
+#ifdef CL_KERNEL\r
+#include <ntddk.h>\r
+#define NTSTRSAFE_LIB\r
+#include <ntstrsafe.h>\r
+\r
+#define CL_LOG_BUF_LEN         512\r
+extern WCHAR g_cl_wlog[ CL_LOG_BUF_LEN ]; \r
+extern UCHAR g_cl_slog[ CL_LOG_BUF_LEN ]; \r
+\r
+static void __build_str( const char *  format, ... )\r
+{\r
+       NTSTATUS status;\r
+       va_list p_arg;\r
+       va_start(p_arg, format);\r
+       status = RtlStringCbVPrintfA((char *)g_cl_slog, sizeof(g_cl_slog), format , p_arg);\r
+       if (status)\r
+               goto end;\r
+       status = RtlStringCchPrintfW(g_cl_wlog, sizeof(g_cl_wlog)/sizeof(g_cl_wlog[0]), L"%S", g_cl_slog);\r
+       if (status)\r
+               goto end;\r
+end:\r
+       va_end(p_arg);\r
+}\r
+\r
+#define CL_PRINT_TO_EVENT_LOG(_obj_,_event_id_,_msg_)  \\r
+       if (_obj_) \\r
+       { \\r
+               NTSTATUS event_id = _event_id_; \\r
+               __build_str _msg_; \\r
+               cl_event_log_write( _obj_, (ULONG)event_id, 0, 0, g_cl_wlog, 0, 0 ); \\r
+       }\r
+#else\r
+\r
+#define CL_PRINT_TO_EVENT_LOG(_obj_,_event_id_,_msg_)\r
+\r
+#endif\r
 \r
 #endif /* _CL_LOG_H_ */\r
index 6867d63..89ec881 100644 (file)
@@ -2937,7 +2937,8 @@ typedef struct _ci_interface
 AL_EXPORT ib_api_status_t\r
 ib_register_ca (\r
        IN              const   ci_interface_t*                         p_ci,\r
-       IN              const   PDEVICE_OBJECT                          p_hca_dev\r
+       IN              const   PDEVICE_OBJECT                          p_hca_dev,\r
+       IN              const   PDEVICE_OBJECT                          p_fdo\r
        );\r
 /*\r
 * DESCRIPTION\r
@@ -2954,6 +2955,8 @@ ib_register_ca (
 *              vector to support verbs functionality.\r
 *      p_hca_dev\r
 *              PDO of HCA device\r
+*      p_fdo\r
+*              FDO of IBBUS device\r
 *\r
 * RETURN VALUE\r
 *      IB_SUCCESS\r
index 42e1859..22fc484 100644 (file)
@@ -56,7 +56,8 @@
 typedef ib_api_status_t\r
 (*ib_pfn_register_ca_t)(\r
        IN              const   ci_interface_t* const           p_ci,\r
-       IN              const   PDEVICE_OBJECT                          p_hca_dev\r
+       IN              const   PDEVICE_OBJECT                          p_hca_dev,\r
+       IN              const   PDEVICE_OBJECT                          p_fdo\r
        );\r
 \r
 \r