]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/IScsiDxe/IScsiDriver.c
cc452e711048314fed534522312928d223930013
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiDriver.c
1 /** @file
2 The entry point of IScsi driver.
3
4 Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "IScsiImpl.h"
16
17 EFI_DRIVER_BINDING_PROTOCOL gIScsiIp4DriverBinding = {
18 IScsiIp4DriverBindingSupported,
19 IScsiIp4DriverBindingStart,
20 IScsiIp4DriverBindingStop,
21 0xa,
22 NULL,
23 NULL
24 };
25
26 EFI_DRIVER_BINDING_PROTOCOL gIScsiIp6DriverBinding = {
27 IScsiIp6DriverBindingSupported,
28 IScsiIp6DriverBindingStart,
29 IScsiIp6DriverBindingStop,
30 0xa,
31 NULL,
32 NULL
33 };
34
35 EFI_GUID gIScsiV4PrivateGuid = ISCSI_V4_PRIVATE_GUID;
36 EFI_GUID gIScsiV6PrivateGuid = ISCSI_V6_PRIVATE_GUID;
37 ISCSI_PRIVATE_DATA *mPrivate = NULL;
38
39 /**
40 Tests to see if this driver supports the RemainingDevicePath.
41
42 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
43 parameter is ignored by device drivers, and is optional for bus
44 drivers. For bus drivers, if this parameter is not NULL, then
45 the bus driver must determine if the bus controller specified
46 by ControllerHandle and the child controller specified
47 by RemainingDevicePath are both supported by this
48 bus driver.
49
50 @retval EFI_SUCCESS The RemainingDevicePath is supported or NULL.
51 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
52 RemainingDevicePath is not supported by the driver specified by This.
53 **/
54 EFI_STATUS
55 IScsiIsDevicePathSupported (
56 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
57 )
58 {
59 EFI_DEVICE_PATH_PROTOCOL *CurrentDevicePath;
60
61 CurrentDevicePath = RemainingDevicePath;
62 if (CurrentDevicePath != NULL) {
63 while (!IsDevicePathEnd (CurrentDevicePath)) {
64 if ((CurrentDevicePath->Type == MESSAGING_DEVICE_PATH) && (CurrentDevicePath->SubType == MSG_ISCSI_DP)) {
65 return EFI_SUCCESS;
66 }
67
68 CurrentDevicePath = NextDevicePathNode (CurrentDevicePath);
69 }
70
71 return EFI_UNSUPPORTED;
72 }
73
74 return EFI_SUCCESS;
75 }
76
77
78 /**
79 Tests to see if this driver supports a given controller. This is the worker function for
80 IScsiIp4(6)DriverBindingSupported.
81
82 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
83 @param[in] ControllerHandle The handle of the controller to test. This handle
84 must support a protocol interface that supplies
85 an I/O abstraction to the driver.
86 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
87 parameter is ignored by device drivers, and is optional for bus
88 drivers. For bus drivers, if this parameter is not NULL, then
89 the bus driver must determine if the bus controller specified
90 by ControllerHandle and the child controller specified
91 by RemainingDevicePath are both supported by this
92 bus driver.
93 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
94
95 @retval EFI_SUCCESS The device specified by ControllerHandle and
96 RemainingDevicePath is supported by the driver specified by This.
97 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
98 RemainingDevicePath is already being managed by the driver
99 specified by This.
100 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
101 RemainingDevicePath is not supported by the driver specified by This.
102 **/
103 EFI_STATUS
104 EFIAPI
105 IScsiSupported (
106 IN EFI_DRIVER_BINDING_PROTOCOL *This,
107 IN EFI_HANDLE ControllerHandle,
108 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,
109 IN UINT8 IpVersion
110 )
111 {
112 EFI_STATUS Status;
113 EFI_GUID *IScsiServiceBindingGuid;
114 EFI_GUID *TcpServiceBindingGuid;
115
116 if (IpVersion == IP_VERSION_4) {
117 IScsiServiceBindingGuid = &gIScsiV4PrivateGuid;
118 TcpServiceBindingGuid = &gEfiTcp4ServiceBindingProtocolGuid;
119 } else {
120 IScsiServiceBindingGuid = &gIScsiV6PrivateGuid;
121 TcpServiceBindingGuid = &gEfiTcp6ServiceBindingProtocolGuid;
122 }
123
124 Status = gBS->OpenProtocol (
125 ControllerHandle,
126 IScsiServiceBindingGuid,
127 NULL,
128 This->DriverBindingHandle,
129 ControllerHandle,
130 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
131 );
132 if (!EFI_ERROR (Status)) {
133 return EFI_ALREADY_STARTED;
134 } else {
135 Status = gBS->OpenProtocol (
136 ControllerHandle,
137 TcpServiceBindingGuid,
138 NULL,
139 This->DriverBindingHandle,
140 ControllerHandle,
141 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
142 );
143 if (!EFI_ERROR (Status)) {
144 Status = IScsiIsDevicePathSupported (RemainingDevicePath);
145 if (!EFI_ERROR (Status)) {
146 return EFI_SUCCESS;
147 }
148 }
149 }
150
151 return EFI_UNSUPPORTED;
152 }
153
154
155 /**
156 Start to manage the controller. This is the worker function for
157 IScsiIp4(6)DriverBindingStart.
158
159 @param[in] Image Handle of the image.
160 @param[in] ControllerHandle Handle of the controller.
161 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
162
163 @retval EFI_SUCCES This driver was started.
164 @retval EFI_ALREADY_STARTED This driver is already running on this device.
165 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
166 @retval EFI_NOT_FOUND There is no sufficient information to establish
167 the iScsi session.
168 @retval EFI_DEVICE_ERROR Failed to get TCP connection device path.
169
170 **/
171 EFI_STATUS
172 IScsiStart (
173 IN EFI_HANDLE Image,
174 IN EFI_HANDLE ControllerHandle,
175 IN UINT8 IpVersion
176 )
177 {
178 EFI_STATUS Status;
179 ISCSI_DRIVER_DATA *Private;
180 LIST_ENTRY *Entry;
181 LIST_ENTRY *NextEntry;
182 ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
183 ISCSI_SESSION *Session;
184 UINT8 Index;
185 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExistIScsiExtScsiPassThru;
186 ISCSI_DRIVER_DATA *ExistPrivate;
187 UINT8 *AttemptConfigOrder;
188 UINTN AttemptConfigOrderSize;
189 UINT8 BootSelected;
190 EFI_HANDLE *HandleBuffer;
191 UINTN NumberOfHandles;
192 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
193 EFI_GUID *IScsiPrivateGuid;
194 EFI_GUID *TcpServiceBindingGuid;
195 CHAR16 MacString[ISCSI_MAX_MAC_STRING_LEN];
196 BOOLEAN NeedUpdate;
197 VOID *Interface;
198 EFI_GUID *ProtocolGuid;
199
200 //
201 // Test to see if iSCSI driver supports the given controller.
202 //
203
204 if (IpVersion == IP_VERSION_4) {
205 IScsiPrivateGuid = &gIScsiV4PrivateGuid;
206 TcpServiceBindingGuid = &gEfiTcp4ServiceBindingProtocolGuid;
207 ProtocolGuid = &gEfiTcp4ProtocolGuid;
208 } else if (IpVersion == IP_VERSION_6) {
209 IScsiPrivateGuid = &gIScsiV6PrivateGuid;
210 TcpServiceBindingGuid = &gEfiTcp6ServiceBindingProtocolGuid;
211 ProtocolGuid = &gEfiTcp6ProtocolGuid;
212 } else {
213 return EFI_INVALID_PARAMETER;
214 }
215
216 Status = gBS->OpenProtocol (
217 ControllerHandle,
218 IScsiPrivateGuid,
219 NULL,
220 Image,
221 ControllerHandle,
222 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
223 );
224 if (!EFI_ERROR (Status)) {
225 return EFI_ALREADY_STARTED;
226 }
227
228 Status = gBS->OpenProtocol (
229 ControllerHandle,
230 TcpServiceBindingGuid,
231 NULL,
232 Image,
233 ControllerHandle,
234 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
235 );
236 if (EFI_ERROR (Status)) {
237 return EFI_UNSUPPORTED;
238 }
239
240 //
241 // Record the incoming NIC info.
242 //
243 Status = IScsiAddNic (ControllerHandle);
244 if (EFI_ERROR (Status)) {
245 return Status;
246 }
247
248 //
249 // Create the instance private data.
250 //
251 Private = IScsiCreateDriverData (Image, ControllerHandle);
252 if (Private == NULL) {
253 return EFI_OUT_OF_RESOURCES;
254 }
255
256 //
257 // Create a underlayer child instance, but not need to configure it. Just open ChildHandle
258 // via BY_DRIVER. That is, establishing the relationship between ControllerHandle and ChildHandle.
259 // Therefore, when DisconnectController(), especially VLAN virtual controller handle,
260 // IScsiDriverBindingStop() will be called.
261 //
262 Status = NetLibCreateServiceChild (
263 ControllerHandle,
264 Image,
265 TcpServiceBindingGuid,
266 &Private->ChildHandle
267 );
268
269 if (EFI_ERROR (Status)) {
270 goto ON_ERROR;
271 }
272
273 Status = gBS->OpenProtocol (
274 Private->ChildHandle,
275 ProtocolGuid,
276 &Interface,
277 Image,
278 ControllerHandle,
279 EFI_OPEN_PROTOCOL_BY_DRIVER
280 );
281
282 if (EFI_ERROR (Status)) {
283 goto ON_ERROR;
284 }
285
286 //
287 // Always install private protocol no matter what happens later. We need to
288 // keep the relationship between ControllerHandle and ChildHandle.
289 //
290 Status = gBS->InstallProtocolInterface (
291 &ControllerHandle,
292 IScsiPrivateGuid,
293 EFI_NATIVE_INTERFACE,
294 &Private->IScsiIdentifier
295 );
296 if (EFI_ERROR (Status)) {
297 goto ON_ERROR;
298 }
299
300 if (IpVersion == IP_VERSION_4) {
301 mPrivate->Ipv6Flag = FALSE;
302 } else {
303 mPrivate->Ipv6Flag = TRUE;
304 }
305
306 //
307 // Get the current iSCSI configuration data.
308 //
309 Status = IScsiGetConfigData (Private);
310 if (EFI_ERROR (Status)) {
311 goto ON_ERROR;
312 }
313
314 //
315 // If there is already a successul attempt, check whether this attempt is the
316 // first "enabled for MPIO" attempt. If not, still try the first attempt.
317 // In single path mode, try all attempts.
318 //
319 ExistPrivate = NULL;
320 Status = EFI_NOT_FOUND;
321
322 if (mPrivate->OneSessionEstablished && mPrivate->EnableMpio) {
323 AttemptConfigData = NULL;
324 NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
325 AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
326 if (AttemptConfigData->SessionConfigData.Enabled == ISCSI_ENABLED_FOR_MPIO) {
327 break;
328 }
329 }
330
331 if (AttemptConfigData == NULL) {
332 goto ON_ERROR;
333 }
334
335 if (AttemptConfigData->AttemptConfigIndex == mPrivate->BootSelectedIndex) {
336 goto ON_EXIT;
337 }
338
339 //
340 // Uninstall the original ExtScsiPassThru first.
341 //
342
343 //
344 // Locate all ExtScsiPassThru protocol instances.
345 //
346 Status = gBS->LocateHandleBuffer (
347 ByProtocol,
348 &gEfiExtScsiPassThruProtocolGuid,
349 NULL,
350 &NumberOfHandles,
351 &HandleBuffer
352 );
353 if (EFI_ERROR (Status)) {
354 goto ON_ERROR;
355 }
356
357 //
358 // Find ExtScsiPassThru protocol instance produced by this driver.
359 //
360 ExistIScsiExtScsiPassThru = NULL;
361 for (Index = 0; Index < NumberOfHandles && ExistIScsiExtScsiPassThru == NULL; Index++) {
362 Status = gBS->HandleProtocol (
363 HandleBuffer[Index],
364 &gEfiDevicePathProtocolGuid,
365 (VOID **) &DevicePath
366 );
367 if (EFI_ERROR (Status)) {
368 continue;
369 }
370
371 while (!IsDevicePathEnd (DevicePath)) {
372 if ((DevicePath->Type == MESSAGING_DEVICE_PATH) && (DevicePath->SubType == MSG_MAC_ADDR_DP)) {
373 //
374 // Get the ExtScsiPassThru protocol instance.
375 //
376 Status = gBS->HandleProtocol (
377 HandleBuffer[Index],
378 &gEfiExtScsiPassThruProtocolGuid,
379 (VOID **) &ExistIScsiExtScsiPassThru
380 );
381 ASSERT_EFI_ERROR (Status);
382 break;
383 }
384
385 DevicePath = NextDevicePathNode (DevicePath);
386 }
387 }
388
389 FreePool (HandleBuffer);
390
391 if (ExistIScsiExtScsiPassThru == NULL) {
392 Status = EFI_NOT_FOUND;
393 goto ON_ERROR;
394 }
395
396 ExistPrivate = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (ExistIScsiExtScsiPassThru);
397
398 Status = gBS->UninstallProtocolInterface (
399 ExistPrivate->ExtScsiPassThruHandle,
400 &gEfiExtScsiPassThruProtocolGuid,
401 &ExistPrivate->IScsiExtScsiPassThru
402 );
403 if (EFI_ERROR (Status)) {
404 goto ON_ERROR;
405 }
406 }
407
408 //
409 // Install the Ext SCSI PASS THRU protocol.
410 //
411 Status = gBS->InstallProtocolInterface (
412 &Private->ExtScsiPassThruHandle,
413 &gEfiExtScsiPassThruProtocolGuid,
414 EFI_NATIVE_INTERFACE,
415 &Private->IScsiExtScsiPassThru
416 );
417 if (EFI_ERROR (Status)) {
418 goto ON_ERROR;
419 }
420
421 BootSelected = 0;
422
423 NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &mPrivate->AttemptConfigs) {
424 AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
425 //
426 // Don't process the attempt that does not associate with the current NIC or
427 // this attempt is disabled or established.
428 //
429 if (AttemptConfigData->NicIndex != mPrivate->CurrentNic ||
430 AttemptConfigData->SessionConfigData.Enabled == ISCSI_DISABLED ||
431 AttemptConfigData->ValidPath) {
432 continue;
433 }
434
435 //
436 // In multipath mode, don't process attempts configured for single path.
437 // In default single path mode, don't process attempts configured for multipath.
438 //
439 if ((mPrivate->EnableMpio &&
440 AttemptConfigData->SessionConfigData.Enabled != ISCSI_ENABLED_FOR_MPIO) ||
441 (!mPrivate->EnableMpio &&
442 AttemptConfigData->SessionConfigData.Enabled != ISCSI_ENABLED)) {
443 continue;
444 }
445
446 //
447 // Don't process the attempt that fails to get the init/target information from DHCP.
448 //
449 if (AttemptConfigData->SessionConfigData.InitiatorInfoFromDhcp &&
450 !AttemptConfigData->DhcpSuccess) {
451 if (!mPrivate->EnableMpio && mPrivate->ValidSinglePathCount > 0) {
452 mPrivate->ValidSinglePathCount--;
453 }
454 continue;
455 }
456
457 //
458 // Don't process the autoconfigure path if it is already established.
459 //
460 if (AttemptConfigData->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG &&
461 AttemptConfigData->AutoConfigureMode == IP_MODE_AUTOCONFIG_SUCCESS) {
462 continue;
463 }
464
465 //
466 // Don't process the attempt if its IP mode is not in the current IP version.
467 //
468 if (!mPrivate->Ipv6Flag) {
469 if (AttemptConfigData->SessionConfigData.IpMode == IP_MODE_IP6) {
470 continue;
471 }
472 if (AttemptConfigData->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG &&
473 AttemptConfigData->AutoConfigureMode == IP_MODE_AUTOCONFIG_IP6) {
474 continue;
475 }
476 } else {
477 if (AttemptConfigData->SessionConfigData.IpMode == IP_MODE_IP4) {
478 continue;
479 }
480 if (AttemptConfigData->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG &&
481 AttemptConfigData->AutoConfigureMode == IP_MODE_AUTOCONFIG_IP4) {
482 continue;
483 }
484 }
485
486 //
487 // Fill in the Session and init it.
488 //
489 Session = (ISCSI_SESSION *) AllocateZeroPool (sizeof (ISCSI_SESSION));
490 if (Session == NULL) {
491 Status = EFI_OUT_OF_RESOURCES;
492 goto ON_ERROR;
493 }
494
495 Session->Private = Private;
496 Session->ConfigData = AttemptConfigData;
497 Session->AuthType = AttemptConfigData->AuthenticationType;
498
499 AsciiStrToUnicodeStr (AttemptConfigData->MacString, MacString);
500 UnicodeSPrint (
501 mPrivate->PortString,
502 (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
503 L"%s%d",
504 MacString,
505 (UINTN) AttemptConfigData->AttemptConfigIndex
506 );
507
508 if (Session->AuthType == ISCSI_AUTH_TYPE_CHAP) {
509 Session->AuthData.CHAP.AuthConfig = &AttemptConfigData->AuthConfigData.CHAP;
510 }
511
512 IScsiSessionInit (Session, FALSE);
513
514 //
515 // Try to login and create an iSCSI session according to the configuration.
516 //
517 Status = IScsiSessionLogin (Session);
518 if (Status == EFI_MEDIA_CHANGED) {
519 //
520 // The specified target is not available, and the redirection information is
521 // received. Login the session again with the updated target address.
522 //
523 Status = IScsiSessionLogin (Session);
524 } else if (Status == EFI_NOT_READY) {
525 Status = IScsiSessionReLogin (Session);
526 }
527
528 if (EFI_ERROR (Status)) {
529 //
530 // In Single path mode, only the successful attempt will be recorded in iBFT;
531 // in multi-path mode, all the attempt entries in MPIO will be recorded in iBFT.
532 //
533 if (!mPrivate->EnableMpio && mPrivate->ValidSinglePathCount > 0) {
534 mPrivate->ValidSinglePathCount--;
535 }
536
537 FreePool (Session);
538
539 } else {
540 AttemptConfigData->ValidPath = TRUE;
541
542 //
543 // Do not record the attempt in iBFT if it login with KRB5.
544 // TODO: record KRB5 attempt information in the iSCSI device path.
545 //
546 if (Session->AuthType == ISCSI_AUTH_TYPE_KRB) {
547 if (!mPrivate->EnableMpio && mPrivate->ValidSinglePathCount > 0) {
548 mPrivate->ValidSinglePathCount--;
549 }
550
551 AttemptConfigData->ValidiBFTPath = FALSE;
552 } else {
553 AttemptConfigData->ValidiBFTPath = TRUE;
554 }
555
556 //
557 // IScsi session success. Update the attempt state to NVR.
558 //
559 if (AttemptConfigData->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG) {
560 AttemptConfigData->AutoConfigureMode = IP_MODE_AUTOCONFIG_SUCCESS;
561 }
562
563 gRT->SetVariable (
564 mPrivate->PortString,
565 &gEfiIScsiInitiatorNameProtocolGuid,
566 ISCSI_CONFIG_VAR_ATTR,
567 sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA),
568 AttemptConfigData
569 );
570
571 //
572 // Select the first login session. Abort others.
573 //
574 if (Private->Session == NULL) {
575 Private->Session = Session;
576 BootSelected = AttemptConfigData->AttemptConfigIndex;
577 //
578 // Don't validate other attempt in multipath mode if one is success.
579 //
580 if (mPrivate->EnableMpio) {
581 break;
582 }
583 } else {
584 IScsiSessionAbort (Session);
585 FreePool (Session);
586 }
587 }
588 }
589
590 //
591 // All attempts configured for this driver instance are not valid.
592 //
593 if (Private->Session == NULL) {
594 Status = gBS->UninstallProtocolInterface (
595 Private->ExtScsiPassThruHandle,
596 &gEfiExtScsiPassThruProtocolGuid,
597 &Private->IScsiExtScsiPassThru
598 );
599 ASSERT_EFI_ERROR (Status);
600 Private->ExtScsiPassThruHandle = NULL;
601
602 //
603 // Reinstall the original ExtScsiPassThru back.
604 //
605 if (mPrivate->OneSessionEstablished && ExistPrivate != NULL) {
606 Status = gBS->InstallProtocolInterface (
607 &ExistPrivate->ExtScsiPassThruHandle,
608 &gEfiExtScsiPassThruProtocolGuid,
609 EFI_NATIVE_INTERFACE,
610 &ExistPrivate->IScsiExtScsiPassThru
611 );
612 if (EFI_ERROR (Status)) {
613 goto ON_ERROR;
614 }
615
616 goto ON_EXIT;
617 }
618
619 Status = EFI_NOT_FOUND;
620
621 goto ON_ERROR;
622 }
623
624 NeedUpdate = TRUE;
625 //
626 // More than one attempt successes.
627 //
628 if (Private->Session != NULL && mPrivate->OneSessionEstablished) {
629
630 AttemptConfigOrder = IScsiGetVariableAndSize (
631 L"AttemptOrder",
632 &gIScsiConfigGuid,
633 &AttemptConfigOrderSize
634 );
635 ASSERT (AttemptConfigOrder != NULL);
636 for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {
637 if (AttemptConfigOrder[Index] == mPrivate->BootSelectedIndex ||
638 AttemptConfigOrder[Index] == BootSelected) {
639 break;
640 }
641 }
642
643 if (mPrivate->EnableMpio) {
644 //
645 // Use the attempt in earlier order. Abort the later one in MPIO.
646 //
647 if (AttemptConfigOrder[Index] == mPrivate->BootSelectedIndex) {
648 IScsiSessionAbort (Private->Session);
649 FreePool (Private->Session);
650 Private->Session = NULL;
651 gBS->UninstallProtocolInterface (
652 Private->ExtScsiPassThruHandle,
653 &gEfiExtScsiPassThruProtocolGuid,
654 &Private->IScsiExtScsiPassThru
655 );
656 Private->ExtScsiPassThruHandle = NULL;
657
658 //
659 // Reinstall the original ExtScsiPassThru back.
660 //
661 Status = gBS->InstallProtocolInterface (
662 &ExistPrivate->ExtScsiPassThruHandle,
663 &gEfiExtScsiPassThruProtocolGuid,
664 EFI_NATIVE_INTERFACE,
665 &ExistPrivate->IScsiExtScsiPassThru
666 );
667 if (EFI_ERROR (Status)) {
668 goto ON_ERROR;
669 }
670
671 goto ON_EXIT;
672 } else {
673 ASSERT (AttemptConfigOrder[Index] == BootSelected);
674 mPrivate->BootSelectedIndex = BootSelected;
675 //
676 // Clear the resource in ExistPrivate.
677 //
678 gBS->UninstallProtocolInterface (
679 ExistPrivate->Controller,
680 IScsiPrivateGuid,
681 &ExistPrivate->IScsiIdentifier
682 );
683
684 IScsiRemoveNic (ExistPrivate->Controller);
685 if (ExistPrivate->Session != NULL) {
686 IScsiSessionAbort (ExistPrivate->Session);
687 }
688
689 IScsiCleanDriverData (ExistPrivate);
690 }
691 } else {
692 //
693 // Use the attempt in earlier order as boot selected in single path mode.
694 //
695 if (AttemptConfigOrder[Index] == mPrivate->BootSelectedIndex) {
696 NeedUpdate = FALSE;
697 }
698 }
699
700 }
701
702 if (NeedUpdate) {
703 mPrivate->OneSessionEstablished = TRUE;
704 mPrivate->BootSelectedIndex = BootSelected;
705 }
706
707 //
708 // Duplicate the Session's tcp connection device path. The source port field
709 // will be set to zero as one iSCSI session is comprised of several iSCSI
710 // connections.
711 //
712 Private->DevicePath = IScsiGetTcpConnDevicePath (Private->Session);
713 if (Private->DevicePath == NULL) {
714 Status = EFI_DEVICE_ERROR;
715 goto ON_ERROR;
716 }
717 //
718 // Install the updated device path onto the ExtScsiPassThruHandle.
719 //
720 Status = gBS->InstallProtocolInterface (
721 &Private->ExtScsiPassThruHandle,
722 &gEfiDevicePathProtocolGuid,
723 EFI_NATIVE_INTERFACE,
724 Private->DevicePath
725 );
726 if (EFI_ERROR (Status)) {
727 goto ON_ERROR;
728 }
729
730 ON_EXIT:
731
732 //
733 // Update/Publish the iSCSI Boot Firmware Table.
734 //
735 if (mPrivate->BootSelectedIndex != 0) {
736 IScsiPublishIbft ();
737 }
738
739 return EFI_SUCCESS;
740
741 ON_ERROR:
742
743 if (Private->Session != NULL) {
744 IScsiSessionAbort (Private->Session);
745 }
746
747 return Status;
748 }
749
750 /**
751 Stops a device controller or a bus controller. This is the worker function for
752 IScsiIp4(6)DriverBindingStop.
753
754 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
755 @param[in] ControllerHandle A handle to the device being stopped. The handle must
756 support a bus specific I/O protocol for the driver
757 to use to stop the device.
758 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
759 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
760 if NumberOfChildren is 0.
761 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
762
763 @retval EFI_SUCCESS The device was stopped.
764 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
765
766 **/
767 EFI_STATUS
768 EFIAPI
769 IScsiStop (
770 IN EFI_DRIVER_BINDING_PROTOCOL *This,
771 IN EFI_HANDLE ControllerHandle,
772 IN UINTN NumberOfChildren,
773 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL,
774 IN UINT8 IpVersion
775 )
776 {
777 EFI_HANDLE IScsiController;
778 EFI_STATUS Status;
779 ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier;
780 ISCSI_DRIVER_DATA *Private;
781 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru;
782 ISCSI_CONNECTION *Conn;
783 EFI_GUID *ProtocolGuid;
784 EFI_GUID *TcpServiceBindingGuid;
785 EFI_GUID *TcpProtocolGuid;
786
787
788 if (NumberOfChildren != 0) {
789 //
790 // We should have only one child.
791 //
792 Status = gBS->OpenProtocol (
793 ChildHandleBuffer[0],
794 &gEfiExtScsiPassThruProtocolGuid,
795 (VOID **) &PassThru,
796 This->DriverBindingHandle,
797 ControllerHandle,
798 EFI_OPEN_PROTOCOL_GET_PROTOCOL
799 );
800 if (EFI_ERROR (Status)) {
801 return EFI_DEVICE_ERROR;
802 }
803
804 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (PassThru);
805 Conn = NET_LIST_HEAD (&Private->Session->Conns, ISCSI_CONNECTION, Link);
806
807 //
808 // Previously the TCP protocol is opened BY_CHILD_CONTROLLER. Just close
809 // the protocol here, but do not uninstall the device path protocol and
810 // EXT SCSI PASS THRU protocol installed on ExtScsiPassThruHandle.
811 //
812 if (IpVersion == IP_VERSION_4) {
813 ProtocolGuid = &gEfiTcp4ProtocolGuid;
814 } else {
815 ProtocolGuid = &gEfiTcp6ProtocolGuid;
816 }
817
818 gBS->CloseProtocol (
819 Conn->TcpIo.Handle,
820 ProtocolGuid,
821 Private->Image,
822 Private->ExtScsiPassThruHandle
823 );
824
825 return EFI_SUCCESS;
826 }
827 //
828 // Get the handle of the controller we are controling.
829 //
830 if (IpVersion == IP_VERSION_4) {
831 ProtocolGuid = &gIScsiV4PrivateGuid;
832 TcpProtocolGuid = &gEfiTcp4ProtocolGuid;
833 TcpServiceBindingGuid = &gEfiTcp4ServiceBindingProtocolGuid;
834 } else {
835 ProtocolGuid = &gIScsiV6PrivateGuid;
836 TcpProtocolGuid = &gEfiTcp6ProtocolGuid;
837 TcpServiceBindingGuid = &gEfiTcp6ServiceBindingProtocolGuid;
838 }
839 IScsiController = NetLibGetNicHandle (ControllerHandle, TcpProtocolGuid);
840 if (IScsiController == NULL) {
841 return EFI_SUCCESS;
842 }
843
844 Status = gBS->OpenProtocol (
845 IScsiController,
846 ProtocolGuid,
847 (VOID **) &IScsiIdentifier,
848 This->DriverBindingHandle,
849 ControllerHandle,
850 EFI_OPEN_PROTOCOL_GET_PROTOCOL
851 );
852 if (EFI_ERROR (Status)) {
853 return EFI_DEVICE_ERROR;
854 }
855
856 Private = ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifier);
857 ASSERT (Private != NULL);
858
859 if (Private->ChildHandle != NULL) {
860 Status = gBS->CloseProtocol (
861 Private->ChildHandle,
862 TcpProtocolGuid,
863 This->DriverBindingHandle,
864 IScsiController
865 );
866
867 ASSERT (!EFI_ERROR (Status));
868
869 Status = NetLibDestroyServiceChild (
870 IScsiController,
871 This->DriverBindingHandle,
872 TcpServiceBindingGuid,
873 Private->ChildHandle
874 );
875
876 ASSERT (!EFI_ERROR (Status));
877 }
878
879 gBS->UninstallProtocolInterface (
880 IScsiController,
881 ProtocolGuid,
882 &Private->IScsiIdentifier
883 );
884
885 //
886 // Remove this NIC.
887 //
888 IScsiRemoveNic (IScsiController);
889
890 //
891 // Update the iSCSI Boot Firware Table.
892 //
893 IScsiPublishIbft ();
894
895 if (Private->Session != NULL) {
896 IScsiSessionAbort (Private->Session);
897 }
898
899 IScsiCleanDriverData (Private);
900
901 return EFI_SUCCESS;
902 }
903
904 /**
905 Tests to see if this driver supports a given controller. If a child device is provided,
906 it tests to see if this driver supports creating a handle for the specified child device.
907
908 This function checks to see if the driver specified by This supports the device specified by
909 ControllerHandle. Drivers typically use the device path attached to
910 ControllerHandle and/or the services from the bus I/O abstraction attached to
911 ControllerHandle to determine if the driver supports ControllerHandle. This function
912 may be called many times during platform initialization. In order to reduce boot times, the tests
913 performed by this function must be very small and take as little time as possible to execute. This
914 function must not change the state of any hardware devices, and this function must be aware that the
915 device specified by ControllerHandle may already be managed by the same driver or a
916 different driver. This function must match its calls to AllocatePages() with FreePages(),
917 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
918 Since ControllerHandle may have been previously started by the same driver, if a protocol is
919 already in the opened state, then it must not be closed with CloseProtocol(). This is required
920 to guarantee the state of ControllerHandle is not modified by this function.
921
922 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
923 @param[in] ControllerHandle The handle of the controller to test. This handle
924 must support a protocol interface that supplies
925 an I/O abstraction to the driver.
926 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
927 parameter is ignored by device drivers, and is optional for bus
928 drivers. For bus drivers, if this parameter is not NULL, then
929 the bus driver must determine if the bus controller specified
930 by ControllerHandle and the child controller specified
931 by RemainingDevicePath are both supported by this
932 bus driver.
933
934 @retval EFI_SUCCESS The device specified by ControllerHandle and
935 RemainingDevicePath is supported by the driver specified by This.
936 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
937 RemainingDevicePath is already managed by the driver
938 specified by This.
939 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
940 RemainingDevicePath is already managed by a different
941 driver or an application that requires exclusive access.
942 Currently not implemented.
943 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
944 RemainingDevicePath is not supported by the driver specified by This.
945 **/
946 EFI_STATUS
947 EFIAPI
948 IScsiIp4DriverBindingSupported (
949 IN EFI_DRIVER_BINDING_PROTOCOL *This,
950 IN EFI_HANDLE ControllerHandle,
951 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
952 )
953 {
954 return IScsiSupported (
955 This,
956 ControllerHandle,
957 RemainingDevicePath,
958 IP_VERSION_4
959 );
960 }
961
962 /**
963 Starts a device controller or a bus controller.
964
965 The Start() function is designed to be invoked from the EFI boot service ConnectController().
966 As a result, much of the error checking on the parameters to Start() has been moved into this
967 common boot service. It is legal to call Start() from other locations,
968 but the following calling restrictions must be followed or the system behavior will not be deterministic.
969 1. ControllerHandle must be a valid EFI_HANDLE.
970 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
971 EFI_DEVICE_PATH_PROTOCOL.
972 3. Prior to calling Start(), the Supported() function for the driver specified by This must
973 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
974
975 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
976 @param[in] ControllerHandle The handle of the controller to start. This handle
977 must support a protocol interface that supplies
978 an I/O abstraction to the driver.
979 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
980 parameter is ignored by device drivers, and is optional for bus
981 drivers. For a bus driver, if this parameter is NULL, then handles
982 for all the children of Controller are created by this driver.
983 If this parameter is not NULL and the first Device Path Node is
984 not the End of Device Path Node, then only the handle for the
985 child device specified by the first Device Path Node of
986 RemainingDevicePath is created by this driver.
987 If the first Device Path Node of RemainingDevicePath is
988 the End of Device Path Node, no child handle is created by this
989 driver.
990
991 @retval EFI_SUCCESS The device was started.
992 @retval EFI_DEVICE_ERROR The device could not be started due to a device error. Currently not implemented.
993 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
994 @retval Others The driver failed to start the device.
995
996 **/
997 EFI_STATUS
998 EFIAPI
999 IScsiIp4DriverBindingStart (
1000 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1001 IN EFI_HANDLE ControllerHandle,
1002 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
1003 )
1004 {
1005 EFI_STATUS Status;
1006
1007 Status = IScsiStart (This->DriverBindingHandle, ControllerHandle, IP_VERSION_4);
1008 if (Status == EFI_ALREADY_STARTED) {
1009 Status = EFI_SUCCESS;
1010 }
1011
1012 return Status;
1013 }
1014
1015 /**
1016 Stops a device controller or a bus controller.
1017
1018 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
1019 As a result, much of the error checking on the parameters to Stop() has been moved
1020 into this common boot service. It is legal to call Stop() from other locations,
1021 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1022 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
1023 same driver's Start() function.
1024 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
1025 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
1026 Start() function, and the Start() function must have called OpenProtocol() on
1027 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1028
1029 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1030 @param[in] ControllerHandle A handle to the device being stopped. The handle must
1031 support a bus specific I/O protocol for the driver
1032 to use to stop the device.
1033 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
1034 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
1035 if NumberOfChildren is 0.
1036
1037 @retval EFI_SUCCESS The device was stopped.
1038 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1039
1040 **/
1041 EFI_STATUS
1042 EFIAPI
1043 IScsiIp4DriverBindingStop (
1044 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1045 IN EFI_HANDLE ControllerHandle,
1046 IN UINTN NumberOfChildren,
1047 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
1048 )
1049 {
1050 return IScsiStop (
1051 This,
1052 ControllerHandle,
1053 NumberOfChildren,
1054 ChildHandleBuffer,
1055 IP_VERSION_4
1056 );
1057 }
1058
1059 /**
1060 Tests to see if this driver supports a given controller. If a child device is provided,
1061 it tests to see if this driver supports creating a handle for the specified child device.
1062
1063 This function checks to see if the driver specified by This supports the device specified by
1064 ControllerHandle. Drivers typically use the device path attached to
1065 ControllerHandle and/or the services from the bus I/O abstraction attached to
1066 ControllerHandle to determine if the driver supports ControllerHandle. This function
1067 may be called many times during platform initialization. In order to reduce boot times, the tests
1068 performed by this function must be very small and take as little time as possible to execute. This
1069 function must not change the state of any hardware devices, and this function must be aware that the
1070 device specified by ControllerHandle may already be managed by the same driver or a
1071 different driver. This function must match its calls to AllocatePages() with FreePages(),
1072 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
1073 Since ControllerHandle may have been previously started by the same driver, if a protocol is
1074 already in the opened state, then it must not be closed with CloseProtocol(). This is required
1075 to guarantee the state of ControllerHandle is not modified by this function.
1076
1077 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1078 @param[in] ControllerHandle The handle of the controller to test. This handle
1079 must support a protocol interface that supplies
1080 an I/O abstraction to the driver.
1081 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
1082 parameter is ignored by device drivers, and is optional for bus
1083 drivers. For bus drivers, if this parameter is not NULL, then
1084 the bus driver must determine if the bus controller specified
1085 by ControllerHandle and the child controller specified
1086 by RemainingDevicePath are both supported by this
1087 bus driver.
1088
1089 @retval EFI_SUCCESS The device specified by ControllerHandle and
1090 RemainingDevicePath is supported by the driver specified by This.
1091 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
1092 RemainingDevicePath is already managed by the driver
1093 specified by This.
1094 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
1095 RemainingDevicePath is already managed by a different
1096 driver or an application that requires exclusive access.
1097 Currently not implemented.
1098 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
1099 RemainingDevicePath is not supported by the driver specified by This.
1100 **/
1101 EFI_STATUS
1102 EFIAPI
1103 IScsiIp6DriverBindingSupported (
1104 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1105 IN EFI_HANDLE ControllerHandle,
1106 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
1107 )
1108 {
1109 return IScsiSupported (
1110 This,
1111 ControllerHandle,
1112 RemainingDevicePath,
1113 IP_VERSION_6
1114 );
1115 }
1116
1117 /**
1118 Starts a device controller or a bus controller.
1119
1120 The Start() function is designed to be invoked from the EFI boot service ConnectController().
1121 As a result, much of the error checking on the parameters to Start() has been moved into this
1122 common boot service. It is legal to call Start() from other locations,
1123 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1124 1. ControllerHandle must be a valid EFI_HANDLE.
1125 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
1126 EFI_DEVICE_PATH_PROTOCOL.
1127 3. Prior to calling Start(), the Supported() function for the driver specified by This must
1128 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
1129
1130 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1131 @param[in] ControllerHandle The handle of the controller to start. This handle
1132 must support a protocol interface that supplies
1133 an I/O abstraction to the driver.
1134 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
1135 parameter is ignored by device drivers, and is optional for bus
1136 drivers. For a bus driver, if this parameter is NULL, then handles
1137 for all the children of Controller are created by this driver.
1138 If this parameter is not NULL and the first Device Path Node is
1139 not the End of Device Path Node, then only the handle for the
1140 child device specified by the first Device Path Node of
1141 RemainingDevicePath is created by this driver.
1142 If the first Device Path Node of RemainingDevicePath is
1143 the End of Device Path Node, no child handle is created by this
1144 driver.
1145
1146 @retval EFI_SUCCESS The device was started.
1147 @retval EFI_DEVICE_ERROR The device could not be started due to a device error. Currently not implemented.
1148 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1149 @retval Others The driver failed to start the device.
1150
1151 **/
1152 EFI_STATUS
1153 EFIAPI
1154 IScsiIp6DriverBindingStart (
1155 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1156 IN EFI_HANDLE ControllerHandle,
1157 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
1158 )
1159 {
1160 EFI_STATUS Status;
1161
1162 Status = IScsiStart (This->DriverBindingHandle, ControllerHandle, IP_VERSION_6);
1163 if (Status == EFI_ALREADY_STARTED) {
1164 Status = EFI_SUCCESS;
1165 }
1166
1167 return Status;
1168 }
1169
1170 /**
1171 Stops a device controller or a bus controller.
1172
1173 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
1174 As a result, much of the error checking on the parameters to Stop() has been moved
1175 into this common boot service. It is legal to call Stop() from other locations,
1176 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1177 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
1178 same driver's Start() function.
1179 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
1180 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
1181 Start() function, and the Start() function must have called OpenProtocol() on
1182 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1183
1184 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1185 @param[in] ControllerHandle A handle to the device being stopped. The handle must
1186 support a bus specific I/O protocol for the driver
1187 to use to stop the device.
1188 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
1189 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
1190 if NumberOfChildren is 0.
1191
1192 @retval EFI_SUCCESS The device was stopped.
1193 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1194
1195 **/
1196 EFI_STATUS
1197 EFIAPI
1198 IScsiIp6DriverBindingStop (
1199 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1200 IN EFI_HANDLE ControllerHandle,
1201 IN UINTN NumberOfChildren,
1202 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
1203 )
1204 {
1205 return IScsiStop (
1206 This,
1207 ControllerHandle,
1208 NumberOfChildren,
1209 ChildHandleBuffer,
1210 IP_VERSION_6
1211 );
1212 }
1213
1214 /**
1215 Unload the iSCSI driver.
1216
1217 @param[in] ImageHandle The handle of the driver image.
1218
1219 @retval EFI_SUCCESS The driver is unloaded.
1220 @retval EFI_DEVICE_ERROR An unexpected error occurred.
1221
1222 **/
1223 EFI_STATUS
1224 EFIAPI
1225 IScsiUnload (
1226 IN EFI_HANDLE ImageHandle
1227 )
1228 {
1229 EFI_STATUS Status;
1230 UINTN DeviceHandleCount;
1231 EFI_HANDLE *DeviceHandleBuffer;
1232 UINTN Index;
1233
1234 //
1235 // Try to disonnect the driver from the devices it's controlling.
1236 //
1237 Status = gBS->LocateHandleBuffer (
1238 AllHandles,
1239 NULL,
1240 NULL,
1241 &DeviceHandleCount,
1242 &DeviceHandleBuffer
1243 );
1244 if (EFI_ERROR (Status)) {
1245 return Status;
1246 }
1247
1248 for (Index = 0; Index < DeviceHandleCount; Index++) {
1249 gBS->DisconnectController (
1250 DeviceHandleBuffer[Index],
1251 gIScsiIp4DriverBinding.DriverBindingHandle,
1252 NULL
1253 );
1254 gBS->DisconnectController (
1255 DeviceHandleBuffer[Index],
1256 gIScsiIp6DriverBinding.DriverBindingHandle,
1257 NULL
1258 );
1259 }
1260
1261 //
1262 // Unload the iSCSI configuration form.
1263 //
1264 IScsiConfigFormUnload (gIScsiIp4DriverBinding.DriverBindingHandle);
1265
1266 //
1267 // Uninstall the protocols installed by iSCSI driver.
1268 //
1269 gBS->UninstallMultipleProtocolInterfaces (
1270 ImageHandle,
1271 &gEfiAuthenticationInfoProtocolGuid,
1272 &gIScsiAuthenticationInfo,
1273 NULL
1274 );
1275
1276 if (gIScsiControllerNameTable!= NULL) {
1277 FreeUnicodeStringTable (gIScsiControllerNameTable);
1278 gIScsiControllerNameTable = NULL;
1279 }
1280
1281 gBS->UninstallMultipleProtocolInterfaces (
1282 gIScsiIp4DriverBinding.DriverBindingHandle,
1283 &gEfiDriverBindingProtocolGuid,
1284 &gIScsiIp4DriverBinding,
1285 &gEfiComponentName2ProtocolGuid,
1286 &gIScsiComponentName2,
1287 &gEfiComponentNameProtocolGuid,
1288 &gIScsiComponentName,
1289 &gEfiIScsiInitiatorNameProtocolGuid,
1290 &gIScsiInitiatorName,
1291 NULL
1292 );
1293
1294 gBS->UninstallMultipleProtocolInterfaces (
1295 gIScsiIp6DriverBinding.DriverBindingHandle,
1296 &gEfiDriverBindingProtocolGuid,
1297 &gIScsiIp6DriverBinding,
1298 &gEfiComponentName2ProtocolGuid,
1299 &gIScsiComponentName2,
1300 &gEfiComponentNameProtocolGuid,
1301 &gIScsiComponentName,
1302 NULL
1303 );
1304
1305 return EFI_SUCCESS;
1306 }
1307
1308 /**
1309 This is the declaration of an EFI image entry point. This entry point is
1310 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
1311 both device drivers and bus drivers.
1312
1313 The entry point for iSCSI driver which initializes the global variables and
1314 installs the driver binding, component name protocol, iSCSI initiator name
1315 protocol and Authentication Info protocol on its image.
1316
1317 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
1318 @param[in] SystemTable A pointer to the EFI System Table.
1319
1320 @retval EFI_SUCCESS The operation completed successfully.
1321 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1322
1323 **/
1324 EFI_STATUS
1325 EFIAPI
1326 IScsiDriverEntryPoint (
1327 IN EFI_HANDLE ImageHandle,
1328 IN EFI_SYSTEM_TABLE *SystemTable
1329 )
1330 {
1331 EFI_STATUS Status;
1332 EFI_ISCSI_INITIATOR_NAME_PROTOCOL *IScsiInitiatorName;
1333 EFI_AUTHENTICATION_INFO_PROTOCOL *AuthenticationInfo;
1334
1335 //
1336 // There should be only one EFI_ISCSI_INITIATOR_NAME_PROTOCOL.
1337 //
1338 Status = gBS->LocateProtocol (
1339 &gEfiIScsiInitiatorNameProtocolGuid,
1340 NULL,
1341 (VOID **) &IScsiInitiatorName
1342 );
1343 if (!EFI_ERROR (Status)) {
1344 return EFI_ACCESS_DENIED;
1345 }
1346
1347 //
1348 // Initialize the EFI Driver Library.
1349 //
1350 Status = EfiLibInstallDriverBindingComponentName2 (
1351 ImageHandle,
1352 SystemTable,
1353 &gIScsiIp4DriverBinding,
1354 ImageHandle,
1355 &gIScsiComponentName,
1356 &gIScsiComponentName2
1357 );
1358 if (EFI_ERROR (Status)) {
1359 return Status;
1360 }
1361
1362 Status = EfiLibInstallDriverBindingComponentName2 (
1363 ImageHandle,
1364 SystemTable,
1365 &gIScsiIp6DriverBinding,
1366 NULL,
1367 &gIScsiComponentName,
1368 &gIScsiComponentName2
1369 );
1370 if (EFI_ERROR (Status)) {
1371 goto Error1;
1372 }
1373
1374 //
1375 // Install the iSCSI Initiator Name Protocol.
1376 //
1377 Status = gBS->InstallProtocolInterface (
1378 &ImageHandle,
1379 &gEfiIScsiInitiatorNameProtocolGuid,
1380 EFI_NATIVE_INTERFACE,
1381 &gIScsiInitiatorName
1382 );
1383 if (EFI_ERROR (Status)) {
1384 goto Error2;
1385 }
1386
1387 //
1388 // Create the private data structures.
1389 //
1390 mPrivate = AllocateZeroPool (sizeof (ISCSI_PRIVATE_DATA));
1391 if (mPrivate == NULL) {
1392 Status = EFI_OUT_OF_RESOURCES;
1393 goto Error3;
1394 }
1395
1396 InitializeListHead (&mPrivate->NicInfoList);
1397 InitializeListHead (&mPrivate->AttemptConfigs);
1398
1399 //
1400 // Initialize the configuration form of iSCSI.
1401 //
1402 Status = IScsiConfigFormInit (gIScsiIp4DriverBinding.DriverBindingHandle);
1403 if (EFI_ERROR (Status)) {
1404 goto Error4;
1405 }
1406
1407 //
1408 // There should be only one EFI_AUTHENTICATION_INFO_PROTOCOL. If already exists,
1409 // do not produce the protocol instance.
1410 //
1411 Status = gBS->LocateProtocol (
1412 &gEfiAuthenticationInfoProtocolGuid,
1413 NULL,
1414 (VOID **) &AuthenticationInfo
1415 );
1416 if (Status == EFI_NOT_FOUND) {
1417 Status = gBS->InstallProtocolInterface (
1418 &ImageHandle,
1419 &gEfiAuthenticationInfoProtocolGuid,
1420 EFI_NATIVE_INTERFACE,
1421 &gIScsiAuthenticationInfo
1422 );
1423 if (EFI_ERROR (Status)) {
1424 goto Error5;
1425 }
1426 }
1427
1428 return EFI_SUCCESS;
1429
1430 Error5:
1431 IScsiConfigFormUnload (gIScsiIp4DriverBinding.DriverBindingHandle);
1432
1433 Error4:
1434 FreePool (mPrivate);
1435
1436 Error3:
1437 gBS->UninstallMultipleProtocolInterfaces (
1438 ImageHandle,
1439 &gEfiIScsiInitiatorNameProtocolGuid,
1440 &gIScsiInitiatorName,
1441 NULL
1442 );
1443
1444 Error2:
1445 gBS->UninstallMultipleProtocolInterfaces (
1446 gIScsiIp6DriverBinding.DriverBindingHandle,
1447 &gEfiDriverBindingProtocolGuid,
1448 &gIScsiIp6DriverBinding,
1449 &gEfiComponentName2ProtocolGuid,
1450 &gIScsiComponentName2,
1451 &gEfiComponentNameProtocolGuid,
1452 &gIScsiComponentName,
1453 NULL
1454 );
1455
1456 Error1:
1457 gBS->UninstallMultipleProtocolInterfaces (
1458 ImageHandle,
1459 &gEfiDriverBindingProtocolGuid,
1460 &gIScsiIp4DriverBinding,
1461 &gEfiComponentName2ProtocolGuid,
1462 &gIScsiComponentName2,
1463 &gEfiComponentNameProtocolGuid,
1464 &gIScsiComponentName,
1465 NULL
1466 );
1467
1468 return Status;
1469 }
1470