3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 IScsiExtScsiPassThru.c
20 #include "IScsiImpl.h"
24 IScsiExtScsiPassThruFunction (
25 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
28 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
*Packet
,
29 IN EFI_EVENT Event OPTIONAL
35 This function sends out the SCSI command via iSCSI transport layer and returned
36 back the data received from the iSCSI target.
40 This - The EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
41 Target - The Target ID of device to send the SCSI Request Packet.
42 Lun - The LUN of the device to send the SCSI Request Packet.
43 Packet - The SCSI Request Packet to send to the device.
44 Event - The event used in non-blocking mode, it should be always NULL.
53 return EFI_INVALID_PARAMETER
;
56 if ((Packet
== NULL
) || (Packet
->Cdb
== NULL
)) {
57 return EFI_INVALID_PARAMETER
;
60 return IScsiExecuteScsiCommand (This
, Target
, Lun
, Packet
);
65 IScsiExtScsiPassThruGetNextTargetLun (
66 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
67 IN OUT UINT8
**Target
,
74 Retrieve the list of legal Target IDs for SCSI devices on a SCSI channel.
78 This - The EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance..
79 Target - On input, a pointer to the Target ID of a SCSI device present on the
80 SCSI channel. On output, a pointer to the Target ID of the next SCSI
81 device present on a SCSI channel. An input value of 0xFFFFFFFF
82 retrieves the Target ID of the first SCSI device present on a SCSI channel.
83 Lun - On input, a pointer to the LUN of a SCSI device present on the SCSI
84 channel. On output, a pointer to the LUN of the next SCSI device present on
89 EFI_SUCCESS - The Target ID and Lun of the next SCSI device
90 on the SCSI channel was returned in Target and Lun.
91 EFI_NOT_FOUND - There are no more SCSI devices on this SCSI channel.
92 EFI_INVALID_PARAMETER - Target is not 0xFFFFFFFF,and Target and Lun were not
93 returned on a previous call to GetNextDevice().
97 ISCSI_DRIVER_DATA
*Private
;
98 ISCSI_SESSION_CONFIG_NVDATA
*ConfigNvData
;
99 UINT8 TargetId
[TARGET_MAX_BYTES
];
101 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This
);
102 ConfigNvData
= &Private
->Session
.ConfigData
.NvData
;
104 if ((*Target
)[0] == 0 && (NetCompareMem (Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
)) == 0)) {
106 // Only one <Target, Lun> pair per iSCSI Driver instance.
108 return EFI_NOT_FOUND
;
111 NetSetMem (TargetId
, TARGET_MAX_BYTES
, 0xFF);
112 if (NetCompareMem (*Target
, TargetId
, TARGET_MAX_BYTES
) == 0) {
114 NetCopyMem (Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
));
119 return EFI_INVALID_PARAMETER
;
124 IScsiExtScsiPassThruBuildDevicePath (
125 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
128 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
134 Allocate and build a device path node for a SCSI device on a SCSI channel.
138 This - Protocol instance pointer.
139 Target - The Target ID of the SCSI device for which
140 a device path node is to be allocated and built.
141 Lun - The LUN of the SCSI device for which a device
142 path node is to be allocated and built.
143 DevicePath - A pointer to a single device path node that
144 describes the SCSI device specified by
145 Target and Lun. This function is responsible
146 for allocating the buffer DevicePath with the boot
147 service AllocatePool(). It is the caller's
148 responsibility to free DevicePath when the caller
149 is finished with DevicePath.
153 EFI_SUCCESS - The device path node that describes the SCSI device
154 specified by Target and Lun was allocated and
155 returned in DevicePath.
156 EFI_NOT_FOUND - The SCSI devices specified by Target and Lun does
157 not exist on the SCSI channel.
158 EFI_INVALID_PARAMETER - DevicePath is NULL.
159 EFI_OUT_OF_RESOURCES - There are not enough resources to allocate
164 ISCSI_DRIVER_DATA
*Private
;
165 ISCSI_SESSION
*Session
;
166 ISCSI_SESSION_CONFIG_NVDATA
*ConfigNvData
;
167 ISCSI_CHAP_AUTH_CONFIG_NVDATA
*AuthConfig
;
169 UINTN DevPathNodeLen
;
171 if ((DevicePath
== NULL
)) {
172 return EFI_INVALID_PARAMETER
;
175 if (Target
[0] != 0) {
176 return EFI_NOT_FOUND
;
179 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This
);
180 Session
= &Private
->Session
;
181 ConfigNvData
= &Session
->ConfigData
.NvData
;
182 AuthConfig
= &Session
->AuthData
.AuthConfig
;
184 if (NetCompareMem (&Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
)) != 0) {
185 return EFI_NOT_FOUND
;
188 DevPathNodeLen
= sizeof (ISCSI_DEVICE_PATH
) + AsciiStrLen (ConfigNvData
->TargetName
) + 1;
189 Node
= NetAllocatePool (DevPathNodeLen
);
191 return EFI_OUT_OF_RESOURCES
;
194 Node
->DevPath
.Type
= MESSAGING_DEVICE_PATH
;
195 Node
->DevPath
.SubType
= MSG_ISCSI_DP
;
196 SetDevicePathNodeLength (&Node
->DevPath
, DevPathNodeLen
);
199 // 0 for TCP, others are reserved.
201 Node
->Iscsi
.NetworkProtocol
= 0;
203 Node
->Iscsi
.LoginOption
= 0;
204 switch (AuthConfig
->CHAPType
) {
205 case ISCSI_CHAP_NONE
:
206 Node
->Iscsi
.LoginOption
|= 0x0800;
210 Node
->Iscsi
.LoginOption
|= 0x1000;
217 NetCopyMem (&Node
->Iscsi
.Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
));
218 Node
->Iscsi
.TargetPortalGroupTag
= Session
->TargetPortalGroupTag
;
219 AsciiStrCpy ((CHAR8
*) Node
+ sizeof (ISCSI_DEVICE_PATH
), ConfigNvData
->TargetName
);
221 *DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) Node
;
228 IScsiExtScsiPassThruGetTargetLun (
229 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
230 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
238 Translate a device path node to a Target ID and LUN.
242 This - Protocol instance pointer.
243 DevicePath - A pointer to the device path node that
244 describes a SCSI device on the SCSI channel.
245 Target - A pointer to the Target ID of a SCSI device
247 Lun - A pointer to the LUN of a SCSI device on
251 EFI_SUCCESS - DevicePath was successfully translated to a
252 Target ID and LUN, and they were returned
254 EFI_INVALID_PARAMETER - DevicePath/Target/Lun is NULL.
255 EFI_UNSUPPORTED - This driver does not support the device path
256 node type in DevicePath.
257 EFI_NOT_FOUND - A valid translation from DevicePath to a
258 Target ID and LUN does not exist.
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 NetZeroMem (*Target
, TARGET_MAX_BYTES
);
281 if (AsciiStrCmp (ConfigNvData
->TargetName
, (CHAR8
*) DevicePath
+ sizeof (ISCSI_DEVICE_PATH
)) != 0) {
282 return EFI_UNSUPPORTED
;
285 NetCopyMem (Lun
, ConfigNvData
->BootLun
, sizeof (UINT64
));
292 IScsiExtScsiPassThruResetChannel (
293 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
299 Resets a SCSI channel.This operation resets all the SCSI devices connected to
304 This - Protocol instance pointer.
308 EFI_UNSUPPORTED - It's not supported.
312 return EFI_UNSUPPORTED
;
317 IScsiExtScsiPassThruResetTargetLun (
318 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
326 Resets a SCSI device that is connected to a SCSI channel.
330 This - Protocol instance pointer.
331 Target - The Target ID of the SCSI device to reset.
332 Lun - The LUN of the SCSI device to reset.
336 EFI_UNSUPPORTED - It's not supported.
340 return EFI_UNSUPPORTED
;
345 IScsiExtScsiPassThruGetNextTarget (
346 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*This
,
347 IN OUT UINT8
**Target
353 Retrieve the list of legal Target IDs for SCSI devices on a SCSI channel.
356 This - Protocol instance pointer.
357 Target - On input, a pointer to the Target ID of a SCSI
358 device present on the SCSI channel. On output,
359 a pointer to the Target ID of the next SCSI device
360 present on a SCSI channel. An input value of
361 0xFFFFFFFF retrieves the Target ID of the first
362 SCSI device present on a SCSI channel.
363 Lun - On input, a pointer to the LUN of a SCSI device
364 present on the SCSI channel. On output, a pointer
365 to the LUN of the next SCSI device present on
370 EFI_SUCCESS - The Target ID and Lun of the next SCSI device
371 on the SCSI channel was returned in Target and Lun.
372 EFI_NOT_FOUND - There are no more SCSI devices on this SCSI channel.
373 EFI_INVALID_PARAMETER - Target is not 0xFFFFFFFF,and Target and Lun were not
374 returned on a previous call to GetNextDevice().
378 UINT8 TargetId
[TARGET_MAX_BYTES
];
380 NetSetMem (TargetId
, TARGET_MAX_BYTES
, 0xFF);
382 if (NetCompareMem (*Target
, TargetId
, TARGET_MAX_BYTES
) == 0) {
385 } else if ((*Target
)[0] == 0) {
386 return EFI_NOT_FOUND
;
388 return EFI_INVALID_PARAMETER
;
392 EFI_EXT_SCSI_PASS_THRU_PROTOCOL gIScsiExtScsiPassThruProtocolTemplate
= {
394 IScsiExtScsiPassThruFunction
,
395 IScsiExtScsiPassThruGetNextTargetLun
,
396 IScsiExtScsiPassThruBuildDevicePath
,
397 IScsiExtScsiPassThruGetTargetLun
,
398 IScsiExtScsiPassThruResetChannel
,
399 IScsiExtScsiPassThruResetTargetLun
,
400 IScsiExtScsiPassThruGetNextTarget