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