a537b7720cae80693676fbb78a4005fd2729686a
[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 /*\r
35  * Provides the driver entry points for the ALTS kernel driver.\r
36  */\r
37 \r
38 \r
39 #include <complib/cl_types.h>\r
40 #include <complib/cl_pnp_po.h>\r
41 #include <complib/cl_thread.h>\r
42 #include "alts_common.h"\r
43 #include "alts_debug.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 #ifdef _DEBUG_\r
137         static boolean_t        exit = FALSE;\r
138 #endif\r
139 \r
140         ALTS_ENTER( ALTS_DBG_DEV );\r
141 \r
142         UNUSED_PARAM( p_registry_path );\r
143 \r
144 #ifdef _DEBUG_\r
145         DbgBreakPoint();\r
146         if( exit )\r
147         {\r
148                 ALTS_TRACE_EXIT( ALTS_DBG_DEV, ("Load aborted.\n") );\r
149                 return STATUS_DRIVER_INTERNAL_ERROR;\r
150         }\r
151 #endif\r
152 \r
153         p_driver_obj->MajorFunction[IRP_MJ_PNP] = cl_pnp;\r
154         p_driver_obj->MajorFunction[IRP_MJ_POWER] = cl_power;\r
155 //      p_driver_obj->MajorFunction[IRP_MJ_DEVICE_CONTROL] = alts_ioctl;\r
156         p_driver_obj->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = alts_sysctl;\r
157         p_driver_obj->DriverUnload = alts_drv_unload;\r
158         p_driver_obj->DriverExtension->AddDevice = alts_add_device;\r
159 \r
160         ALTS_EXIT( ALTS_DBG_DEV );\r
161         return STATUS_SUCCESS;\r
162 }\r
163 \r
164 \r
165 static void\r
166 alts_drv_unload(\r
167         IN                              PDRIVER_OBJECT                  p_driver_obj )\r
168 {\r
169         ALTS_ENTER( ALTS_DBG_DEV );\r
170 \r
171         UNUSED_PARAM( p_driver_obj );\r
172 \r
173         ALTS_EXIT( ALTS_DBG_DEV );\r
174 }\r
175 \r
176 \r
177 //static NTSTATUS\r
178 //alts_ioctl(\r
179 //      IN                              DEVICE_OBJECT                           *p_dev_obj,\r
180 //      IN                              IRP                                                     *p_irp )\r
181 //{\r
182 //\r
183 //}\r
184 \r
185 \r
186 static NTSTATUS\r
187 alts_sysctl(\r
188         IN                              DEVICE_OBJECT                           *p_dev_obj,\r
189         IN                              IRP                                                     *p_irp )\r
190 {\r
191         NTSTATUS                status;\r
192         cl_pnp_po_ext_t *p_ext;\r
193 \r
194         ALTS_ENTER( ALTS_DBG_DEV );\r
195 \r
196         p_ext = p_dev_obj->DeviceExtension;\r
197 \r
198         IoSkipCurrentIrpStackLocation( p_irp );\r
199         status = IoCallDriver( p_ext->p_next_do, p_irp );\r
200 \r
201         ALTS_EXIT( ALTS_DBG_DEV );\r
202         return status;\r
203 }\r
204 \r
205 \r
206 static NTSTATUS\r
207 alts_add_device(\r
208         IN                              DRIVER_OBJECT                           *p_driver_obj,\r
209         IN                              DEVICE_OBJECT                           *p_pdo )\r
210 {\r
211         NTSTATUS                        status;\r
212         DEVICE_OBJECT           *p_dev_obj, *p_next_do;\r
213 \r
214         ALTS_ENTER( ALTS_DBG_PNP );\r
215 \r
216         /*\r
217          * Create the device so that we have a device extension to store stuff in.\r
218          */\r
219         status = IoCreateDevice( p_driver_obj, sizeof(cl_pnp_po_ext_t),\r
220                 NULL, FILE_DEVICE_INFINIBAND, FILE_DEVICE_SECURE_OPEN,\r
221                 FALSE, &p_dev_obj );\r
222         if( !NT_SUCCESS( status ) )\r
223         {\r
224                 ALTS_TRACE_EXIT( ALTS_DBG_ERROR,\r
225                         ("IoCreateDevice returned 0x%08X.\n", status) );\r
226                 return status;\r
227         }\r
228 \r
229         /* Attach to the device stack. */\r
230         p_next_do = IoAttachDeviceToDeviceStack( p_dev_obj, p_pdo );\r
231         if( !p_next_do )\r
232         {\r
233                 IoDeleteDevice( p_dev_obj );\r
234                 ALTS_TRACE_EXIT( ALTS_DBG_ERROR,\r
235                         ("IoAttachDeviceToDeviceStack failed.\n") );\r
236                 return STATUS_NO_SUCH_DEVICE;\r
237         }\r
238 \r
239         /* Inititalize the complib extension. */\r
240         cl_init_pnp_po_ext( p_dev_obj, p_next_do, p_pdo, alts_dbg_lvl,\r
241                 &alts_vfptr_pnp, NULL );\r
242 \r
243         ALTS_EXIT( ALTS_DBG_PNP );\r
244         return status;\r
245 }\r
246 \r
247 \r
248 static NTSTATUS\r
249 alts_start_tests(\r
250         IN                              DEVICE_OBJECT* const            p_dev_obj,\r
251         IN                              IRP* const                                      p_irp,\r
252                 OUT                     cl_irp_action_t* const          p_action )\r
253 {\r
254         NTSTATUS                status;\r
255         ib_api_status_t ib_status;\r
256 \r
257         status = cl_do_sync_pnp( p_dev_obj, p_irp, p_action );\r
258         if( !NT_SUCCESS( status ) )\r
259                 return status;\r
260 \r
261         /* Wait 10 seconds for LIDs to get assigned. */\r
262         cl_thread_suspend( 60000 );\r
263 \r
264         /* We're started.  Launch the tests. */\r
265         ib_status = al_test_openclose();\r
266         ALTS_TRACE( ALTS_DBG_STATUS,\r
267                 ("\nOpenClose returned %s\n\n", ib_get_err_str( ib_status )) );\r
268 \r
269         ib_status = al_test_querycaattr();\r
270         ALTS_TRACE( ALTS_DBG_STATUS,\r
271                 ("\nQueryCAAttribute returned %s\n\n", ib_get_err_str( ib_status )) );\r
272 \r
273         ib_status = al_test_modifycaattr();\r
274         ALTS_TRACE( ALTS_DBG_STATUS,\r
275                 ("\nModifyCAAttribute returned %s\n\n", ib_get_err_str( ib_status )) );\r
276 \r
277         ib_status = al_test_alloc_dealloc_pd();\r
278         ALTS_TRACE( ALTS_DBG_STATUS,\r
279                 ("\nAllocDeallocPD returned %s\n\n", ib_get_err_str( ib_status )) );\r
280 \r
281         ib_status = al_test_create_destroy_av();\r
282         ALTS_TRACE( ALTS_DBG_STATUS,\r
283                 ("\nCreateDestroyAV returned %s\n\n", ib_get_err_str( ib_status )) );\r
284 \r
285         ib_status = al_test_query_modify_av();\r
286         ALTS_TRACE( ALTS_DBG_STATUS,\r
287                 ("\nQueryAndModifyAV returned %s\n\n", ib_get_err_str( ib_status )) );\r
288 \r
289         ib_status = al_test_create_destroy_cq();\r
290         ALTS_TRACE( ALTS_DBG_STATUS,\r
291                 ("\nCreateAndDestroyCQ returned %s\n\n", ib_get_err_str( ib_status )) );\r
292 \r
293         ib_status = al_test_query_modify_cq();\r
294         ALTS_TRACE( ALTS_DBG_STATUS,\r
295                 ("\nQueryAndModifyCQ returned %s\n\n", ib_get_err_str( ib_status )) );\r
296 \r
297         ib_status = al_test_register_mem();\r
298         ALTS_TRACE( ALTS_DBG_STATUS,\r
299                 ("\nRegisterMemRegion returned %s\n\n", ib_get_err_str( ib_status )) );\r
300 \r
301         ib_status = al_test_register_phys_mem();\r
302         ALTS_TRACE( ALTS_DBG_STATUS,\r
303                 ("\nRegisterPhyMemRegion returned %s\n\n", ib_get_err_str( ib_status )) );\r
304 \r
305         ib_status = al_test_create_mem_window();\r
306         ALTS_TRACE( ALTS_DBG_STATUS,\r
307                 ("\nCreateMemWindow returned %s\n\n", ib_get_err_str( ib_status )) );\r
308 \r
309         ib_status = al_test_register_shared_mem();\r
310         ALTS_TRACE( ALTS_DBG_STATUS,\r
311                 ("\nRegisterSharedMemRegion returned %s\n\n", ib_get_err_str( ib_status )) );\r
312 \r
313         ib_status = al_test_multi_send_recv();\r
314         ALTS_TRACE( ALTS_DBG_STATUS,\r
315                 ("\nMultiSend returned %s\n\n", ib_get_err_str( ib_status )) );\r
316 \r
317         ib_status = al_test_register_pnp();\r
318         ALTS_TRACE( ALTS_DBG_STATUS,\r
319                 ("\nRegisterPnP returned %s\n\n", ib_get_err_str( ib_status )) );\r
320 \r
321         ib_status = al_test_mad();\r
322         ALTS_TRACE( ALTS_DBG_STATUS,\r
323                 ("\nMadTests returned %s\n\n", ib_get_err_str( ib_status )) );\r
324 \r
325         ib_status = al_test_query();\r
326         ALTS_TRACE( ALTS_DBG_STATUS,\r
327                 ("\nMadQuery returned %s\n\n", ib_get_err_str( ib_status )) );\r
328 \r
329         ib_status = al_test_cm();\r
330         ALTS_TRACE( ALTS_DBG_STATUS,\r
331                 ("\nCmTests returned %s\n\n", ib_get_err_str( ib_status )) );\r
332 \r
333         return status;\r
334 }\r
335 \r
336 \r
337 static void\r
338 alts_release_resources(\r
339         IN                              DEVICE_OBJECT* const            p_dev_obj )\r
340 {\r
341         UNUSED_PARAM( p_dev_obj );\r
342 }\r