Make kernel complib static
[mirror/winof/.git] / ulp / srp / kernel / srp_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 #include "srp_data.h"\r
34 #include "srp_data_path.h"\r
35 #include "srp_debug.h"\r
36 #include "srp_descriptors.h"\r
37 #include "srp_hba.h"\r
38 #include "srp_session.h"\r
39 \r
40 #include <complib/cl_math.h>\r
41 #include <complib/cl_mutex.h>\r
42 #include <complib/cl_init.h>\r
43 \r
44 \r
45 #define SCSI_MAXIMUM_TRANSFER_SIZE (1024 * 1024)\r
46 \r
47 BOOLEAN             g_srp_system_shutdown = FALSE;\r
48 \r
49 //uint32_t            g_srp_dbg_lvl = SRP_DBG_PNP | SRP_DBG_ERROR | SRP_DBG_WARN | SRP_DBG_VERBOSE | SRP_DBG_FUNC;\r
50 uint32_t            g_srp_dbg_lvl = SRP_DBG_DEBUG | SRP_DBG_ERROR | SRP_DBG_WARN;\r
51 \r
52 char g_srb_function_name[][32] =\r
53 {\r
54         "EXECUTE_SCSI",          // 0x00\r
55         "CLAIM_DEVICE",          // 0x01\r
56         "IO_CONTROL",            // 0x02\r
57         "RECEIVE_EVENT",         // 0x03\r
58         "RELEASE_QUEUE",         // 0x04\r
59         "ATTACH_DEVICE",         // 0x05\r
60         "RELEASE_DEVICE",        // 0x06\r
61         "SHUTDOWN",              // 0x07\r
62         "FLUSH",                 // 0x08\r
63         "",                      // 0x09\r
64         "",                      // 0x0A\r
65         "",                      // 0x0B\r
66         "",                      // 0x0C\r
67         "",                      // 0x0D\r
68         "",                      // 0x0E\r
69         "",                      // 0x0F\r
70         "ABORT_COMMAND",         // 0x10\r
71         "RELEASE_RECOVERY",      // 0x11\r
72         "RESET_BUS",             // 0x12\r
73         "RESET_DEVICE",          // 0x13\r
74         "TERMINATE_IO",          // 0x14\r
75         "FLUSH_QUEUE",           // 0x15\r
76         "REMOVE_DEVICE",         // 0x16\r
77         "WMI",                   // 0x17\r
78         "LOCK_QUEUE",            // 0x18\r
79         "UNLOCK_QUEUE",          // 0x19\r
80         "",                      // 0x1A\r
81         "",                      // 0x1B\r
82         "",                      // 0x1C\r
83         "",                      // 0x1D\r
84         "",                      // 0x1E\r
85         "",                      // 0x1F\r
86         "RESET_LOGICAL_UNIT",    // 0x20\r
87         "SET_LINK_TIMEOUT",      // 0x21\r
88         "LINK_TIMEOUT_OCCURRED", // 0x22\r
89         "LINK_TIMEOUT_COMPLETE"  // 0x23\r
90 };\r
91 \r
92 char g_srb_status_name[][32] =\r
93 {\r
94         "PENDING",                // 0x00\r
95         "SUCCESS",                // 0x01\r
96         "ABORTED",                // 0x02\r
97         "ABORT_FAILED",           // 0x03\r
98         "ERROR",                  // 0x04\r
99         "BUSY",                   // 0x05\r
100         "INVALID_REQUEST",        // 0x06\r
101         "INVALID_PATH_ID",        // 0x07\r
102         "NO_DEVICE",              // 0x08\r
103         "TIMEOUT",                // 0x09\r
104         "SELECTION_TIMEOUT",      // 0x0A\r
105         "COMMAND_TIMEOUT",        // 0x0B\r
106         "",                       // 0x0C\r
107         "MESSAGE_REJECTED",       // 0x0D\r
108         "BUS_RESET",              // 0x0E\r
109         "PARITY_ERROR",           // 0x0F\r
110         "REQUEST_SENSE_FAILED",   // 0x10\r
111         "NO_HBA",                 // 0x11\r
112         "DATA_OVERRUN",           // 0x12\r
113         "UNEXPECTED_BUS_FREE",    // 0x13\r
114         "PHASE_SEQUENCE_FAILURE", // 0x14\r
115         "BAD_SRB_BLOCK_LENGTH",   // 0x15\r
116         "REQUEST_FLUSHED",        // 0x16\r
117         "",                       // 0x17\r
118         "",                       // 0x18\r
119         "",                       // 0x19\r
120         "",                       // 0x1A\r
121         "",                       // 0x1B\r
122         "",                       // 0x1C\r
123         "",                       // 0x1D\r
124         "",                       // 0x1E\r
125         "",                       // 0x1F\r
126         "INVALID_LUN",            // 0x20\r
127         "INVALID_TARGET_ID",      // 0x21\r
128         "BAD_FUNCTION",           // 0x22\r
129         "ERROR_RECOVERY",         // 0x23\r
130         "NOT_POWERED",            // 0x24\r
131         "LINK_DOWN"               // 0x25\r
132 };\r
133 \r
134 \r
135 DRIVER_OBJECT       *gp_drv_obj;\r
136 cl_obj_t            g_drv_obj;\r
137 \r
138 /* Mutex protecting the next lower device object pointer. */\r
139 KMUTEX              g_srp_pnp_mutex;\r
140 \r
141 PDRIVER_DISPATCH    gpfn_pnp;\r
142 PDRIVER_ADD_DEVICE  gpfn_add_device;\r
143 PDRIVER_UNLOAD      gpfn_unload;\r
144 \r
145 NTSTATUS\r
146 srp_add_device(\r
147         IN              DRIVER_OBJECT               *p_drv_obj,\r
148         IN              DEVICE_OBJECT               *p_pdo );\r
149 \r
150 NTSTATUS\r
151 srp_dispatch_pnp(\r
152         IN              DEVICE_OBJECT               *p_dev_obj,\r
153         IN              IRP                         *p_irp );\r
154 \r
155 BOOLEAN\r
156 srp_init(\r
157         IN              PVOID                       p_dev_ext );\r
158 \r
159 BOOLEAN\r
160 srp_start_io(\r
161         IN              PVOID                       p_dev_ext,\r
162         IN              PSCSI_REQUEST_BLOCK         p_srb );\r
163 \r
164 BOOLEAN\r
165 srp_isr(\r
166         IN              PVOID                       p_dev_ext );\r
167 \r
168 ULONG\r
169 srp_find_adapter(\r
170         IN              PVOID                       p_dev_ext,\r
171         IN              PVOID                       resv1,\r
172         IN              PVOID                       resv2,\r
173         IN              PCHAR                       arg_str,\r
174         IN  OUT         PPORT_CONFIGURATION_INFORMATION     p_config,\r
175                 OUT         PBOOLEAN                    resv3 );\r
176 \r
177 BOOLEAN\r
178 srp_reset(\r
179         IN              PVOID                       p_dev_ext,\r
180         IN              ULONG                       path_id );\r
181 \r
182 SCSI_ADAPTER_CONTROL_STATUS\r
183 srp_adapter_ctrl(\r
184         IN              PVOID                       p_dev_ext,\r
185         IN              SCSI_ADAPTER_CONTROL_TYPE   ctrl_type,\r
186         IN              PVOID                       params );\r
187 \r
188 BOOLEAN\r
189 srp_build_io(\r
190         IN              PVOID                       p_dev_ext,\r
191         IN              PSCSI_REQUEST_BLOCK         p_srb );\r
192 \r
193 static void\r
194 srp_unload(\r
195         IN              DRIVER_OBJECT               *p_drv_obj );\r
196 \r
197 static void\r
198 __srp_free(\r
199         IN              cl_obj_t                    *p_obj );\r
200 \r
201 ULONG\r
202 DriverEntry(\r
203         IN              DRIVER_OBJECT               *p_drv_obj,\r
204         IN              UNICODE_STRING              *p_registry_path )\r
205 {\r
206         ULONG                       status;\r
207         HW_INITIALIZATION_DATA      hw_data;\r
208         cl_status_t                 cl_status;\r
209 \r
210         SRP_ENTER( SRP_DBG_PNP );\r
211 \r
212         status = CL_INIT;\r
213         if( !NT_SUCCESS(status) )\r
214         {\r
215                 SRP_TRACE_EXIT( SRP_DBG_ERROR,\r
216                         ("cl_init returned %08X.\n", status) );\r
217                 return status;\r
218         }\r
219 \r
220         gp_drv_obj = p_drv_obj;\r
221 \r
222         cl_obj_construct( &g_drv_obj, SRP_OBJ_TYPE_DRV );\r
223 \r
224         KeInitializeMutex( &g_srp_pnp_mutex, 0 );\r
225 \r
226         cl_memclr( &hw_data, sizeof(HW_INITIALIZATION_DATA) );\r
227 \r
228         hw_data.HwInitializationDataSize = sizeof(HW_INITIALIZATION_DATA);\r
229 \r
230         hw_data.AdapterInterfaceType = Internal;\r
231 \r
232         /* Miniport driver routines */\r
233         hw_data.HwInitialize     = srp_init;\r
234         hw_data.HwStartIo        = srp_start_io;\r
235 //      hw_data.HwInterrupt      = srp_isr;\r
236         hw_data.HwInterrupt      = NULL;\r
237         hw_data.HwFindAdapter    = srp_find_adapter;\r
238         hw_data.HwResetBus       = srp_reset;\r
239         hw_data.HwAdapterControl = srp_adapter_ctrl;\r
240         hw_data.HwBuildIo        = srp_build_io;\r
241         hw_data.HwDmaStarted     = NULL;\r
242         hw_data.HwAdapterState   = NULL;\r
243 \r
244         /* Extension sizes. */\r
245         hw_data.DeviceExtensionSize = sizeof(srp_ext_t);\r
246         /* TODO: Do we need per-LU data? */\r
247         hw_data.SpecificLuExtensionSize = 0;\r
248         hw_data.SrbExtensionSize = sizeof(srp_send_descriptor_t);\r
249 \r
250         /* Driver parameters. */\r
251         hw_data.NumberOfAccessRanges = 1;\r
252         /* TODO: Can this be STOR_MAP_NO_BUFFERS? */\r
253         hw_data.MapBuffers = STOR_MAP_NON_READ_WRITE_BUFFERS;\r
254 \r
255         hw_data.NeedPhysicalAddresses = TRUE;\r
256         hw_data.TaggedQueuing = TRUE;\r
257         hw_data.AutoRequestSense = TRUE;\r
258         hw_data.MultipleRequestPerLu = TRUE;\r
259 \r
260         cl_status =\r
261                 cl_obj_init( &g_drv_obj, CL_DESTROY_SYNC, NULL, NULL, __srp_free );\r
262         if( cl_status == CL_SUCCESS )\r
263         {\r
264                 // Invoke the port initialization function.\r
265                 status = StorPortInitialize(p_drv_obj, p_registry_path, &hw_data, NULL);\r
266                 if( NT_SUCCESS( status ) )\r
267                 {\r
268                         /*\r
269                          * Overwrite the PnP entrypoint, but save the original\r
270                          * so we can call it.\r
271                          */\r
272                         gpfn_pnp = p_drv_obj->MajorFunction[IRP_MJ_PNP];\r
273                         p_drv_obj->MajorFunction[IRP_MJ_PNP] = srp_dispatch_pnp;\r
274                         gpfn_add_device = p_drv_obj->DriverExtension->AddDevice;\r
275                         p_drv_obj->DriverExtension->AddDevice = srp_add_device;\r
276                         gpfn_unload = p_drv_obj->DriverUnload;\r
277                         p_drv_obj->DriverUnload = srp_unload;\r
278                 }\r
279                 else\r
280                 {\r
281                         CL_DEINIT;\r
282                         SRP_TRACE( SRP_DBG_ERROR,\r
283                                 ("StorPortInitialize returned 0x%x.\n", status) );\r
284                 }\r
285         }\r
286         else\r
287         {\r
288                 CL_DEINIT;\r
289                 status = (ULONG)STATUS_INSUFFICIENT_RESOURCES;\r
290         }\r
291 \r
292         SRP_TRACE_EXIT( SRP_DBG_PNP, ("DriverEntry returning status of 0x%x.\n", status) );\r
293         return status;\r
294 }\r
295 \r
296 static void\r
297 srp_unload(\r
298         IN              DRIVER_OBJECT               *p_drv_obj )\r
299 {\r
300         SRP_ENTER( SRP_DBG_PNP );\r
301 \r
302         /* Kill all SRP objects. */\r
303         SRP_TRACE( SRP_DBG_DEBUG, ("Destroying all SRP objects.\n") );\r
304         SRP_TRACE( SRP_DBG_VERBOSE, ("Driver Object ref_cnt = %d\n", g_drv_obj.ref_cnt) );\r
305         cl_obj_destroy( &g_drv_obj );\r
306 \r
307         CL_DEINIT;\r
308 \r
309         /* Invoke the port driver's unload routine. */\r
310         SRP_TRACE( SRP_DBG_DEBUG, ("Invoking the port driver's unload routine.\n") );\r
311         gpfn_unload( p_drv_obj );\r
312 \r
313         SRP_EXIT( SRP_DBG_PNP );\r
314 }\r
315 \r
316 \r
317 static void\r
318 __srp_free(\r
319         IN              cl_obj_t                    *p_obj )\r
320 {\r
321 //  CL_ASSERT( p_obj == &g_drv_obj );\r
322         UNUSED_PARAM ( p_obj );\r
323         cl_obj_deinit( &g_drv_obj );\r
324 }\r
325 \r
326 \r
327 NTSTATUS\r
328 srp_add_device(\r
329         IN              DRIVER_OBJECT               *p_drv_obj,\r
330         IN              DEVICE_OBJECT               *p_pdo )\r
331 {\r
332         NTSTATUS    status;\r
333 \r
334         SRP_ENTER( SRP_DBG_PNP );\r
335 \r
336         status = gpfn_add_device( p_drv_obj, p_pdo );\r
337         SRP_TRACE( SRP_DBG_PNP,\r
338                 ("srp_add_device status = 0x%x.\n", status) );\r
339 \r
340         SRP_EXIT( SRP_DBG_PNP );\r
341         return status;\r
342 }\r
343 \r
344 \r
345 NTSTATUS\r
346 srp_dispatch_pnp(\r
347         IN              DEVICE_OBJECT               *p_dev_obj,\r
348         IN              IRP                         *p_irp )\r
349 {\r
350         NTSTATUS            status;\r
351         IO_STACK_LOCATION   *p_stack;\r
352         UCHAR               minor;\r
353         SRP_ENTER( SRP_DBG_PNP );\r
354 \r
355         p_stack = IoGetCurrentIrpStackLocation( p_irp );\r
356         minor = p_stack->MinorFunction;\r
357         SRP_TRACE( SRP_DBG_PNP,\r
358                 ("Minor PNP Function = %d.\n", minor) );\r
359 \r
360         if( minor == IRP_MN_START_DEVICE )\r
361         {\r
362                 NTSTATUS    wait_status;\r
363 \r
364                 wait_status = KeWaitForMutexObject(\r
365                         &g_srp_pnp_mutex, Executive, KernelMode, FALSE, NULL );\r
366 \r
367                 SRP_TRACE( SRP_DBG_PNP,\r
368                         ("KeWaitForMutexObject status = 0x%x.\n", wait_status) );\r
369                 gp_self_do = p_dev_obj;\r
370         }\r
371         status = gpfn_pnp( p_dev_obj, p_irp );\r
372         SRP_TRACE( SRP_DBG_PNP,\r
373                 ("gpfn_pnp status = 0x%x.\n", status) );\r
374 \r
375         if( minor == IRP_MN_START_DEVICE )\r
376         {\r
377                 LONG    release_status;\r
378                 gp_self_do = NULL;\r
379                 release_status = KeReleaseMutex( &g_srp_pnp_mutex, FALSE );\r
380                 SRP_TRACE( SRP_DBG_PNP,\r
381                         ("KeReleaseMutex status = %d.\n", release_status) );\r
382         }\r
383 \r
384         SRP_EXIT( SRP_DBG_PNP );\r
385         return status;\r
386 }\r
387 \r
388 \r
389 ULONG\r
390 srp_find_adapter(\r
391         IN                              PVOID                                           p_dev_ext,\r
392         IN                              PVOID                                           resv1,\r
393         IN                              PVOID                                           resv2,\r
394         IN                              PCHAR                                           arg_str,\r
395         IN      OUT                     PPORT_CONFIGURATION_INFORMATION         p_config,\r
396                 OUT                     PBOOLEAN                                        resv3 )\r
397 {\r
398         srp_ext_t                       *p_ext;\r
399         ib_api_status_t         ib_status;\r
400 \r
401         SRP_ENTER( SRP_DBG_PNP );\r
402 \r
403         UNUSED_PARAM( resv1 );\r
404         UNUSED_PARAM( resv2 );\r
405         UNUSED_PARAM( resv3 );\r
406         UNUSED_PARAM( arg_str );\r
407         UNUSED_PARAM( p_config );\r
408 \r
409         if( KeGetCurrentIrql() >= DISPATCH_LEVEL )\r
410         {\r
411                 SRP_TRACE_EXIT( SRP_DBG_ERROR,\r
412                         ("Improper IRQL!\n") );\r
413                 return SP_RETURN_ERROR;\r
414         }\r
415 \r
416         p_ext = (srp_ext_t*)p_dev_ext;\r
417 \r
418         ib_status = srp_hba_create( &g_drv_obj, p_ext );\r
419         if( ib_status != IB_SUCCESS )\r
420         {\r
421                 SRP_TRACE_EXIT( SRP_DBG_ERROR,\r
422                         ("srp_hba_create returned %d\n", ib_status) );\r
423                 return SP_RETURN_ERROR;\r
424         }\r
425 \r
426         p_config->SrbExtensionSize            = MAX( p_ext->p_hba->max_srb_ext_sz, sizeof( srp_send_descriptor_t ));\r
427         //CL_ASSERT( p_config->SrbExtensionSize >= sizeof( srp_send_descriptor_t ) );\r
428 \r
429         p_config->MaximumTransferLength       = SCSI_MAXIMUM_TRANSFER_SIZE;\r
430         p_config->AlignmentMask               = 0; /* byte alignment */\r
431         p_config->NumberOfBuses               = 1;\r
432         p_config->ScatterGather               = TRUE;\r
433     p_config->Master                      = TRUE; // The HBA is a "bus" master.\r
434 //      p_config->CachesData                  = TRUE; // Assume the HBA does cache data.\r
435         p_config->CachesData                  = FALSE; // Assume the HBA does not cache data.\r
436         p_config->MaximumNumberOfTargets      = p_ext->p_hba->ioc_info.profile.num_svc_entries;\r
437         p_config->MaximumNumberOfLogicalUnits = SCSI_MAXIMUM_LUNS_PER_TARGET;\r
438         p_config->MultipleRequestPerLu        = TRUE;\r
439         p_config->SynchronizationModel        = StorSynchronizeFullDuplex;\r
440         p_config->MapBuffers                  = STOR_MAP_NON_READ_WRITE_BUFFERS;\r
441         p_config->ResetTargetSupported        = FALSE;\r
442 \r
443 //      p_config->InitiatorBusId[0]           = 127;\r
444 //      p_config->DeviceExtensionSize         = sizeof( srp_ext_t );\r
445 \r
446         SRP_TRACE( SRP_DBG_VERBOSE,\r
447                 ("NumberOfPhysicalBreaks passed in = %d.\n", p_config->NumberOfPhysicalBreaks) );\r
448 \r
449         if ( p_config->NumberOfPhysicalBreaks == SP_UNINITIALIZED_VALUE )\r
450         {\r
451                 p_config->NumberOfPhysicalBreaks = p_ext->p_hba->max_sg - 1;\r
452         }\r
453         else\r
454         {\r
455                 p_config->NumberOfPhysicalBreaks = MIN( p_ext->p_hba->max_sg - 1, p_config->NumberOfPhysicalBreaks );\r
456         }\r
457 \r
458         SRP_TRACE( SRP_DBG_VERBOSE,\r
459                 ("NumberOfPhysicalBreaks set to = %d.\n", p_config->NumberOfPhysicalBreaks) );\r
460 \r
461         SRP_EXIT( SRP_DBG_PNP );\r
462         return SP_RETURN_FOUND;\r
463 }\r
464 \r
465 BOOLEAN\r
466 srp_init(\r
467         IN              PVOID                       p_dev_ext )\r
468 {\r
469         SRP_ENTER( SRP_DBG_PNP );\r
470 \r
471         UNUSED_PARAM( p_dev_ext );\r
472 \r
473         SRP_TRACE( SRP_DBG_PNP, ("called at IRQL %d\n", KeGetCurrentIrql()) );\r
474 \r
475         SRP_EXIT( SRP_DBG_PNP );\r
476         return TRUE;\r
477 }\r
478 \r
479 BOOLEAN\r
480 srp_start_io(\r
481         IN              PVOID                       p_dev_ext,\r
482         IN              PSCSI_REQUEST_BLOCK         p_srb )\r
483 {\r
484         SRP_ENTER( SRP_DBG_FUNC );\r
485 \r
486         SRP_TRACE( SRP_DBG_VERBOSE,\r
487                            ("Starting I/O for Function = %s(0x%x), Path = 0x%x, Target = 0x%x, Lun = 0x%x\n",\r
488                            g_srb_function_name[p_srb->Function],\r
489                            p_srb->Function,\r
490                            p_srb->PathId,\r
491                            p_srb->TargetId,\r
492                            p_srb->Lun) );\r
493 \r
494         CL_ASSERT( p_srb->SrbExtension != NULL );\r
495 \r
496         // Check the operation here\r
497         switch ( p_srb->Function )\r
498         {\r
499                 case SRB_FUNCTION_EXECUTE_SCSI:\r
500                         srp_post_io_request( p_dev_ext, p_srb );\r
501                         break;\r
502 \r
503                 case SRB_FUNCTION_ABORT_COMMAND:\r
504                         srp_abort_command( p_dev_ext, p_srb  );\r
505                         break;\r
506 #if !defined(WinXP)\r
507                 case SRB_FUNCTION_RESET_LOGICAL_UNIT:\r
508 #endif\r
509                 case SRB_FUNCTION_RESET_DEVICE:\r
510                         srp_lun_reset( p_dev_ext, p_srb  );\r
511                         break;\r
512 \r
513                 case SRB_FUNCTION_SHUTDOWN: /* Only receive this if CachesData is TRUE in PORT_CONFIGURATION_INFORMATION */\r
514                 {\r
515                         srp_hba_t       *p_hba         = ((srp_ext_t *)p_dev_ext)->p_hba;\r
516                         srp_session_t   *p_srp_session = p_hba->session_list[p_srb->TargetId];\r
517 \r
518                         g_srp_system_shutdown = TRUE;\r
519 \r
520                         if ( (p_srb->Lun == 0) && (p_srp_session != NULL) )\r
521                         {\r
522                                 p_hba->session_list[p_srb->TargetId] = NULL;\r
523 \r
524                                 CL_ASSERT( p_srp_session != NULL );\r
525 \r
526                                 p_srp_session->p_shutdown_srb = p_srb;\r
527                                 cl_obj_destroy( &p_srp_session->obj );\r
528 \r
529                                 SRP_TRACE( SRP_DBG_DEBUG,\r
530                                                    ("Returning SrbStatus %s(0x%x) for Function = %s(0x%x), Path = 0x%x, Target = 0x%x, Lun = 0x%x\n",\r
531                                                    g_srb_status_name[p_srb->SrbStatus],\r
532                                                    p_srb->SrbStatus,\r
533                                                    g_srb_function_name[p_srb->Function],\r
534                                                    p_srb->Function,\r
535                                                    p_srb->PathId,\r
536                                                    p_srb->TargetId,\r
537                                                    p_srb->Lun) );\r
538                         }\r
539                         else\r
540                         {\r
541                                 p_srb->SrbStatus = SRB_STATUS_SUCCESS;\r
542                                 SRP_TRACE( SRP_DBG_DEBUG,\r
543                                                    ("Returning SrbStatus %s(0x%x) for Function = %s(0x%x), Path = 0x%x, Target = 0x%x, Lun = 0x%x\n",\r
544                                                    g_srb_status_name[p_srb->SrbStatus],\r
545                                                    p_srb->SrbStatus,\r
546                                                    g_srb_function_name[p_srb->Function],\r
547                                                    p_srb->Function,\r
548                                                    p_srb->PathId,\r
549                                                    p_srb->TargetId,\r
550                                                    p_srb->Lun) );\r
551                                 StorPortNotification( RequestComplete, p_dev_ext, p_srb );\r
552                         }\r
553                         break;\r
554                 }\r
555 \r
556                 case SRB_FUNCTION_FLUSH: /* Only receive this if CachesData is TRUE in PORT_CONFIGURATION_INFORMATION */\r
557                         p_srb->SrbStatus = SRB_STATUS_SUCCESS;\r
558                         SRP_TRACE( SRP_DBG_DEBUG,\r
559                                            ("Returning SrbStatus %s(0x%x) for Function = %s(0x%x), Path = 0x%x, Target = 0x%x, Lun = 0x%x\n",\r
560                                            g_srb_status_name[p_srb->SrbStatus],\r
561                                            p_srb->SrbStatus,\r
562                                            g_srb_function_name[p_srb->Function],\r
563                                            p_srb->Function,\r
564                                            p_srb->PathId,\r
565                                            p_srb->TargetId,\r
566                                            p_srb->Lun) );\r
567                         StorPortNotification( RequestComplete, p_dev_ext, p_srb );\r
568                         break;\r
569 \r
570                 case SRB_FUNCTION_IO_CONTROL: /***** May Need To Support *****/\r
571 \r
572                 case SRB_FUNCTION_RESET_BUS:\r
573                 case SRB_FUNCTION_TERMINATE_IO:\r
574                 case SRB_FUNCTION_RELEASE_RECOVERY:\r
575                 case SRB_FUNCTION_RECEIVE_EVENT:\r
576                 case SRB_FUNCTION_LOCK_QUEUE:\r
577                 case SRB_FUNCTION_UNLOCK_QUEUE:\r
578                 case SRB_FUNCTION_CLAIM_DEVICE:\r
579                 case SRB_FUNCTION_RELEASE_QUEUE:\r
580                 case SRB_FUNCTION_ATTACH_DEVICE:\r
581                 case SRB_FUNCTION_RELEASE_DEVICE:\r
582                 case SRB_FUNCTION_FLUSH_QUEUE:\r
583                 case SRB_FUNCTION_REMOVE_DEVICE:\r
584                 case SRB_FUNCTION_WMI:\r
585 #if !defined(WinXP)\r
586                 case SRB_FUNCTION_SET_LINK_TIMEOUT:\r
587                 case SRB_FUNCTION_LINK_TIMEOUT_OCCURRED:\r
588                 case SRB_FUNCTION_LINK_TIMEOUT_COMPLETE:\r
589 #endif\r
590                 default:\r
591                         p_srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;\r
592                         SRP_TRACE( SRP_DBG_DEBUG,\r
593                                            ("Returning SrbStatus %s(0x%x) for Function = %s(0x%x), Path = 0x%x, Target = 0x%x, Lun = 0x%x\n",\r
594                                            g_srb_status_name[p_srb->SrbStatus],\r
595                                            p_srb->SrbStatus,\r
596                                            g_srb_function_name[p_srb->Function],\r
597                                            p_srb->Function,\r
598                                            p_srb->PathId,\r
599                                            p_srb->TargetId,\r
600                                            p_srb->Lun) );\r
601                         StorPortNotification( RequestComplete, p_dev_ext, p_srb );\r
602 \r
603         }\r
604 \r
605         SRP_EXIT( SRP_DBG_FUNC );\r
606 \r
607         return ( TRUE );\r
608 }\r
609 \r
610 BOOLEAN\r
611 srp_isr(\r
612         IN              PVOID                       p_dev_ext )\r
613 {\r
614         SRP_ENTER( SRP_DBG_PNP );\r
615 \r
616         UNUSED_PARAM( p_dev_ext );\r
617 \r
618         SRP_TRACE( SRP_DBG_PNP, ("called at IRQL %d\n", KeGetCurrentIrql()) );\r
619 \r
620         SRP_EXIT( SRP_DBG_PNP );\r
621         return TRUE;\r
622 }\r
623 \r
624 BOOLEAN\r
625 srp_reset(\r
626         IN              PVOID                       p_dev_ext,\r
627         IN              ULONG                       path_id )\r
628 {\r
629         SRP_ENTER( SRP_DBG_PNP );\r
630 \r
631         UNUSED_PARAM( p_dev_ext );\r
632         UNUSED_PARAM( path_id );\r
633 \r
634         SRP_EXIT( SRP_DBG_PNP );\r
635         return FALSE;\r
636 }\r
637 \r
638 SCSI_ADAPTER_CONTROL_STATUS\r
639 srp_adapter_ctrl(\r
640         IN              PVOID                       p_dev_ext,\r
641         IN              SCSI_ADAPTER_CONTROL_TYPE   ctrl_type,\r
642         IN              PVOID                       params )\r
643 {\r
644         srp_ext_t                           *p_ext;\r
645         SCSI_SUPPORTED_CONTROL_TYPE_LIST    *p_ctrl_list;\r
646 \r
647         SRP_ENTER( SRP_DBG_PNP );\r
648 \r
649         SRP_TRACE( SRP_DBG_PNP, ("called at IRQL %d\n", KeGetCurrentIrql()) );\r
650 \r
651         p_ext = (srp_ext_t*)p_dev_ext;\r
652 \r
653         switch( ctrl_type )\r
654         {\r
655         case ScsiQuerySupportedControlTypes:\r
656                 SRP_TRACE( SRP_DBG_DEBUG | SRP_DBG_VERBOSE,\r
657                         ("ScsiQuerySupportedControlTypes\n") );\r
658                 p_ctrl_list = (SCSI_SUPPORTED_CONTROL_TYPE_LIST*)params;\r
659                 p_ctrl_list->SupportedTypeList[ScsiQuerySupportedControlTypes] = TRUE;\r
660                 p_ctrl_list->SupportedTypeList[ScsiStopAdapter] = TRUE;\r
661                 p_ctrl_list->SupportedTypeList[ScsiRestartAdapter] = FALSE;\r
662                 p_ctrl_list->SupportedTypeList[ScsiSetBootConfig] = FALSE;\r
663                 p_ctrl_list->SupportedTypeList[ScsiSetRunningConfig] = FALSE;\r
664                 break;\r
665 \r
666         case ScsiStopAdapter:\r
667                 SRP_TRACE( SRP_DBG_DEBUG | SRP_DBG_VERBOSE,\r
668                         ("ScsiStopAdapter\n") );\r
669                 if( p_ext->p_hba )\r
670                 {\r
671                         SRP_TRACE( SRP_DBG_VERBOSE, ("HBA Object ref_cnt = %d\n", p_ext->p_hba->obj.ref_cnt) );\r
672                         cl_obj_destroy( &p_ext->p_hba->obj );\r
673                         p_ext->p_hba = NULL;\r
674                 }\r
675                 break;\r
676 \r
677         case ScsiRestartAdapter:\r
678                 SRP_TRACE( SRP_DBG_DEBUG | SRP_DBG_VERBOSE,\r
679                         ("ScsiRestartAdapter\n") );\r
680                 break;\r
681 \r
682         case ScsiSetBootConfig:\r
683                 SRP_TRACE( SRP_DBG_DEBUG | SRP_DBG_VERBOSE,\r
684                         ("ScsiSetBootConfig\n") );\r
685                 break;\r
686 \r
687         case ScsiSetRunningConfig:\r
688                 SRP_TRACE( SRP_DBG_DEBUG | SRP_DBG_VERBOSE,\r
689                         ("ScsiSetRunningConfig\n") );\r
690                 break;\r
691         }\r
692 \r
693         SRP_EXIT( SRP_DBG_PNP );\r
694         return ScsiAdapterControlSuccess;\r
695 }\r
696 \r
697 BOOLEAN\r
698 srp_build_io(\r
699         IN              PVOID                       p_dev_ext,\r
700         IN              PSCSI_REQUEST_BLOCK         p_srb )\r
701 {\r
702         SRP_ENTER( SRP_DBG_FUNC );\r
703 \r
704         if ( p_srb->Function == SRB_FUNCTION_EXECUTE_SCSI )\r
705         {\r
706 \r
707                 CL_ASSERT( p_srb->SrbExtension != NULL );\r
708 \r
709                 SRP_TRACE( SRP_DBG_VERBOSE,\r
710                                    ("Building I/O for Function = %s(0x%x), Path = 0x%x, Target = 0x%x, Lun = 0x%x\n",\r
711                                    g_srb_function_name[p_srb->Function],\r
712                                    p_srb->Function,\r
713                                    p_srb->PathId,\r
714                                    p_srb->TargetId,\r
715                                    p_srb->Lun) );\r
716 \r
717                 if ( srp_format_io_request( p_dev_ext, p_srb ) == FALSE )\r
718                 {\r
719                         SRP_TRACE_EXIT( SRP_DBG_ERROR,\r
720                                                         ("Returning SrbStatus %s(0x%x) for Function = %s(0x%x), Path = 0x%x, Target = 0x%x, Lun = 0x%x\n",\r
721                                                     g_srb_status_name[p_srb->SrbStatus],\r
722                                                         p_srb->SrbStatus,\r
723                                                         g_srb_function_name[p_srb->Function],\r
724                                                         p_srb->Function,\r
725                                                         p_srb->PathId,\r
726                                                         p_srb->TargetId,\r
727                                                         p_srb->Lun) );\r
728 \r
729                         StorPortNotification( RequestComplete, p_dev_ext, p_srb );\r
730 \r
731                         return ( FALSE );\r
732                 }\r
733         }\r
734 \r
735         SRP_EXIT( SRP_DBG_FUNC );\r
736 \r
737         return ( TRUE );\r
738 }\r