]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/IScsiDxe/IScsiExtScsiPassThru.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiExtScsiPassThru.c
CommitLineData
12618416 1/** @file\r
aeb49322 2 The IScsi's EFI_EXT_SCSI_PASS_THRU_PROTOCOL driver.\r
6a690e23 3\r
d1102dba 4Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 5This program and the accompanying materials\r
7a444476 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
6a690e23 12\r
12618416 13**/\r
6a690e23 14\r
15#include "IScsiImpl.h"\r
16\r
12618416 17/**\r
d1102dba 18 Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function\r
aeb49322 19 supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the\r
d1102dba 20 nonblocking I/O functionality is optional.\r
aeb49322 21\r
22 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
23 @param[in] Target The Target is an array of size TARGET_MAX_BYTES and it represents\r
24 the id of the SCSI device to send the SCSI Request Packet. Each\r
25 transport driver may chose to utilize a subset of this size to suit the needs\r
26 of transport target representation. For example, a Fibre Channel driver\r
27 may use only 8 bytes (WWN) to represent an FC target.\r
28 @param[in] Lun The LUN of the SCSI device to send the SCSI Request Packet.\r
29 @param[in, out] Packet A pointer to the SCSI Request Packet to send to the SCSI device\r
30 specified by Target and Lun.\r
31 @param[in] Event If nonblocking I/O is not supported then Event is ignored, and blocking\r
32 I/O is performed. If Event is NULL, then blocking I/O is performed. If\r
33 Event is not NULL and non blocking I/O is supported, then\r
34 nonblocking I/O is performed, and Event will be signaled when the\r
35 SCSI Request Packet completes.\r
36\r
37 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host. For bi-directional\r
38 commands, InTransferLength bytes were transferred from\r
39 InDataBuffer. For write and bi-directional commands,\r
40 OutTransferLength bytes were transferred by\r
41 OutDataBuffer.\r
42 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was not executed. The number of bytes that\r
43 could be transferred is returned in InTransferLength. For write\r
44 and bi-directional commands, OutTransferLength bytes were\r
d1102dba 45 transferred by OutDataBuffer. Currently not implemeted.\r
aeb49322 46 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many\r
d1102dba 47 SCSI Request Packets already queued. The caller may retry again later.\r
aeb49322 48 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request\r
d1102dba 49 Packet.\r
aeb49322 50 @retval EFI_INVALID_PARAMETER Target, Lun, or the contents of ScsiRequestPacket are invalid.\r
51 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported\r
52 by the host adapter. This includes the case of Bi-directional SCSI\r
53 commands not supported by the implementation. The SCSI Request\r
54 Packet was not sent, so no additional status information is available.\r
55 Currently not implemeted.\r
d1102dba 56 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.\r
12618416 57**/\r
6a690e23 58EFI_STATUS\r
59EFIAPI\r
60IScsiExtScsiPassThruFunction (\r
61 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
62 IN UINT8 *Target,\r
63 IN UINT64 Lun,\r
64 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,\r
65 IN EFI_EVENT Event OPTIONAL\r
66 )\r
6a690e23 67{\r
f035af2e 68 ISCSI_DRIVER_DATA *Private;\r
69 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;\r
d1102dba 70 EFI_STATUS Status;\r
f035af2e 71\r
72 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);\r
73 ConfigNvData = &Private->Session.ConfigData.NvData;\r
74\r
75 if (Target[0] != 0 || (CompareMem (&Lun, ConfigNvData->BootLun, sizeof (UINT64)) != 0)) {\r
6a690e23 76 return EFI_INVALID_PARAMETER;\r
77 }\r
78\r
79 if ((Packet == NULL) || (Packet->Cdb == NULL)) {\r
80 return EFI_INVALID_PARAMETER;\r
81 }\r
82\r
f20fc992
FS
83 Status = IScsiExecuteScsiCommand (This, Target, Lun, Packet);\r
84 if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_READY)) {\r
85 //\r
86 // Try to reinstate the session and re-execute the Scsi command.\r
87 //\r
88 if (EFI_ERROR (IScsiSessionReinstatement (Private))) {\r
89 return EFI_DEVICE_ERROR;\r
90 }\r
91\r
92 Status = IScsiExecuteScsiCommand (This, Target, Lun, Packet);\r
93 }\r
94\r
95 return Status;\r
6a690e23 96}\r
97\r
12618416 98/**\r
d1102dba 99 Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These\r
aeb49322 100 can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal\r
d1102dba
LG
101 Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the\r
102 Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI\r
103 channel.\r
aeb49322 104\r
105 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
106 @param[in, out] Target On input, a pointer to the Target ID (an array of size\r
107 TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.\r
108 On output, a pointer to the Target ID (an array of\r
109 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI\r
110 channel. An input value of 0xF(all bytes in the array are 0xF) in the\r
111 Target array retrieves the Target ID of the first SCSI device present on a\r
112 SCSI channel.\r
113 @param[in, out] Lun On input, a pointer to the LUN of a SCSI device present on the SCSI\r
114 channel. On output, a pointer to the LUN of the next SCSI device present\r
115 on a SCSI channel.\r
116\r
117 @retval EFI_SUCCESS The Target ID and LUN of the next SCSI device on the SCSI\r
118 channel was returned in Target and Lun.\r
119 @retval EFI_INVALID_PARAMETER Target array is not all 0xF, and Target and Lun were\r
120 not returned on a previous call to GetNextTargetLun().\r
12618416 121 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.\r
12618416 122**/\r
123EFI_STATUS\r
124EFIAPI\r
125IScsiExtScsiPassThruGetNextTargetLun (\r
126 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
127 IN OUT UINT8 **Target,\r
128 IN OUT UINT64 *Lun\r
129 )\r
6a690e23 130{\r
131 ISCSI_DRIVER_DATA *Private;\r
132 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;\r
133 UINT8 TargetId[TARGET_MAX_BYTES];\r
134\r
135 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);\r
136 ConfigNvData = &Private->Session.ConfigData.NvData;\r
137\r
e48e37fc 138 if ((*Target)[0] == 0 && (CompareMem (Lun, ConfigNvData->BootLun, sizeof (UINT64)) == 0)) {\r
6a690e23 139 //\r
140 // Only one <Target, Lun> pair per iSCSI Driver instance.\r
141 //\r
142 return EFI_NOT_FOUND;\r
143 }\r
144\r
e48e37fc 145 SetMem (TargetId, TARGET_MAX_BYTES, 0xFF);\r
146 if (CompareMem (*Target, TargetId, TARGET_MAX_BYTES) == 0) {\r
6a690e23 147 (*Target)[0] = 0;\r
e48e37fc 148 CopyMem (Lun, ConfigNvData->BootLun, sizeof (UINT64));\r
6a690e23 149\r
150 return EFI_SUCCESS;\r
151 }\r
152\r
153 return EFI_INVALID_PARAMETER;\r
154}\r
155\r
12618416 156/**\r
aeb49322 157 Used to allocate and build a device path node for a SCSI device on a SCSI channel.\r
158\r
159 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
160 @param[in] Target The Target is an array of size TARGET_MAX_BYTES and it specifies the\r
161 Target ID of the SCSI device for which a device path node is to be\r
162 allocated and built. Transport drivers may chose to utilize a subset of\r
163 this size to suit the representation of targets. For example, a Fibre\r
164 Channel driver may use only 8 bytes (WWN) in the array to represent a\r
165 FC target.\r
166 @param[in] Lun The LUN of the SCSI device for which a device path node is to be\r
167 allocated and built.\r
168 @param[in, out] DevicePath A pointer to a single device path node that describes the SCSI device\r
169 specified by Target and Lun. This function is responsible for\r
170 allocating the buffer DevicePath with the boot service\r
171 AllocatePool(). It is the caller's responsibility to free\r
172 DevicePath when the caller is finished with DevicePath.\r
173\r
174 @retval EFI_SUCCESS The device path node that describes the SCSI device specified by\r
175 Target and Lun was allocated and returned in\r
12618416 176 DevicePath.\r
aeb49322 177 @retval EFI_INVALID_PARAMETER DevicePath is NULL.\r
178 @retval EFI_NOT_FOUND The SCSI devices specified by Target and Lun does not exist\r
179 on the SCSI channel.\r
180 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.\r
12618416 181\r
182**/\r
6a690e23 183EFI_STATUS\r
184EFIAPI\r
185IScsiExtScsiPassThruBuildDevicePath (\r
186 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
187 IN UINT8 *Target,\r
188 IN UINT64 Lun,\r
189 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath\r
190 )\r
6a690e23 191{\r
192 ISCSI_DRIVER_DATA *Private;\r
193 ISCSI_SESSION *Session;\r
194 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;\r
195 ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfig;\r
196 EFI_DEV_PATH *Node;\r
197 UINTN DevPathNodeLen;\r
198\r
63e78d52 199 if (DevicePath == NULL) {\r
6a690e23 200 return EFI_INVALID_PARAMETER;\r
201 }\r
202\r
203 if (Target[0] != 0) {\r
204 return EFI_NOT_FOUND;\r
205 }\r
206\r
207 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);\r
208 Session = &Private->Session;\r
209 ConfigNvData = &Session->ConfigData.NvData;\r
210 AuthConfig = &Session->AuthData.AuthConfig;\r
211\r
e48e37fc 212 if (CompareMem (&Lun, ConfigNvData->BootLun, sizeof (UINT64)) != 0) {\r
6a690e23 213 return EFI_NOT_FOUND;\r
214 }\r
215\r
216 DevPathNodeLen = sizeof (ISCSI_DEVICE_PATH) + AsciiStrLen (ConfigNvData->TargetName) + 1;\r
e48e37fc 217 Node = AllocatePool (DevPathNodeLen);\r
6a690e23 218 if (Node == NULL) {\r
219 return EFI_OUT_OF_RESOURCES;\r
220 }\r
221\r
222 Node->DevPath.Type = MESSAGING_DEVICE_PATH;\r
223 Node->DevPath.SubType = MSG_ISCSI_DP;\r
1232b214 224 SetDevicePathNodeLength (&Node->DevPath, (UINT16)DevPathNodeLen);\r
6a690e23 225\r
226 //\r
227 // 0 for TCP, others are reserved.\r
228 //\r
229 Node->Iscsi.NetworkProtocol = 0;\r
230\r
231 Node->Iscsi.LoginOption = 0;\r
232 switch (AuthConfig->CHAPType) {\r
233 case ISCSI_CHAP_NONE:\r
234 Node->Iscsi.LoginOption |= 0x0800;\r
235 break;\r
236\r
237 case ISCSI_CHAP_UNI:\r
238 Node->Iscsi.LoginOption |= 0x1000;\r
239 break;\r
240\r
241 default:\r
242 break;\r
243 }\r
244\r
e48e37fc 245 CopyMem (&Node->Iscsi.Lun, ConfigNvData->BootLun, sizeof (UINT64));\r
6a690e23 246 Node->Iscsi.TargetPortalGroupTag = Session->TargetPortalGroupTag;\r
206b5f51 247 AsciiStrCpyS ((CHAR8 *) Node + sizeof (ISCSI_DEVICE_PATH), AsciiStrLen (ConfigNvData->TargetName) + 1, ConfigNvData->TargetName);\r
6a690e23 248\r
249 *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Node;\r
250\r
251 return EFI_SUCCESS;\r
252}\r
253\r
12618416 254/**\r
aeb49322 255 Used to translate a device path node to a Target ID and LUN.\r
256\r
257 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
258 @param[in] DevicePath A pointer to a single device path node that describes the SCSI device\r
259 on the SCSI channel.\r
260 @param[out] Target A pointer to the Target Array which represents the ID of a SCSI device\r
261 on the SCSI channel.\r
262 @param[out] Lun A pointer to the LUN of a SCSI device on the SCSI channel.\r
263\r
264 @retval EFI_SUCCESS DevicePath was successfully translated to a Target ID and\r
265 LUN, and they were returned in Target and Lun.\r
266 @retval EFI_INVALID_PARAMETER DevicePath or Target or Lun is NULL.\r
267 @retval EFI_NOT_FOUND A valid translation from DevicePath to a Target ID and LUN\r
268 does not exist.Currently not implemented.\r
269 @retval EFI_UNSUPPORTED This driver does not support the device path node type in\r
270 DevicePath.\r
12618416 271**/\r
6a690e23 272EFI_STATUS\r
273EFIAPI\r
274IScsiExtScsiPassThruGetTargetLun (\r
275 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
276 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
277 OUT UINT8 **Target,\r
278 OUT UINT64 *Lun\r
279 )\r
6a690e23 280{\r
281 ISCSI_DRIVER_DATA *Private;\r
282 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;\r
283\r
284 if ((DevicePath == NULL) || (Target == NULL) || (Lun == NULL)) {\r
285 return EFI_INVALID_PARAMETER;\r
286 }\r
287\r
288 if ((DevicePath->Type != MESSAGING_DEVICE_PATH) ||\r
289 (DevicePath->SubType != MSG_ISCSI_DP) ||\r
290 (DevicePathNodeLength (DevicePath) <= sizeof (ISCSI_DEVICE_PATH))\r
291 ) {\r
292 return EFI_UNSUPPORTED;\r
293 }\r
294\r
295 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);\r
296 ConfigNvData = &Private->Session.ConfigData.NvData;\r
297\r
4a4bb30e 298 SetMem (*Target, TARGET_MAX_BYTES, 0xFF);\r
08654acb 299 (*Target)[0] = 0;\r
6a690e23 300\r
301 if (AsciiStrCmp (ConfigNvData->TargetName, (CHAR8 *) DevicePath + sizeof (ISCSI_DEVICE_PATH)) != 0) {\r
302 return EFI_UNSUPPORTED;\r
303 }\r
304\r
e48e37fc 305 CopyMem (Lun, ConfigNvData->BootLun, sizeof (UINT64));\r
6a690e23 306\r
307 return EFI_SUCCESS;\r
308}\r
309\r
12618416 310/**\r
aeb49322 311 Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel.\r
312 Currently not implemented.\r
d1102dba 313\r
aeb49322 314 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
315\r
316 @retval EFI_SUCCESS The SCSI channel was reset.\r
317 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI channel.\r
318 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI channel.\r
319 @retval EFI_UNSUPPORTED The SCSI channel does not support a channel reset operation.\r
12618416 320**/\r
6a690e23 321EFI_STATUS\r
322EFIAPI\r
323IScsiExtScsiPassThruResetChannel (\r
324 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This\r
325 )\r
12618416 326{\r
327 return EFI_UNSUPPORTED;\r
328}\r
6a690e23 329\r
12618416 330/**\r
aeb49322 331 Resets a SCSI logical unit that is connected to a SCSI channel. Currently not implemented.\r
332\r
333 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
334 @param[in] Target The Target is an array of size TARGET_MAX_BYTE and it represents the\r
335 target port ID of the SCSI device containing the SCSI logical unit to\r
336 reset. Transport drivers may chose to utilize a subset of this array to suit\r
337 the representation of their targets.\r
338 @param[in] Lun The LUN of the SCSI device to reset.\r
339\r
340 @retval EFI_SUCCESS The SCSI device specified by Target and Lun was reset.\r
341 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.\r
342 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI device\r
343 specified by Target and Lun.\r
344 @retval EFI_UNSUPPORTED The SCSI channel does not support a target reset operation.\r
345 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI device\r
346 specified by Target and Lun.\r
6a690e23 347\r
12618416 348**/\r
6a690e23 349EFI_STATUS\r
350EFIAPI\r
351IScsiExtScsiPassThruResetTargetLun (\r
352 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
353 IN UINT8 *Target,\r
354 IN UINT64 Lun\r
355 )\r
12618416 356{\r
357 return EFI_UNSUPPORTED;\r
358}\r
6a690e23 359\r
12618416 360/**\r
d1102dba 361 Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either\r
aeb49322 362 be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs\r
d1102dba
LG
363 for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to\r
364 see if a SCSI device is actually present at that location on the SCSI channel.\r
aeb49322 365\r
366 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
367 @param[in, out] Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.\r
368 On output, a pointer to the Target ID (an array of\r
369 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI\r
370 channel. An input value of 0xF(all bytes in the array are 0xF) in the\r
371 Target array retrieves the Target ID of the first SCSI device present on a\r
372 SCSI channel.\r
373\r
374 @retval EFI_SUCCESS The Target ID of the next SCSI device on the SCSI\r
375 channel was returned in Target.\r
376 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.\r
377 @retval EFI_TIMEOUT Target array is not all 0xF, and Target were not\r
378 returned on a previous call to GetNextTarget().\r
379 Currently not implemented.\r
12618416 380 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.\r
12618416 381**/\r
6a690e23 382EFI_STATUS\r
383EFIAPI\r
384IScsiExtScsiPassThruGetNextTarget (\r
385 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
386 IN OUT UINT8 **Target\r
387 )\r
6a690e23 388{\r
389 UINT8 TargetId[TARGET_MAX_BYTES];\r
390\r
e48e37fc 391 SetMem (TargetId, TARGET_MAX_BYTES, 0xFF);\r
6a690e23 392\r
e48e37fc 393 if (CompareMem (*Target, TargetId, TARGET_MAX_BYTES) == 0) {\r
6a690e23 394 (*Target)[0] = 0;\r
395 return EFI_SUCCESS;\r
396 } else if ((*Target)[0] == 0) {\r
397 return EFI_NOT_FOUND;\r
398 } else {\r
399 return EFI_INVALID_PARAMETER;\r
400 }\r
401}\r
402\r
403EFI_EXT_SCSI_PASS_THRU_PROTOCOL gIScsiExtScsiPassThruProtocolTemplate = {\r
404 NULL,\r
405 IScsiExtScsiPassThruFunction,\r
406 IScsiExtScsiPassThruGetNextTargetLun,\r
407 IScsiExtScsiPassThruBuildDevicePath,\r
408 IScsiExtScsiPassThruGetTargetLun,\r
409 IScsiExtScsiPassThruResetChannel,\r
410 IScsiExtScsiPassThruResetTargetLun,\r
411 IScsiExtScsiPassThruGetNextTarget\r
412};\r