Make kernel complib static
[mirror/winof/.git] / tests / alts / kernel / alts_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 ALTS kernel driver.\r
35  */\r
36 \r
37 \r
38 #include <complib/cl_types.h>\r
39 #include <complib/cl_pnp_po.h>\r
40 #include <complib/cl_thread.h>\r
41 #include "alts_common.h"\r
42 #include "alts_debug.h"\r
43 #include <complib/cl_init.h>\r
44 \r
45 \r
46 #if !defined(FILE_DEVICE_INFINIBAND) // Not defined in WXP DDK\r
47 #define FILE_DEVICE_INFINIBAND          0x0000003B\r
48 #endif\r
49 \r
50 uint32_t        alts_dbg_lvl = ALTS_DBG_ERROR | ALTS_DBG_STATUS;\r
51 \r
52 \r
53 NTSTATUS\r
54 DriverEntry(\r
55         IN                              DRIVER_OBJECT                           *p_driver_obj,\r
56         IN                              UNICODE_STRING                          *p_registry_path );\r
57 \r
58 static void\r
59 alts_drv_unload(\r
60         IN                              DRIVER_OBJECT                           *p_driver_obj );\r
61 \r
62 //static NTSTATUS\r
63 //alts_ioctl(\r
64 //      IN                              DEVICE_OBJECT                           *p_dev_obj,\r
65 //      IN                              IRP                                                     *p_irp );\r
66 \r
67 static NTSTATUS\r
68 alts_sysctl(\r
69         IN                              DEVICE_OBJECT                           *p_dev_obj,\r
70         IN                              IRP                                                     *p_irp );\r
71 \r
72 static NTSTATUS\r
73 alts_add_device(\r
74         IN                              DRIVER_OBJECT                           *p_driver_obj,\r
75         IN                              DEVICE_OBJECT                           *p_pdo );\r
76 \r
77 static NTSTATUS\r
78 alts_start_tests(\r
79         IN                              DEVICE_OBJECT* const            p_dev_obj,\r
80         IN                              IRP* const                                      p_irp,\r
81                 OUT                     cl_irp_action_t* const          p_action );\r
82 \r
83 static void\r
84 alts_release_resources(\r
85         IN                              DEVICE_OBJECT* const            p_dev_obj );\r
86 \r
87 \r
88 #ifdef ALLOC_PRAGMA\r
89 #pragma alloc_text (INIT, DriverEntry)\r
90 #pragma alloc_text (PAGE, alts_drv_unload)\r
91 //#pragma alloc_text (PAGE, alts_ioctl)\r
92 #pragma alloc_text (PAGE, alts_sysctl)\r
93 #endif\r
94 \r
95 \r
96 static const cl_vfptr_pnp_po_t  alts_vfptr_pnp = {\r
97         "ALTS",\r
98         alts_start_tests,               // StartDevice\r
99         cl_irp_skip,\r
100         cl_irp_skip,\r
101         cl_irp_skip,\r
102         cl_irp_skip,                    // QueryRemove\r
103         alts_release_resources,\r
104         cl_do_remove,                   // Remove\r
105         cl_irp_skip,                    // CancelRemove\r
106         cl_irp_skip,                    // SurpriseRemove\r
107         cl_irp_skip,            \r
108         cl_irp_skip,\r
109         cl_irp_skip,\r
110         cl_irp_skip,\r
111         cl_irp_skip,\r
112         cl_irp_ignore,\r
113         cl_irp_ignore,\r
114         cl_irp_ignore,\r
115         cl_irp_ignore,\r
116         cl_irp_ignore,\r
117         cl_irp_ignore,\r
118         cl_irp_ignore,\r
119         cl_irp_ignore,\r
120         cl_irp_ignore,\r
121         cl_irp_ignore,\r
122         cl_irp_ignore,\r
123         cl_irp_ignore,\r
124         cl_irp_ignore,                  // QueryPower\r
125         cl_irp_ignore,                  // SetPower\r
126         cl_irp_ignore,                  // PowerSequence\r
127         cl_irp_ignore                   // WaitWake\r
128 };\r
129 \r
130 \r
131 NTSTATUS\r
132 DriverEntry(\r
133         IN                              PDRIVER_OBJECT                  p_driver_obj,\r
134         IN                              PUNICODE_STRING                 p_registry_path )\r
135 {\r
136         NTSTATUS                        status;\r
137 #ifdef _DEBUG_\r
138         static boolean_t        exit = FALSE;\r
139 #endif\r
140 \r
141         ALTS_ENTER( ALTS_DBG_DEV );\r
142 \r
143         UNUSED_PARAM( p_registry_path );\r
144 \r
145 #ifdef _DEBUG_\r
146         DbgBreakPoint();\r
147         if( exit )\r
148         {\r
149                 ALTS_TRACE_EXIT( ALTS_DBG_DEV, ("Load aborted.\n") );\r
150                 return STATUS_DRIVER_INTERNAL_ERROR;\r
151         }\r
152 #endif\r
153 \r
154         status = CL_INIT;\r
155         if( !NT_SUCCESS(status) )\r
156         {\r
157                 ALTS_TRACE_EXIT( ALTS_DBG_ERROR,\r
158                         ("cl_init returned %08X.\n", status) );\r
159                 return status;\r
160         }\r
161 \r
162         p_driver_obj->MajorFunction[IRP_MJ_PNP] = cl_pnp;\r
163         p_driver_obj->MajorFunction[IRP_MJ_POWER] = cl_power;\r
164 //      p_driver_obj->MajorFunction[IRP_MJ_DEVICE_CONTROL] = alts_ioctl;\r
165         p_driver_obj->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = alts_sysctl;\r
166         p_driver_obj->DriverUnload = alts_drv_unload;\r
167         p_driver_obj->DriverExtension->AddDevice = alts_add_device;\r
168 \r
169         ALTS_EXIT( ALTS_DBG_DEV );\r
170         return STATUS_SUCCESS;\r
171 }\r
172 \r
173 \r
174 static void\r
175 alts_drv_unload(\r
176         IN                              PDRIVER_OBJECT                  p_driver_obj )\r
177 {\r
178         ALTS_ENTER( ALTS_DBG_DEV );\r
179 \r
180         UNUSED_PARAM( p_driver_obj );\r
181 \r
182         CL_DEINIT;\r
183 \r
184         ALTS_EXIT( ALTS_DBG_DEV );\r
185 }\r
186 \r
187 \r
188 //static NTSTATUS\r
189 //alts_ioctl(\r
190 //      IN                              DEVICE_OBJECT                           *p_dev_obj,\r
191 //      IN                              IRP                                                     *p_irp )\r
192 //{\r
193 //\r
194 //}\r
195 \r
196 \r
197 static NTSTATUS\r
198 alts_sysctl(\r
199         IN                              DEVICE_OBJECT                           *p_dev_obj,\r
200         IN                              IRP                                                     *p_irp )\r
201 {\r
202         NTSTATUS                status;\r
203         cl_pnp_po_ext_t *p_ext;\r
204 \r
205         ALTS_ENTER( ALTS_DBG_DEV );\r
206 \r
207         p_ext = p_dev_obj->DeviceExtension;\r
208 \r
209         IoSkipCurrentIrpStackLocation( p_irp );\r
210         status = IoCallDriver( p_ext->p_next_do, p_irp );\r
211 \r
212         ALTS_EXIT( ALTS_DBG_DEV );\r
213         return status;\r
214 }\r
215 \r
216 \r
217 static NTSTATUS\r
218 alts_add_device(\r
219         IN                              DRIVER_OBJECT                           *p_driver_obj,\r
220         IN                              DEVICE_OBJECT                           *p_pdo )\r
221 {\r
222         NTSTATUS                        status;\r
223         DEVICE_OBJECT           *p_dev_obj, *p_next_do;\r
224 \r
225         ALTS_ENTER( ALTS_DBG_PNP );\r
226 \r
227         /*\r
228          * Create the device so that we have a device extension to store stuff in.\r
229          */\r
230         status = IoCreateDevice( p_driver_obj, sizeof(cl_pnp_po_ext_t),\r
231                 NULL, FILE_DEVICE_INFINIBAND, FILE_DEVICE_SECURE_OPEN,\r
232                 FALSE, &p_dev_obj );\r
233         if( !NT_SUCCESS( status ) )\r
234         {\r
235                 ALTS_TRACE_EXIT( ALTS_DBG_ERROR,\r
236                         ("IoCreateDevice returned 0x%08X.\n", status) );\r
237                 return status;\r
238         }\r
239 \r
240         /* Attach to the device stack. */\r
241         p_next_do = IoAttachDeviceToDeviceStack( p_dev_obj, p_pdo );\r
242         if( !p_next_do )\r
243         {\r
244                 IoDeleteDevice( p_dev_obj );\r
245                 ALTS_TRACE_EXIT( ALTS_DBG_ERROR,\r
246                         ("IoAttachDeviceToDeviceStack failed.\n") );\r
247                 return STATUS_NO_SUCH_DEVICE;\r
248         }\r
249 \r
250         /* Inititalize the complib extension. */\r
251         cl_init_pnp_po_ext( p_dev_obj, p_next_do, p_pdo, alts_dbg_lvl,\r
252                 &alts_vfptr_pnp, NULL );\r
253 \r
254         ALTS_EXIT( ALTS_DBG_PNP );\r
255         return status;\r
256 }\r
257 \r
258 \r
259 static NTSTATUS\r
260 alts_start_tests(\r
261         IN                              DEVICE_OBJECT* const            p_dev_obj,\r
262         IN                              IRP* const                                      p_irp,\r
263                 OUT                     cl_irp_action_t* const          p_action )\r
264 {\r
265         NTSTATUS                status;\r
266         ib_api_status_t ib_status;\r
267 \r
268         status = cl_do_sync_pnp( p_dev_obj, p_irp, p_action );\r
269         if( !NT_SUCCESS( status ) )\r
270                 return status;\r
271 \r
272         /* Wait 10 seconds for LIDs to get assigned. */\r
273         cl_thread_suspend( 60000 );\r
274 \r
275         /* We're started.  Launch the tests. */\r
276         ib_status = al_test_openclose();\r
277         ALTS_TRACE( ALTS_DBG_STATUS,\r
278                 ("\nOpenClose returned %s\n\n", ib_get_err_str( ib_status )) );\r
279 \r
280         ib_status = al_test_querycaattr();\r
281         ALTS_TRACE( ALTS_DBG_STATUS,\r
282                 ("\nQueryCAAttribute returned %s\n\n", ib_get_err_str( ib_status )) );\r
283 \r
284         ib_status = al_test_modifycaattr();\r
285         ALTS_TRACE( ALTS_DBG_STATUS,\r
286                 ("\nModifyCAAttribute returned %s\n\n", ib_get_err_str( ib_status )) );\r
287 \r
288         ib_status = al_test_alloc_dealloc_pd();\r
289         ALTS_TRACE( ALTS_DBG_STATUS,\r
290                 ("\nAllocDeallocPD returned %s\n\n", ib_get_err_str( ib_status )) );\r
291 \r
292         ib_status = al_test_create_destroy_av();\r
293         ALTS_TRACE( ALTS_DBG_STATUS,\r
294                 ("\nCreateDestroyAV returned %s\n\n", ib_get_err_str( ib_status )) );\r
295 \r
296         ib_status = al_test_query_modify_av();\r
297         ALTS_TRACE( ALTS_DBG_STATUS,\r
298                 ("\nQueryAndModifyAV returned %s\n\n", ib_get_err_str( ib_status )) );\r
299 \r
300         ib_status = al_test_create_destroy_cq();\r
301         ALTS_TRACE( ALTS_DBG_STATUS,\r
302                 ("\nCreateAndDestroyCQ returned %s\n\n", ib_get_err_str( ib_status )) );\r
303 \r
304         ib_status = al_test_query_modify_cq();\r
305         ALTS_TRACE( ALTS_DBG_STATUS,\r
306                 ("\nQueryAndModifyCQ returned %s\n\n", ib_get_err_str( ib_status )) );\r
307 \r
308         ib_status = al_test_register_mem();\r
309         ALTS_TRACE( ALTS_DBG_STATUS,\r
310                 ("\nRegisterMemRegion returned %s\n\n", ib_get_err_str( ib_status )) );\r
311 \r
312         ib_status = al_test_register_phys_mem();\r
313         ALTS_TRACE( ALTS_DBG_STATUS,\r
314                 ("\nRegisterPhyMemRegion returned %s\n\n", ib_get_err_str( ib_status )) );\r
315 \r
316         ib_status = al_test_create_mem_window();\r
317         ALTS_TRACE( ALTS_DBG_STATUS,\r
318                 ("\nCreateMemWindow returned %s\n\n", ib_get_err_str( ib_status )) );\r
319 \r
320         ib_status = al_test_register_shared_mem();\r
321         ALTS_TRACE( ALTS_DBG_STATUS,\r
322                 ("\nRegisterSharedMemRegion returned %s\n\n", ib_get_err_str( ib_status )) );\r
323 \r
324         ib_status = al_test_multi_send_recv();\r
325         ALTS_TRACE( ALTS_DBG_STATUS,\r
326                 ("\nMultiSend returned %s\n\n", ib_get_err_str( ib_status )) );\r
327 \r
328         ib_status = al_test_register_pnp();\r
329         ALTS_TRACE( ALTS_DBG_STATUS,\r
330                 ("\nRegisterPnP returned %s\n\n", ib_get_err_str( ib_status )) );\r
331 \r
332         ib_status = al_test_mad();\r
333         ALTS_TRACE( ALTS_DBG_STATUS,\r
334                 ("\nMadTests returned %s\n\n", ib_get_err_str( ib_status )) );\r
335 \r
336         ib_status = al_test_query();\r
337         ALTS_TRACE( ALTS_DBG_STATUS,\r
338                 ("\nMadQuery returned %s\n\n", ib_get_err_str( ib_status )) );\r
339 \r
340         ib_status = al_test_cm();\r
341         ALTS_TRACE( ALTS_DBG_STATUS,\r
342                 ("\nCmTests returned %s\n\n", ib_get_err_str( ib_status )) );\r
343 \r
344         return status;\r
345 }\r
346 \r
347 \r
348 static void\r
349 alts_release_resources(\r
350         IN                              DEVICE_OBJECT* const            p_dev_obj )\r
351 {\r
352         UNUSED_PARAM( p_dev_obj );\r
353 }\r