From 05a300115ab80963e2a722aaaa8adbb3b6c5007c Mon Sep 17 00:00:00 2001 From: Wu Jiaxin Date: Fri, 25 Oct 2013 08:05:47 +0000 Subject: [PATCH 1/1] =?utf8?q?Fix=20a=20bug=20about=20the=20iSCSI=20DHCP?= =?utf8?q?=20dependency=20issue.=20Create=20rules=20to=20determine=20wheth?= =?utf8?q?er=20iSCSI=20need=20DHCP=20protocol=20in=20current=20configurati?= =?utf8?q?on=20by=20examining=20user=E2=80=99s=20configuration=20data=20in?= =?utf8?q?=20DriverBindingSupported().?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Wu Jiaxin Reviewed-by: Ye Ting Reviewed-by: Fu Siyuan git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14802 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Universal/Network/IScsiDxe/IScsiDriver.c | 67 +++++++++++++++---- .../Universal/Network/IScsiDxe/IScsiMisc.c | 56 +++++++++++++++- .../Universal/Network/IScsiDxe/IScsiMisc.h | 16 ++++- 3 files changed, 125 insertions(+), 14 deletions(-) diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiDriver.c b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiDriver.c index f668fe3d9c..f4663d9f59 100644 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiDriver.c +++ b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiDriver.c @@ -1,7 +1,7 @@ /** @file The entry point of IScsi driver. -Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -23,6 +23,44 @@ EFI_DRIVER_BINDING_PROTOCOL gIScsiDriverBinding = { NULL }; +/** + Tests to see if this driver supports the RemainingDevicePath. + + @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This + parameter is ignored by device drivers, and is optional for bus + drivers. For bus drivers, if this parameter is not NULL, then + the bus driver must determine if the bus controller specified + by ControllerHandle and the child controller specified + by RemainingDevicePath are both supported by this + bus driver. + + @retval EFI_SUCCESS The RemainingDevicePath is supported or NULL. + @retval EFI_UNSUPPORTED The device specified by ControllerHandle and + RemainingDevicePath is not supported by the driver specified by This. +**/ +EFI_STATUS +IScsiIsDevicePathSupported ( + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ) +{ + EFI_DEVICE_PATH_PROTOCOL *CurrentDevicePath; + + CurrentDevicePath = RemainingDevicePath; + if (CurrentDevicePath != NULL) { + while (!IsDevicePathEnd (CurrentDevicePath)) { + if ((CurrentDevicePath->Type == MESSAGING_DEVICE_PATH) && (CurrentDevicePath->SubType == MSG_ISCSI_DP)) { + return EFI_SUCCESS; + } + + CurrentDevicePath = NextDevicePathNode (CurrentDevicePath); + } + + return EFI_UNSUPPORTED; + } + + return EFI_SUCCESS; +} + /** Tests to see if this driver supports a given controller. If a child device is provided, it further tests to see if this driver supports creating a handle for the specified child device. @@ -56,7 +94,6 @@ IScsiDriverBindingSupported ( ) { EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *CurrentDevicePath; Status = gBS->OpenProtocol ( ControllerHandle, @@ -82,17 +119,23 @@ IScsiDriverBindingSupported ( return EFI_UNSUPPORTED; } - CurrentDevicePath = RemainingDevicePath; - if (CurrentDevicePath != NULL) { - while (!IsDevicePathEnd (CurrentDevicePath)) { - if ((CurrentDevicePath->Type == MESSAGING_DEVICE_PATH) && (CurrentDevicePath->SubType == MSG_ISCSI_DP)) { - return EFI_SUCCESS; - } + Status = IScsiIsDevicePathSupported (RemainingDevicePath); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } - CurrentDevicePath = NextDevicePathNode (CurrentDevicePath); + if (IScsiDhcpIsConfigured (ControllerHandle)) { + Status = gBS->OpenProtocol ( + ControllerHandle, + &gEfiDhcp4ServiceBindingProtocolGuid, + NULL, + This->DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_TEST_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; } - - return EFI_UNSUPPORTED; } return EFI_SUCCESS; @@ -170,7 +213,7 @@ IScsiDriverBindingStart ( goto ON_ERROR; } - // + // // Always install private protocol no matter what happens later. We need to // keep the relationship between ControllerHandle and ChildHandle. // diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c index 5341e5a01e..16ffec09bd 100644 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c +++ b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c @@ -1,7 +1,7 @@ /** @file Miscellaneous routines for iSCSI driver. -Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -616,6 +616,60 @@ IScsiCleanDriverData ( FreePool (Private); } +/** + Check wheather the Controller is configured to use DHCP protocol. + + @param[in] Controller The handle of the controller. + + @retval TRUE The handle of the controller need the Dhcp protocol. + @retval FALSE The handle of the controller does not need the Dhcp protocol. + +**/ +BOOLEAN +IScsiDhcpIsConfigured ( + IN EFI_HANDLE Controller + ) +{ + EFI_STATUS Status; + EFI_MAC_ADDRESS MacAddress; + UINTN HwAddressSize; + UINT16 VlanId; + CHAR16 MacString[70]; + ISCSI_SESSION_CONFIG_NVDATA *ConfigDataTmp; + + // + // Get the mac string, it's the name of various variable + // + Status = NetLibGetMacAddress (Controller, &MacAddress, &HwAddressSize); + if (EFI_ERROR (Status)) { + return FALSE; + } + VlanId = NetLibGetVlanId (Controller); + IScsiMacAddrToStr (&MacAddress, (UINT32) HwAddressSize, VlanId, MacString); + + // + // Get the normal configuration. + // + Status = GetVariable2 ( + MacString, + &gEfiIScsiInitiatorNameProtocolGuid, + (VOID**)&ConfigDataTmp, + NULL + ); + if (EFI_ERROR (Status)) { + return FALSE; + } + + + if (ConfigDataTmp->Enabled && ConfigDataTmp->InitiatorInfoFromDhcp) { + FreePool (ConfigDataTmp); + return TRUE; + } + + FreePool (ConfigDataTmp); + return FALSE; +} + /** Get the various configuration data of this iSCSI instance. diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.h b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.h index 512c67c38c..b310c9c579 100644 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.h +++ b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.h @@ -1,7 +1,7 @@ /** @file Miscellaneous definitions for iSCSI driver. -Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -221,6 +221,20 @@ IScsiCleanDriverData ( IN ISCSI_DRIVER_DATA *Private ); +/** + Check wheather the Controller is configured to use DHCP protocol. + + @param[in] Controller The handle of the controller. + + @retval TRUE The handle of the controller need the Dhcp protocol. + @retval FALSE The handle of the controller does not need the Dhcp protocol. + +**/ +BOOLEAN +IScsiDhcpIsConfigured ( + IN EFI_HANDLE Controller + ); + /** Get the various configuration data of this iSCSI instance. -- 2.39.2