Revision: 19367
          http://sourceforge.net/p/edk2/code/19367
Author:   tye1
Date:     2015-12-18 06:31:31 +0000 (Fri, 18 Dec 2015)
Log Message:
-----------
NetworkPkg: Update iSCSI driver to check existing AIP instances

According to UEFI spec, iSCSI HBA must install an AIP instance
with network boot information block. This patch updates UEFI
iSCSI driver to check whether there are AIP instances installed
by iSCSI HBA adapter and if yes, the UEFI iSCSI driver will return
EFI_ABORTED in its driver binding Start(). Also the patch
introduces a PCD PcdIScsiAIPNetworkBootPolicy for
platform owner to define particular policy when the iSCSI HBA
will survive and UEFI iSCSI will fail. The default policy is
STOP_UEFI_ISCSI_IF_AIP_SUPPORT_OFFLOAD which means that when ISCSI HBA
adapter installs an AIP and claims it supports an offload engine
for iSCSI boot, the UEFI iSCSI driver will return EFI_ABORTED.

The patch V2 adds a new value ALWAYS_USE_UEFI_ISCSI_AND_IGNORE_AIP
to PCD PcdIScsiAIPNetworkBootPolicy. This allows the platform to
avoid running into buggy IHV drivers that have issue with AIP.
It is suggested by El-Haj-Mahmoud,Samer <[email protected]>.

Cc: El-Haj-Mahmoud Samer <[email protected]>

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ye Ting <[email protected]>
Reviewed-by: Fu siyuan <[email protected]>
Reviewed-by: Wu Jiaxin <[email protected]>
Reviewed-by: El-Haj-Mahmoud Samer <[email protected]>

Modified Paths:
--------------
    trunk/edk2/NetworkPkg/IScsiDxe/IScsiDriver.c
    trunk/edk2/NetworkPkg/IScsiDxe/IScsiDriver.h
    trunk/edk2/NetworkPkg/IScsiDxe/IScsiDxe.inf
    trunk/edk2/NetworkPkg/IScsiDxe/IScsiImpl.h
    trunk/edk2/NetworkPkg/NetworkPkg.dec
    trunk/edk2/NetworkPkg/NetworkPkg.uni

Modified: trunk/edk2/NetworkPkg/IScsiDxe/IScsiDriver.c
===================================================================
--- trunk/edk2/NetworkPkg/IScsiDxe/IScsiDriver.c        2015-12-18 06:07:50 UTC 
(rev 19366)
+++ trunk/edk2/NetworkPkg/IScsiDxe/IScsiDriver.c        2015-12-18 06:31:31 UTC 
(rev 19367)
@@ -74,7 +74,143 @@
   return EFI_SUCCESS;
 }
 
