]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/IScsiDxe/IScsiExtScsiPassThru.c
add error handler to pass K8 check
[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
aeb49322 4Copyright (c) 2004 - 2007, Intel Corporation.<BR>\r
7a444476 5All rights reserved. This program and the accompanying materials\r
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
aeb49322 18 Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function \r
19 supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the\r
20 nonblocking I/O functionality is optional. \r
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
45 transferred by OutDataBuffer. Currently not implemeted. \r
46 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many\r
47 SCSI Request Packets already queued. The caller may retry again later. \r
48 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request\r
49 Packet. \r
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
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
70\r
71 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);\r
72 ConfigNvData = &Private->Session.ConfigData.NvData;\r
73\r
74 if (Target[0] != 0 || (CompareMem (&Lun, ConfigNvData->BootLun, sizeof (UINT64)) != 0)) {\r
6a690e23 75 return EFI_INVALID_PARAMETER;\r
76 }\r
77\r
78 if ((Packet == NULL) || (Packet->Cdb == NULL)) {\r
79 return EFI_INVALID_PARAMETER;\r
80 }\r
81\r
82 return IScsiExecuteScsiCommand (This, Target, Lun, Packet);\r
83}\r
84\r
12618416 85/**\r
aeb49322 86 Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These \r
87 can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal\r
88 Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the \r
89 Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI \r
90 channel. \r
91\r
92 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
93 @param[in, out] Target On input, a pointer to the Target ID (an array of size\r
94 TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.\r
95 On output, a pointer to the Target ID (an array of\r
96 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI\r
97 channel. An input value of 0xF(all bytes in the array are 0xF) in the\r
98 Target array retrieves the Target ID of the first SCSI device present on a\r
99 SCSI channel.\r
100 @param[in, out] Lun On input, a pointer to the LUN of a SCSI device present on the SCSI\r
101 channel. On output, a pointer to the LUN of the next SCSI device present\r
102 on a SCSI channel.\r
103\r
104 @retval EFI_SUCCESS The Target ID and LUN of the next SCSI device on the SCSI\r
105 channel was returned in Target and Lun.\r
106 @retval EFI_INVALID_PARAMETER Target array is not all 0xF, and Target and Lun were\r
107 not returned on a previous call to GetNextTargetLun().\r
12618416 108 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.\r
12618416 109**/\r
110EFI_STATUS\r
111EFIAPI\r
112IScsiExtScsiPassThruGetNextTargetLun (\r
113 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
114 IN OUT UINT8 **Target,\r
115 IN OUT UINT64 *Lun\r
116 )\r
6a690e23 117{\r
118 ISCSI_DRIVER_DATA *Private;\r
119 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;\r
120 UINT8 TargetId[TARGET_MAX_BYTES];\r
121\r
122 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);\r
123 ConfigNvData = &Private->Session.ConfigData.NvData;\r
124\r
e48e37fc 125 if ((*Target)[0] == 0 && (CompareMem (Lun, ConfigNvData->BootLun, sizeof (UINT64)) == 0)) {\r
6a690e23 126 //\r
127 // Only one <Target, Lun> pair per iSCSI Driver instance.\r
128 //\r
129 return EFI_NOT_FOUND;\r
130 }\r
131\r
e48e37fc 132 SetMem (TargetId, TARGET_MAX_BYTES, 0xFF);\r
133 if (CompareMem (*Target, TargetId, TARGET_MAX_BYTES) == 0) {\r
6a690e23 134 (*Target)[0] = 0;\r
e48e37fc 135 CopyMem (Lun, ConfigNvData->BootLun, sizeof (UINT64));\r
6a690e23 136\r
137 return EFI_SUCCESS;\r
138 }\r
139\r
140 return EFI_INVALID_PARAMETER;\r
141}\r
142\r
12618416 143/**\r
aeb49322 144 Used to allocate and build a device path node for a SCSI device on a SCSI channel.\r
145\r
146 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
147 @param[in] Target The Target is an array of size TARGET_MAX_BYTES and it specifies the\r
148 Target ID of the SCSI device for which a device path node is to be\r
149 allocated and built. Transport drivers may chose to utilize a subset of\r
150 this size to suit the representation of targets. For example, a Fibre\r
151 Channel driver may use only 8 bytes (WWN) in the array to represent a\r
152 FC target.\r
153 @param[in] Lun The LUN of the SCSI device for which a device path node is to be\r
154 allocated and built.\r
155 @param[in, out] DevicePath A pointer to a single device path node that describes the SCSI device\r
156 specified by Target and Lun. This function is responsible for\r
157 allocating the buffer DevicePath with the boot service\r
158 AllocatePool(). It is the caller's responsibility to free\r
159 DevicePath when the caller is finished with DevicePath.\r
160\r
161 @retval EFI_SUCCESS The device path node that describes the SCSI device specified by\r
162 Target and Lun was allocated and returned in\r
12618416 163 DevicePath.\r
aeb49322 164 @retval EFI_INVALID_PARAMETER DevicePath is NULL.\r
165 @retval EFI_NOT_FOUND The SCSI devices specified by Target and Lun does not exist\r
166 on the SCSI channel.\r
167 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.\r
12618416 168\r
169**/\r
6a690e23 170EFI_STATUS\r
171EFIAPI\r
172IScsiExtScsiPassThruBuildDevicePath (\r
173 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
174 IN UINT8 *Target,\r
175 IN UINT64 Lun,\r
176 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath\r
177 )\r
6a690e23 178{\r
179 ISCSI_DRIVER_DATA *Private;\r
180 ISCSI_SESSION *Session;\r
181 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;\r
182 ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfig;\r
183 EFI_DEV_PATH *Node;\r
184 UINTN DevPathNodeLen;\r
185\r
186 if ((DevicePath == NULL)) {\r
187 return EFI_INVALID_PARAMETER;\r
188 }\r
189\r
190 if (Target[0] != 0) {\r
191 return EFI_NOT_FOUND;\r
192 }\r
193\r
194 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);\r
195 Session = &Private->Session;\r
196 ConfigNvData = &Session->ConfigData.NvData;\r
197 AuthConfig = &Session->AuthData.AuthConfig;\r
198\r
e48e37fc 199 if (CompareMem (&Lun, ConfigNvData->BootLun, sizeof (UINT64)) != 0) {\r
6a690e23 200 return EFI_NOT_FOUND;\r
201 }\r
202\r
203 DevPathNodeLen = sizeof (ISCSI_DEVICE_PATH) + AsciiStrLen (ConfigNvData->TargetName) + 1;\r
e48e37fc 204 Node = AllocatePool (DevPathNodeLen);\r
6a690e23 205 if (Node == NULL) {\r
206 return EFI_OUT_OF_RESOURCES;\r
207 }\r
208\r
209 Node->DevPath.Type = MESSAGING_DEVICE_PATH;\r
210 Node->DevPath.SubType = MSG_ISCSI_DP;\r
1232b214 211 SetDevicePathNodeLength (&Node->DevPath, (UINT16)DevPathNodeLen);\r
6a690e23 212\r
213 //\r
214 // 0 for TCP, others are reserved.\r
215 //\r
216 Node->Iscsi.NetworkProtocol = 0;\r
217\r
218 Node->Iscsi.LoginOption = 0;\r
219 switch (AuthConfig->CHAPType) {\r
220 case ISCSI_CHAP_NONE:\r
221 Node->Iscsi.LoginOption |= 0x0800;\r
222 break;\r
223\r
224 case ISCSI_CHAP_UNI:\r
225 Node->Iscsi.LoginOption |= 0x1000;\r
226 break;\r
227\r
228 default:\r
229 break;\r
230 }\r
231\r
e48e37fc 232 CopyMem (&Node->Iscsi.Lun, ConfigNvData->BootLun, sizeof (UINT64));\r
6a690e23 233 Node->Iscsi.TargetPortalGroupTag = Session->TargetPortalGroupTag;\r
234 AsciiStrCpy ((CHAR8 *) Node + sizeof (ISCSI_DEVICE_PATH), ConfigNvData->TargetName);\r
235\r
236 *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Node;\r
237\r
238 return EFI_SUCCESS;\r
239}\r
240\r
12618416 241/**\r
aeb49322 242 Used to translate a device path node to a Target ID and LUN.\r
243\r
244 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
245 @param[in] DevicePath A pointer to a single device path node that describes the SCSI device\r
246 on the SCSI channel.\r
247 @param[out] Target A pointer to the Target Array which represents the ID of a SCSI device\r
248 on the SCSI channel.\r
249 @param[out] Lun A pointer to the LUN of a SCSI device on the SCSI channel.\r
250\r
251 @retval EFI_SUCCESS DevicePath was successfully translated to a Target ID and\r
252 LUN, and they were returned in Target and Lun.\r
253 @retval EFI_INVALID_PARAMETER DevicePath or Target or Lun is NULL.\r
254 @retval EFI_NOT_FOUND A valid translation from DevicePath to a Target ID and LUN\r
255 does not exist.Currently not implemented.\r
256 @retval EFI_UNSUPPORTED This driver does not support the device path node type in\r
257 DevicePath.\r
12618416 258**/\r
6a690e23 259EFI_STATUS\r
260EFIAPI\r
261IScsiExtScsiPassThruGetTargetLun (\r
262 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
263 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
264 OUT UINT8 **Target,\r
265 OUT UINT64 *Lun\r
266 )\r
6a690e23 267{\r
268 ISCSI_DRIVER_DATA *Private;\r
269 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;\r
270\r
271 if ((DevicePath == NULL) || (Target == NULL) || (Lun == NULL)) {\r
272 return EFI_INVALID_PARAMETER;\r
273 }\r
274\r
275 if ((DevicePath->Type != MESSAGING_DEVICE_PATH) ||\r
276 (DevicePath->SubType != MSG_ISCSI_DP) ||\r
277 (DevicePathNodeLength (DevicePath) <= sizeof (ISCSI_DEVICE_PATH))\r
278 ) {\r
279 return EFI_UNSUPPORTED;\r
280 }\r
281\r
282 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);\r
283 ConfigNvData = &Private->Session.ConfigData.NvData;\r
284\r
08654acb 285 (*Target)[0] = 0;\r
6a690e23 286\r
287 if (AsciiStrCmp (ConfigNvData->TargetName, (CHAR8 *) DevicePath + sizeof (ISCSI_DEVICE_PATH)) != 0) {\r
288 return EFI_UNSUPPORTED;\r
289 }\r
290\r
e48e37fc 291 CopyMem (Lun, ConfigNvData->BootLun, sizeof (UINT64));\r
6a690e23 292\r
293 return EFI_SUCCESS;\r
294}\r
295\r
12618416 296/**\r
aeb49322 297 Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel.\r
298 Currently not implemented.\r
299 \r
300 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
301\r
302 @retval EFI_SUCCESS The SCSI channel was reset.\r
303 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI channel.\r
304 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI channel.\r
305 @retval EFI_UNSUPPORTED The SCSI channel does not support a channel reset operation.\r
12618416 306**/\r
6a690e23 307EFI_STATUS\r
308EFIAPI\r
309IScsiExtScsiPassThruResetChannel (\r
310 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This\r
311 )\r
12618416 312{\r
313 return EFI_UNSUPPORTED;\r
314}\r
6a690e23 315\r
12618416 316/**\r
aeb49322 317 Resets a SCSI logical unit that is connected to a SCSI channel. Currently not implemented.\r
318\r
319 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
320 @param[in] Target The Target is an array of size TARGET_MAX_BYTE and it represents the\r
321 target port ID of the SCSI device containing the SCSI logical unit to\r
322 reset. Transport drivers may chose to utilize a subset of this array to suit\r
323 the representation of their targets.\r
324 @param[in] Lun The LUN of the SCSI device to reset.\r
325\r
326 @retval EFI_SUCCESS The SCSI device specified by Target and Lun was reset.\r
327 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.\r
328 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI device\r
329 specified by Target and Lun.\r
330 @retval EFI_UNSUPPORTED The SCSI channel does not support a target reset operation.\r
331 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI device\r
332 specified by Target and Lun.\r
6a690e23 333\r
12618416 334**/\r
6a690e23 335EFI_STATUS\r
336EFIAPI\r
337IScsiExtScsiPassThruResetTargetLun (\r
338 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
339 IN UINT8 *Target,\r
340 IN UINT64 Lun\r
341 )\r
12618416 342{\r
343 return EFI_UNSUPPORTED;\r
344}\r
6a690e23 345\r
12618416 346/**\r
aeb49322 347 Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either \r
348 be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs\r
349 for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to \r
350 see if a SCSI device is actually present at that location on the SCSI channel. \r
351\r
352 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
353 @param[in, out] Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.\r
354 On output, a pointer to the Target ID (an array of\r
355 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI\r
356 channel. An input value of 0xF(all bytes in the array are 0xF) in the\r
357 Target array retrieves the Target ID of the first SCSI device present on a\r
358 SCSI channel.\r
359\r
360 @retval EFI_SUCCESS The Target ID of the next SCSI device on the SCSI\r
361 channel was returned in Target.\r
362 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.\r
363 @retval EFI_TIMEOUT Target array is not all 0xF, and Target were not\r
364 returned on a previous call to GetNextTarget().\r
365 Currently not implemented.\r
12618416 366 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.\r
12618416 367**/\r
6a690e23 368EFI_STATUS\r
369EFIAPI\r
370IScsiExtScsiPassThruGetNextTarget (\r
371 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
372 IN OUT UINT8 **Target\r
373 )\r
6a690e23 374{\r
375 UINT8 TargetId[TARGET_MAX_BYTES];\r
376\r
e48e37fc 377 SetMem (TargetId, TARGET_MAX_BYTES, 0xFF);\r
6a690e23 378\r
e48e37fc 379 if (CompareMem (*Target, TargetId, TARGET_MAX_BYTES) == 0) {\r
6a690e23 380 (*Target)[0] = 0;\r
381 return EFI_SUCCESS;\r
382 } else if ((*Target)[0] == 0) {\r
383 return EFI_NOT_FOUND;\r
384 } else {\r
385 return EFI_INVALID_PARAMETER;\r
386 }\r
387}\r
388\r
389EFI_EXT_SCSI_PASS_THRU_PROTOCOL gIScsiExtScsiPassThruProtocolTemplate = {\r
390 NULL,\r
391 IScsiExtScsiPassThruFunction,\r
392 IScsiExtScsiPassThruGetNextTargetLun,\r
393 IScsiExtScsiPassThruBuildDevicePath,\r
394 IScsiExtScsiPassThruGetTargetLun,\r
395 IScsiExtScsiPassThruResetChannel,\r
396 IScsiExtScsiPassThruResetTargetLun,\r
397 IScsiExtScsiPassThruGetNextTarget\r
398};\r