]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/IScsiDxe/IScsiExtScsiPassThru.c
update file header
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiExtScsiPassThru.c
1 /** @file
2 The IScsi's EFI_EXT_SCSI_PASS_THRU_PROTOCOL driver.
3
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
9
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.
12
13 **/
14
15 #include "IScsiImpl.h"
16
17 /**
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.
21
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.
36
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
41 OutDataBuffer.
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
49 Packet.
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.
57 **/
58 EFI_STATUS
59 EFIAPI
60 IScsiExtScsiPassThruFunction (
61 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
62 IN UINT8 *Target,
63 IN UINT64 Lun,
64 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
65 IN EFI_EVENT Event OPTIONAL
66 )
67 {
68 if (Target[0] != 0) {
69 return EFI_INVALID_PARAMETER;
70 }
71
72 if ((Packet == NULL) || (Packet->Cdb == NULL)) {
73 return EFI_INVALID_PARAMETER;
74 }
75
76 return IScsiExecuteScsiCommand (This, Target, Lun, Packet);
77 }
78
79 /**
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
84 channel.
85
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
93 SCSI channel.
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
96 on a SCSI channel.
97
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.
103 **/
104 EFI_STATUS
105 EFIAPI
106 IScsiExtScsiPassThruGetNextTargetLun (
107 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
108 IN OUT UINT8 **Target,
109 IN OUT UINT64 *Lun
110 )
111 {
112 ISCSI_DRIVER_DATA *Private;
113 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;
114 UINT8 TargetId[TARGET_MAX_BYTES];
115
116 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);
117 ConfigNvData = &Private->Session.ConfigData.NvData;
118
119 if ((*Target)[0] == 0 && (CompareMem (Lun, ConfigNvData->BootLun, sizeof (UINT64)) == 0)) {
120 //
121 // Only one <Target, Lun> pair per iSCSI Driver instance.
122 //
123 return EFI_NOT_FOUND;
124 }
125
126 SetMem (TargetId, TARGET_MAX_BYTES, 0xFF);
127 if (CompareMem (*Target, TargetId, TARGET_MAX_BYTES) == 0) {
128 (*Target)[0] = 0;
129 CopyMem (Lun, ConfigNvData->BootLun, sizeof (UINT64));
130
131 return EFI_SUCCESS;
132 }
133
134 return EFI_INVALID_PARAMETER;
135 }
136
137 /**
138 Used to allocate and build a device path node for a SCSI device on a SCSI channel.
139
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
146 FC target.
147 @param[in] Lun The LUN of the SCSI device for which a device path node is to be
148 allocated and built.
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.
154
155 @retval EFI_SUCCESS The device path node that describes the SCSI device specified by
156 Target and Lun was allocated and returned in
157 DevicePath.
158 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
159 @retval EFI_NOT_FOUND The SCSI devices specified by Target and Lun does not exist
160 on the SCSI channel.
161 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.
162
163 **/
164 EFI_STATUS
165 EFIAPI
166 IScsiExtScsiPassThruBuildDevicePath (
167 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
168 IN UINT8 *Target,
169 IN UINT64 Lun,
170 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
171 )
172 {
173 ISCSI_DRIVER_DATA *Private;
174 ISCSI_SESSION *Session;
175 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;
176 ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfig;
177 EFI_DEV_PATH *Node;
178 UINTN DevPathNodeLen;
179
180 if ((DevicePath == NULL)) {
181 return EFI_INVALID_PARAMETER;
182 }
183
184 if (Target[0] != 0) {
185 return EFI_NOT_FOUND;
186 }
187
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;
192
193 if (CompareMem (&Lun, ConfigNvData->BootLun, sizeof (UINT64)) != 0) {
194 return EFI_NOT_FOUND;
195 }
196
197 DevPathNodeLen = sizeof (ISCSI_DEVICE_PATH) + AsciiStrLen (ConfigNvData->TargetName) + 1;
198 Node = AllocatePool (DevPathNodeLen);
199 if (Node == NULL) {
200 return EFI_OUT_OF_RESOURCES;
201 }
202
203 Node->DevPath.Type = MESSAGING_DEVICE_PATH;
204 Node->DevPath.SubType = MSG_ISCSI_DP;
205 SetDevicePathNodeLength (&Node->DevPath, (UINT16)DevPathNodeLen);
206
207 //
208 // 0 for TCP, others are reserved.
209 //
210 Node->Iscsi.NetworkProtocol = 0;
211
212 Node->Iscsi.LoginOption = 0;
213 switch (AuthConfig->CHAPType) {
214 case ISCSI_CHAP_NONE:
215 Node->Iscsi.LoginOption |= 0x0800;
216 break;
217
218 case ISCSI_CHAP_UNI:
219 Node->Iscsi.LoginOption |= 0x1000;
220 break;
221
222 default:
223 break;
224 }
225
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);
229
230 *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Node;
231
232 return EFI_SUCCESS;
233 }
234
235 /**
236 Used to translate a device path node to a Target ID and LUN.
237
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
240 on the SCSI channel.
241 @param[out] Target A pointer to the Target Array which represents the ID of a SCSI device
242 on the SCSI channel.
243 @param[out] Lun A pointer to the LUN of a SCSI device on the SCSI channel.
244
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
251 DevicePath.
252 **/
253 EFI_STATUS
254 EFIAPI
255 IScsiExtScsiPassThruGetTargetLun (
256 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
257 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
258 OUT UINT8 **Target,
259 OUT UINT64 *Lun
260 )
261 {
262 ISCSI_DRIVER_DATA *Private;
263 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;
264
265 if ((DevicePath == NULL) || (Target == NULL) || (Lun == NULL)) {
266 return EFI_INVALID_PARAMETER;
267 }
268
269 if ((DevicePath->Type != MESSAGING_DEVICE_PATH) ||
270 (DevicePath->SubType != MSG_ISCSI_DP) ||
271 (DevicePathNodeLength (DevicePath) <= sizeof (ISCSI_DEVICE_PATH))
272 ) {
273 return EFI_UNSUPPORTED;
274 }
275
276 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);
277 ConfigNvData = &Private->Session.ConfigData.NvData;
278
279 ZeroMem (*Target, TARGET_MAX_BYTES);
280
281 if (AsciiStrCmp (ConfigNvData->TargetName, (CHAR8 *) DevicePath + sizeof (ISCSI_DEVICE_PATH)) != 0) {
282 return EFI_UNSUPPORTED;
283 }
284
285 CopyMem (Lun, ConfigNvData->BootLun, sizeof (UINT64));
286
287 return EFI_SUCCESS;
288 }
289
290 /**
291 Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel.
292 Currently not implemented.
293
294 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
295
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.
300 **/
301 EFI_STATUS
302 EFIAPI
303 IScsiExtScsiPassThruResetChannel (
304 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This
305 )
306 {
307 return EFI_UNSUPPORTED;
308 }
309
310 /**
311 Resets a SCSI logical unit that is connected to a SCSI channel. Currently not implemented.
312
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.
319
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.
327
328 **/
329 EFI_STATUS
330 EFIAPI
331 IScsiExtScsiPassThruResetTargetLun (
332 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
333 IN UINT8 *Target,
334 IN UINT64 Lun
335 )
336 {
337 return EFI_UNSUPPORTED;
338 }
339
340 /**
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.
345
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
352 SCSI channel.
353
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.
361 **/
362 EFI_STATUS
363 EFIAPI
364 IScsiExtScsiPassThruGetNextTarget (
365 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
366 IN OUT UINT8 **Target
367 )
368 {
369 UINT8 TargetId[TARGET_MAX_BYTES];
370
371 SetMem (TargetId, TARGET_MAX_BYTES, 0xFF);
372
373 if (CompareMem (*Target, TargetId, TARGET_MAX_BYTES) == 0) {
374 (*Target)[0] = 0;
375 return EFI_SUCCESS;
376 } else if ((*Target)[0] == 0) {
377 return EFI_NOT_FOUND;
378 } else {
379 return EFI_INVALID_PARAMETER;
380 }
381 }
382
383 EFI_EXT_SCSI_PASS_THRU_PROTOCOL gIScsiExtScsiPassThruProtocolTemplate = {
384 NULL,
385 IScsiExtScsiPassThruFunction,
386 IScsiExtScsiPassThruGetNextTargetLun,
387 IScsiExtScsiPassThruBuildDevicePath,
388 IScsiExtScsiPassThruGetTargetLun,
389 IScsiExtScsiPassThruResetChannel,
390 IScsiExtScsiPassThruResetTargetLun,
391 IScsiExtScsiPassThruGetNextTarget
392 };