]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiBusDxe / ScsiBus.h
... / ...
CommitLineData
1/** @file\r
2 Header file for SCSI Bus Driver.\r
3\r
4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
5SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
7**/\r
8\r
9#ifndef _SCSI_BUS_H_\r
10#define _SCSI_BUS_H_\r
11\r
12\r
13#include <Uefi.h>\r
14\r
15#include <Protocol/ScsiPassThru.h>\r
16#include <Protocol/ScsiPassThruExt.h>\r
17#include <Protocol/ScsiIo.h>\r
18#include <Protocol/ComponentName.h>\r
19#include <Protocol/DriverBinding.h>\r
20#include <Protocol/DevicePath.h>\r
21\r
22#include <Library/DebugLib.h>\r
23#include <Library/UefiDriverEntryPoint.h>\r
24#include <Library/UefiLib.h>\r
25#include <Library/BaseMemoryLib.h>\r
26#include <Library/MemoryAllocationLib.h>\r
27#include <Library/UefiScsiLib.h>\r
28#include <Library/UefiBootServicesTableLib.h>\r
29#include <Library/DevicePathLib.h>\r
30#include <Library/ReportStatusCodeLib.h>\r
31\r
32#include <IndustryStandard/Scsi.h>\r
33\r
34#define SCSI_IO_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'i', 'o')\r
35\r
36typedef union {\r
37 UINT32 Scsi;\r
38 UINT8 ExtScsi[4];\r
39} SCSI_ID;\r
40\r
41typedef struct _SCSI_TARGET_ID {\r
42 SCSI_ID ScsiId;\r
43 UINT8 ExtScsiId[12];\r
44}SCSI_TARGET_ID;\r
45\r
46\r
47typedef struct {\r
48 VOID *Data1;\r
49 VOID *Data2;\r
50} SCSI_EVENT_DATA;\r
51\r
52//\r
53// SCSI Bus Controller device strcuture\r
54//\r
55#define SCSI_BUS_DEVICE_SIGNATURE SIGNATURE_32 ('s', 'c', 's', 'i')\r
56\r
57//\r
58// SCSI Bus Timeout Experience Value\r
59//\r
60#define SCSI_BUS_TIMEOUT EFI_TIMER_PERIOD_SECONDS (3)\r
61\r
62//\r
63// The ScsiBusProtocol is just used to locate ScsiBusDev\r
64// structure in the SCSIBusDriverBindingStop(). Then we can\r
65// Close all opened protocols and release this structure.\r
66// ScsiBusProtocol is the private protocol.\r
67// gEfiCallerIdGuid will be used as its protocol guid.\r
68//\r
69typedef struct _EFI_SCSI_BUS_PROTOCOL {\r
70 UINT64 Reserved;\r
71} EFI_SCSI_BUS_PROTOCOL;\r
72\r
73typedef struct _SCSI_BUS_DEVICE {\r
74 UINTN Signature;\r
75 EFI_SCSI_BUS_PROTOCOL BusIdentify;\r
76 BOOLEAN ExtScsiSupport;\r
77 EFI_SCSI_PASS_THRU_PROTOCOL *ScsiInterface;\r
78 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtScsiInterface;\r
79 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
80} SCSI_BUS_DEVICE;\r
81\r
82#define SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS(a) CR (a, SCSI_BUS_DEVICE, BusIdentify, SCSI_BUS_DEVICE_SIGNATURE)\r
83\r
84typedef struct {\r
85 UINT32 Signature;\r
86 EFI_HANDLE Handle;\r
87 EFI_SCSI_IO_PROTOCOL ScsiIo;\r
88 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
89 BOOLEAN ExtScsiSupport;\r
90 EFI_SCSI_PASS_THRU_PROTOCOL *ScsiPassThru;\r
91 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtScsiPassThru;\r
92 SCSI_BUS_DEVICE *ScsiBusDeviceData;\r
93 SCSI_TARGET_ID Pun;\r
94 UINT64 Lun;\r
95 UINT8 ScsiDeviceType;\r
96 UINT8 ScsiVersion;\r
97 BOOLEAN RemovableDevice;\r
98} SCSI_IO_DEV;\r
99\r
100#define SCSI_IO_DEV_FROM_THIS(a) CR (a, SCSI_IO_DEV, ScsiIo, SCSI_IO_DEV_SIGNATURE)\r
101\r
102//\r
103// Global Variables\r
104//\r
105extern EFI_DRIVER_BINDING_PROTOCOL gScsiBusDriverBinding;\r
106extern EFI_COMPONENT_NAME_PROTOCOL gScsiBusComponentName;\r
107extern EFI_COMPONENT_NAME2_PROTOCOL gScsiBusComponentName2;\r
108\r
109/**\r
110 Test to see if this driver supports ControllerHandle.\r
111\r
112 This service is called by the EFI boot service ConnectController(). In order\r
113 to make drivers as small as possible, there are a few calling restrictions for\r
114 this service. ConnectController() must follow these calling restrictions. If\r
115 any other agent wishes to call Supported() it must also follow these calling\r
116 restrictions.\r
117\r
118 @param This Protocol instance pointer.\r
119 @param ControllerHandle Handle of device to test\r
120 @param RemainingDevicePath Optional parameter use to pick a specific child\r
121 device to start.\r
122\r
123 @retval EFI_SUCCESS This driver supports this device\r
124 @retval EFI_ALREADY_STARTED This driver is already running on this device\r
125 @retval other This driver does not support this device\r
126\r
127**/\r
128EFI_STATUS\r
129EFIAPI\r
130SCSIBusDriverBindingSupported (\r
131 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
132 IN EFI_HANDLE Controller,\r
133 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
134 );\r
135\r
136/**\r
137 Start this driver on ControllerHandle.\r
138\r
139 This service is called by the EFI boot service ConnectController(). In order\r
140 to make drivers as small as possible, there are a few calling restrictions for\r
141 this service. ConnectController() must follow these calling restrictions. If\r
142 any other agent wishes to call Start() it must also follow these calling\r
143 restrictions.\r
144\r
145 @param This Protocol instance pointer.\r
146 @param ControllerHandle Handle of device to bind driver to\r
147 @param RemainingDevicePath Optional parameter use to pick a specific child\r
148 device to start.\r
149\r
150 @retval EFI_SUCCESS This driver is added to ControllerHandle\r
151 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
152 @retval other This driver does not support this device\r
153\r
154**/\r
155EFI_STATUS\r
156EFIAPI\r
157SCSIBusDriverBindingStart (\r
158 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
159 IN EFI_HANDLE Controller,\r
160 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
161 );\r
162\r
163/**\r
164 Stop this driver on ControllerHandle.\r
165\r
166 This service is called by the EFI boot service DisconnectController().\r
167 In order to make drivers as small as possible, there are a few calling\r
168 restrictions for this service. DisconnectController() must follow these\r
169 calling restrictions. If any other agent wishes to call Stop() it must also\r
170 follow these calling restrictions.\r
171\r
172 @param This Protocol instance pointer.\r
173 @param ControllerHandle Handle of device to stop driver on\r
174 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
175 children is zero stop the entire bus driver.\r
176 @param ChildHandleBuffer List of Child Handles to Stop.\r
177\r
178 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
179 @retval other This driver was not removed from this device\r
180\r
181**/\r
182EFI_STATUS\r
183EFIAPI\r
184SCSIBusDriverBindingStop (\r
185 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
186 IN EFI_HANDLE Controller,\r
187 IN UINTN NumberOfChildren,\r
188 IN EFI_HANDLE *ChildHandleBuffer\r
189 );\r
190\r
191//\r
192// EFI Component Name Functions\r
193//\r
194/**\r
195 Retrieves a Unicode string that is the user readable name of the driver.\r
196\r
197 This function retrieves the user readable name of a driver in the form of a\r
198 Unicode string. If the driver specified by This has a user readable name in\r
199 the language specified by Language, then a pointer to the driver name is\r
200 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
201 by This does not support the language specified by Language,\r
202 then EFI_UNSUPPORTED is returned.\r
203\r
204 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
205 EFI_COMPONENT_NAME_PROTOCOL instance.\r
206\r
207 @param Language A pointer to a Null-terminated ASCII string\r
208 array indicating the language. This is the\r
209 language of the driver name that the caller is\r
210 requesting, and it must match one of the\r
211 languages specified in SupportedLanguages. The\r
212 number of languages supported by a driver is up\r
213 to the driver writer. Language is specified\r
214 in RFC 4646 or ISO 639-2 language code format.\r
215\r
216 @param DriverName A pointer to the Unicode string to return.\r
217 This Unicode string is the name of the\r
218 driver specified by This in the language\r
219 specified by Language.\r
220\r
221 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
222 This and the language specified by Language was\r
223 returned in DriverName.\r
224\r
225 @retval EFI_INVALID_PARAMETER Language is NULL.\r
226\r
227 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
228\r
229 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
230 the language specified by Language.\r
231\r
232**/\r
233EFI_STATUS\r
234EFIAPI\r
235ScsiBusComponentNameGetDriverName (\r
236 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
237 IN CHAR8 *Language,\r
238 OUT CHAR16 **DriverName\r
239 );\r
240\r
241/**\r
242 Retrieves a Unicode string that is the user readable name of the controller\r
243 that is being managed by a driver.\r
244\r
245 This function retrieves the user readable name of the controller specified by\r
246 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
247 driver specified by This has a user readable name in the language specified by\r
248 Language, then a pointer to the controller name is returned in ControllerName,\r
249 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
250 managing the controller specified by ControllerHandle and ChildHandle,\r
251 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
252 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
253\r
254 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
255 EFI_COMPONENT_NAME_PROTOCOL instance.\r
256\r
257 @param ControllerHandle The handle of a controller that the driver\r
258 specified by This is managing. This handle\r
259 specifies the controller whose name is to be\r
260 returned.\r
261\r
262 @param ChildHandle The handle of the child controller to retrieve\r
263 the name of. This is an optional parameter that\r
264 may be NULL. It will be NULL for device\r
265 drivers. It will also be NULL for a bus drivers\r
266 that wish to retrieve the name of the bus\r
267 controller. It will not be NULL for a bus\r
268 driver that wishes to retrieve the name of a\r
269 child controller.\r
270\r
271 @param Language A pointer to a Null-terminated ASCII string\r
272 array indicating the language. This is the\r
273 language of the driver name that the caller is\r
274 requesting, and it must match one of the\r
275 languages specified in SupportedLanguages. The\r
276 number of languages supported by a driver is up\r
277 to the driver writer. Language is specified in\r
278 RFC 4646 or ISO 639-2 language code format.\r
279\r
280 @param ControllerName A pointer to the Unicode string to return.\r
281 This Unicode string is the name of the\r
282 controller specified by ControllerHandle and\r
283 ChildHandle in the language specified by\r
284 Language from the point of view of the driver\r
285 specified by This.\r
286\r
287 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
288 the language specified by Language for the\r
289 driver specified by This was returned in\r
290 DriverName.\r
291\r
292 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
293\r
294 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
295 EFI_HANDLE.\r
296\r
297 @retval EFI_INVALID_PARAMETER Language is NULL.\r
298\r
299 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
300\r
301 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
302 managing the controller specified by\r
303 ControllerHandle and ChildHandle.\r
304\r
305 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
306 the language specified by Language.\r
307\r
308**/\r
309EFI_STATUS\r
310EFIAPI\r
311ScsiBusComponentNameGetControllerName (\r
312 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
313 IN EFI_HANDLE ControllerHandle,\r
314 IN EFI_HANDLE ChildHandle OPTIONAL,\r
315 IN CHAR8 *Language,\r
316 OUT CHAR16 **ControllerName\r
317 );\r
318\r
319/**\r
320 Retrieves the device type information of the SCSI Controller.\r
321\r
322 @param This Protocol instance pointer.\r
323 @param DeviceType A pointer to the device type information retrieved from\r
324 the SCSI Controller.\r
325\r
326 @retval EFI_SUCCESS Retrieves the device type information successfully.\r
327 @retval EFI_INVALID_PARAMETER The DeviceType is NULL.\r
328\r
329**/\r
330EFI_STATUS\r
331EFIAPI\r
332ScsiGetDeviceType (\r
333 IN EFI_SCSI_IO_PROTOCOL *This,\r
334 OUT UINT8 *DeviceType\r
335 );\r
336\r
337/**\r
338 Retrieves the device location in the SCSI channel.\r
339\r
340 @param This Protocol instance pointer.\r
341 @param Target A pointer to the Target ID of a SCSI device\r
342 on the SCSI channel.\r
343 @param Lun A pointer to the LUN of the SCSI device on\r
344 the SCSI channel.\r
345\r
346 @retval EFI_SUCCESS Retrieves the device location successfully.\r
347 @retval EFI_INVALID_PARAMETER The Target or Lun is NULL.\r
348\r
349**/\r
350EFI_STATUS\r
351EFIAPI\r
352ScsiGetDeviceLocation (\r
353 IN EFI_SCSI_IO_PROTOCOL *This,\r
354 IN OUT UINT8 **Target,\r
355 OUT UINT64 *Lun\r
356 );\r
357\r
358/**\r
359 Resets the SCSI Bus that the SCSI Controller is attached to.\r
360\r
361 @param This Protocol instance pointer.\r
362\r
363 @retval EFI_SUCCESS The SCSI bus is reset successfully.\r
364 @retval EFI_DEVICE_ERROR Errors encountered when resetting the SCSI bus.\r
365 @retval EFI_UNSUPPORTED The bus reset operation is not supported by the\r
366 SCSI Host Controller.\r
367 @retval EFI_TIMEOUT A timeout occurred while attempting to reset\r
368 the SCSI bus.\r
369**/\r
370EFI_STATUS\r
371EFIAPI\r
372ScsiResetBus (\r
373 IN EFI_SCSI_IO_PROTOCOL *This\r
374 );\r
375\r
376/**\r
377 Resets the SCSI Controller that the device handle specifies.\r
378\r
379 @param This Protocol instance pointer.\r
380\r
381 @retval EFI_SUCCESS Reset the SCSI controller successfully.\r
382 @retval EFI_DEVICE_ERROR Errors are encountered when resetting the SCSI Controller.\r
383 @retval EFI_UNSUPPORTED The SCSI bus does not support a device reset operation.\r
384 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the\r
385 SCSI Controller.\r
386**/\r
387EFI_STATUS\r
388EFIAPI\r
389ScsiResetDevice (\r
390 IN EFI_SCSI_IO_PROTOCOL *This\r
391 );\r
392\r
393/**\r
394 Sends a SCSI Request Packet to the SCSI Controller for execution.\r
395\r
396 @param This Protocol instance pointer.\r
397 @param CommandPacket The SCSI request packet to send to the SCSI\r
398 Controller specified by the device handle.\r
399 @param Event If the SCSI bus where the SCSI device is attached\r
400 does not support non-blocking I/O, then Event is\r
401 ignored, and blocking I/O is performed.\r
402 If Event is NULL, then blocking I/O is performed.\r
403 If Event is not NULL and non-blocking I/O is\r
404 supported, then non-blocking I/O is performed,\r
405 and Event will be signaled when the SCSI Request\r
406 Packet completes.\r
407\r
408 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host\r
409 successfully, and TransferLength bytes were\r
410 transferred to/from DataBuffer.See\r
411 HostAdapterStatus, TargetStatus,\r
412 SenseDataLength, and SenseData in that order\r
413 for additional status information.\r
414 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,\r
415 but the entire DataBuffer could not be transferred.\r
416 The actual number of bytes transferred is returned\r
417 in TransferLength. See HostAdapterStatus,\r
418 TargetStatus, SenseDataLength, and SenseData in\r
419 that order for additional status information.\r
420 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because\r
421 there are too many SCSI Command Packets already\r
422 queued.The caller may retry again later.\r
423 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send\r
424 the SCSI Request Packet. See HostAdapterStatus,\r
425 TargetStatus, SenseDataLength, and SenseData in\r
426 that order for additional status information.\r
427 @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid.\r
428 The SCSI Request Packet was not sent, so no\r
429 additional status information is available.\r
430 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet\r
431 is not supported by the SCSI initiator(i.e., SCSI\r
432 Host Controller). The SCSI Request Packet was not\r
433 sent, so no additional status information is\r
434 available.\r
435 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI\r
436 Request Packet to execute. See HostAdapterStatus,\r
437 TargetStatus, SenseDataLength, and SenseData in\r
438 that order for additional status information.\r
439**/\r
440EFI_STATUS\r
441EFIAPI\r
442ScsiExecuteSCSICommand (\r
443 IN EFI_SCSI_IO_PROTOCOL *This,\r
444 IN OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET *CommandPacket,\r
445 IN EFI_EVENT Event OPTIONAL\r
446 );\r
447\r
448/**\r
449 Scan SCSI Bus to discover the device, and attach ScsiIoProtocol to it.\r
450\r
451 @param This Protocol instance pointer\r
452 @param Controller Controller handle\r
453 @param TargetId Tartget to be scanned\r
454 @param Lun The Lun of the SCSI device on the SCSI channel.\r
455 @param ScsiBusDev The pointer of SCSI_BUS_DEVICE\r
456\r
457 @retval EFI_SUCCESS Successfully to discover the device and attach\r
458 ScsiIoProtocol to it.\r
459 @retval EFI_OUT_OF_RESOURCES Fail to discover the device.\r
460\r
461**/\r
462EFI_STATUS\r
463EFIAPI\r
464ScsiScanCreateDevice (\r
465 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
466 IN EFI_HANDLE Controller,\r
467 IN SCSI_TARGET_ID *TargetId,\r
468 IN UINT64 Lun,\r
469 IN OUT SCSI_BUS_DEVICE *ScsiBusDev\r
470 );\r
471\r
472/**\r
473 Discovery SCSI Device\r
474\r
475 @param ScsiIoDevice The pointer of SCSI_IO_DEV\r
476\r
477 @retval TRUE Find SCSI Device and verify it.\r
478 @retval FALSE Unable to find SCSI Device.\r
479\r
480**/\r
481BOOLEAN\r
482DiscoverScsiDevice (\r
483 IN OUT SCSI_IO_DEV *ScsiIoDevice\r
484 );\r
485\r
486#endif\r