[edk2] [Patch 2/3 V2] NetworkPkg: Update Api from NetLibDetectMedia to NetLibDetectMediaWaitTimeout.

fanwang2 posted 3 patches 6 years, 10 months ago
[edk2] [Patch 2/3 V2] NetworkPkg: Update Api from NetLibDetectMedia to NetLibDetectMediaWaitTimeout.
Posted by fanwang2 6 years, 10 months ago
From: Wang Fan <fan.wang@intel.com>

V2:
   *Define time period in a macro instead of hard code.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wang Fan <fan.wang@intel.com>
---
 NetworkPkg/Dhcp6Dxe/Dhcp6Impl.c       |  8 ++++----
 NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h       |  2 ++
 NetworkPkg/DnsDxe/DnsDhcp.c           | 16 ++++++++--------
 NetworkPkg/DnsDxe/DnsDhcp.h           |  2 ++
 NetworkPkg/HttpBootDxe/HttpBootImpl.c |  8 ++++----
 NetworkPkg/HttpBootDxe/HttpBootImpl.h |  2 ++
 NetworkPkg/IScsiDxe/IScsiDhcp.c       |  9 +++++----
 NetworkPkg/IScsiDxe/IScsiDhcp6.c      |  9 +++++----
 NetworkPkg/IScsiDxe/IScsiProto.c      |  8 ++++----
 NetworkPkg/IScsiDxe/IScsiProto.h      |  3 +++
 NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c   |  8 ++++----
 NetworkPkg/UefiPxeBcDxe/PxeBcImpl.h   |  2 ++
 12 files changed, 45 insertions(+), 32 deletions(-)

