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