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