[IOU] Add WPP tracing to IOU bus driver.
[mirror/winof/.git] / core / iou / kernel / iou_driver.c
1 /*\r
2  * Copyright (c) 2005 SilverStorm Technologies.  All rights reserved.\r
3  *\r
4  * This software is available to you under the OpenIB.org BSD license\r
5  * below:\r
6  *\r
7  *     Redistribution and use in source and binary forms, with or\r
8  *     without modification, are permitted provided that the following\r
9  *     conditions are met:\r
10  *\r
11  *      - Redistributions of source code must retain the above\r
12  *        copyright notice, this list of conditions and the following\r
13  *        disclaimer.\r
14  *\r
15  *      - Redistributions in binary form must reproduce the above\r
16  *        copyright notice, this list of conditions and the following\r
17  *        disclaimer in the documentation and/or other materials\r
18  *        provided with the distribution.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
27  * SOFTWARE.\r
28  *\r
29  * $Id$\r
30  */\r
31 \r
32 \r
33 /*\r
34  * Provides the driver entry points for the InfiniBand I/O Unit Bus Driver.\r
35  */\r
36 \r
37 #include <complib/cl_types.h>\r
38 #include "iou_driver.h"\r
39 #if defined(EVENT_TRACING)\r
40 #ifdef offsetof\r
41 #undef offsetof\r
42 #endif\r
43 #include "iou_driver.tmh"\r
44 #endif\r
45 #include "iou_pnp.h"\r
46 #include <complib/cl_init.h>\r
47 \r
48 \r
49 iou_globals_t   iou_globals = {\r
50         NULL\r
51 };\r
52 \r
53 uint32_t                g_iou_dbg_level = TRACE_LEVEL_ERROR;\r
54 uint32_t                g_iou_dbg_flags = 0x00000fff;\r
55 \r
56 static NTSTATUS\r
57 __read_registry(\r
58         IN                              UNICODE_STRING* const           p_Param_Path );\r
59 \r
60 static NTSTATUS\r
61 iou_drv_open(\r
62         IN                              DEVICE_OBJECT                           *p_dev_obj,\r
63         IN                              IRP                                                     *p_irp );\r
64 \r
65 static NTSTATUS\r
66 iou_drv_close(\r
67         IN                              DEVICE_OBJECT                           *p_dev_obj,\r
68         IN                              IRP                                                     *p_irp );\r
69 \r
70 static NTSTATUS\r
71 iou_drv_ioctl(\r
72         IN                              DEVICE_OBJECT                           *p_dev_obj,\r
73         IN                              IRP                                                     *p_irp );\r
74 \r
75 /***f* InfiniBand Bus Driver/iou_sysctl\r
76 * NAME\r
77 *       iou_sysctl\r
78 *\r
79 * DESCRIPTION\r
80 *       Entry point for handling WMI IRPs.\r
81 *\r
82 * SYNOPSIS\r
83 */\r
84 static NTSTATUS\r
85 iou_sysctl(\r
86         IN                              DEVICE_OBJECT                           *p_dev_obj,\r
87         IN                              IRP                                                     *p_irp );\r
88 /**********/\r
89 \r
90 static void\r
91 iou_unload(\r
92         IN                              DRIVER_OBJECT                           *p_driver_obj );\r
93 \r
94 NTSTATUS\r
95 DriverEntry(\r
96         IN                              DRIVER_OBJECT                           *p_driver_obj,\r
97         IN                              UNICODE_STRING                          *p_registry_path );\r
98 \r
99 #ifdef ALLOC_PRAGMA\r
100 #pragma alloc_text (INIT, DriverEntry)\r
101 #pragma alloc_text (INIT, __read_registry)\r
102 #pragma alloc_text (PAGE, iou_unload)\r
103 #pragma alloc_text (PAGE, iou_drv_open)\r
104 #pragma alloc_text (PAGE, iou_drv_close)\r
105 #pragma alloc_text (PAGE, iou_drv_ioctl)\r
106 #pragma alloc_text (PAGE_PNP, iou_sysctl)\r
107 #endif\r
108 \r
109 \r
110 static NTSTATUS\r
111 __read_registry(\r
112         IN                              UNICODE_STRING* const           p_registry_path )\r
113 {\r
114         NTSTATUS                                        status;\r
115         /* Remember the terminating entry in the table below. */\r
116         RTL_QUERY_REGISTRY_TABLE        table[3];\r
117         UNICODE_STRING                          param_path;\r
118 \r
119         IOU_ENTER( IOU_DBG_DRV );\r
120 \r
121         RtlInitUnicodeString( &param_path, NULL );\r
122         param_path.MaximumLength = p_registry_path->Length + \r
123                 sizeof(L"\\Parameters");\r
124         param_path.Buffer = cl_zalloc( param_path.MaximumLength );\r
125         if( !param_path.Buffer )\r
126         {\r
127                 IOU_PRINT_EXIT( TRACE_LEVEL_ERROR,IOU_DBG_ERROR,\r
128                         ("Failed to allocate parameters path buffer.\n") );\r
129                 return STATUS_INSUFFICIENT_RESOURCES;\r
130         }\r
131 \r
132         RtlAppendUnicodeStringToString( &param_path, p_registry_path );\r
133         RtlAppendUnicodeToString( &param_path, L"\\Parameters" );\r
134 \r
135         /*\r
136          * Clear the table.  This clears all the query callback pointers,\r
137          * and sets up the terminating table entry.\r
138          */\r
139         cl_memclr( table, sizeof(table) );\r
140 \r
141         /* Setup the table entries. */\r
142         table[0].Flags = RTL_QUERY_REGISTRY_DIRECT;\r
143         table[0].Name = L"DebugFlags";\r
144         table[0].EntryContext = &g_iou_dbg_level;\r
145         table[0].DefaultType = REG_DWORD;\r
146         table[0].DefaultData = &g_iou_dbg_level;\r
147         table[0].DefaultLength = sizeof(ULONG);\r
148 \r
149         table[1].Flags = RTL_QUERY_REGISTRY_DIRECT;\r
150         table[1].Name = L"DebugFlags";\r
151         table[1].EntryContext = &g_iou_dbg_flags;\r
152         table[1].DefaultType = REG_DWORD;\r
153         table[1].DefaultData = &g_iou_dbg_flags;\r
154         table[1].DefaultLength = sizeof(ULONG);\r
155         /* Have at it! */\r
156         status = RtlQueryRegistryValues( RTL_REGISTRY_ABSOLUTE,\r
157                 param_path.Buffer, table, NULL, NULL );\r
158 \r
159         if( g_iou_dbg_flags & IOU_DBG_ERR )\r
160                 g_iou_dbg_flags |= CL_DBG_ERROR;\r
161 \r
162         cl_free( param_path.Buffer );\r
163         IOU_EXIT( IOU_DBG_DRV );\r
164         return status;\r
165 }\r
166 \r
167 \r
168 static NTSTATUS\r
169 iou_sysctl(\r
170         IN                              DEVICE_OBJECT                           *p_dev_obj,\r
171         IN                              IRP                                                     *p_irp )\r
172 {\r
173         NTSTATUS                status;\r
174         cl_pnp_po_ext_t *p_ext;\r
175 \r
176         IOU_ENTER( IOU_DBG_DRV );\r
177 \r
178         CL_ASSERT( p_dev_obj );\r
179         CL_ASSERT( p_irp );\r
180 \r
181         p_ext = p_dev_obj->DeviceExtension;\r
182 \r
183         if( p_ext->p_next_do )\r
184         {\r
185                 IoSkipCurrentIrpStackLocation( p_irp );\r
186                 status = IoCallDriver( p_ext->p_next_do, p_irp );\r
187         }\r
188         else\r
189         {\r
190                 status = p_irp->IoStatus.Status;\r
191                 IoCompleteRequest( p_irp, IO_NO_INCREMENT );\r
192         }\r
193 \r
194         IOU_EXIT( IOU_DBG_DRV );\r
195         return status;\r
196 }\r
197 \r
198 \r
199 static void\r
200 iou_unload(\r
201         IN                              DRIVER_OBJECT                           *p_driver_obj )\r
202 {\r
203         IOU_ENTER( IOU_DBG_DRV );\r
204 #if defined(EVENT_TRACING)\r
205         WPP_CLEANUP( p_drv_obj );\r
206 #endif\r
207 \r
208         UNUSED_PARAM( p_driver_obj );\r
209 \r
210         CL_DEINIT;\r
211 \r
212         IOU_EXIT( IOU_DBG_DRV );\r
213 }\r
214 \r
215 \r
216 NTSTATUS\r
217 DriverEntry(\r
218         IN                              DRIVER_OBJECT                           *p_driver_obj,\r
219         IN                              UNICODE_STRING                          *p_registry_path )\r
220 {\r
221         NTSTATUS                        status;\r
222 \r
223         IOU_ENTER( IOU_DBG_DRV );\r
224 \r
225 #if defined(EVENT_TRACING)\r
226         WPP_INIT_TRACING( p_drv_obj, p_registry_path );\r
227 #endif\r
228 \r
229         status = CL_INIT;\r
230         if( !NT_SUCCESS(status) )\r
231         {\r
232                 IOU_PRINT_EXIT( TRACE_LEVEL_ERROR, IOU_DBG_ERROR,\r
233                         ("cl_init returned %08X.\n", status) );\r
234                 return status;\r
235         }\r
236 \r
237         /* Store the driver object pointer in the global parameters. */\r
238         iou_globals.p_driver_obj = p_driver_obj;\r
239 \r
240         /* Get the registry values. */\r
241         status = __read_registry( p_registry_path );\r
242         if( !NT_SUCCESS(status) )\r
243         {\r
244                 CL_DEINIT;\r
245                 IOU_PRINT_EXIT( TRACE_LEVEL_ERROR, IOU_DBG_ERROR,\r
246                         ("__read_registry returned %08x.\n", status) );\r
247                 return status;\r
248         }\r
249 \r
250         /* Setup the entry points. */\r
251         p_driver_obj->MajorFunction[IRP_MJ_PNP] = cl_pnp;\r
252         p_driver_obj->MajorFunction[IRP_MJ_POWER] = cl_power;\r
253         p_driver_obj->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = iou_sysctl;\r
254         p_driver_obj->DriverUnload = iou_unload;\r
255         p_driver_obj->DriverExtension->AddDevice = iou_add_device;\r
256 \r
257         IOU_EXIT( IOU_DBG_DRV );\r
258         return STATUS_SUCCESS;\r
259 }\r