Re: [edk2] [Patch v2] MdeModulePkg/NetLib: Add NetLibDetectMediaWaitTimeout() API to support EFI_NOT_READY media state detection

2017-12-05 Thread Wu, Jiaxin
Reviewed-by: Jiaxin Wu 



> -Original Message-
> From: Fu, Siyuan
> Sent: Tuesday, December 5, 2017 4:06 PM
> To: Wang, Fan ; edk2-devel@lists.01.org
> Cc: Ye, Ting ; Wu, Jiaxin 
> Subject: RE: [Patch v2] MdeModulePkg/NetLib: Add
> NetLibDetectMediaWaitTimeout() API to support EFI_NOT_READY media
> state detection
> 
> Reviewed-by: Fu Siyuan 
> 
> > -Original Message-
> > From: Wang, Fan
> > Sent: Monday, December 4, 2017 11:42 AM
> > To: edk2-devel@lists.01.org
> > Cc: Fu, Siyuan ; Ye, Ting ; Wu,
> > Jiaxin ; Wang, Fan 
> > Subject: [Patch v2] MdeModulePkg/NetLib: Add
> NetLibDetectMediaWaitTimeout()
> > API to support EFI_NOT_READY media state detection
> >
> > V2:
> >   * Return error status code directly when Aip protocol falied to detect
> > media rather than wait for another time's check.
> >   * Set media state default value to EFI_SUCCESS since some platforms may
> > not support retrieving media state from Aip protocol.
> >
> > Cc: Fu Siyuan 
> > Cc: Ye Ting 
> > Cc: Jiaxin Wu 
> > Contributed-under: TianoCore Contribution Agreement 1.0
> > Signed-off-by: Wang Fan 
> > ---
> >  MdeModulePkg/Include/Library/NetLib.h|  40 +++
> >  MdeModulePkg/Library/DxeNetLib/DxeNetLib.c   | 163
> > +++
> >  MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf |   2 +
> >  3 files changed, 205 insertions(+)
> >
> > diff --git a/MdeModulePkg/Include/Library/NetLib.h
> > b/MdeModulePkg/Include/Library/NetLib.h
> > index b9df46c..7862df9 100644
> > --- a/MdeModulePkg/Include/Library/NetLib.h
> > +++ b/MdeModulePkg/Include/Library/NetLib.h
> > @@ -93,10 +93,16 @@ typedef UINT16  TCP_PORTNO;
> >  #define  DNS_CLASS_INET1
> >  #define  DNS_CLASS_CH  3
> >  #define  DNS_CLASS_HS  4
> >  #define  DNS_CLASS_ANY 255
> >
> > +//
> > +// Number of 100ns units time Interval for network media state detect
> > +//
> > +#define MEDIA_STATE_DETECT_TIME_INTERVAL  100U
> > +
> > +
> >  #pragma pack(1)
> >
> >  //
> >  // Ethernet head definition
> >  //
> > @@ -1246,10 +1252,44 @@ NetLibDetectMedia (
> >IN  EFI_HANDLEServiceHandle,
> >OUT BOOLEAN   *MediaPresent
> >);
> >
> >  /**
> > +
> > +  Detect media state for a network device. This routine will wait for a
> > period of time at
> > +  a specified checking interval when a certain network is under
> > connecting until connection
> > +  process finishes or timeout. If Aip protocol is supported by low layer
> > drivers, three kinds
> > +  of media states can be detected: EFI_SUCCESS, EFI_NOT_READY and
> > EFI_NO_MEDIA, represents
> > +  connected state, connecting state and no media state respectively.
> When
> > function detects
> > +  the current state is EFI_NOT_READY, it will loop to wait for next
> > time's check until state
> > +  turns to be EFI_SUCCESS or EFI_NO_MEDIA. If Aip protocol is not
> > supported, function will
> > +  call NetLibDetectMedia() and return state directly.
> > +
> > +  @param[in]   ServiceHandleThe handle where network service binding
> > protocols are
> > +installed on.
> > +  @param[in]   Timeout  The maximum number of 100ns units to wait
> > when network
> > +is connecting. Zero value means detect
> > once and return
> > +immediately.
> > +  @param[out]  MediaState   The pointer to the detected media state.
> > +
> > +  @retval EFI_SUCCESS   Media detection success.
> > +  @retval EFI_INVALID_PARAMETER ServiceHandle is not a valid network
> > device handle or
> > +MediaState pointer is NULL.
> > +  @retval EFI_DEVICE_ERROR  A device error occurred.
> > +  @retval EFI_TIMEOUT   Network is connecting but timeout.
> > +
> > +**/
> > +EFI_STATUS
> > +EFIAPI
> > +NetLibDetectMediaWaitTimeout (
> > +  IN  EFI_HANDLEServiceHandle,
> > +  IN  UINT64Timeout,
> > +  OUT EFI_STATUS*MediaState
> > +  );
> > +
> > +
> > +/**
> >Create an IPv4 device path node.
> >
> >The header type of IPv4 device path node is MESSAGING_DEVICE_PATH.
> >The header subtype of IPv4 device path node is MSG_IPv4_DP.
> >The length of the IPv4 device path node in bytes is 19.
> > diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> > b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> > index b8544b8..1bfa33d 100644
> > --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> > +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> > @@ -17,10 +17,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF
> ANY KIND,
> > EITHER EXPRESS OR IMPLIED.
> >  #include 
> >
> >  #include 
> >  #include 
> >  

Re: [edk2] [Patch v2] MdeModulePkg/NetLib: Add NetLibDetectMediaWaitTimeout() API to support EFI_NOT_READY media state detection

2017-12-05 Thread Fu, Siyuan
Reviewed-by: Fu Siyuan 

> -Original Message-
> From: Wang, Fan
> Sent: Monday, December 4, 2017 11:42 AM
> To: edk2-devel@lists.01.org
> Cc: Fu, Siyuan ; Ye, Ting ; Wu,
> Jiaxin ; Wang, Fan 
> Subject: [Patch v2] MdeModulePkg/NetLib: Add NetLibDetectMediaWaitTimeout()
> API to support EFI_NOT_READY media state detection
> 
> V2:
>   * Return error status code directly when Aip protocol falied to detect
> media rather than wait for another time's check.
>   * Set media state default value to EFI_SUCCESS since some platforms may
> not support retrieving media state from Aip protocol.
> 
> Cc: Fu Siyuan 
> Cc: Ye Ting 
> Cc: Jiaxin Wu 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Wang Fan 
> ---
>  MdeModulePkg/Include/Library/NetLib.h|  40 +++
>  MdeModulePkg/Library/DxeNetLib/DxeNetLib.c   | 163
> +++
>  MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf |   2 +
>  3 files changed, 205 insertions(+)
> 
> diff --git a/MdeModulePkg/Include/Library/NetLib.h
> b/MdeModulePkg/Include/Library/NetLib.h
> index b9df46c..7862df9 100644
> --- a/MdeModulePkg/Include/Library/NetLib.h
> +++ b/MdeModulePkg/Include/Library/NetLib.h
> @@ -93,10 +93,16 @@ typedef UINT16  TCP_PORTNO;
>  #define  DNS_CLASS_INET1
>  #define  DNS_CLASS_CH  3
>  #define  DNS_CLASS_HS  4
>  #define  DNS_CLASS_ANY 255
> 
> +//
> +// Number of 100ns units time Interval for network media state detect
> +//
> +#define MEDIA_STATE_DETECT_TIME_INTERVAL  100U
> +
> +
>  #pragma pack(1)
> 
>  //
>  // Ethernet head definition
>  //
> @@ -1246,10 +1252,44 @@ NetLibDetectMedia (
>IN  EFI_HANDLEServiceHandle,
>OUT BOOLEAN   *MediaPresent
>);
> 
>  /**
> +
> +  Detect media state for a network device. This routine will wait for a
> period of time at
> +  a specified checking interval when a certain network is under
> connecting until connection
> +  process finishes or timeout. If Aip protocol is supported by low layer
> drivers, three kinds
> +  of media states can be detected: EFI_SUCCESS, EFI_NOT_READY and
> EFI_NO_MEDIA, represents
> +  connected state, connecting state and no media state respectively. When
> function detects
> +  the current state is EFI_NOT_READY, it will loop to wait for next
> time's check until state
> +  turns to be EFI_SUCCESS or EFI_NO_MEDIA. If Aip protocol is not
> supported, function will
> +  call NetLibDetectMedia() and return state directly.
> +
> +  @param[in]   ServiceHandleThe handle where network service binding
> protocols are
> +installed on.
> +  @param[in]   Timeout  The maximum number of 100ns units to wait
> when network
> +is connecting. Zero value means detect
> once and return
> +immediately.
> +  @param[out]  MediaState   The pointer to the detected media state.
> +
> +  @retval EFI_SUCCESS   Media detection success.
> +  @retval EFI_INVALID_PARAMETER ServiceHandle is not a valid network
> device handle or
> +MediaState pointer is NULL.
> +  @retval EFI_DEVICE_ERROR  A device error occurred.
> +  @retval EFI_TIMEOUT   Network is connecting but timeout.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +NetLibDetectMediaWaitTimeout (
> +  IN  EFI_HANDLEServiceHandle,
> +  IN  UINT64Timeout,
> +  OUT EFI_STATUS*MediaState
> +  );
> +
> +
> +/**
>Create an IPv4 device path node.
> 
>The header type of IPv4 device path node is MESSAGING_DEVICE_PATH.
>The header subtype of IPv4 device path node is MSG_IPv4_DP.
>The length of the IPv4 device path node in bytes is 19.
> diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> index b8544b8..1bfa33d 100644
> --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
> @@ -17,10 +17,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND,
> EITHER EXPRESS OR IMPLIED.
>  #include 
> 
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
>  #include 
> 
> @@ -2501,10 +2502,172 @@ Exit:
> 
>return Status;
>  }
> 
>  /**
> +
> +  Detect media state for a network device. This routine will wait for a
> period of time at
> +  a specified checking interval when a certain network is under
> connecting until connection
> +  process finishs or timeout. If Aip protocol is supported by low layer
> drivers, three kinds
> +  of media states can be detected: EFI_SUCCESS, EFI_NOT_READY and
> EFI_NO_MEDIA, represents
> +  connected state, connecting state and no media state respectively. When
> function detects
> +  the 

[edk2] [Patch v2] MdeModulePkg/NetLib: Add NetLibDetectMediaWaitTimeout() API to support EFI_NOT_READY media state detection

2017-12-03 Thread fanwang2
V2:
  * Return error status code directly when Aip protocol falied to detect
media rather than wait for another time's check.
  * Set media state default value to EFI_SUCCESS since some platforms may
not support retrieving media state from Aip protocol.

Cc: Fu Siyuan 
Cc: Ye Ting 
Cc: Jiaxin Wu 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wang Fan 
---
 MdeModulePkg/Include/Library/NetLib.h|  40 +++
 MdeModulePkg/Library/DxeNetLib/DxeNetLib.c   | 163 +++
 MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf |   2 +
 3 files changed, 205 insertions(+)

diff --git a/MdeModulePkg/Include/Library/NetLib.h 
b/MdeModulePkg/Include/Library/NetLib.h
index b9df46c..7862df9 100644
--- a/MdeModulePkg/Include/Library/NetLib.h
+++ b/MdeModulePkg/Include/Library/NetLib.h
@@ -93,10 +93,16 @@ typedef UINT16  TCP_PORTNO;
 #define  DNS_CLASS_INET1
 #define  DNS_CLASS_CH  3
 #define  DNS_CLASS_HS  4
 #define  DNS_CLASS_ANY 255
 
+//
+// Number of 100ns units time Interval for network media state detect
+//
+#define MEDIA_STATE_DETECT_TIME_INTERVAL  100U
+
+
 #pragma pack(1)
 
 //
 // Ethernet head definition
 //
@@ -1246,10 +1252,44 @@ NetLibDetectMedia (
   IN  EFI_HANDLEServiceHandle,
   OUT BOOLEAN   *MediaPresent
   );
 
 /**
+
+  Detect media state for a network device. This routine will wait for a period 
of time at 
+  a specified checking interval when a certain network is under connecting 
until connection 
+  process finishes or timeout. If Aip protocol is supported by low layer 
drivers, three kinds
+  of media states can be detected: EFI_SUCCESS, EFI_NOT_READY and 
EFI_NO_MEDIA, represents
+  connected state, connecting state and no media state respectively. When 
function detects 
+  the current state is EFI_NOT_READY, it will loop to wait for next time's 
check until state 
+  turns to be EFI_SUCCESS or EFI_NO_MEDIA. If Aip protocol is not supported, 
function will 
+  call NetLibDetectMedia() and return state directly.
+
+  @param[in]   ServiceHandleThe handle where network service binding 
protocols are
+installed on.
+  @param[in]   Timeout  The maximum number of 100ns units to wait when 
network
+is connecting. Zero value means detect once 
and return
+immediately.
+  @param[out]  MediaState   The pointer to the detected media state.
+
+  @retval EFI_SUCCESS   Media detection success.
+  @retval EFI_INVALID_PARAMETER ServiceHandle is not a valid network device 
handle or 
+MediaState pointer is NULL.
+  @retval EFI_DEVICE_ERROR  A device error occurred.
+  @retval EFI_TIMEOUT   Network is connecting but timeout.
+
+**/
+EFI_STATUS
+EFIAPI
+NetLibDetectMediaWaitTimeout (
+  IN  EFI_HANDLEServiceHandle,
+  IN  UINT64Timeout,
+  OUT EFI_STATUS*MediaState
+  );
+
+
+/**
   Create an IPv4 device path node.
 
   The header type of IPv4 device path node is MESSAGING_DEVICE_PATH.
   The header subtype of IPv4 device path node is MSG_IPv4_DP.
   The length of the IPv4 device path node in bytes is 19.
diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c 
b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
index b8544b8..1bfa33d 100644
--- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
+++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c
@@ -17,10 +17,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 #include 
 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 
@@ -2501,10 +2502,172 @@ Exit:
 
   return Status;
 }
 
 /**
+
+  Detect media state for a network device. This routine will wait for a period 
of time at 
+  a specified checking interval when a certain network is under connecting 
until connection 
+  process finishs or timeout. If Aip protocol is supported by low layer 
drivers, three kinds
+  of media states can be detected: EFI_SUCCESS, EFI_NOT_READY and 
EFI_NO_MEDIA, represents
+  connected state, connecting state and no media state respectively. When 
function detects 
+  the current state is EFI_NOT_READY, it will loop to wait for next time's 
check until state 
+  turns to be EFI_SUCCESS or EFI_NO_MEDIA. If Aip protocol is not supported, 
function will 
+  call NetLibDetectMedia() and return state directly.
+
+  @param[in]   ServiceHandleThe handle where network service binding 
protocols are
+installed on.
+  @param[in]   Timeout  The maximum number of 100ns units to wait when 
network
+is connecting. Zero value means detect once 
and return
+immediately.
+  @param[out]  MediaState   The pointer to the detected