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