2 The IScsi's EFI_EXT_SCSI_PASS_THRU_PROTOCOL driver.
4 Copyright (c) 2004 - 2007, Intel Corporation.<BR>
5 All rights reserved. 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
69 return EFI_INVALID_PARAMETER
;
72 if ((Packet
== NULL
) || (Packet
->Cdb
== NULL
)) {
73 return EFI_INVALID_PARAMETER
;
76 return IScsiExecuteScsiCommand (This
, Target
, Lun
, Packet
);
80 Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These
81 can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal
82 Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the
83 Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI
86 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
87 @param[in, out] Target On input, a pointer to the Target ID (an array of size
88 TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
89 On output, a pointer to the Target ID (an array of
90 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI
91 channel. An input value of 0xF(all bytes in the array are 0xF) in the
92 Target array retrieves the Target ID of the first SCSI device present on a
94 @param[in, out] Lun On input, a pointer to the LUN of a SCSI device present on the SCSI
95 channel. On output, a pointer to the LUN of the next SCSI device present
98 @retval EFI_SUCCESS The Target ID and LUN of the next SCSI device on the SCSI
99 channel was returned in Target and Lun.
100 @retval EFI_INVALID_PARAMETER Target array is not all 0xF, and Target and Lun were
101 not returned on a previous call to GetNextTargetLun().
102 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.
106 IScsiExtScsiPassThruGetNextTargetLun (
107 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
108 IN OUT UINT8
**Target
,
112 ISCSI_DRIVER_DATA
*Private
;
113 ISCSI_SESSION_CONFIG_NVDATA
*ConfigNvData
;
114 UINT8 TargetId
[TARGET_MAX_BYTES
];
116 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This
);
117 ConfigNvData
= &Private
->Session
.ConfigData
.NvData
;
119 if ((*Target
)[0] == 0 && (CompareMem (Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
)) == 0)) {
121 // Only one <Target, Lun> pair per iSCSI Driver instance.
123 return EFI_NOT_FOUND
;
126 SetMem (TargetId
, TARGET_MAX_BYTES
, 0xFF);
127 if (CompareMem (*Target
, TargetId
, TARGET_MAX_BYTES
) == 0) {
129 CopyMem (Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
));
134 return EFI_INVALID_PARAMETER
;
138 Used to allocate and build a device path node for a SCSI device on a SCSI channel.
140 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
141 @param[in] Target The Target is an array of size TARGET_MAX_BYTES and it specifies the
142 Target ID of the SCSI device for which a device path node is to be
143 allocated and built. Transport drivers may chose to utilize a subset of
144 this size to suit the representation of targets. For example, a Fibre
145 Channel driver may use only 8 bytes (WWN) in the array to represent a
147 @param[in] Lun The LUN of the SCSI device for which a device path node is to be
149 @param[in, out] DevicePath A pointer to a single device path node that describes the SCSI device
150 specified by Target and Lun. This function is responsible for
151 allocating the buffer DevicePath with the boot service
152 AllocatePool(). It is the caller's responsibility to free
153 DevicePath when the caller is finished with DevicePath.
155 @retval EFI_SUCCESS The device path node that describes the SCSI device specified by
156 Target and Lun was allocated and returned in
158 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
159 @retval EFI_NOT_FOUND The SCSI devices specified by Target and Lun does not exist
161 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.
166 IScsiExtScsiPassThruBuildDevicePath (
167 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
170 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
173 ISCSI_DRIVER_DATA
*Private
;
174 ISCSI_SESSION
*Session
;
175 ISCSI_SESSION_CONFIG_NVDATA
*ConfigNvData
;
176 ISCSI_CHAP_AUTH_CONFIG_NVDATA
*AuthConfig
;
178 UINTN DevPathNodeLen
;
180 if ((DevicePath
== NULL
)) {
181 return EFI_INVALID_PARAMETER
;
184 if (Target
[0] != 0) {
185 return EFI_NOT_FOUND
;
188 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This
);
189 Session
= &Private
->Session
;
190 ConfigNvData
= &Session
->ConfigData
.NvData
;
191 AuthConfig
= &Session
->AuthData
.AuthConfig
;
193 if (CompareMem (&Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
)) != 0) {
194 return EFI_NOT_FOUND
;
197 DevPathNodeLen
= sizeof (ISCSI_DEVICE_PATH
) + AsciiStrLen (ConfigNvData
->TargetName
) + 1;
198 Node
= AllocatePool (DevPathNodeLen
);
200 return EFI_OUT_OF_RESOURCES
;
203 Node
->DevPath
.Type
= MESSAGING_DEVICE_PATH
;
204 Node
->DevPath
.SubType
= MSG_ISCSI_DP
;
205 SetDevicePathNodeLength (&Node
->DevPath
, (UINT16
)DevPathNodeLen
);
208 // 0 for TCP, others are reserved.
210 Node
->Iscsi
.NetworkProtocol
= 0;
212 Node
->Iscsi
.LoginOption
= 0;
213 switch (AuthConfig
->CHAPType
) {
214 case ISCSI_CHAP_NONE
:
215 Node
->Iscsi
.LoginOption
|= 0x0800;
219 Node
->Iscsi
.LoginOption
|= 0x1000;
226 CopyMem (&Node
->Iscsi
.Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
));
227 Node
->Iscsi
.TargetPortalGroupTag
= Session
->TargetPortalGroupTag
;
228 AsciiStrCpy ((CHAR8
*) Node
+ sizeof (ISCSI_DEVICE_PATH
), ConfigNvData
->TargetName
);
230 *DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) Node
;
236 Used to translate a device path node to a Target ID and LUN.
238 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
239 @param[in] DevicePath A pointer to a single device path node that describes the SCSI device
241 @param[out] Target A pointer to the Target Array which represents the ID of a SCSI device
243 @param[out] Lun A pointer to the LUN of a SCSI device on the SCSI channel.
245 @retval EFI_SUCCESS DevicePath was successfully translated to a Target ID and
246 LUN, and they were returned in Target and Lun.
247 @retval EFI_INVALID_PARAMETER DevicePath or Target or Lun is NULL.
248 @retval EFI_NOT_FOUND A valid translation from DevicePath to a Target ID and LUN
249 does not exist.Currently not implemented.
250 @retval EFI_UNSUPPORTED This driver does not support the device path node type in
255 IScsiExtScsiPassThruGetTargetLun (
256 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
257 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
262 ISCSI_DRIVER_DATA
*Private
;
263 ISCSI_SESSION_CONFIG_NVDATA
*ConfigNvData
;
265 if ((DevicePath
== NULL
) || (Target
== NULL
) || (Lun
== NULL
)) {
266 return EFI_INVALID_PARAMETER
;
269 if ((DevicePath
->Type
!= MESSAGING_DEVICE_PATH
) ||
270 (DevicePath
->SubType
!= MSG_ISCSI_DP
) ||
271 (DevicePathNodeLength (DevicePath
) <= sizeof (ISCSI_DEVICE_PATH
))
273 return EFI_UNSUPPORTED
;
276 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This
);
277 ConfigNvData
= &Private
->Session
.ConfigData
.NvData
;
279 ZeroMem (*Target
, TARGET_MAX_BYTES
);
281 if (AsciiStrCmp (ConfigNvData
->TargetName
, (CHAR8
*) DevicePath
+ sizeof (ISCSI_DEVICE_PATH
)) != 0) {
282 return EFI_UNSUPPORTED
;
285 CopyMem (Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
));
291 Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel.
292 Currently not implemented.
294 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
296 @retval EFI_SUCCESS The SCSI channel was reset.
297 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI channel.
298 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI channel.
299 @retval EFI_UNSUPPORTED The SCSI channel does not support a channel reset operation.
303 IScsiExtScsiPassThruResetChannel (
304 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
307 return EFI_UNSUPPORTED
;
311 Resets a SCSI logical unit that is connected to a SCSI channel. Currently not implemented.
313 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
314 @param[in] Target The Target is an array of size TARGET_MAX_BYTE and it represents the
315 target port ID of the SCSI device containing the SCSI logical unit to
316 reset. Transport drivers may chose to utilize a subset of this array to suit
317 the representation of their targets.
318 @param[in] Lun The LUN of the SCSI device to reset.
320 @retval EFI_SUCCESS The SCSI device specified by Target and Lun was reset.
321 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.
322 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI device
323 specified by Target and Lun.
324 @retval EFI_UNSUPPORTED The SCSI channel does not support a target reset operation.
325 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI device
326 specified by Target and Lun.
331 IScsiExtScsiPassThruResetTargetLun (
332 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
337 return EFI_UNSUPPORTED
;
341 Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either
342 be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs
343 for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to
344 see if a SCSI device is actually present at that location on the SCSI channel.
346 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
347 @param[in, out] Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
348 On output, a pointer to the Target ID (an array of
349 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI
350 channel. An input value of 0xF(all bytes in the array are 0xF) in the
351 Target array retrieves the Target ID of the first SCSI device present on a
354 @retval EFI_SUCCESS The Target ID of the next SCSI device on the SCSI
355 channel was returned in Target.
356 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.
357 @retval EFI_TIMEOUT Target array is not all 0xF, and Target were not
358 returned on a previous call to GetNextTarget().
359 Currently not implemented.
360 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.
364 IScsiExtScsiPassThruGetNextTarget (
365 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
366 IN OUT UINT8
**Target
369 UINT8 TargetId
[TARGET_MAX_BYTES
];
371 SetMem (TargetId
, TARGET_MAX_BYTES
, 0xFF);
373 if (CompareMem (*Target
, TargetId
, TARGET_MAX_BYTES
) == 0) {
376 } else if ((*Target
)[0] == 0) {
377 return EFI_NOT_FOUND
;
379 return EFI_INVALID_PARAMETER
;
383 EFI_EXT_SCSI_PASS_THRU_PROTOCOL gIScsiExtScsiPassThruProtocolTemplate
= {
385 IScsiExtScsiPassThruFunction
,
386 IScsiExtScsiPassThruGetNextTargetLun
,
387 IScsiExtScsiPassThruBuildDevicePath
,
388 IScsiExtScsiPassThruGetTargetLun
,
389 IScsiExtScsiPassThruResetChannel
,
390 IScsiExtScsiPassThruResetTargetLun
,
391 IScsiExtScsiPassThruGetNextTarget