+/**
+  Check whether an iSCSI HBA adapter already installs an AIP instance with
+  network boot policy matching the value specified in 
PcdIScsiAIPNetworkBootPolicy.
+  If yes, return EFI_SUCCESS.
 
+  @retval EFI_SUCCESS              Found an AIP with matching network boot 
policy.
+  @retval EFI_NOT_FOUND            AIP is unavailable or the network boot 
policy
+                                   not matched.
+**/
+EFI_STATUS
+IScsiCheckAip (
+  )
+{
+  UINTN                            AipHandleCount;
+  EFI_HANDLE                       *AipHandleBuffer;
+  UINTN                            AipIndex;
+  EFI_ADAPTER_INFORMATION_PROTOCOL *Aip;
+  EFI_EXT_SCSI_PASS_THRU_PROTOCOL  *ExtScsiPassThru;
+  EFI_GUID                         *InfoTypesBuffer;
+  UINTN                            InfoTypeBufferCount;
+  UINTN                            TypeIndex;
+  VOID                             *InfoBlock;
+  UINTN                            InfoBlockSize;
+  BOOLEAN                          Supported;
+  EFI_ADAPTER_INFO_NETWORK_BOOT    *NetworkBoot;
+  EFI_STATUS                       Status;
+  UINT8                            NetworkBootPolicy;
+
+  //
+  // Check any AIP instances exist in system.
+  //
+  AipHandleCount = 0;
+  Status = gBS->LocateHandleBuffer (
+                  ByProtocol,
+                  &gEfiAdapterInformationProtocolGuid,
+                  NULL,
+                  &AipHandleCount,
+                  &AipHandleBuffer
+                  );
+  if (EFI_ERROR (Status) || AipHandleCount == 0) {
+    return EFI_NOT_FOUND;
+  }
+
+  InfoBlock = NULL;
+
+  for (AipIndex = 0; AipIndex < AipHandleCount; AipIndex++) {
+    Status = gBS->HandleProtocol (
+                    AipHandleBuffer[AipIndex],
+                    &gEfiAdapterInformationProtocolGuid,
+                    (VOID *) &Aip
+                    );
+    ASSERT_EFI_ERROR (Status);
+    ASSERT (Aip != NULL);
+
+    Status = gBS->HandleProtocol (
+                    AipHandleBuffer[AipIndex],
+                    &gEfiExtScsiPassThruProtocolGuid,
+                    (VOID *) &ExtScsiPassThru
+                    );
+    if (EFI_ERROR (Status) || ExtScsiPassThru == NULL) {
+      continue;
+    }
+
+    InfoTypesBuffer     = NULL;
+    InfoTypeBufferCount = 0;
+    Status = Aip->GetSupportedTypes (Aip, &InfoTypesBuffer, 
&InfoTypeBufferCount);
+    if (EFI_ERROR (Status) || InfoTypesBuffer == NULL) {
+      continue;
+    }
+    //
+    // Check whether the AIP instance has Network boot information block.
+    //
+    Supported = FALSE;
+    for (TypeIndex = 0; TypeIndex < InfoTypeBufferCount; TypeIndex++) {
+      if (CompareGuid (&InfoTypesBuffer[TypeIndex], 
&gEfiAdapterInfoNetworkBootGuid)) {
+        Supported = TRUE;
+        break;
+      }
+    }
+
+    FreePool (InfoTypesBuffer);
+    if (!Supported) {
+      continue;
+    }
+
+    //
+    // We now have network boot information block.
+    //
+    InfoBlock     = NULL;
+    InfoBlockSize = 0;
+    Status = Aip->GetInformation (Aip, &gEfiAdapterInfoNetworkBootGuid, 
&InfoBlock, &InfoBlockSize);
+    if (EFI_ERROR (Status) || InfoBlock == NULL) {
+      continue;
+    }
+
+    //
+    // Check whether the network boot policy matches.
+    //
+    NetworkBoot = (EFI_ADAPTER_INFO_NETWORK_BOOT *) InfoBlock;
+    NetworkBootPolicy = PcdGet8 (PcdIScsiAIPNetworkBootPolicy);
+
+    if (NetworkBootPolicy == STOP_UEFI_ISCSI_IF_HBA_INSTALL_AIP) {
+      Status = EFI_SUCCESS;
+      goto Exit;
+    }
+    if (((NetworkBootPolicy & STOP_UEFI_ISCSI_IF_AIP_SUPPORT_IP4) != 0 &&
+         !NetworkBoot->iScsiIpv4BootCapablity) ||
+         ((NetworkBootPolicy & STOP_UEFI_ISCSI_IF_AIP_SUPPORT_IP6) != 0 &&
+         !NetworkBoot->iScsiIpv6BootCapablity) ||
+         ((NetworkBootPolicy & STOP_UEFI_ISCSI_IF_AIP_SUPPORT_OFFLOAD) != 0 &&
+         !NetworkBoot->OffloadCapability) ||
+         ((NetworkBootPolicy & STOP_UEFI_ISCSI_IF_AIP_SUPPORT_MPIO) != 0 &&
+         !NetworkBoot->iScsiMpioCapability) ||
+         ((NetworkBootPolicy & STOP_UEFI_ISCSI_IF_AIP_CONFIGURED_IP4) != 0 &&
+         !NetworkBoot->iScsiIpv4Boot) ||
+         ((NetworkBootPolicy & STOP_UEFI_ISCSI_IF_AIP_CONFIGURED_IP6) != 0 &&
+         !NetworkBoot->iScsiIpv6Boot)) {
+      FreePool (InfoBlock);
+      continue;
+    }
+
+    Status = EFI_SUCCESS;
+    goto Exit;
+  }
+
+  Status = EFI_NOT_FOUND;
+
+Exit:
+  if (InfoBlock != NULL) {
+    FreePool (InfoBlock);
+  }
+  if (AipHandleBuffer != NULL) {
+    FreePool (AipHandleBuffer);
+  }
+  return Status;
+}
+
 /**
   Tests to see if this driver supports a given controller. This is the worker 
function for
   IScsiIp4(6)DriverBindingSupported.
@@ -215,6 +351,7 @@
   BOOLEAN                         NeedUpdate;
   VOID                            *Interface;
   EFI_GUID                        *ProtocolGuid;
+  UINT8                           NetworkBootPolicy;
 
   //
   // Test to see if iSCSI driver supports the given controller.
@@ -256,6 +393,20 @@
     return EFI_UNSUPPORTED;
   }
 
+  NetworkBootPolicy = PcdGet8 (PcdIScsiAIPNetworkBootPolicy);
+  if (NetworkBootPolicy != ALWAYS_USE_UEFI_ISCSI_AND_IGNORE_AIP) {
+    //
+    // Check existing iSCSI AIP.
+    //
+    Status = IScsiCheckAip ();
+    if (!EFI_ERROR (Status)) {
+      //
+      // Find iSCSI AIP with specified network boot policy. return EFI_ABORTED.
+      //
+      return EFI_ABORTED;
+    }
+  }
+  
   //
   // Record the incoming NIC info.
   //

Modified: trunk/edk2/NetworkPkg/IScsiDxe/IScsiDriver.h
===================================================================
--- trunk/edk2/NetworkPkg/IScsiDxe/IScsiDriver.h        2015-12-18 06:07:50 UTC 
(rev 19366)
+++ trunk/edk2/NetworkPkg/IScsiDxe/IScsiDriver.h        2015-12-18 06:31:31 UTC 
(rev 19367)
@@ -29,6 +29,14 @@
 
 #define IP_MODE_AUTOCONFIG_IP4     3
 #define IP_MODE_AUTOCONFIG_IP6     4
+#define ALWAYS_USE_UEFI_ISCSI_AND_IGNORE_AIP    0x00
+#define STOP_UEFI_ISCSI_IF_HBA_INSTALL_AIP      0x01
+#define STOP_UEFI_ISCSI_IF_AIP_SUPPORT_IP4      0x02
+#define STOP_UEFI_ISCSI_IF_AIP_SUPPORT_IP6      0x04
+#define STOP_UEFI_ISCSI_IF_AIP_SUPPORT_OFFLOAD  0x08
+#define STOP_UEFI_ISCSI_IF_AIP_SUPPORT_MPIO     0x10
+#define STOP_UEFI_ISCSI_IF_AIP_CONFIGURED_IP4   0x20
+#define STOP_UEFI_ISCSI_IF_AIP_CONFIGURED_IP6   0x40
 
 extern EFI_COMPONENT_NAME2_PROTOCOL       gIScsiComponentName2;
 extern EFI_COMPONENT_NAME_PROTOCOL        gIScsiComponentName;

Modified: trunk/edk2/NetworkPkg/IScsiDxe/IScsiDxe.inf
===================================================================
--- trunk/edk2/NetworkPkg/IScsiDxe/IScsiDxe.inf 2015-12-18 06:07:50 UTC (rev 
19366)
+++ trunk/edk2/NetworkPkg/IScsiDxe/IScsiDxe.inf 2015-12-18 06:31:31 UTC (rev 
19367)
@@ -4,7 +4,7 @@
 #  The iSCSI driver provides iSCSI service in the preboot environment and 
supports
 #  booting over iSCSI.
 #                                                    
-# Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
 # 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
@@ -106,7 +106,9 @@
   ## UNDEFINED # Variable
   gEfiIScsiInitiatorNameProtocolGuid
   ## PRODUCES       
-  gEfiAuthenticationInfoProtocolGuid            
+  gEfiAuthenticationInfoProtocolGuid
+  ## CONSUMES
+  gEfiAdapterInformationProtocolGuid
 
 [Guids]
   gEfiEventExitBootServicesGuid                 ## SOMETIMES_CONSUMES ## Event
@@ -114,6 +116,7 @@
   gEfiAcpiTableGuid                             ## SOMETIMES_CONSUMES ## 
SystemTable
   gEfiAcpi10TableGuid                           ## SOMETIMES_CONSUMES ## 
SystemTable
   gEfiAcpi20TableGuid                           ## SOMETIMES_CONSUMES ## 
SystemTable
+  gEfiAdapterInfoNetworkBootGuid                ## SOMETIMES_CONSUMES ## 
UNDEFINED
   
   ## SOMETIMES_PRODUCES ## Variable:L"AttemptOrder"
   ## SOMETIMES_CONSUMES ## Variable:L"AttemptOrder"
@@ -123,6 +126,9 @@
   ## SOMETIMES_CONSUMES ## UNDEFINED # HiiSetBrowserData     mVendorStorageName
   ## SOMETIMES_CONSUMES ## HII
   gIScsiConfigGuid
+
+[Pcd]
+  gEfiNetworkPkgTokenSpaceGuid.PcdIScsiAIPNetworkBootPolicy ## CONSUMES
   
 [UserExtensions.TianoCore."ExtraFiles"]
   IScsiDxeExtra.uni

Modified: trunk/edk2/NetworkPkg/IScsiDxe/IScsiImpl.h
===================================================================
--- trunk/edk2/NetworkPkg/IScsiDxe/IScsiImpl.h  2015-12-18 06:07:50 UTC (rev 
19366)
+++ trunk/edk2/NetworkPkg/IScsiDxe/IScsiImpl.h  2015-12-18 06:31:31 UTC (rev 
19367)
@@ -1,7 +1,7 @@
 /** @file
   The shared head file for iSCSI driver.
 
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
 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
@@ -32,6 +32,7 @@
 #include <Protocol/AuthenticationInfo.h>
 #include <Protocol/IScsiInitiatorName.h>
 #include <Protocol/ScsiPassThruExt.h>
+#include <Protocol/AdapterInformation.h>
 
 #include <Library/HiiLib.h>
 #include <Library/UefiHiiServicesLib.h>

Modified: trunk/edk2/NetworkPkg/NetworkPkg.dec
===================================================================
--- trunk/edk2/NetworkPkg/NetworkPkg.dec        2015-12-18 06:07:50 UTC (rev 
19366)
+++ trunk/edk2/NetworkPkg/NetworkPkg.dec        2015-12-18 06:31:31 UTC (rev 
19367)
@@ -78,5 +78,17 @@
   # @Prompt Type Value of Dhcp6 Unique Identifier (DUID).
   gEfiNetworkPkgTokenSpaceGuid.PcdDhcp6UidType|4|UINT8|0x10000001
 
+  ## Network boot policy to stop UEFI iSCSI if applicable.
+  # 0x00 = Always use UEFI iSCSI and ignore AIP.
+  # 0x01 = Stop UEFI iSCSI if iSCSI HBA adapter produces AIP protocol with 
Network Boot.
+  # 0x02 = Stop UEFI iSCSI if iSCSI HBA adapter supports booting from iSCSI 
IPv4 targets.
+  # 0x04 = Stop UEFI iSCSI if iSCSI HBA adapter supports booting from iSCSI 
IPv6 targets.
+  # 0x08 = Stop UEFI iSCSI if iSCSI HBA adapter supports an offload engine for 
iSCSI boot.
+  # 0x10 = Stop UEFI iSCSI if iSCSI HBA adapter supports multipath I/O for 
iSCSI boot.
+  # 0x20 = Stop UEFI iSCSI if iSCSI HBA adapter is currently configured to 
boot from iSCSI IPv4 targets.
+  # 0x40 = Stop UEFI iSCSI if iSCSI HBA adapter is currently configured to 
boot from iSCSI IPv6 targets.
+  # @Prompt Type Value of network boot policy used in iSCSI.
+  
gEfiNetworkPkgTokenSpaceGuid.PcdIScsiAIPNetworkBootPolicy|0x08|UINT8|0x10000007
+
 [UserExtensions.TianoCore."ExtraFiles"]
   NetworkPkgExtra.uni

Modified: trunk/edk2/NetworkPkg/NetworkPkg.uni
===================================================================
--- trunk/edk2/NetworkPkg/NetworkPkg.uni        2015-12-18 06:07:50 UTC (rev 
19366)
+++ trunk/edk2/NetworkPkg/NetworkPkg.uni        2015-12-18 06:31:31 UTC (rev 
19367)
@@ -1,62 +1,147 @@
-// /** @file
-// This package provides network modules that conform to UEFI 2.4 
specification.
-//
-// This package provides network modules that conform to UEFI 2.4 
specification.
-//
-// Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
-//
-// 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
-// http://opensource.org/licenses/bsd-license.php
-// 
-// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
-//
-// **/
-
-
-#string STR_PACKAGE_ABSTRACT            #language en-US "This package provides 
network modules that conform to UEFI 2.4 specification."
-
-#string STR_PACKAGE_DESCRIPTION         #language en-US "This package provides 
network modules that conform to UEFI 2.4 specification."
-
-
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdIpsecUefiCaFile_PROMPT  #language 
en-US "CA file."
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdIpsecUefiCaFile_HELP  #language 
en-US "CA certificate used by IPsec."
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdIpsecUefiCaFileSize_PROMPT  
#language en-US "CA file's size."
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdIpsecUefiCaFileSize_HELP  
#language en-US "CA certificate file's size."
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdIpsecUefiCertificate_PROMPT  
#language en-US "Pubic Key for remote peer."
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdIpsecUefiCertificate_HELP  
#language en-US "X509 certificate as Public Key which is used by IPsec (DER 
format)"
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdIpsecUefiCertificateSize_PROMPT  
#language en-US "Pubic Key's size."
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdIpsecUefiCertificateSize_HELP  
#language en-US "X509 certificate as Public Key's size."
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdIpsecUefiCertificateKey_PROMPT  
#language en-US "Private Key."
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdIpsecUefiCertificateKey_HELP  
#language en-US "Private Key used by IPsec (PEM format)."
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdIpsecUefiCertificateKeySize_PROMPT 
 #language en-US "Private Key's size."
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdIpsecUefiCertificateKeySize_HELP  
#language en-US "Private Key's size."
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdIpsecCertificateEnabled_PROMPT  
#language en-US "Enable IPsec IKEv2 Certificate Authentication."
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdIpsecCertificateEnabled_HELP  
#language en-US "Indicates if the IPsec IKEv2 Certificate Authentication 
feature is enabled or not.<BR><BR>\n"
-                                                                               
           "TRUE  - Certificate Authentication feature is enabled.<BR>\n"
-                                                                               
           "FALSE - Does not support Certificate Authentication.<BR>"
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdDhcp6UidType_PROMPT  #language 
en-US "Type Value of Dhcp6 Unique Identifier (DUID)."
-
-#string STR_gEfiNetworkPkgTokenSpaceGuid_PcdDhcp6UidType_HELP  #language en-US 
"IPv6 DHCP Unique Identifier (DUID) Type configuration (From RFCs 3315 and 
6355).\n"
-                                                                               
"01 = DUID Based on Link-layer Address Plus Time [DUID-LLT]\n"
-                                                                               
"04 = UUID-Based DHCPv6 Unique Identifier (DUID-UUID)\n"
-                                                                               
"02 = DUID Assigned by Vendor Based on Enterprise Number [DUID-EN] (not 
supported)\n"
-                                                                               
"03 = DUID Based on Link-layer Address [DUID-LL] (not supported)"
-
+\xFF\xFE/+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\
 No newline at end of file


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to