2 The entry point of IScsi driver.
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
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.
15 #include "IScsiImpl.h"
17 EFI_DRIVER_BINDING_PROTOCOL gIScsiIp4DriverBinding
= {
18 IScsiIp4DriverBindingSupported
,
19 IScsiIp4DriverBindingStart
,
20 IScsiIp4DriverBindingStop
,
26 EFI_DRIVER_BINDING_PROTOCOL gIScsiIp6DriverBinding
= {
27 IScsiIp6DriverBindingSupported
,
28 IScsiIp6DriverBindingStart
,
29 IScsiIp6DriverBindingStop
,
35 EFI_GUID gIScsiV4PrivateGuid
= ISCSI_V4_PRIVATE_GUID
;
36 EFI_GUID gIScsiV6PrivateGuid
= ISCSI_V6_PRIVATE_GUID
;
37 ISCSI_PRIVATE_DATA
*mPrivate
= NULL
;
40 Tests to see if this driver supports the RemainingDevicePath.
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
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.
55 IScsiIsDevicePathSupported (
56 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
59 EFI_DEVICE_PATH_PROTOCOL
*CurrentDevicePath
;
61 CurrentDevicePath
= RemainingDevicePath
;
62 if (CurrentDevicePath
!= NULL
) {
63 while (!IsDevicePathEnd (CurrentDevicePath
)) {
64 if ((CurrentDevicePath
->Type
== MESSAGING_DEVICE_PATH
) && (CurrentDevicePath
->SubType
== MSG_ISCSI_DP
)) {
68 CurrentDevicePath
= NextDevicePathNode (CurrentDevicePath
);
71 return EFI_UNSUPPORTED
;
79 Tests to see if this driver supports a given controller. This is the worker function for
80 IScsiIp4(6)DriverBindingSupported.
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
93 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
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
100 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
101 RemainingDevicePath is not supported by the driver specified by This.
106 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
107 IN EFI_HANDLE ControllerHandle
,
108 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
,
113 EFI_GUID
*IScsiServiceBindingGuid
;
114 EFI_GUID
*TcpServiceBindingGuid
;
116 if (IpVersion
== IP_VERSION_4
) {
117 IScsiServiceBindingGuid
= &gIScsiV4PrivateGuid
;
118 TcpServiceBindingGuid
= &gEfiTcp4ServiceBindingProtocolGuid
;
120 IScsiServiceBindingGuid
= &gIScsiV6PrivateGuid
;
121 TcpServiceBindingGuid
= &gEfiTcp6ServiceBindingProtocolGuid
;
124 Status
= gBS
->OpenProtocol (
126 IScsiServiceBindingGuid
,
128 This
->DriverBindingHandle
,
130 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
132 if (!EFI_ERROR (Status
)) {
133 return EFI_ALREADY_STARTED
;
135 Status
= gBS
->OpenProtocol (
137 TcpServiceBindingGuid
,
139 This
->DriverBindingHandle
,
141 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
143 if (!EFI_ERROR (Status
)) {
144 Status
= IScsiIsDevicePathSupported (RemainingDevicePath
);
145 if (!EFI_ERROR (Status
)) {
151 return EFI_UNSUPPORTED
;
156 Start to manage the controller. This is the worker function for
157 IScsiIp4(6)DriverBindingStart.
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.
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
168 @retval EFI_DEVICE_ERROR Failed to get TCP connection device path.
174 IN EFI_HANDLE ControllerHandle
,
179 ISCSI_DRIVER_DATA
*Private
;
181 LIST_ENTRY
*NextEntry
;
182 ISCSI_ATTEMPT_CONFIG_NVDATA
*AttemptConfigData
;
183 ISCSI_SESSION
*Session
;
185 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*ExistIScsiExtScsiPassThru
;
186 ISCSI_DRIVER_DATA
*ExistPrivate
;
187 UINT8
*AttemptConfigOrder
;
188 UINTN AttemptConfigOrderSize
;
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
];
198 EFI_GUID
*ProtocolGuid
;
201 // Test to see if iSCSI driver supports the given controller.
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
;
213 return EFI_INVALID_PARAMETER
;
216 Status
= gBS
->OpenProtocol (
222 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
224 if (!EFI_ERROR (Status
)) {
225 return EFI_ALREADY_STARTED
;
228 Status
= gBS
->OpenProtocol (
230 TcpServiceBindingGuid
,
234 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
236 if (EFI_ERROR (Status
)) {
237 return EFI_UNSUPPORTED
;
241 // Record the incoming NIC info.
243 Status
= IScsiAddNic (ControllerHandle
);
244 if (EFI_ERROR (Status
)) {
249 // Create the instance private data.
251 Private
= IScsiCreateDriverData (Image
, ControllerHandle
);
252 if (Private
== NULL
) {
253 return EFI_OUT_OF_RESOURCES
;
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.
262 Status
= NetLibCreateServiceChild (
265 TcpServiceBindingGuid
,
266 &Private
->ChildHandle
269 if (EFI_ERROR (Status
)) {
273 Status
= gBS
->OpenProtocol (
274 Private
->ChildHandle
,
279 EFI_OPEN_PROTOCOL_BY_DRIVER
282 if (EFI_ERROR (Status
)) {
287 // Always install private protocol no matter what happens later. We need to
288 // keep the relationship between ControllerHandle and ChildHandle.
290 Status
= gBS
->InstallProtocolInterface (
293 EFI_NATIVE_INTERFACE
,
294 &Private
->IScsiIdentifier
296 if (EFI_ERROR (Status
)) {
300 if (IpVersion
== IP_VERSION_4
) {
301 mPrivate
->Ipv6Flag
= FALSE
;
303 mPrivate
->Ipv6Flag
= TRUE
;
307 // Get the current iSCSI configuration data.
309 Status
= IScsiGetConfigData (Private
);
310 if (EFI_ERROR (Status
)) {
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.
320 Status
= EFI_NOT_FOUND
;
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
) {
331 if (AttemptConfigData
== NULL
) {
335 if (AttemptConfigData
->AttemptConfigIndex
== mPrivate
->BootSelectedIndex
) {
340 // Uninstall the original ExtScsiPassThru first.
344 // Locate all ExtScsiPassThru protocol instances.
346 Status
= gBS
->LocateHandleBuffer (
348 &gEfiExtScsiPassThruProtocolGuid
,
353 if (EFI_ERROR (Status
)) {
358 // Find ExtScsiPassThru protocol instance produced by this driver.
360 ExistIScsiExtScsiPassThru
= NULL
;
361 for (Index
= 0; Index
< NumberOfHandles
&& ExistIScsiExtScsiPassThru
== NULL
; Index
++) {
362 Status
= gBS
->HandleProtocol (
364 &gEfiDevicePathProtocolGuid
,
365 (VOID
**) &DevicePath
367 if (EFI_ERROR (Status
)) {
371 while (!IsDevicePathEnd (DevicePath
)) {
372 if ((DevicePath
->Type
== MESSAGING_DEVICE_PATH
) && (DevicePath
->SubType
== MSG_MAC_ADDR_DP
)) {
374 // Get the ExtScsiPassThru protocol instance.
376 Status
= gBS
->HandleProtocol (
378 &gEfiExtScsiPassThruProtocolGuid
,
379 (VOID
**) &ExistIScsiExtScsiPassThru
381 ASSERT_EFI_ERROR (Status
);
385 DevicePath
= NextDevicePathNode (DevicePath
);
389 FreePool (HandleBuffer
);
391 if (ExistIScsiExtScsiPassThru
== NULL
) {
392 Status
= EFI_NOT_FOUND
;
396 ExistPrivate
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (ExistIScsiExtScsiPassThru
);
398 Status
= gBS
->UninstallProtocolInterface (
399 ExistPrivate
->ExtScsiPassThruHandle
,
400 &gEfiExtScsiPassThruProtocolGuid
,
401 &ExistPrivate
->IScsiExtScsiPassThru
403 if (EFI_ERROR (Status
)) {
409 // Install the Ext SCSI PASS THRU protocol.
411 Status
= gBS
->InstallProtocolInterface (
412 &Private
->ExtScsiPassThruHandle
,
413 &gEfiExtScsiPassThruProtocolGuid
,
414 EFI_NATIVE_INTERFACE
,
415 &Private
->IScsiExtScsiPassThru
417 if (EFI_ERROR (Status
)) {
423 NET_LIST_FOR_EACH_SAFE (Entry
, NextEntry
, &mPrivate
->AttemptConfigs
) {
424 AttemptConfigData
= NET_LIST_USER_STRUCT (Entry
, ISCSI_ATTEMPT_CONFIG_NVDATA
, Link
);
426 // Don't process the attempt that does not associate with the current NIC or
427 // this attempt is disabled or established.
429 if (AttemptConfigData
->NicIndex
!= mPrivate
->CurrentNic
||
430 AttemptConfigData
->SessionConfigData
.Enabled
== ISCSI_DISABLED
||
431 AttemptConfigData
->ValidPath
) {
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.
439 if ((mPrivate
->EnableMpio
&&
440 AttemptConfigData
->SessionConfigData
.Enabled
!= ISCSI_ENABLED_FOR_MPIO
) ||
441 (!mPrivate
->EnableMpio
&&
442 AttemptConfigData
->SessionConfigData
.Enabled
!= ISCSI_ENABLED
)) {
447 // Don't process the attempt that fails to get the init/target information from DHCP.
449 if (AttemptConfigData
->SessionConfigData
.InitiatorInfoFromDhcp
&&
450 !AttemptConfigData
->DhcpSuccess
) {
451 if (!mPrivate
->EnableMpio
&& mPrivate
->ValidSinglePathCount
> 0) {
452 mPrivate
->ValidSinglePathCount
--;
458 // Don't process the autoconfigure path if it is already established.
460 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
&&
461 AttemptConfigData
->AutoConfigureMode
== IP_MODE_AUTOCONFIG_SUCCESS
) {
466 // Don't process the attempt if its IP mode is not in the current IP version.
468 if (!mPrivate
->Ipv6Flag
) {
469 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_IP6
) {
472 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
&&
473 AttemptConfigData
->AutoConfigureMode
== IP_MODE_AUTOCONFIG_IP6
) {
477 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_IP4
) {
480 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
&&
481 AttemptConfigData
->AutoConfigureMode
== IP_MODE_AUTOCONFIG_IP4
) {
487 // Fill in the Session and init it.
489 Session
= (ISCSI_SESSION
*) AllocateZeroPool (sizeof (ISCSI_SESSION
));
490 if (Session
== NULL
) {
491 Status
= EFI_OUT_OF_RESOURCES
;
495 Session
->Private
= Private
;
496 Session
->ConfigData
= AttemptConfigData
;
497 Session
->AuthType
= AttemptConfigData
->AuthenticationType
;
499 AsciiStrToUnicodeStr (AttemptConfigData
->MacString
, MacString
);
501 mPrivate
->PortString
,
502 (UINTN
) ISCSI_NAME_IFR_MAX_SIZE
,
505 (UINTN
) AttemptConfigData
->AttemptConfigIndex
508 if (Session
->AuthType
== ISCSI_AUTH_TYPE_CHAP
) {
509 Session
->AuthData
.CHAP
.AuthConfig
= &AttemptConfigData
->AuthConfigData
.CHAP
;
512 IScsiSessionInit (Session
, FALSE
);
515 // Try to login and create an iSCSI session according to the configuration.
517 Status
= IScsiSessionLogin (Session
);
518 if (Status
== EFI_MEDIA_CHANGED
) {
520 // The specified target is not available, and the redirection information is
521 // received. Login the session again with the updated target address.
523 Status
= IScsiSessionLogin (Session
);
524 } else if (Status
== EFI_NOT_READY
) {
525 Status
= IScsiSessionReLogin (Session
);
528 if (EFI_ERROR (Status
)) {
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.
533 if (!mPrivate
->EnableMpio
&& mPrivate
->ValidSinglePathCount
> 0) {
534 mPrivate
->ValidSinglePathCount
--;
540 AttemptConfigData
->ValidPath
= TRUE
;
543 // Do not record the attempt in iBFT if it login with KRB5.
544 // TODO: record KRB5 attempt information in the iSCSI device path.
546 if (Session
->AuthType
== ISCSI_AUTH_TYPE_KRB
) {
547 if (!mPrivate
->EnableMpio
&& mPrivate
->ValidSinglePathCount
> 0) {
548 mPrivate
->ValidSinglePathCount
--;
551 AttemptConfigData
->ValidiBFTPath
= FALSE
;
553 AttemptConfigData
->ValidiBFTPath
= TRUE
;
557 // IScsi session success. Update the attempt state to NVR.
559 if (AttemptConfigData
->SessionConfigData
.IpMode
== IP_MODE_AUTOCONFIG
) {
560 AttemptConfigData
->AutoConfigureMode
= IP_MODE_AUTOCONFIG_SUCCESS
;
564 mPrivate
->PortString
,
565 &gEfiIScsiInitiatorNameProtocolGuid
,
566 ISCSI_CONFIG_VAR_ATTR
,
567 sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA
),
572 // Select the first login session. Abort others.
574 if (Private
->Session
== NULL
) {
575 Private
->Session
= Session
;
576 BootSelected
= AttemptConfigData
->AttemptConfigIndex
;
578 // Don't validate other attempt in multipath mode if one is success.
580 if (mPrivate
->EnableMpio
) {
584 IScsiSessionAbort (Session
);
591 // All attempts configured for this driver instance are not valid.
593 if (Private
->Session
== NULL
) {
594 Status
= gBS
->UninstallProtocolInterface (
595 Private
->ExtScsiPassThruHandle
,
596 &gEfiExtScsiPassThruProtocolGuid
,
597 &Private
->IScsiExtScsiPassThru
599 ASSERT_EFI_ERROR (Status
);
600 Private
->ExtScsiPassThruHandle
= NULL
;
603 // Reinstall the original ExtScsiPassThru back.
605 if (mPrivate
->OneSessionEstablished
&& ExistPrivate
!= NULL
) {
606 Status
= gBS
->InstallProtocolInterface (
607 &ExistPrivate
->ExtScsiPassThruHandle
,
608 &gEfiExtScsiPassThruProtocolGuid
,
609 EFI_NATIVE_INTERFACE
,
610 &ExistPrivate
->IScsiExtScsiPassThru
612 if (EFI_ERROR (Status
)) {
619 Status
= EFI_NOT_FOUND
;
626 // More than one attempt successes.
628 if (Private
->Session
!= NULL
&& mPrivate
->OneSessionEstablished
) {
630 AttemptConfigOrder
= IScsiGetVariableAndSize (
633 &AttemptConfigOrderSize
635 ASSERT (AttemptConfigOrder
!= NULL
);
636 for (Index
= 0; Index
< AttemptConfigOrderSize
/ sizeof (UINT8
); Index
++) {
637 if (AttemptConfigOrder
[Index
] == mPrivate
->BootSelectedIndex
||
638 AttemptConfigOrder
[Index
] == BootSelected
) {
643 if (mPrivate
->EnableMpio
) {
645 // Use the attempt in earlier order. Abort the later one in MPIO.
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
656 Private
->ExtScsiPassThruHandle
= NULL
;
659 // Reinstall the original ExtScsiPassThru back.
661 Status
= gBS
->InstallProtocolInterface (
662 &ExistPrivate
->ExtScsiPassThruHandle
,
663 &gEfiExtScsiPassThruProtocolGuid
,
664 EFI_NATIVE_INTERFACE
,
665 &ExistPrivate
->IScsiExtScsiPassThru
667 if (EFI_ERROR (Status
)) {
673 ASSERT (AttemptConfigOrder
[Index
] == BootSelected
);
674 mPrivate
->BootSelectedIndex
= BootSelected
;
676 // Clear the resource in ExistPrivate.
678 gBS
->UninstallProtocolInterface (
679 ExistPrivate
->Controller
,
681 &ExistPrivate
->IScsiIdentifier
684 IScsiRemoveNic (ExistPrivate
->Controller
);
685 if (ExistPrivate
->Session
!= NULL
) {
686 IScsiSessionAbort (ExistPrivate
->Session
);
689 IScsiCleanDriverData (ExistPrivate
);
693 // Use the attempt in earlier order as boot selected in single path mode.
695 if (AttemptConfigOrder
[Index
] == mPrivate
->BootSelectedIndex
) {
703 mPrivate
->OneSessionEstablished
= TRUE
;
704 mPrivate
->BootSelectedIndex
= BootSelected
;
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
712 Private
->DevicePath
= IScsiGetTcpConnDevicePath (Private
->Session
);
713 if (Private
->DevicePath
== NULL
) {
714 Status
= EFI_DEVICE_ERROR
;
718 // Install the updated device path onto the ExtScsiPassThruHandle.
720 Status
= gBS
->InstallProtocolInterface (
721 &Private
->ExtScsiPassThruHandle
,
722 &gEfiDevicePathProtocolGuid
,
723 EFI_NATIVE_INTERFACE
,
726 if (EFI_ERROR (Status
)) {
733 // Update/Publish the iSCSI Boot Firmware Table.
735 if (mPrivate
->BootSelectedIndex
!= 0) {
743 if (Private
->Session
!= NULL
) {
744 IScsiSessionAbort (Private
->Session
);
751 Stops a device controller or a bus controller. This is the worker function for
752 IScsiIp4(6)DriverBindingStop.
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.
763 @retval EFI_SUCCESS The device was stopped.
764 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
770 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
771 IN EFI_HANDLE ControllerHandle
,
772 IN UINTN NumberOfChildren
,
773 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
,
777 EFI_HANDLE IScsiController
;
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
;
788 if (NumberOfChildren
!= 0) {
790 // We should have only one child.
792 Status
= gBS
->OpenProtocol (
793 ChildHandleBuffer
[0],
794 &gEfiExtScsiPassThruProtocolGuid
,
796 This
->DriverBindingHandle
,
798 EFI_OPEN_PROTOCOL_GET_PROTOCOL
800 if (EFI_ERROR (Status
)) {
801 return EFI_DEVICE_ERROR
;
804 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (PassThru
);
805 Conn
= NET_LIST_HEAD (&Private
->Session
->Conns
, ISCSI_CONNECTION
, Link
);
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.
812 if (IpVersion
== IP_VERSION_4
) {
813 ProtocolGuid
= &gEfiTcp4ProtocolGuid
;
815 ProtocolGuid
= &gEfiTcp6ProtocolGuid
;
822 Private
->ExtScsiPassThruHandle
828 // Get the handle of the controller we are controling.
830 if (IpVersion
== IP_VERSION_4
) {
831 ProtocolGuid
= &gIScsiV4PrivateGuid
;
832 TcpProtocolGuid
= &gEfiTcp4ProtocolGuid
;
833 TcpServiceBindingGuid
= &gEfiTcp4ServiceBindingProtocolGuid
;
835 ProtocolGuid
= &gIScsiV6PrivateGuid
;
836 TcpProtocolGuid
= &gEfiTcp6ProtocolGuid
;
837 TcpServiceBindingGuid
= &gEfiTcp6ServiceBindingProtocolGuid
;
839 IScsiController
= NetLibGetNicHandle (ControllerHandle
, TcpProtocolGuid
);
840 if (IScsiController
== NULL
) {
844 Status
= gBS
->OpenProtocol (
847 (VOID
**) &IScsiIdentifier
,
848 This
->DriverBindingHandle
,
850 EFI_OPEN_PROTOCOL_GET_PROTOCOL
852 if (EFI_ERROR (Status
)) {
853 return EFI_DEVICE_ERROR
;
856 Private
= ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifier
);
857 ASSERT (Private
!= NULL
);
859 if (Private
->ChildHandle
!= NULL
) {
860 Status
= gBS
->CloseProtocol (
861 Private
->ChildHandle
,
863 This
->DriverBindingHandle
,
867 ASSERT (!EFI_ERROR (Status
));
869 Status
= NetLibDestroyServiceChild (
871 This
->DriverBindingHandle
,
872 TcpServiceBindingGuid
,
876 ASSERT (!EFI_ERROR (Status
));
879 gBS
->UninstallProtocolInterface (
882 &Private
->IScsiIdentifier
888 IScsiRemoveNic (IScsiController
);
891 // Update the iSCSI Boot Firware Table.
895 if (Private
->Session
!= NULL
) {
896 IScsiSessionAbort (Private
->Session
);
899 IScsiCleanDriverData (Private
);
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.
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.
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
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
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.
948 IScsiIp4DriverBindingSupported (
949 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
950 IN EFI_HANDLE ControllerHandle
,
951 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
954 return IScsiSupported (
963 Starts a device controller or a bus controller.
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.
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
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.
999 IScsiIp4DriverBindingStart (
1000 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1001 IN EFI_HANDLE ControllerHandle
,
1002 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
1007 Status
= IScsiStart (This
->DriverBindingHandle
, ControllerHandle
, IP_VERSION_4
);
1008 if (Status
== EFI_ALREADY_STARTED
) {
1009 Status
= EFI_SUCCESS
;
1016 Stops a device controller or a bus controller.
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.
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.
1037 @retval EFI_SUCCESS The device was stopped.
1038 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1043 IScsiIp4DriverBindingStop (
1044 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1045 IN EFI_HANDLE ControllerHandle
,
1046 IN UINTN NumberOfChildren
,
1047 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
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.
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.
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
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
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.
1103 IScsiIp6DriverBindingSupported (
1104 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1105 IN EFI_HANDLE ControllerHandle
,
1106 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
1109 return IScsiSupported (
1112 RemainingDevicePath
,
1118 Starts a device controller or a bus controller.
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.
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
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.
1154 IScsiIp6DriverBindingStart (
1155 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1156 IN EFI_HANDLE ControllerHandle
,
1157 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
1162 Status
= IScsiStart (This
->DriverBindingHandle
, ControllerHandle
, IP_VERSION_6
);
1163 if (Status
== EFI_ALREADY_STARTED
) {
1164 Status
= EFI_SUCCESS
;
1171 Stops a device controller or a bus controller.
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.
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.
1192 @retval EFI_SUCCESS The device was stopped.
1193 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1198 IScsiIp6DriverBindingStop (
1199 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1200 IN EFI_HANDLE ControllerHandle
,
1201 IN UINTN NumberOfChildren
,
1202 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
1215 Unload the iSCSI driver.
1217 @param[in] ImageHandle The handle of the driver image.
1219 @retval EFI_SUCCESS The driver is unloaded.
1220 @retval EFI_DEVICE_ERROR An unexpected error occurred.
1226 IN EFI_HANDLE ImageHandle
1230 UINTN DeviceHandleCount
;
1231 EFI_HANDLE
*DeviceHandleBuffer
;
1235 // Try to disonnect the driver from the devices it's controlling.
1237 Status
= gBS
->LocateHandleBuffer (
1244 if (EFI_ERROR (Status
)) {
1248 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
1249 gBS
->DisconnectController (
1250 DeviceHandleBuffer
[Index
],
1251 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1254 gBS
->DisconnectController (
1255 DeviceHandleBuffer
[Index
],
1256 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1262 // Unload the iSCSI configuration form.
1264 IScsiConfigFormUnload (gIScsiIp4DriverBinding
.DriverBindingHandle
);
1267 // Uninstall the protocols installed by iSCSI driver.
1269 gBS
->UninstallMultipleProtocolInterfaces (
1271 &gEfiAuthenticationInfoProtocolGuid
,
1272 &gIScsiAuthenticationInfo
,
1276 if (gIScsiControllerNameTable
!= NULL
) {
1277 FreeUnicodeStringTable (gIScsiControllerNameTable
);
1278 gIScsiControllerNameTable
= NULL
;
1281 gBS
->UninstallMultipleProtocolInterfaces (
1282 gIScsiIp4DriverBinding
.DriverBindingHandle
,
1283 &gEfiDriverBindingProtocolGuid
,
1284 &gIScsiIp4DriverBinding
,
1285 &gEfiComponentName2ProtocolGuid
,
1286 &gIScsiComponentName2
,
1287 &gEfiComponentNameProtocolGuid
,
1288 &gIScsiComponentName
,
1289 &gEfiIScsiInitiatorNameProtocolGuid
,
1290 &gIScsiInitiatorName
,
1294 gBS
->UninstallMultipleProtocolInterfaces (
1295 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1296 &gEfiDriverBindingProtocolGuid
,
1297 &gIScsiIp6DriverBinding
,
1298 &gEfiComponentName2ProtocolGuid
,
1299 &gIScsiComponentName2
,
1300 &gEfiComponentNameProtocolGuid
,
1301 &gIScsiComponentName
,
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.
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.
1317 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
1318 @param[in] SystemTable A pointer to the EFI System Table.
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.
1326 IScsiDriverEntryPoint (
1327 IN EFI_HANDLE ImageHandle
,
1328 IN EFI_SYSTEM_TABLE
*SystemTable
1332 EFI_ISCSI_INITIATOR_NAME_PROTOCOL
*IScsiInitiatorName
;
1333 EFI_AUTHENTICATION_INFO_PROTOCOL
*AuthenticationInfo
;
1336 // There should be only one EFI_ISCSI_INITIATOR_NAME_PROTOCOL.
1338 Status
= gBS
->LocateProtocol (
1339 &gEfiIScsiInitiatorNameProtocolGuid
,
1341 (VOID
**) &IScsiInitiatorName
1343 if (!EFI_ERROR (Status
)) {
1344 return EFI_ACCESS_DENIED
;
1348 // Initialize the EFI Driver Library.
1350 Status
= EfiLibInstallDriverBindingComponentName2 (
1353 &gIScsiIp4DriverBinding
,
1355 &gIScsiComponentName
,
1356 &gIScsiComponentName2
1358 if (EFI_ERROR (Status
)) {
1362 Status
= EfiLibInstallDriverBindingComponentName2 (
1365 &gIScsiIp6DriverBinding
,
1367 &gIScsiComponentName
,
1368 &gIScsiComponentName2
1370 if (EFI_ERROR (Status
)) {
1375 // Install the iSCSI Initiator Name Protocol.
1377 Status
= gBS
->InstallProtocolInterface (
1379 &gEfiIScsiInitiatorNameProtocolGuid
,
1380 EFI_NATIVE_INTERFACE
,
1381 &gIScsiInitiatorName
1383 if (EFI_ERROR (Status
)) {
1388 // Create the private data structures.
1390 mPrivate
= AllocateZeroPool (sizeof (ISCSI_PRIVATE_DATA
));
1391 if (mPrivate
== NULL
) {
1392 Status
= EFI_OUT_OF_RESOURCES
;
1396 InitializeListHead (&mPrivate
->NicInfoList
);
1397 InitializeListHead (&mPrivate
->AttemptConfigs
);
1400 // Initialize the configuration form of iSCSI.
1402 Status
= IScsiConfigFormInit (gIScsiIp4DriverBinding
.DriverBindingHandle
);
1403 if (EFI_ERROR (Status
)) {
1408 // There should be only one EFI_AUTHENTICATION_INFO_PROTOCOL. If already exists,
1409 // do not produce the protocol instance.
1411 Status
= gBS
->LocateProtocol (
1412 &gEfiAuthenticationInfoProtocolGuid
,
1414 (VOID
**) &AuthenticationInfo
1416 if (Status
== EFI_NOT_FOUND
) {
1417 Status
= gBS
->InstallProtocolInterface (
1419 &gEfiAuthenticationInfoProtocolGuid
,
1420 EFI_NATIVE_INTERFACE
,
1421 &gIScsiAuthenticationInfo
1423 if (EFI_ERROR (Status
)) {
1431 IScsiConfigFormUnload (gIScsiIp4DriverBinding
.DriverBindingHandle
);
1434 FreePool (mPrivate
);
1437 gBS
->UninstallMultipleProtocolInterfaces (
1439 &gEfiIScsiInitiatorNameProtocolGuid
,
1440 &gIScsiInitiatorName
,
1445 gBS
->UninstallMultipleProtocolInterfaces (
1446 gIScsiIp6DriverBinding
.DriverBindingHandle
,
1447 &gEfiDriverBindingProtocolGuid
,
1448 &gIScsiIp6DriverBinding
,
1449 &gEfiComponentName2ProtocolGuid
,
1450 &gIScsiComponentName2
,
1451 &gEfiComponentNameProtocolGuid
,
1452 &gIScsiComponentName
,
1457 gBS
->UninstallMultipleProtocolInterfaces (
1459 &gEfiDriverBindingProtocolGuid
,
1460 &gIScsiIp4DriverBinding
,
1461 &gEfiComponentName2ProtocolGuid
,
1462 &gIScsiComponentName2
,
1463 &gEfiComponentNameProtocolGuid
,
1464 &gIScsiComponentName
,