]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/IScsiDxe/IScsiExtScsiPassThru.c
Use Mde library and definition instead of some native definitions in NetLib, to simpl...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiExtScsiPassThru.c
CommitLineData
6a690e23 1/*++\r
2\r
7a444476 3Copyright (c) 2004 - 2007, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
6a690e23 11\r
12Module Name:\r
13\r
14 IScsiExtScsiPassThru.c\r
15\r
16Abstract:\r
17\r
18--*/\r
19\r
20#include "IScsiImpl.h"\r
21\r
22EFI_STATUS\r
23EFIAPI\r
24IScsiExtScsiPassThruFunction (\r
25 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
26 IN UINT8 *Target,\r
27 IN UINT64 Lun,\r
28 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,\r
29 IN EFI_EVENT Event OPTIONAL\r
30 )\r
31/*++\r
32\r
33Routine Description:\r
34\r
35 This function sends out the SCSI command via iSCSI transport layer and returned\r
36 back the data received from the iSCSI target. \r
37\r
38Arguments:\r
39\r
40 This - The EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
41 Target - The Target ID of device to send the SCSI Request Packet. \r
42 Lun - The LUN of the device to send the SCSI Request Packet.\r
43 Packet - The SCSI Request Packet to send to the device.\r
44 Event - The event used in non-blocking mode, it should be always NULL.\r
45\r
46Returns:\r
47\r
48 EFI_STATUS\r
49\r
50--*/\r
51{\r
52 if (Target[0] != 0) {\r
53 return EFI_INVALID_PARAMETER;\r
54 }\r
55\r
56 if ((Packet == NULL) || (Packet->Cdb == NULL)) {\r
57 return EFI_INVALID_PARAMETER;\r
58 }\r
59\r
60 return IScsiExecuteScsiCommand (This, Target, Lun, Packet);\r
61}\r
62\r
63EFI_STATUS\r
64EFIAPI\r
65IScsiExtScsiPassThruGetNextTargetLun (\r
66 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
67 IN OUT UINT8 **Target,\r
68 IN OUT UINT64 *Lun\r
69 )\r
70/*++\r
71\r
72Routine Description:\r
73\r
74 Retrieve the list of legal Target IDs for SCSI devices on a SCSI channel.\r
75\r
76Arguments:\r
77\r
78 This - The EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance..\r
79 Target - On input, a pointer to the Target ID of a SCSI device present on the\r
80 SCSI channel. On output, a pointer to the Target ID of the next SCSI\r
81 device present on a SCSI channel. An input value of 0xFFFFFFFF\r
82 retrieves the Target ID of the first SCSI device present on a SCSI channel.\r
83 Lun - On input, a pointer to the LUN of a SCSI device present on the SCSI\r
84 channel. On output, a pointer to the LUN of the next SCSI device present on \r
85 a SCSI channel.\r
86\r
87Returns:\r
88\r
89 EFI_SUCCESS - The Target ID and Lun of the next SCSI device \r
90 on the SCSI channel was returned in Target and Lun.\r
91 EFI_NOT_FOUND - There are no more SCSI devices on this SCSI channel.\r
92 EFI_INVALID_PARAMETER - Target is not 0xFFFFFFFF,and Target and Lun were not\r
93 returned on a previous call to GetNextDevice().\r
94\r
95--*/\r
96{\r
97 ISCSI_DRIVER_DATA *Private;\r
98 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;\r
99 UINT8 TargetId[TARGET_MAX_BYTES];\r
100\r
101 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);\r
102 ConfigNvData = &Private->Session.ConfigData.NvData;\r
103\r
e48e37fc 104 if ((*Target)[0] == 0 && (CompareMem (Lun, ConfigNvData->BootLun, sizeof (UINT64)) == 0)) {\r
6a690e23 105 //\r
106 // Only one <Target, Lun> pair per iSCSI Driver instance.\r
107 //\r
108 return EFI_NOT_FOUND;\r
109 }\r
110\r
e48e37fc 111 SetMem (TargetId, TARGET_MAX_BYTES, 0xFF);\r
112 if (CompareMem (*Target, TargetId, TARGET_MAX_BYTES) == 0) {\r
6a690e23 113 (*Target)[0] = 0;\r
e48e37fc 114 CopyMem (Lun, ConfigNvData->BootLun, sizeof (UINT64));\r
6a690e23 115\r
116 return EFI_SUCCESS;\r
117 }\r
118\r
119 return EFI_INVALID_PARAMETER;\r
120}\r
121\r
122EFI_STATUS\r
123EFIAPI\r
124IScsiExtScsiPassThruBuildDevicePath (\r
125 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
126 IN UINT8 *Target,\r
127 IN UINT64 Lun,\r
128 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath\r
129 )\r
130/*++\r
131\r
132Routine Description:\r
133\r
134 Allocate and build a device path node for a SCSI device on a SCSI channel.\r
135\r
136Arguments:\r
137\r
138 This - Protocol instance pointer.\r
139 Target - The Target ID of the SCSI device for which\r
140 a device path node is to be allocated and built.\r
141 Lun - The LUN of the SCSI device for which a device \r
142 path node is to be allocated and built.\r
143 DevicePath - A pointer to a single device path node that \r
144 describes the SCSI device specified by \r
145 Target and Lun. This function is responsible \r
146 for allocating the buffer DevicePath with the boot\r
147 service AllocatePool(). It is the caller's \r
148 responsibility to free DevicePath when the caller\r
149 is finished with DevicePath. \r
150\r
151Returns:\r
152\r
153 EFI_SUCCESS - The device path node that describes the SCSI device\r
154 specified by Target and Lun was allocated and \r
155 returned in DevicePath.\r
156 EFI_NOT_FOUND - The SCSI devices specified by Target and Lun does\r
157 not exist on the SCSI channel.\r
158 EFI_INVALID_PARAMETER - DevicePath is NULL.\r
159 EFI_OUT_OF_RESOURCES - There are not enough resources to allocate \r
160 DevicePath.\r
161\r
162--*/\r
163{\r
164 ISCSI_DRIVER_DATA *Private;\r
165 ISCSI_SESSION *Session;\r
166 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;\r
167 ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfig;\r
168 EFI_DEV_PATH *Node;\r
169 UINTN DevPathNodeLen;\r
170\r
171 if ((DevicePath == NULL)) {\r
172 return EFI_INVALID_PARAMETER;\r
173 }\r
174\r
175 if (Target[0] != 0) {\r
176 return EFI_NOT_FOUND;\r
177 }\r
178\r
179 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);\r
180 Session = &Private->Session;\r
181 ConfigNvData = &Session->ConfigData.NvData;\r
182 AuthConfig = &Session->AuthData.AuthConfig;\r
183\r
e48e37fc 184 if (CompareMem (&Lun, ConfigNvData->BootLun, sizeof (UINT64)) != 0) {\r
6a690e23 185 return EFI_NOT_FOUND;\r
186 }\r
187\r
188 DevPathNodeLen = sizeof (ISCSI_DEVICE_PATH) + AsciiStrLen (ConfigNvData->TargetName) + 1;\r
e48e37fc 189 Node = AllocatePool (DevPathNodeLen);\r
6a690e23 190 if (Node == NULL) {\r
191 return EFI_OUT_OF_RESOURCES;\r
192 }\r
193\r
194 Node->DevPath.Type = MESSAGING_DEVICE_PATH;\r
195 Node->DevPath.SubType = MSG_ISCSI_DP;\r
196 SetDevicePathNodeLength (&Node->DevPath, DevPathNodeLen);\r
197\r
198 //\r
199 // 0 for TCP, others are reserved.\r
200 //\r
201 Node->Iscsi.NetworkProtocol = 0;\r
202\r
203 Node->Iscsi.LoginOption = 0;\r
204 switch (AuthConfig->CHAPType) {\r
205 case ISCSI_CHAP_NONE:\r
206 Node->Iscsi.LoginOption |= 0x0800;\r
207 break;\r
208\r
209 case ISCSI_CHAP_UNI:\r
210 Node->Iscsi.LoginOption |= 0x1000;\r
211 break;\r
212\r
213 default:\r
214 break;\r
215 }\r
216\r
e48e37fc 217 CopyMem (&Node->Iscsi.Lun, ConfigNvData->BootLun, sizeof (UINT64));\r
6a690e23 218 Node->Iscsi.TargetPortalGroupTag = Session->TargetPortalGroupTag;\r
219 AsciiStrCpy ((CHAR8 *) Node + sizeof (ISCSI_DEVICE_PATH), ConfigNvData->TargetName);\r
220\r
221 *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Node;\r
222\r
223 return EFI_SUCCESS;\r
224}\r
225\r
226EFI_STATUS\r
227EFIAPI\r
228IScsiExtScsiPassThruGetTargetLun (\r
229 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
230 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
231 OUT UINT8 **Target,\r
232 OUT UINT64 *Lun\r
233 )\r
234/*++\r
235\r
236Routine Description:\r
237\r
238 Translate a device path node to a Target ID and LUN.\r
239\r
240Arguments:\r
241\r
242 This - Protocol instance pointer.\r
243 DevicePath - A pointer to the device path node that \r
244 describes a SCSI device on the SCSI channel.\r
245 Target - A pointer to the Target ID of a SCSI device \r
246 on the SCSI channel. \r
247 Lun - A pointer to the LUN of a SCSI device on \r
248 the SCSI channel. \r
249Returns:\r
250\r
251 EFI_SUCCESS - DevicePath was successfully translated to a \r
252 Target ID and LUN, and they were returned \r
253 in Target and Lun.\r
254 EFI_INVALID_PARAMETER - DevicePath/Target/Lun is NULL.\r
255 EFI_UNSUPPORTED - This driver does not support the device path \r
256 node type in DevicePath.\r
257 EFI_NOT_FOUND - A valid translation from DevicePath to a \r
258 Target ID and LUN does not exist.\r
259\r
260--*/\r
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
290EFI_STATUS\r
291EFIAPI\r
292IScsiExtScsiPassThruResetChannel (\r
293 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This\r
294 )\r
295/*++\r
296\r
297Routine Description:\r
298\r
299 Resets a SCSI channel.This operation resets all the SCSI devices connected to\r
300 the SCSI channel.\r
301\r
302Arguments:\r
303\r
304 This - Protocol instance pointer.\r
305\r
306Returns:\r
307\r
308 EFI_UNSUPPORTED - It's not supported.\r
309\r
310--*/\r
311{\r
312 return EFI_UNSUPPORTED;\r
313}\r
314\r
315EFI_STATUS\r
316EFIAPI\r
317IScsiExtScsiPassThruResetTargetLun (\r
318 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
319 IN UINT8 *Target,\r
320 IN UINT64 Lun\r
321 )\r
322/*++\r
323\r
324Routine Description:\r
325\r
326 Resets a SCSI device that is connected to a SCSI channel.\r
327\r
328Arguments:\r
329\r
330 This - Protocol instance pointer.\r
331 Target - The Target ID of the SCSI device to reset. \r
332 Lun - The LUN of the SCSI device to reset.\r
333 \r
334Returns:\r
335\r
336 EFI_UNSUPPORTED - It's not supported.\r
337\r
338--*/\r
339{\r
340 return EFI_UNSUPPORTED;\r
341}\r
342\r
343EFI_STATUS\r
344EFIAPI\r
345IScsiExtScsiPassThruGetNextTarget (\r
346 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
347 IN OUT UINT8 **Target\r
348 )\r
349/*++\r
350\r
351Routine Description:\r
352\r
353 Retrieve the list of legal Target IDs for SCSI devices on a SCSI channel.\r
354\r
355Arguments:\r
356 This - Protocol instance pointer.\r
357 Target - On input, a pointer to the Target ID of a SCSI \r
358 device present on the SCSI channel. On output, \r
359 a pointer to the Target ID of the next SCSI device\r
360 present on a SCSI channel. An input value of \r
361 0xFFFFFFFF retrieves the Target ID of the first \r
362 SCSI device present on a SCSI channel.\r
363 Lun - On input, a pointer to the LUN of a SCSI device\r
364 present on the SCSI channel. On output, a pointer\r
365 to the LUN of the next SCSI device present on \r
366 a SCSI channel.\r
367 \r
368Returns:\r
369\r
370 EFI_SUCCESS - The Target ID and Lun of the next SCSI device \r
371 on the SCSI channel was returned in Target and Lun.\r
372 EFI_NOT_FOUND - There are no more SCSI devices on this SCSI channel.\r
373 EFI_INVALID_PARAMETER - Target is not 0xFFFFFFFF,and Target and Lun were not\r
374 returned on a previous call to GetNextDevice().\r
375\r
376--*/\r
377{\r
378 UINT8 TargetId[TARGET_MAX_BYTES];\r
379\r
e48e37fc 380 SetMem (TargetId, TARGET_MAX_BYTES, 0xFF);\r
6a690e23 381\r
e48e37fc 382 if (CompareMem (*Target, TargetId, TARGET_MAX_BYTES) == 0) {\r
6a690e23 383 (*Target)[0] = 0;\r
384 return EFI_SUCCESS;\r
385 } else if ((*Target)[0] == 0) {\r
386 return EFI_NOT_FOUND;\r
387 } else {\r
388 return EFI_INVALID_PARAMETER;\r
389 }\r
390}\r
391\r
392EFI_EXT_SCSI_PASS_THRU_PROTOCOL gIScsiExtScsiPassThruProtocolTemplate = {\r
393 NULL,\r
394 IScsiExtScsiPassThruFunction,\r
395 IScsiExtScsiPassThruGetNextTargetLun,\r
396 IScsiExtScsiPassThruBuildDevicePath,\r
397 IScsiExtScsiPassThruGetTargetLun,\r
398 IScsiExtScsiPassThruResetChannel,\r
399 IScsiExtScsiPassThruResetTargetLun,\r
400 IScsiExtScsiPassThruGetNextTarget\r
401};\r