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