2 The IScsi's EFI_EXT_SCSI_PASS_THRU_PROTOCOL driver.
4 Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "IScsiImpl.h"
18 Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function
19 supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the
20 nonblocking I/O functionality is optional.
22 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
23 @param[in] Target The Target is an array of size TARGET_MAX_BYTES and it represents
24 the id of the SCSI device to send the SCSI Request Packet. Each
25 transport driver may chose to utilize a subset of this size to suit the needs
26 of transport target representation. For example, a Fibre Channel driver
27 may use only 8 bytes (WWN) to represent an FC target.
28 @param[in] Lun The LUN of the SCSI device to send the SCSI Request Packet.
29 @param[in, out] Packet A pointer to the SCSI Request Packet to send to the SCSI device
30 specified by Target and Lun.
31 @param[in] Event If nonblocking I/O is not supported then Event is ignored, and blocking
32 I/O is performed. If Event is NULL, then blocking I/O is performed. If
33 Event is not NULL and non blocking I/O is supported, then
34 nonblocking I/O is performed, and Event will be signaled when the
35 SCSI Request Packet completes.
37 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host. For bi-directional
38 commands, InTransferLength bytes were transferred from
39 InDataBuffer. For write and bi-directional commands,
40 OutTransferLength bytes were transferred by
42 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was not executed. The number of bytes that
43 could be transferred is returned in InTransferLength. For write
44 and bi-directional commands, OutTransferLength bytes were
45 transferred by OutDataBuffer. Currently not implemeted.
46 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
47 SCSI Request Packets already queued. The caller may retry again later.
48 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request
50 @retval EFI_INVALID_PARAMETER Target, Lun, or the contents of ScsiRequestPacket are invalid.
51 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported
52 by the host adapter. This includes the case of Bi-directional SCSI
53 commands not supported by the implementation. The SCSI Request
54 Packet was not sent, so no additional status information is available.
55 Currently not implemeted.
56 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
60 IScsiExtScsiPassThruFunction (
61 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
64 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
*Packet
,
65 IN EFI_EVENT Event OPTIONAL
68 ISCSI_DRIVER_DATA
*Private
;
69 ISCSI_SESSION_CONFIG_NVDATA
*ConfigNvData
;
72 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This
);
73 ConfigNvData
= &Private
->Session
.ConfigData
.NvData
;
75 if (Target
[0] != 0 || (CompareMem (&Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
)) != 0)) {
76 return EFI_INVALID_PARAMETER
;
79 if ((Packet
== NULL
) || (Packet
->Cdb
== NULL
)) {
80 return EFI_INVALID_PARAMETER
;
83 Status
= IScsiExecuteScsiCommand (This
, Target
, Lun
, Packet
);
84 if ((Status
!= EFI_SUCCESS
) && (Status
!= EFI_NOT_READY
)) {
86 // Try to reinstate the session and re-execute the Scsi command.
88 if (EFI_ERROR (IScsiSessionReinstatement (Private
))) {
89 return EFI_DEVICE_ERROR
;
92 Status
= IScsiExecuteScsiCommand (This
, Target
, Lun
, Packet
);
99 Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These
100 can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal
101 Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the
102 Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI
105 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
106 @param[in, out] Target On input, a pointer to the Target ID (an array of size
107 TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
108 On output, a pointer to the Target ID (an array of
109 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI
110 channel. An input value of 0xF(all bytes in the array are 0xF) in the
111 Target array retrieves the Target ID of the first SCSI device present on a
113 @param[in, out] Lun On input, a pointer to the LUN of a SCSI device present on the SCSI
114 channel. On output, a pointer to the LUN of the next SCSI device present
117 @retval EFI_SUCCESS The Target ID and LUN of the next SCSI device on the SCSI
118 channel was returned in Target and Lun.
119 @retval EFI_INVALID_PARAMETER Target array is not all 0xF, and Target and Lun were
120 not returned on a previous call to GetNextTargetLun().
121 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.
125 IScsiExtScsiPassThruGetNextTargetLun (
126 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
127 IN OUT UINT8
**Target
,
131 ISCSI_DRIVER_DATA
*Private
;
132 ISCSI_SESSION_CONFIG_NVDATA
*ConfigNvData
;
133 UINT8 TargetId
[TARGET_MAX_BYTES
];
135 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This
);
136 ConfigNvData
= &Private
->Session
.ConfigData
.NvData
;
138 if ((*Target
)[0] == 0 && (CompareMem (Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
)) == 0)) {
140 // Only one <Target, Lun> pair per iSCSI Driver instance.
142 return EFI_NOT_FOUND
;
145 SetMem (TargetId
, TARGET_MAX_BYTES
, 0xFF);
146 if (CompareMem (*Target
, TargetId
, TARGET_MAX_BYTES
) == 0) {
148 CopyMem (Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
));
153 return EFI_INVALID_PARAMETER
;
157 Used to allocate and build a device path node for a SCSI device on a SCSI channel.
159 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
160 @param[in] Target The Target is an array of size TARGET_MAX_BYTES and it specifies the
161 Target ID of the SCSI device for which a device path node is to be
162 allocated and built. Transport drivers may chose to utilize a subset of
163 this size to suit the representation of targets. For example, a Fibre
164 Channel driver may use only 8 bytes (WWN) in the array to represent a
166 @param[in] Lun The LUN of the SCSI device for which a device path node is to be
168 @param[in, out] DevicePath A pointer to a single device path node that describes the SCSI device
169 specified by Target and Lun. This function is responsible for
170 allocating the buffer DevicePath with the boot service
171 AllocatePool(). It is the caller's responsibility to free
172 DevicePath when the caller is finished with DevicePath.
174 @retval EFI_SUCCESS The device path node that describes the SCSI device specified by
175 Target and Lun was allocated and returned in
177 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
178 @retval EFI_NOT_FOUND The SCSI devices specified by Target and Lun does not exist
180 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.
185 IScsiExtScsiPassThruBuildDevicePath (
186 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
189 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
192 ISCSI_DRIVER_DATA
*Private
;
193 ISCSI_SESSION
*Session
;
194 ISCSI_SESSION_CONFIG_NVDATA
*ConfigNvData
;
195 ISCSI_CHAP_AUTH_CONFIG_NVDATA
*AuthConfig
;
197 UINTN DevPathNodeLen
;
199 if (DevicePath
== NULL
) {
200 return EFI_INVALID_PARAMETER
;
203 if (Target
[0] != 0) {
204 return EFI_NOT_FOUND
;
207 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This
);
208 Session
= &Private
->Session
;
209 ConfigNvData
= &Session
->ConfigData
.NvData
;
210 AuthConfig
= &Session
->AuthData
.AuthConfig
;
212 if (CompareMem (&Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
)) != 0) {
213 return EFI_NOT_FOUND
;
216 DevPathNodeLen
= sizeof (ISCSI_DEVICE_PATH
) + AsciiStrLen (ConfigNvData
->TargetName
) + 1;
217 Node
= AllocatePool (DevPathNodeLen
);
219 return EFI_OUT_OF_RESOURCES
;
222 Node
->DevPath
.Type
= MESSAGING_DEVICE_PATH
;
223 Node
->DevPath
.SubType
= MSG_ISCSI_DP
;
224 SetDevicePathNodeLength (&Node
->DevPath
, (UINT16
)DevPathNodeLen
);
227 // 0 for TCP, others are reserved.
229 Node
->Iscsi
.NetworkProtocol
= 0;
231 Node
->Iscsi
.LoginOption
= 0;
232 switch (AuthConfig
->CHAPType
) {
233 case ISCSI_CHAP_NONE
:
234 Node
->Iscsi
.LoginOption
|= 0x0800;
238 Node
->Iscsi
.LoginOption
|= 0x1000;
245 CopyMem (&Node
->Iscsi
.Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
));
246 Node
->Iscsi
.TargetPortalGroupTag
= Session
->TargetPortalGroupTag
;
247 AsciiStrCpyS ((CHAR8
*) Node
+ sizeof (ISCSI_DEVICE_PATH
), AsciiStrLen (ConfigNvData
->TargetName
) + 1, ConfigNvData
->TargetName
);
249 *DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) Node
;
255 Used to translate a device path node to a Target ID and LUN.
257 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
258 @param[in] DevicePath A pointer to a single device path node that describes the SCSI device
260 @param[out] Target A pointer to the Target Array which represents the ID of a SCSI device
262 @param[out] Lun A pointer to the LUN of a SCSI device on the SCSI channel.
264 @retval EFI_SUCCESS DevicePath was successfully translated to a Target ID and
265 LUN, and they were returned in Target and Lun.
266 @retval EFI_INVALID_PARAMETER DevicePath or Target or Lun is NULL.
267 @retval EFI_NOT_FOUND A valid translation from DevicePath to a Target ID and LUN
268 does not exist.Currently not implemented.
269 @retval EFI_UNSUPPORTED This driver does not support the device path node type in
274 IScsiExtScsiPassThruGetTargetLun (
275 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
276 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
281 ISCSI_DRIVER_DATA
*Private
;
282 ISCSI_SESSION_CONFIG_NVDATA
*ConfigNvData
;
284 if ((DevicePath
== NULL
) || (Target
== NULL
) || (Lun
== NULL
)) {
285 return EFI_INVALID_PARAMETER
;
288 if ((DevicePath
->Type
!= MESSAGING_DEVICE_PATH
) ||
289 (DevicePath
->SubType
!= MSG_ISCSI_DP
) ||
290 (DevicePathNodeLength (DevicePath
) <= sizeof (ISCSI_DEVICE_PATH
))
292 return EFI_UNSUPPORTED
;
295 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This
);
296 ConfigNvData
= &Private
->Session
.ConfigData
.NvData
;
298 SetMem (*Target
, TARGET_MAX_BYTES
, 0xFF);
301 if (AsciiStrCmp (ConfigNvData
->TargetName
, (CHAR8
*) DevicePath
+ sizeof (ISCSI_DEVICE_PATH
)) != 0) {
302 return EFI_UNSUPPORTED
;
305 CopyMem (Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
));
311 Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel.
312 Currently not implemented.
314 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
316 @retval EFI_SUCCESS The SCSI channel was reset.
317 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI channel.
318 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI channel.
319 @retval EFI_UNSUPPORTED The SCSI channel does not support a channel reset operation.
323 IScsiExtScsiPassThruResetChannel (
324 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
327 return EFI_UNSUPPORTED
;
331 Resets a SCSI logical unit that is connected to a SCSI channel. Currently not implemented.
333 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
334 @param[in] Target The Target is an array of size TARGET_MAX_BYTE and it represents the
335 target port ID of the SCSI device containing the SCSI logical unit to
336 reset. Transport drivers may chose to utilize a subset of this array to suit
337 the representation of their targets.
338 @param[in] Lun The LUN of the SCSI device to reset.
340 @retval EFI_SUCCESS The SCSI device specified by Target and Lun was reset.
341 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.
342 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI device
343 specified by Target and Lun.
344 @retval EFI_UNSUPPORTED The SCSI channel does not support a target reset operation.
345 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI device
346 specified by Target and Lun.
351 IScsiExtScsiPassThruResetTargetLun (
352 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
357 return EFI_UNSUPPORTED
;
361 Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either
362 be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs
363 for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to
364 see if a SCSI device is actually present at that location on the SCSI channel.
366 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
367 @param[in, out] Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
368 On output, a pointer to the Target ID (an array of
369 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI
370 channel. An input value of 0xF(all bytes in the array are 0xF) in the
371 Target array retrieves the Target ID of the first SCSI device present on a
374 @retval EFI_SUCCESS The Target ID of the next SCSI device on the SCSI
375 channel was returned in Target.
376 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.
377 @retval EFI_TIMEOUT Target array is not all 0xF, and Target were not
378 returned on a previous call to GetNextTarget().
379 Currently not implemented.
380 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.
384 IScsiExtScsiPassThruGetNextTarget (
385 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
386 IN OUT UINT8
**Target
389 UINT8 TargetId
[TARGET_MAX_BYTES
];
391 SetMem (TargetId
, TARGET_MAX_BYTES
, 0xFF);
393 if (CompareMem (*Target
, TargetId
, TARGET_MAX_BYTES
) == 0) {
396 } else if ((*Target
)[0] == 0) {
397 return EFI_NOT_FOUND
;
399 return EFI_INVALID_PARAMETER
;
403 EFI_EXT_SCSI_PASS_THRU_PROTOCOL gIScsiExtScsiPassThruProtocolTemplate
= {
405 IScsiExtScsiPassThruFunction
,
406 IScsiExtScsiPassThruGetNextTargetLun
,
407 IScsiExtScsiPassThruBuildDevicePath
,
408 IScsiExtScsiPassThruGetTargetLun
,
409 IScsiExtScsiPassThruResetChannel
,
410 IScsiExtScsiPassThruResetTargetLun
,
411 IScsiExtScsiPassThruGetNextTarget