]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/IScsiDxe/IScsiExtScsiPassThru.c
Update the copyright notice format
[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
e5eed7d3
HT
4Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>\r
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
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
4a4bb30e 285 SetMem (*Target, TARGET_MAX_BYTES, 0xFF);\r
08654acb 286 (*Target)[0] = 0;\r
6a690e23 287\r
288 if (AsciiStrCmp (ConfigNvData->TargetName, (CHAR8 *) DevicePath + sizeof (ISCSI_DEVICE_PATH)) != 0) {\r
289 return EFI_UNSUPPORTED;\r
290 }\r
291\r
e48e37fc 292 CopyMem (Lun, ConfigNvData->BootLun, sizeof (UINT64));\r
6a690e23 293\r
294 return EFI_SUCCESS;\r
295}\r
296\r
12618416 297/**\r
aeb49322 298 Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel.\r
299 Currently not implemented.\r
300 \r
301 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
302\r
303 @retval EFI_SUCCESS The SCSI channel was reset.\r
304 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI channel.\r
305 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI channel.\r
306 @retval EFI_UNSUPPORTED The SCSI channel does not support a channel reset operation.\r
12618416 307**/\r
6a690e23 308EFI_STATUS\r
309EFIAPI\r
310IScsiExtScsiPassThruResetChannel (\r
311 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This\r
312 )\r
12618416 313{\r
314 return EFI_UNSUPPORTED;\r
315}\r
6a690e23 316\r
12618416 317/**\r
aeb49322 318 Resets a SCSI logical unit that is connected to a SCSI channel. Currently not implemented.\r
319\r
320 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
321 @param[in] Target The Target is an array of size TARGET_MAX_BYTE and it represents the\r
322 target port ID of the SCSI device containing the SCSI logical unit to\r
323 reset. Transport drivers may chose to utilize a subset of this array to suit\r
324 the representation of their targets.\r
325 @param[in] Lun The LUN of the SCSI device to reset.\r
326\r
327 @retval EFI_SUCCESS The SCSI device specified by Target and Lun was reset.\r
328 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.\r
329 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI device\r
330 specified by Target and Lun.\r
331 @retval EFI_UNSUPPORTED The SCSI channel does not support a target reset operation.\r
332 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI device\r
333 specified by Target and Lun.\r
6a690e23 334\r
12618416 335**/\r
6a690e23 336EFI_STATUS\r
337EFIAPI\r
338IScsiExtScsiPassThruResetTargetLun (\r
339 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
340 IN UINT8 *Target,\r
341 IN UINT64 Lun\r
342 )\r
12618416 343{\r
344 return EFI_UNSUPPORTED;\r
345}\r
6a690e23 346\r
12618416 347/**\r
aeb49322 348 Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either \r
349 be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs\r
350 for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to \r
351 see if a SCSI device is actually present at that location on the SCSI channel. \r
352\r
353 @param[in] This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
354 @param[in, out] Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.\r
355 On output, a pointer to the Target ID (an array of\r
356 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI\r
357 channel. An input value of 0xF(all bytes in the array are 0xF) in the\r
358 Target array retrieves the Target ID of the first SCSI device present on a\r
359 SCSI channel.\r
360\r
361 @retval EFI_SUCCESS The Target ID of the next SCSI device on the SCSI\r
362 channel was returned in Target.\r
363 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.\r
364 @retval EFI_TIMEOUT Target array is not all 0xF, and Target were not\r
365 returned on a previous call to GetNextTarget().\r
366 Currently not implemented.\r
12618416 367 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.\r
12618416 368**/\r
6a690e23 369EFI_STATUS\r
370EFIAPI\r
371IScsiExtScsiPassThruGetNextTarget (\r
372 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
373 IN OUT UINT8 **Target\r
374 )\r
6a690e23 375{\r
376 UINT8 TargetId[TARGET_MAX_BYTES];\r
377\r
e48e37fc 378 SetMem (TargetId, TARGET_MAX_BYTES, 0xFF);\r
6a690e23 379\r
e48e37fc 380 if (CompareMem (*Target, TargetId, TARGET_MAX_BYTES) == 0) {\r
6a690e23 381 (*Target)[0] = 0;\r
382 return EFI_SUCCESS;\r
383 } else if ((*Target)[0] == 0) {\r
384 return EFI_NOT_FOUND;\r
385 } else {\r
386 return EFI_INVALID_PARAMETER;\r
387 }\r
388}\r
389\r
390EFI_EXT_SCSI_PASS_THRU_PROTOCOL gIScsiExtScsiPassThruProtocolTemplate = {\r
391 NULL,\r
392 IScsiExtScsiPassThruFunction,\r
393 IScsiExtScsiPassThruGetNextTargetLun,\r
394 IScsiExtScsiPassThruBuildDevicePath,\r
395 IScsiExtScsiPassThruGetTargetLun,\r
396 IScsiExtScsiPassThruResetChannel,\r
397 IScsiExtScsiPassThruResetTargetLun,\r
398 IScsiExtScsiPassThruGetNextTarget\r
399};\r