2 Header file for SCSI Bus Driver.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
15 #include <Protocol/ScsiPassThru.h>
16 #include <Protocol/ScsiPassThruExt.h>
17 #include <Protocol/ScsiIo.h>
18 #include <Protocol/ComponentName.h>
19 #include <Protocol/DriverBinding.h>
20 #include <Protocol/DevicePath.h>
22 #include <Library/DebugLib.h>
23 #include <Library/UefiDriverEntryPoint.h>
24 #include <Library/UefiLib.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Library/MemoryAllocationLib.h>
27 #include <Library/UefiScsiLib.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/DevicePathLib.h>
30 #include <Library/ReportStatusCodeLib.h>
32 #include <IndustryStandard/Scsi.h>
34 #define SCSI_IO_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'i', 'o')
41 typedef struct _SCSI_TARGET_ID
{
53 // SCSI Bus Controller device strcuture
55 #define SCSI_BUS_DEVICE_SIGNATURE SIGNATURE_32 ('s', 'c', 's', 'i')
58 // SCSI Bus Timeout Experience Value
60 #define SCSI_BUS_TIMEOUT EFI_TIMER_PERIOD_SECONDS (3)
63 // The ScsiBusProtocol is just used to locate ScsiBusDev
64 // structure in the SCSIBusDriverBindingStop(). Then we can
65 // Close all opened protocols and release this structure.
66 // ScsiBusProtocol is the private protocol.
67 // gEfiCallerIdGuid will be used as its protocol guid.
69 typedef struct _EFI_SCSI_BUS_PROTOCOL
{
71 } EFI_SCSI_BUS_PROTOCOL
;
73 typedef struct _SCSI_BUS_DEVICE
{
75 EFI_SCSI_BUS_PROTOCOL BusIdentify
;
76 BOOLEAN ExtScsiSupport
;
77 EFI_SCSI_PASS_THRU_PROTOCOL
*ScsiInterface
;
78 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*ExtScsiInterface
;
79 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
82 #define SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS(a) CR (a, SCSI_BUS_DEVICE, BusIdentify, SCSI_BUS_DEVICE_SIGNATURE)
87 EFI_SCSI_IO_PROTOCOL ScsiIo
;
88 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
89 BOOLEAN ExtScsiSupport
;
90 EFI_SCSI_PASS_THRU_PROTOCOL
*ScsiPassThru
;
91 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*ExtScsiPassThru
;
92 SCSI_BUS_DEVICE
*ScsiBusDeviceData
;
97 BOOLEAN RemovableDevice
;
100 #define SCSI_IO_DEV_FROM_THIS(a) CR (a, SCSI_IO_DEV, ScsiIo, SCSI_IO_DEV_SIGNATURE)
105 extern EFI_DRIVER_BINDING_PROTOCOL gScsiBusDriverBinding
;
106 extern EFI_COMPONENT_NAME_PROTOCOL gScsiBusComponentName
;
107 extern EFI_COMPONENT_NAME2_PROTOCOL gScsiBusComponentName2
;
110 Test to see if this driver supports ControllerHandle.
112 This service is called by the EFI boot service ConnectController(). In order
113 to make drivers as small as possible, there are a few calling restrictions for
114 this service. ConnectController() must follow these calling restrictions. If
115 any other agent wishes to call Supported() it must also follow these calling
118 @param This Protocol instance pointer.
119 @param ControllerHandle Handle of device to test
120 @param RemainingDevicePath Optional parameter use to pick a specific child
123 @retval EFI_SUCCESS This driver supports this device
124 @retval EFI_ALREADY_STARTED This driver is already running on this device
125 @retval other This driver does not support this device
130 SCSIBusDriverBindingSupported (
131 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
132 IN EFI_HANDLE Controller
,
133 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
137 Start this driver on ControllerHandle.
139 This service is called by the EFI boot service ConnectController(). In order
140 to make drivers as small as possible, there are a few calling restrictions for
141 this service. ConnectController() must follow these calling restrictions. If
142 any other agent wishes to call Start() it must also follow these calling
145 @param This Protocol instance pointer.
146 @param ControllerHandle Handle of device to bind driver to
147 @param RemainingDevicePath Optional parameter use to pick a specific child
150 @retval EFI_SUCCESS This driver is added to ControllerHandle
151 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
152 @retval other This driver does not support this device
157 SCSIBusDriverBindingStart (
158 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
159 IN EFI_HANDLE Controller
,
160 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
164 Stop this driver on ControllerHandle.
166 This service is called by the EFI boot service DisconnectController().
167 In order to make drivers as small as possible, there are a few calling
168 restrictions for this service. DisconnectController() must follow these
169 calling restrictions. If any other agent wishes to call Stop() it must also
170 follow these calling restrictions.
172 @param This Protocol instance pointer.
173 @param ControllerHandle Handle of device to stop driver on
174 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
175 children is zero stop the entire bus driver.
176 @param ChildHandleBuffer List of Child Handles to Stop.
178 @retval EFI_SUCCESS This driver is removed ControllerHandle
179 @retval other This driver was not removed from this device
184 SCSIBusDriverBindingStop (
185 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
186 IN EFI_HANDLE Controller
,
187 IN UINTN NumberOfChildren
,
188 IN EFI_HANDLE
*ChildHandleBuffer
192 // EFI Component Name Functions
195 Retrieves a Unicode string that is the user readable name of the driver.
197 This function retrieves the user readable name of a driver in the form of a
198 Unicode string. If the driver specified by This has a user readable name in
199 the language specified by Language, then a pointer to the driver name is
200 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
201 by This does not support the language specified by Language,
202 then EFI_UNSUPPORTED is returned.
204 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
205 EFI_COMPONENT_NAME_PROTOCOL instance.
207 @param Language A pointer to a Null-terminated ASCII string
208 array indicating the language. This is the
209 language of the driver name that the caller is
210 requesting, and it must match one of the
211 languages specified in SupportedLanguages. The
212 number of languages supported by a driver is up
213 to the driver writer. Language is specified
214 in RFC 4646 or ISO 639-2 language code format.
216 @param DriverName A pointer to the Unicode string to return.
217 This Unicode string is the name of the
218 driver specified by This in the language
219 specified by Language.
221 @retval EFI_SUCCESS The Unicode string for the Driver specified by
222 This and the language specified by Language was
223 returned in DriverName.
225 @retval EFI_INVALID_PARAMETER Language is NULL.
227 @retval EFI_INVALID_PARAMETER DriverName is NULL.
229 @retval EFI_UNSUPPORTED The driver specified by This does not support
230 the language specified by Language.
235 ScsiBusComponentNameGetDriverName (
236 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
238 OUT CHAR16
**DriverName
242 Retrieves a Unicode string that is the user readable name of the controller
243 that is being managed by a driver.
245 This function retrieves the user readable name of the controller specified by
246 ControllerHandle and ChildHandle in the form of a Unicode string. If the
247 driver specified by This has a user readable name in the language specified by
248 Language, then a pointer to the controller name is returned in ControllerName,
249 and EFI_SUCCESS is returned. If the driver specified by This is not currently
250 managing the controller specified by ControllerHandle and ChildHandle,
251 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
252 support the language specified by Language, then EFI_UNSUPPORTED is returned.
254 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
255 EFI_COMPONENT_NAME_PROTOCOL instance.
257 @param ControllerHandle The handle of a controller that the driver
258 specified by This is managing. This handle
259 specifies the controller whose name is to be
262 @param ChildHandle The handle of the child controller to retrieve
263 the name of. This is an optional parameter that
264 may be NULL. It will be NULL for device
265 drivers. It will also be NULL for a bus drivers
266 that wish to retrieve the name of the bus
267 controller. It will not be NULL for a bus
268 driver that wishes to retrieve the name of a
271 @param Language A pointer to a Null-terminated ASCII string
272 array indicating the language. This is the
273 language of the driver name that the caller is
274 requesting, and it must match one of the
275 languages specified in SupportedLanguages. The
276 number of languages supported by a driver is up
277 to the driver writer. Language is specified in
278 RFC 4646 or ISO 639-2 language code format.
280 @param ControllerName A pointer to the Unicode string to return.
281 This Unicode string is the name of the
282 controller specified by ControllerHandle and
283 ChildHandle in the language specified by
284 Language from the point of view of the driver
287 @retval EFI_SUCCESS The Unicode string for the user readable name in
288 the language specified by Language for the
289 driver specified by This was returned in
292 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
294 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
297 @retval EFI_INVALID_PARAMETER Language is NULL.
299 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
301 @retval EFI_UNSUPPORTED The driver specified by This is not currently
302 managing the controller specified by
303 ControllerHandle and ChildHandle.
305 @retval EFI_UNSUPPORTED The driver specified by This does not support
306 the language specified by Language.
311 ScsiBusComponentNameGetControllerName (
312 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
313 IN EFI_HANDLE ControllerHandle
,
314 IN EFI_HANDLE ChildHandle OPTIONAL
,
316 OUT CHAR16
**ControllerName
320 Retrieves the device type information of the SCSI Controller.
322 @param This Protocol instance pointer.
323 @param DeviceType A pointer to the device type information retrieved from
326 @retval EFI_SUCCESS Retrieves the device type information successfully.
327 @retval EFI_INVALID_PARAMETER The DeviceType is NULL.
333 IN EFI_SCSI_IO_PROTOCOL
*This
,
334 OUT UINT8
*DeviceType
338 Retrieves the device location in the SCSI channel.
340 @param This Protocol instance pointer.
341 @param Target A pointer to the Target ID of a SCSI device
343 @param Lun A pointer to the LUN of the SCSI device on
346 @retval EFI_SUCCESS Retrieves the device location successfully.
347 @retval EFI_INVALID_PARAMETER The Target or Lun is NULL.
352 ScsiGetDeviceLocation (
353 IN EFI_SCSI_IO_PROTOCOL
*This
,
354 IN OUT UINT8
**Target
,
359 Resets the SCSI Bus that the SCSI Controller is attached to.
361 @param This Protocol instance pointer.
363 @retval EFI_SUCCESS The SCSI bus is reset successfully.
364 @retval EFI_DEVICE_ERROR Errors encountered when resetting the SCSI bus.
365 @retval EFI_UNSUPPORTED The bus reset operation is not supported by the
366 SCSI Host Controller.
367 @retval EFI_TIMEOUT A timeout occurred while attempting to reset
373 IN EFI_SCSI_IO_PROTOCOL
*This
377 Resets the SCSI Controller that the device handle specifies.
379 @param This Protocol instance pointer.
381 @retval EFI_SUCCESS Reset the SCSI controller successfully.
382 @retval EFI_DEVICE_ERROR Errors are encountered when resetting the SCSI Controller.
383 @retval EFI_UNSUPPORTED The SCSI bus does not support a device reset operation.
384 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the
390 IN EFI_SCSI_IO_PROTOCOL
*This
394 Sends a SCSI Request Packet to the SCSI Controller for execution.
396 @param This Protocol instance pointer.
397 @param CommandPacket The SCSI request packet to send to the SCSI
398 Controller specified by the device handle.
399 @param Event If the SCSI bus where the SCSI device is attached
400 does not support non-blocking I/O, then Event is
401 ignored, and blocking I/O is performed.
402 If Event is NULL, then blocking I/O is performed.
403 If Event is not NULL and non-blocking I/O is
404 supported, then non-blocking I/O is performed,
405 and Event will be signaled when the SCSI Request
408 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host
409 successfully, and TransferLength bytes were
410 transferred to/from DataBuffer.See
411 HostAdapterStatus, TargetStatus,
412 SenseDataLength, and SenseData in that order
413 for additional status information.
414 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
415 but the entire DataBuffer could not be transferred.
416 The actual number of bytes transferred is returned
417 in TransferLength. See HostAdapterStatus,
418 TargetStatus, SenseDataLength, and SenseData in
419 that order for additional status information.
420 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
421 there are too many SCSI Command Packets already
422 queued.The caller may retry again later.
423 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
424 the SCSI Request Packet. See HostAdapterStatus,
425 TargetStatus, SenseDataLength, and SenseData in
426 that order for additional status information.
427 @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid.
428 The SCSI Request Packet was not sent, so no
429 additional status information is available.
430 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
431 is not supported by the SCSI initiator(i.e., SCSI
432 Host Controller). The SCSI Request Packet was not
433 sent, so no additional status information is
435 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
436 Request Packet to execute. See HostAdapterStatus,
437 TargetStatus, SenseDataLength, and SenseData in
438 that order for additional status information.
442 ScsiExecuteSCSICommand (
443 IN EFI_SCSI_IO_PROTOCOL
*This
,
444 IN OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
,
445 IN EFI_EVENT Event OPTIONAL
449 Scan SCSI Bus to discover the device, and attach ScsiIoProtocol to it.
451 @param This Protocol instance pointer
452 @param Controller Controller handle
453 @param TargetId Tartget to be scanned
454 @param Lun The Lun of the SCSI device on the SCSI channel.
455 @param ScsiBusDev The pointer of SCSI_BUS_DEVICE
457 @retval EFI_SUCCESS Successfully to discover the device and attach
458 ScsiIoProtocol to it.
459 @retval EFI_OUT_OF_RESOURCES Fail to discover the device.
464 ScsiScanCreateDevice (
465 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
466 IN EFI_HANDLE Controller
,
467 IN SCSI_TARGET_ID
*TargetId
,
469 IN OUT SCSI_BUS_DEVICE
*ScsiBusDev
473 Discovery SCSI Device
475 @param ScsiIoDevice The pointer of SCSI_IO_DEV
477 @retval TRUE Find SCSI Device and verify it.
478 @retval FALSE Unable to find SCSI Device.
483 IN OUT SCSI_IO_DEV
*ScsiIoDevice