diff --git a/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.c b/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.c
index 1107865..b479421 100644
--- a/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.c
+++ b/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.c
@@ -74,11 +74,11 @@ EfiDhcp6Start (
 {
   EFI_STATUS                   Status;
   EFI_TPL                      OldTpl;
   DHCP6_INSTANCE               *Instance;
   DHCP6_SERVICE                *Service;
-  BOOLEAN                      MediaPresent;
+  EFI_STATUS                   MediaStatus;
 
   if (This == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
@@ -104,13 +104,13 @@ EfiDhcp6Start (
   OldTpl           = gBS->RaiseTPL (TPL_CALLBACK);
 
   //
   // Check Media Satus.
   //
-  MediaPresent = TRUE;
-  NetLibDetectMedia (Service->Controller, &MediaPresent);
-  if (!MediaPresent) {
+  MediaStatus = EFI_SUCCESS;
+  NetLibDetectMediaWaitTimeout (Service->Controller, DHCP_CHECK_MEDIA_WAITING_TIME, &MediaStatus);
+  if (MediaStatus != EFI_SUCCESS) {
     Status = EFI_NO_MEDIA;
     goto ON_ERROR;
   }
 
   Instance->UdpSts = EFI_ALREADY_STARTED;
diff --git a/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h b/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h
index 06780b6..7110bf8 100644
--- a/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h
+++ b/NetworkPkg/Dhcp6Dxe/Dhcp6Impl.h
@@ -60,10 +60,12 @@ typedef struct _DHCP6_INSTANCE DHCP6_INSTANCE;
 #define DHCP6_BASE_PACKET_SIZE    1024
 
 #define DHCP6_PORT_CLIENT         546
 #define DHCP6_PORT_SERVER         547
 
+#define DHCP_CHECK_MEDIA_WAITING_TIME    EFI_TIMER_PERIOD_SECONDS(20)
+
 #define DHCP6_INSTANCE_FROM_THIS(Instance) CR ((Instance), DHCP6_INSTANCE, Dhcp6, DHCP6_INSTANCE_SIGNATURE)
 #define DHCP6_SERVICE_FROM_THIS(Service)   CR ((Service), DHCP6_SERVICE, ServiceBinding, DHCP6_SERVICE_SIGNATURE)
 
 extern EFI_IPv6_ADDRESS           mAllDhcpRelayAndServersAddress;
 extern EFI_IPv6_ADDRESS           mAllDhcpServersAddress;
diff --git a/NetworkPkg/DnsDxe/DnsDhcp.c b/NetworkPkg/DnsDxe/DnsDhcp.c
index 93779be..951477b 100644
--- a/NetworkPkg/DnsDxe/DnsDhcp.c
+++ b/NetworkPkg/DnsDxe/DnsDhcp.c
@@ -267,11 +267,11 @@ GetDns4ServerFromDhcp4 (
   )
 {
   EFI_STATUS                          Status;
   EFI_HANDLE                          Image;
   EFI_HANDLE                          Controller;
-  BOOLEAN                             MediaPresent;
+  EFI_STATUS                          MediaStatus;
   EFI_HANDLE                          MnpChildHandle;  
   EFI_MANAGED_NETWORK_PROTOCOL        *Mnp;
   EFI_MANAGED_NETWORK_CONFIG_DATA     MnpConfigData;
   EFI_HANDLE                          Dhcp4Handle;  
   EFI_DHCP4_PROTOCOL                  *Dhcp4;
@@ -314,13 +314,13 @@ GetDns4ServerFromDhcp4 (
   IsDone = FALSE;
 
   //
   // Check media.
   //
-  MediaPresent = TRUE;
-  NetLibDetectMedia (Controller, &MediaPresent);
-  if (!MediaPresent) {
+  MediaStatus = EFI_SUCCESS;
+  NetLibDetectMediaWaitTimeout (Controller, DNS_CHECK_MEDIA_GET_DHCP_WAITING_TIME, &MediaStatus);
+  if (MediaStatus != EFI_SUCCESS) {
     return EFI_NO_MEDIA;
   }
 
   //
   // Create a Mnp child instance, get the protocol and config for it.
@@ -618,11 +618,11 @@ GetDns6ServerFromDhcp6 (
   EFI_STATUS                Status;
   EFI_STATUS                TimerStatus;
   EFI_DHCP6_PACKET_OPTION   *Oro;
   EFI_DHCP6_RETRANSMISSION  InfoReqReXmit;
   EFI_EVENT                 Timer;
-  BOOLEAN                   MediaPresent;
+  EFI_STATUS                MediaStatus;
   DNS6_SERVER_INFOR         DnsServerInfor;
 
   Dhcp6Handle = NULL;
   Dhcp6       = NULL;
   Oro         = NULL;
@@ -633,13 +633,13 @@ GetDns6ServerFromDhcp6 (
   DnsServerInfor.ServerCount = DnsServerCount;
 
   //
   // Check media status before doing DHCP.
   //
-  MediaPresent = TRUE;
-  NetLibDetectMedia (Controller, &MediaPresent);
-  if (!MediaPresent) {
+  MediaStatus = EFI_SUCCESS;
+  NetLibDetectMediaWaitTimeout (Controller, DNS_CHECK_MEDIA_GET_DHCP_WAITING_TIME, &MediaStatus);
+  if (MediaStatus != EFI_SUCCESS) {
     return EFI_NO_MEDIA;
   }
 
   //
   // Create a DHCP6 child instance and get the protocol.
diff --git a/NetworkPkg/DnsDxe/DnsDhcp.h b/NetworkPkg/DnsDxe/DnsDhcp.h
index 62bf717..9c61f84 100644
--- a/NetworkPkg/DnsDxe/DnsDhcp.h
+++ b/NetworkPkg/DnsDxe/DnsDhcp.h
@@ -35,10 +35,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 
 #define DHCP6_TAG_DNS_REQUEST        6
 #define DHCP6_TAG_DNS_SERVER         23
 
+#define DNS_CHECK_MEDIA_GET_DHCP_WAITING_TIME    EFI_TIMER_PERIOD_SECONDS(20)
+
 //
 // The required Dns4 server information.
 //
 typedef struct {
   UINT32                     *ServerCount;
diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.c b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
index d591db5..7f0616d 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootImpl.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
@@ -546,11 +546,11 @@ HttpBootDxeLoadFile (
   IN VOID                             *Buffer OPTIONAL
   )
 {
   HTTP_BOOT_PRIVATE_DATA        *Private;
   HTTP_BOOT_VIRTUAL_NIC         *VirtualNic;
-  BOOLEAN                       MediaPresent;
+  EFI_STATUS                    MediaStatus;
   BOOLEAN                       UsingIpv6;
   EFI_STATUS                    Status;
   HTTP_BOOT_IMAGE_TYPE          ImageType;
 
   if (This == NULL || BufferSize == NULL || FilePath == NULL) {
@@ -568,13 +568,13 @@ HttpBootDxeLoadFile (
   Private = VirtualNic->Private;
   
   //
   // Check media status before HTTP boot start
   //
-  MediaPresent = TRUE;
-  NetLibDetectMedia (Private->Controller, &MediaPresent);
-  if (!MediaPresent) {
+  MediaStatus = EFI_SUCCESS;
+  NetLibDetectMediaWaitTimeout (Private->Controller, HTTP_BOOT_CHECK_MEDIA_WAITING_TIME, &MediaStatus);
+  if (MediaStatus != EFI_SUCCESS) {
     AsciiPrint ("\n  Error: Could not detect network connection.\n");
     return EFI_NO_MEDIA;
   }
   
   //
diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.h b/NetworkPkg/HttpBootDxe/HttpBootImpl.h
index da58bb6..5316035 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootImpl.h
+++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.h
@@ -12,10 +12,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 **/
 #ifndef __EFI_HTTP_BOOT_IMPL_H__
 #define __EFI_HTTP_BOOT_IMPL_H__
 
+#define HTTP_BOOT_CHECK_MEDIA_WAITING_TIME          EFI_TIMER_PERIOD_SECONDS(20)
+
 /**
   Attempt to complete a DHCPv4 D.O.R.A or DHCPv6 S.R.A.A sequence to retrieve the boot resource information.
 
   @param[in]    Private            The pointer to the driver's private data.
 
diff --git a/NetworkPkg/IScsiDxe/IScsiDhcp.c b/NetworkPkg/IScsiDxe/IScsiDhcp.c
index 309ce0d..e6f6972 100644
--- a/NetworkPkg/IScsiDxe/IScsiDhcp.c
+++ b/NetworkPkg/IScsiDxe/IScsiDhcp.c
@@ -441,23 +441,24 @@ IScsiDoDhcp (
   EFI_DHCP4_PROTOCOL            *Dhcp4;
   EFI_STATUS                    Status;
   EFI_DHCP4_PACKET_OPTION       *ParaList;
   EFI_DHCP4_CONFIG_DATA         Dhcp4ConfigData;
   ISCSI_SESSION_CONFIG_NVDATA   *NvData;
-  BOOLEAN                       MediaPresent;
+  EFI_STATUS                    MediaStatus;
 
   Dhcp4Handle = NULL;
   Ip4Config2  = NULL;
   Dhcp4       = NULL;
   ParaList    = NULL;
 
   //
   // Check media status before doing DHCP.
   //
-  MediaPresent = TRUE;
-  NetLibDetectMedia (Controller, &MediaPresent);
-  if (!MediaPresent) {
+  MediaStatus = EFI_SUCCESS;
+  NetLibDetectMediaWaitTimeout (Controller, ISCSI_CHECK_MEDIA_GET_DHCP_WAITING_TIME, &MediaStatus);
+  if (MediaStatus!= EFI_SUCCESS) {
+    AsciiPrint ("\n  Error: Could not detect network connection.\n");
     return EFI_NO_MEDIA;
   }
 
   //
   // DHCP4 service allows only one of its children to be configured in  
diff --git a/NetworkPkg/IScsiDxe/IScsiDhcp6.c b/NetworkPkg/IScsiDxe/IScsiDhcp6.c
index 06c634c..90acb94 100644
--- a/NetworkPkg/IScsiDxe/IScsiDhcp6.c
+++ b/NetworkPkg/IScsiDxe/IScsiDhcp6.c
@@ -399,18 +399,19 @@ IScsiDoDhcp6 (
   EFI_STATUS                Status;
   EFI_STATUS                TimerStatus;
   EFI_DHCP6_PACKET_OPTION   *Oro;
   EFI_DHCP6_RETRANSMISSION  InfoReqReXmit;
   EFI_EVENT                 Timer;
-  BOOLEAN                   MediaPresent;
+  EFI_STATUS                MediaStatus;
 
   //
   // Check media status before doing DHCP.
   //
-  MediaPresent = TRUE;
-  NetLibDetectMedia (Controller, &MediaPresent);
-  if (!MediaPresent) {
+  MediaStatus = EFI_SUCCESS;
+  NetLibDetectMediaWaitTimeout (Controller, ISCSI_CHECK_MEDIA_GET_DHCP_WAITING_TIME, &MediaStatus);
+  if (MediaStatus != EFI_SUCCESS) {
+    AsciiPrint ("\n  Error: Could not detect network connection.\n");
     return EFI_NO_MEDIA;
   }
 
   //
   // iSCSI will only request target info from DHCPv6 server.
diff --git a/NetworkPkg/IScsiDxe/IScsiProto.c b/NetworkPkg/IScsiDxe/IScsiProto.c
index 1602a26..38e4af2 100644
--- a/NetworkPkg/IScsiDxe/IScsiProto.c
+++ b/NetworkPkg/IScsiDxe/IScsiProto.c
@@ -442,18 +442,18 @@ IScsiSessionLogin (
   EFI_STATUS        Status;
   ISCSI_CONNECTION  *Conn;
   VOID              *Tcp;
   EFI_GUID          *ProtocolGuid;
   UINT8             RetryCount;
-  BOOLEAN           MediaPresent;
+  EFI_STATUS        MediaStatus;
 
   //
   // Check media status before session login.
   //
-  MediaPresent = TRUE;
-  NetLibDetectMedia (Session->Private->Controller, &MediaPresent);
-  if (!MediaPresent) {
+  MediaStatus = EFI_SUCCESS;
+  NetLibDetectMediaWaitTimeout (Session->Private->Controller, ISCSI_CHECK_MEDIA_LOGIN_WAITING_TIME, &MediaStatus);
+  if (MediaStatus != EFI_SUCCESS) {
     return EFI_NO_MEDIA;
   }
 
   //
   // Set session identifier
diff --git a/NetworkPkg/IScsiDxe/IScsiProto.h b/NetworkPkg/IScsiDxe/IScsiProto.h
index 367914d..d57bda5 100644
--- a/NetworkPkg/IScsiDxe/IScsiProto.h
+++ b/NetworkPkg/IScsiDxe/IScsiProto.h
@@ -38,10 +38,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define DEFAULT_MAX_OUTSTANDING_R2T             1
 
 #define ISCSI_VERSION_MAX                       0x00
 #define ISCSI_VERSION_MIN                       0x00
 
+#define ISCSI_CHECK_MEDIA_LOGIN_WAITING_TIME       EFI_TIMER_PERIOD_SECONDS(20)
+#define ISCSI_CHECK_MEDIA_GET_DHCP_WAITING_TIME    EFI_TIMER_PERIOD_SECONDS(20)
+
 #define ISCSI_REDIRECT_ADDR_START_DELIMITER     '['
 #define ISCSI_REDIRECT_ADDR_END_DELIMITER       ']'
 
 #define ISCSI_KEY_AUTH_METHOD                   "AuthMethod"
 #define ISCSI_KEY_HEADER_DIGEST                 "HeaderDigest"
diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
index ab9e494..5a0fb32 100644
--- a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
+++ b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.c
@@ -2345,11 +2345,11 @@ EfiPxeLoadFile (
   PXEBC_PRIVATE_DATA          *Private;
   PXEBC_VIRTUAL_NIC           *VirtualNic;
   EFI_PXE_BASE_CODE_PROTOCOL  *PxeBc;
   BOOLEAN                     UsingIpv6;
   EFI_STATUS                  Status;
-  BOOLEAN                     MediaPresent;
+  EFI_STATUS                  MediaStatus;
 
   if (FilePath == NULL || !IsDevicePathEnd (FilePath)) {
     return EFI_INVALID_PARAMETER;
   }
   
@@ -2371,13 +2371,13 @@ EfiPxeLoadFile (
   }
 
   //
   // Check media status before PXE start
   //
-  MediaPresent = TRUE;
-  NetLibDetectMedia (Private->Controller, &MediaPresent);
-  if (!MediaPresent) {
+  MediaStatus = EFI_SUCCESS;
+  NetLibDetectMediaWaitTimeout (Private->Controller, PXEBC_CHECK_MEDIA_WAITING_TIME, &MediaStatus);
+  if (MediaStatus != EFI_SUCCESS) {
     return EFI_NO_MEDIA;
   }
 
   //
   // Check whether the virtual nic is using IPv6 or not.
diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.h b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.h
index 2cdc8bf..7f1ecfb 100644
--- a/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.h
+++ b/NetworkPkg/UefiPxeBcDxe/PxeBcImpl.h
@@ -74,10 +74,12 @@ typedef struct _PXEBC_VIRTUAL_NIC   PXEBC_VIRTUAL_NIC;
 #define PXEBC_MTFTP_RETRIES           6
 #define PXEBC_DHCP_RETRIES            4        // refers to mPxeDhcpTimeout, also by PXE2.1 spec.
 #define PXEBC_MENU_MAX_NUM            24
 #define PXEBC_OFFER_MAX_NUM           16
 
+#define PXEBC_CHECK_MEDIA_WAITING_TIME        EFI_TIMER_PERIOD_SECONDS(20)
+
 #define PXEBC_PRIVATE_DATA_SIGNATURE          SIGNATURE_32 ('P', 'X', 'E', 'P')
 #define PXEBC_VIRTUAL_NIC_SIGNATURE           SIGNATURE_32 ('P', 'X', 'E', 'V')
 #define PXEBC_PRIVATE_DATA_FROM_PXEBC(a)      CR (a, PXEBC_PRIVATE_DATA, PxeBc, PXEBC_PRIVATE_DATA_SIGNATURE)
 #define PXEBC_PRIVATE_DATA_FROM_ID(a)         CR (a, PXEBC_PRIVATE_DATA, Id, PXEBC_PRIVATE_DATA_SIGNATURE)
 #define PXEBC_VIRTUAL_NIC_FROM_LOADFILE(a)    CR (a, PXEBC_VIRTUAL_NIC, LoadFile, PXEBC_VIRTUAL_NIC_SIGNATURE)
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel