]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/IScsiDxe/IScsiDriver.c
Open default Tcp child via BY_CHILD_CONTROLLER.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiDriver.c
CommitLineData
12618416 1/** @file\r
fd82de4e 2 The entry point of IScsi driver.\r
6a690e23 3\r
0e402402 4Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 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
17EFI_DRIVER_BINDING_PROTOCOL gIScsiDriverBinding = {\r
18 IScsiDriverBindingSupported,\r
19 IScsiDriverBindingStart,\r
20 IScsiDriverBindingStop,\r
21 0xa,\r
22 NULL,\r
23 NULL\r
24};\r
25\r
05a30011
WJ
26/**\r
27 Tests to see if this driver supports the RemainingDevicePath. \r
28\r
29 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r
30 parameter is ignored by device drivers, and is optional for bus \r
31 drivers. For bus drivers, if this parameter is not NULL, then \r
32 the bus driver must determine if the bus controller specified \r
33 by ControllerHandle and the child controller specified \r
34 by RemainingDevicePath are both supported by this \r
35 bus driver.\r
36\r
37 @retval EFI_SUCCESS The RemainingDevicePath is supported or NULL.\r
38 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
39 RemainingDevicePath is not supported by the driver specified by This.\r
40**/\r
41EFI_STATUS\r
42IScsiIsDevicePathSupported (\r
43 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
44 )\r
45{\r
46 EFI_DEVICE_PATH_PROTOCOL *CurrentDevicePath;\r
47\r
48 CurrentDevicePath = RemainingDevicePath;\r
49 if (CurrentDevicePath != NULL) {\r
50 while (!IsDevicePathEnd (CurrentDevicePath)) {\r
51 if ((CurrentDevicePath->Type == MESSAGING_DEVICE_PATH) && (CurrentDevicePath->SubType == MSG_ISCSI_DP)) {\r
52 return EFI_SUCCESS;\r
53 }\r
54\r
55 CurrentDevicePath = NextDevicePathNode (CurrentDevicePath);\r
56 }\r
57\r
58 return EFI_UNSUPPORTED;\r
59 }\r
60\r
61 return EFI_SUCCESS;\r
62}\r
63\r
fd82de4e 64/**\r
65 Tests to see if this driver supports a given controller. If a child device is provided, \r
66 it further tests to see if this driver supports creating a handle for the specified child device.\r
67\r
68 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
69 @param[in] ControllerHandle The handle of the controller to test. This handle \r
70 must support a protocol interface that supplies \r
71 an I/O abstraction to the driver.\r
72 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. \r
73 This parameter is ignored by device drivers, and is optional for bus drivers.\r
74\r
75\r
76 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
77 RemainingDevicePath is supported by the driver specified by This.\r
78 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
79 RemainingDevicePath is already being managed by the driver\r
80 specified by This.\r
81 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
82 RemainingDevicePath is already being managed by a different\r
83 driver or an application that requires exclusive acces.\r
84 Currently not implemented.\r
85 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
86 RemainingDevicePath is not supported by the driver specified by This.\r
12618416 87**/\r
88EFI_STATUS\r
89EFIAPI\r
90IScsiDriverBindingSupported (\r
fd82de4e 91 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
12618416 92 IN EFI_HANDLE ControllerHandle,\r
fd82de4e 93 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
12618416 94 )\r
6a690e23 95{\r
96 EFI_STATUS Status;\r
6a690e23 97\r
98 Status = gBS->OpenProtocol (\r
99 ControllerHandle,\r
c8ad2d7a 100 &gEfiCallerIdGuid,\r
6a690e23 101 NULL,\r
102 This->DriverBindingHandle,\r
103 ControllerHandle,\r
104 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
105 );\r
106 if (!EFI_ERROR (Status)) {\r
107 return EFI_ALREADY_STARTED;\r
108 }\r
109\r
110 Status = gBS->OpenProtocol (\r
111 ControllerHandle,\r
112 &gEfiTcp4ServiceBindingProtocolGuid,\r
113 NULL,\r
114 This->DriverBindingHandle,\r
115 ControllerHandle,\r
116 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
117 );\r
118 if (EFI_ERROR (Status)) {\r
119 return EFI_UNSUPPORTED;\r
120 }\r
121\r
05a30011
WJ
122 Status = IScsiIsDevicePathSupported (RemainingDevicePath);\r
123 if (EFI_ERROR (Status)) {\r
124 return EFI_UNSUPPORTED;\r
125 }\r
6a690e23 126\r
05a30011
WJ
127 if (IScsiDhcpIsConfigured (ControllerHandle)) {\r
128 Status = gBS->OpenProtocol (\r
129 ControllerHandle,\r
130 &gEfiDhcp4ServiceBindingProtocolGuid,\r
131 NULL,\r
132 This->DriverBindingHandle,\r
133 ControllerHandle,\r
134 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
135 );\r
136 if (EFI_ERROR (Status)) {\r
137 return EFI_UNSUPPORTED;\r
6a690e23 138 }\r
6a690e23 139 }\r
140\r
141 return EFI_SUCCESS;\r
142}\r
143\r
12618416 144/**\r
55a64ae0 145 Start this driver on ControllerHandle. \r
146 \r
147 The Start() function is designed to be invoked from the EFI boot service ConnectController(). \r
148 As a result, much of the error checking on the parameters to Start() has been moved into this \r
149 common boot service. It is legal to call Start() from other locations, but the following calling \r
150 restrictions must be followed or the system behavior will not be deterministic.\r
fd82de4e 151 1. ControllerHandle must be a valid EFI_HANDLE.\r
152 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
153 EFI_DEVICE_PATH_PROTOCOL.\r
154 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
155 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS. \r
156\r
157 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
158 @param[in] ControllerHandle The handle of the controller to start. This handle \r
159 must support a protocol interface that supplies \r
160 an I/O abstraction to the driver.\r
161 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. \r
162 This parameter is ignored by device drivers, and is optional for bus drivers.\r
163\r
164 @retval EFI_SUCCESS The device was started.\r
165 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.\r
166 Currently not implemented.\r
167 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
168 @retval Others The driver failded to start the device.\r
12618416 169**/\r
6a690e23 170EFI_STATUS\r
171EFIAPI\r
172IScsiDriverBindingStart (\r
fd82de4e 173 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
6a690e23 174 IN EFI_HANDLE ControllerHandle,\r
fd82de4e 175 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
6a690e23 176 )\r
6a690e23 177{\r
178 EFI_STATUS Status;\r
179 ISCSI_DRIVER_DATA *Private;\r
fd627b16 180 VOID *Interface;\r
181\r
182 Private = IScsiCreateDriverData (This->DriverBindingHandle, ControllerHandle);\r
183 if (Private == NULL) {\r
184 return EFI_OUT_OF_RESOURCES;\r
185 }\r
186\r
187 //\r
188 // Create a underlayer child instance, but not need to configure it. Just open ChildHandle\r
189 // via BY_DRIVER. That is, establishing the relationship between ControllerHandle and ChildHandle.\r
190 // Therefore, when DisconnectController(), especially VLAN virtual controller handle,\r
191 // IScsiDriverBindingStop() will be called.\r
192 //\r
193 Status = NetLibCreateServiceChild (\r
194 ControllerHandle,\r
195 This->DriverBindingHandle,\r
196 &gEfiTcp4ServiceBindingProtocolGuid,\r
197 &Private->ChildHandle\r
198 );\r
199\r
200 if (EFI_ERROR (Status)) {\r
201 goto ON_ERROR;\r
202 }\r
203\r
204 Status = gBS->OpenProtocol (\r
205 Private->ChildHandle,\r
206 &gEfiTcp4ProtocolGuid,\r
207 &Interface,\r
208 This->DriverBindingHandle,\r
209 ControllerHandle,\r
210 EFI_OPEN_PROTOCOL_BY_DRIVER\r
211 );\r
212 if (EFI_ERROR (Status)) {\r
213 goto ON_ERROR;\r
214 }\r
215\r
05a30011 216 //\r
fd627b16 217 // Always install private protocol no matter what happens later. We need to \r
218 // keep the relationship between ControllerHandle and ChildHandle.\r
219 //\r
220 Status = gBS->InstallProtocolInterface (\r
221 &ControllerHandle,\r
c8ad2d7a 222 &gEfiCallerIdGuid,\r
fd627b16 223 EFI_NATIVE_INTERFACE,\r
224 &Private->IScsiIdentifier\r
225 );\r
226 if (EFI_ERROR (Status)) {\r
227 goto ON_ERROR;\r
228 }\r
6a690e23 229\r
230 //\r
231 // Try to add a port configuration page for this controller.\r
232 //\r
233 IScsiConfigUpdateForm (This->DriverBindingHandle, ControllerHandle, TRUE);\r
234\r
6a690e23 235 //\r
236 // Get the iSCSI configuration data of this controller.\r
237 //\r
238 Status = IScsiGetConfigData (Private);\r
239 if (EFI_ERROR (Status)) {\r
240 goto ON_ERROR;\r
241 }\r
242 //\r
243 // Try to login and create an iSCSI session according to the configuration.\r
244 //\r
245 Status = IScsiSessionLogin (Private);\r
246 if (Status == EFI_MEDIA_CHANGED) {\r
247 //\r
248 // The specified target is not available and the redirection information is\r
249 // got, login the session again with the updated target address.\r
250 //\r
251 Status = IScsiSessionLogin (Private);\r
252 }\r
253\r
254 if (EFI_ERROR (Status)) {\r
255 goto ON_ERROR;\r
256 }\r
257 //\r
258 // Duplicate the Session's tcp connection device path. The source port field\r
259 // will be set to zero as one iSCSI session is comprised of several iSCSI\r
260 // connections.\r
261 //\r
262 Private->DevicePath = IScsiGetTcpConnDevicePath (Private);\r
263 if (Private->DevicePath == NULL) {\r
264 goto ON_ERROR;\r
265 }\r
266 //\r
267 // Install the updated device path onto the ExtScsiPassThruHandle.\r
268 //\r
269 Status = gBS->InstallProtocolInterface (\r
270 &Private->ExtScsiPassThruHandle,\r
271 &gEfiDevicePathProtocolGuid,\r
272 EFI_NATIVE_INTERFACE,\r
273 Private->DevicePath\r
274 );\r
275 if (EFI_ERROR (Status)) {\r
276 goto ON_ERROR;\r
277 }\r
fd627b16 278\r
0e402402
WJ
279 //\r
280 // ISCSI children should share the default Tcp child, just open the default Tcp child via BY_CHILD_CONTROLLER.\r
281 //\r
282 Status = gBS->OpenProtocol (\r
283 Private->ChildHandle, /// Default Tcp child\r
284 &gEfiTcp4ProtocolGuid,\r
285 &Interface,\r
286 This->DriverBindingHandle,\r
287 Private->ExtScsiPassThruHandle,\r
288 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
289 ); \r
290 if (EFI_ERROR (Status)) {\r
291 gBS->UninstallMultipleProtocolInterfaces (\r
292 Private->ExtScsiPassThruHandle,\r
293 &gEfiExtScsiPassThruProtocolGuid,\r
294 &Private->IScsiExtScsiPassThru,\r
295 &gEfiDevicePathProtocolGuid,\r
296 Private->DevicePath,\r
297 NULL\r
298 );\r
299 \r
300 goto ON_ERROR;\r
301 }\r
302\r
6a690e23 303 //\r
304 // Update/Publish the iSCSI Boot Firmware Table.\r
305 //\r
306 IScsiPublishIbft ();\r
307\r
308 return EFI_SUCCESS;\r
309\r
310ON_ERROR:\r
311\r
312 IScsiSessionAbort (&Private->Session);\r
6a690e23 313\r
314 return Status;\r
315}\r
316\r
12618416 317/**\r
fd82de4e 318 Stop this driver on ControllerHandle. \r
319 \r
320 Release the control of this controller and remove the IScsi functions. The Stop()\r
321 function is designed to be invoked from the EFI boot service DisconnectController(). \r
322 As a result, much of the error checking on the parameters to Stop() has been moved \r
323 into this common boot service. It is legal to call Stop() from other locations, \r
324 but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
325 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
326 same driver's Start() function.\r
327 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
328 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
329 Start() function, and the Start() function must have called OpenProtocol() on\r
330 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
331 \r
332 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
333 @param[in] ControllerHandle A handle to the device being stopped. The handle must \r
334 support a bus specific I/O protocol for the driver \r
335 to use to stop the device.\r
336 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.Not used.\r
337 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL \r
338 if NumberOfChildren is 0.Not used.\r
339\r
340 @retval EFI_SUCCESS The device was stopped.\r
341 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
12618416 342**/\r
6a690e23 343EFI_STATUS\r
344EFIAPI\r
345IScsiDriverBindingStop (\r
346 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
347 IN EFI_HANDLE ControllerHandle,\r
348 IN UINTN NumberOfChildren,\r
c5de0d55 349 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r
6a690e23 350 )\r
6a690e23 351{\r
352 EFI_HANDLE IScsiController;\r
353 EFI_STATUS Status;\r
354 ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier;\r
355 ISCSI_DRIVER_DATA *Private;\r
356 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru;\r
357 ISCSI_CONNECTION *Conn;\r
358\r
359 if (NumberOfChildren != 0) {\r
360 //\r
361 // We should have only one child.\r
362 //\r
363 Status = gBS->OpenProtocol (\r
364 ChildHandleBuffer[0],\r
365 &gEfiExtScsiPassThruProtocolGuid,\r
366 (VOID **) &PassThru,\r
367 This->DriverBindingHandle,\r
368 ControllerHandle,\r
369 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
370 );\r
371 if (EFI_ERROR (Status)) {\r
372 return EFI_DEVICE_ERROR;\r
373 }\r
374\r
375 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (PassThru);\r
376 Conn = NET_LIST_HEAD (&Private->Session.Conns, ISCSI_CONNECTION, Link);\r
377\r
378 //\r
379 // Previously the TCP4 protocol is opened BY_CHILD_CONTROLLER. Just close\r
380 // the protocol here but not uninstall the device path protocol and\r
381 // EXT SCSI PASS THRU protocol installed on ExtScsiPassThruHandle.\r
382 //\r
0e402402
WJ
383 gBS->CloseProtocol (\r
384 Private->ChildHandle,\r
385 &gEfiTcp4ProtocolGuid,\r
386 Private->Image,\r
387 Private->ExtScsiPassThruHandle\r
388 );\r
389 \r
6a690e23 390 gBS->CloseProtocol (\r
391 Conn->Tcp4Io.Handle,\r
392 &gEfiTcp4ProtocolGuid,\r
393 Private->Image,\r
394 Private->ExtScsiPassThruHandle\r
395 );\r
396\r
397 return EFI_SUCCESS;\r
398 }\r
399 //\r
400 // Get the handle of the controller we are controling.\r
401 //\r
402 IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);\r
403\r
404 Status = gBS->OpenProtocol (\r
405 IScsiController,\r
c8ad2d7a 406 &gEfiCallerIdGuid,\r
6a690e23 407 (VOID **)&IScsiIdentifier,\r
408 This->DriverBindingHandle,\r
409 ControllerHandle,\r
410 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
411 );\r
412 if (EFI_ERROR (Status)) {\r
413 return EFI_DEVICE_ERROR;\r
414 }\r
415\r
416 Private = ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifier);\r
417\r
fd627b16 418 if (Private->ChildHandle != NULL) {\r
419 Status = gBS->CloseProtocol (\r
420 Private->ChildHandle,\r
421 &gEfiTcp4ProtocolGuid,\r
422 This->DriverBindingHandle,\r
423 IScsiController\r
424 );\r
425\r
426 ASSERT (!EFI_ERROR (Status));\r
427\r
428 Status = NetLibDestroyServiceChild (\r
429 IScsiController,\r
430 This->DriverBindingHandle,\r
431 &gEfiTcp4ServiceBindingProtocolGuid,\r
432 Private->ChildHandle\r
433 );\r
434 ASSERT (!EFI_ERROR (Status));\r
435 }\r
436\r
437 IScsiConfigUpdateForm (This->DriverBindingHandle, IScsiController, FALSE);\r
438\r
6a690e23 439 //\r
440 // Uninstall the private protocol.\r
441 //\r
442 gBS->UninstallProtocolInterface (\r
443 IScsiController,\r
c8ad2d7a 444 &gEfiCallerIdGuid,\r
6a690e23 445 &Private->IScsiIdentifier\r
446 );\r
447\r
448 //\r
449 // Update the iSCSI Boot Firware Table.\r
450 //\r
451 IScsiPublishIbft ();\r
452\r
453 IScsiSessionAbort (&Private->Session);\r
454 IScsiCleanDriverData (Private);\r
455\r
456 return EFI_SUCCESS;\r
457}\r
458\r
12618416 459/**\r
fd82de4e 460 Unloads an image(the iSCSI driver).\r
6a690e23 461\r
fd82de4e 462 @param[in] ImageHandle Handle that identifies the image to be unloaded.\r
6a690e23 463\r
fd82de4e 464 @retval EFI_SUCCESS The image has been unloaded.\r
963dbb30 465 @retval Others Other errors as indicated.\r
12618416 466**/\r
467EFI_STATUS\r
468EFIAPI\r
469EfiIScsiUnload (\r
470 IN EFI_HANDLE ImageHandle\r
471 )\r
6a690e23 472{\r
18b24f92
FS
473 EFI_STATUS Status;\r
474 UINTN DeviceHandleCount;\r
475 EFI_HANDLE *DeviceHandleBuffer;\r
476 UINTN Index;\r
477 EFI_COMPONENT_NAME_PROTOCOL *ComponentName;\r
478 EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;\r
6a690e23 479\r
480 //\r
481 // Try to disonnect the driver from the devices it's controlling.\r
482 //\r
483 Status = gBS->LocateHandleBuffer (\r
484 AllHandles,\r
485 NULL,\r
486 NULL,\r
487 &DeviceHandleCount,\r
488 &DeviceHandleBuffer\r
489 );\r
18b24f92
FS
490 if (EFI_ERROR (Status)) {\r
491 return Status;\r
492 }\r
6a690e23 493\r
18b24f92
FS
494 for (Index = 0; Index < DeviceHandleCount; Index++) {\r
495 Status = IScsiTestManagedDevice (\r
496 DeviceHandleBuffer[Index],\r
497 gIScsiDriverBinding.DriverBindingHandle,\r
498 &gEfiTcp4ProtocolGuid\r
499 );\r
500 if (EFI_ERROR (Status)) {\r
501 continue;\r
6a690e23 502 }\r
18b24f92
FS
503 Status = gBS->DisconnectController (\r
504 DeviceHandleBuffer[Index],\r
505 gIScsiDriverBinding.DriverBindingHandle,\r
506 NULL\r
507 );\r
508 if (EFI_ERROR (Status)) {\r
509 goto ON_EXIT;\r
510 }\r
511 } \r
512\r
6a690e23 513 //\r
514 // Unload the iSCSI configuration form.\r
515 //\r
18b24f92
FS
516 Status = IScsiConfigFormUnload (gIScsiDriverBinding.DriverBindingHandle);\r
517 if (EFI_ERROR (Status)) {\r
518 goto ON_EXIT;\r
519 }\r
6a690e23 520\r
521 //\r
18b24f92
FS
522 // Uninstall the ComponentName and ComponentName2 protocol from iSCSI4 driver binding handle\r
523 // if it has been installed.\r
6a690e23 524 //\r
18b24f92
FS
525 Status = gBS->HandleProtocol (\r
526 gIScsiDriverBinding.DriverBindingHandle,\r
527 &gEfiComponentNameProtocolGuid,\r
528 (VOID **) &ComponentName\r
529 );\r
530 if (!EFI_ERROR (Status)) {\r
531 Status = gBS->UninstallMultipleProtocolInterfaces (\r
532 gIScsiDriverBinding.DriverBindingHandle,\r
533 &gEfiComponentNameProtocolGuid,\r
534 ComponentName,\r
535 NULL\r
536 );\r
537 if (EFI_ERROR (Status)) {\r
538 goto ON_EXIT;\r
539 }\r
540 }\r
541 \r
542 Status = gBS->HandleProtocol (\r
543 gIScsiDriverBinding.DriverBindingHandle,\r
544 &gEfiComponentName2ProtocolGuid,\r
545 (VOID **) &ComponentName2\r
546 );\r
547 if (!EFI_ERROR (Status)) {\r
548 gBS->UninstallMultipleProtocolInterfaces (\r
549 gIScsiDriverBinding.DriverBindingHandle,\r
550 &gEfiComponentName2ProtocolGuid,\r
551 ComponentName2,\r
552 NULL\r
553 );\r
554 if (EFI_ERROR (Status)) {\r
555 goto ON_EXIT;\r
556 }\r
557 }\r
558\r
6a690e23 559 Status = gBS->UninstallMultipleProtocolInterfaces (\r
560 ImageHandle,\r
561 &gEfiDriverBindingProtocolGuid,\r
562 &gIScsiDriverBinding,\r
6a690e23 563 &gEfiIScsiInitiatorNameProtocolGuid,\r
564 &gIScsiInitiatorName,\r
565 NULL\r
566 );\r
18b24f92 567ON_EXIT:\r
6a690e23 568\r
18b24f92
FS
569 if (DeviceHandleBuffer != NULL) {\r
570 FreePool (DeviceHandleBuffer);\r
571 }\r
572 \r
6a690e23 573 return Status;\r
574}\r
575\r
12618416 576/**\r
fd82de4e 577 This is the declaration of an EFI image entry point. This entry point is\r
578 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r
579 both device drivers and bus drivers. It initialize the global variables and \r
580 publish the driver binding protocol.\r
6a690e23 581\r
fd82de4e 582 @param[in] ImageHandle The firmware allocated handle for the UEFI image.\r
583 @param[in] SystemTable A pointer to the EFI System Table.\r
6a690e23 584\r
fd82de4e 585 @retval EFI_SUCCESS The operation completed successfully.\r
586 @retval EFI_ACCESS_DENIED EFI_ISCSI_INITIATOR_NAME_PROTOCOL was installed unexpectedly.\r
963dbb30 587 @retval Others Other errors as indicated.\r
12618416 588**/\r
589EFI_STATUS\r
590EFIAPI\r
591IScsiDriverEntryPoint (\r
592 IN EFI_HANDLE ImageHandle,\r
593 IN EFI_SYSTEM_TABLE *SystemTable\r
594 )\r
6a690e23 595{\r
f2a94e25 596 EFI_STATUS Status;\r
597 EFI_ISCSI_INITIATOR_NAME_PROTOCOL *IScsiInitiatorName;\r
598\r
599 //\r
600 // There should be only one EFI_ISCSI_INITIATOR_NAME_PROTOCOL.\r
601 //\r
602 Status = gBS->LocateProtocol (\r
603 &gEfiIScsiInitiatorNameProtocolGuid,\r
604 NULL,\r
b4df5011 605 (VOID**) &IScsiInitiatorName\r
f2a94e25 606 );\r
607\r
608 if (!EFI_ERROR (Status)) {\r
609 return EFI_ACCESS_DENIED;\r
610 }\r
6a690e23 611\r
612 //\r
613 // Initialize the EFI Driver Library\r
614 //\r
615 Status = EfiLibInstallDriverBindingComponentName2 (\r
616 ImageHandle,\r
617 SystemTable,\r
618 &gIScsiDriverBinding,\r
619 ImageHandle,\r
620 &gIScsiComponentName,\r
621 &gIScsiComponentName2\r
622 );\r
6a690e23 623\r
624 if (!EFI_ERROR (Status)) {\r
f2a94e25 625 //\r
626 // Install the iSCSI Initiator Name Protocol.\r
627 //\r
6a690e23 628 Status = gBS->InstallProtocolInterface (\r
629 &ImageHandle,\r
630 &gEfiIScsiInitiatorNameProtocolGuid,\r
631 EFI_NATIVE_INTERFACE,\r
632 &gIScsiInitiatorName\r
633 );\r
634 if (EFI_ERROR (Status)) {\r
635 gBS->UninstallMultipleProtocolInterfaces (\r
636 ImageHandle,\r
637 &gEfiDriverBindingProtocolGuid,\r
638 &gIScsiDriverBinding,\r
639 &gEfiComponentName2ProtocolGuid,\r
640 &gIScsiComponentName2,\r
641 &gEfiComponentNameProtocolGuid,\r
642 &gIScsiComponentName,\r
643 NULL\r
644 );\r
f2a94e25 645 return Status;\r
646 }\r
647 \r
648 //\r
649 // Initialize the configuration form of iSCSI.\r
650 //\r
963dbb30 651 Status = IScsiConfigFormInit ();\r
f2a94e25 652 if (EFI_ERROR (Status)) {\r
653 gBS->UninstallMultipleProtocolInterfaces (\r
654 ImageHandle,\r
655 &gEfiDriverBindingProtocolGuid,\r
656 &gIScsiDriverBinding,\r
657 &gEfiComponentName2ProtocolGuid,\r
658 &gIScsiComponentName2,\r
659 &gEfiComponentNameProtocolGuid,\r
660 &gIScsiComponentName,\r
661 &gEfiIScsiInitiatorNameProtocolGuid,\r
662 &gIScsiInitiatorName,\r
663 NULL\r
664 );\r
6a690e23 665 }\r
666 }\r
6a690e23 667 return Status;\r
668}\r
669\r