From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4C36D220FB317 for ; Tue, 5 Dec 2017 19:41:23 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Dec 2017 19:45:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,366,1508828400"; d="scan'208";a="10929012" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga001.fm.intel.com with ESMTP; 05 Dec 2017 19:45:54 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 5 Dec 2017 19:45:53 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.213]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.159]) with mapi id 14.03.0319.002; Wed, 6 Dec 2017 11:45:52 +0800 From: "Wu, Jiaxin" To: "Fu, Siyuan" , "Wang, Fan" , "edk2-devel@lists.01.org" CC: "Ye, Ting" Thread-Topic: [Patch v2] MdeModulePkg/NetLib: Add NetLibDetectMediaWaitTimeout() API to support EFI_NOT_READY media state detection Thread-Index: AQHTbLHWqeH4TvcNhEqpBXKPo0QPmKMz4FQAgAHPqqA= Date: Wed, 6 Dec 2017 03:45:52 +0000 Message-ID: <895558F6EA4E3B41AC93A00D163B7274163502AB@SHSMSX103.ccr.corp.intel.com> References: <1512358893-9164-1-git-send-email-fan.wang@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNWY5MzA4MmQtMzQ4MC00YTQ4LWJmYjEtNTQ3YmUzY2Y3NjdlIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6IjVJMDA2SEpqOVZBd0ZxblMzT2Z3MiszYWxnendPVW0zUW5iZ2JXNUdRbFU9In0= x-ctpclassification: CTP_IC dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch v2] MdeModulePkg/NetLib: Add NetLibDetectMediaWaitTimeout() API to support EFI_NOT_READY media state detection X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Dec 2017 03:41:23 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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 >=20 > Reviewed-by: Fu Siyuan >=20 > > -----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 detec= t > > media rather than wait for another time's check. > > * Set media state default value to EFI_SUCCESS since some platforms m= ay > > 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_INET 1 > > #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 1000000U > > + > > + > > #pragma pack(1) > > > > // > > // Ethernet head definition > > // > > @@ -1246,10 +1252,44 @@ NetLibDetectMedia ( > > IN EFI_HANDLE ServiceHandle, > > 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 lay= er > > 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] ServiceHandle The handle where network service bindi= ng > > protocols are > > + installed on. > > + @param[in] Timeout The maximum number of 100ns units to w= ait > > when network > > + is connecting. Zero value means detect > > once and return > > + immediately. > > + @param[out] MediaState The pointer to the detected media stat= e. > > + > > + @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_HANDLE ServiceHandle, > > + IN UINT64 Timeout, > > + 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 laye= r > > 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] ServiceHandle The handle where network service bindi= ng > > protocols are > > + installed on. > > + @param[in] Timeout The maximum number of 100ns units to w= ait > > when network > > + is connecting. Zero value means detect > > once and return > > + immediately. > > + @param[out] MediaState The pointer to the detected media stat= e. > > + > > + @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_HANDLE ServiceHandle, > > + IN UINT64 Timeout, > > + OUT EFI_STATUS *MediaState > > + ) > > +{ > > + EFI_STATUS Status; > > + EFI_HANDLE SnpHandle; > > + EFI_SIMPLE_NETWORK_PROTOCOL *Snp; > > + EFI_ADAPTER_INFORMATION_PROTOCOL *Aip; > > + EFI_ADAPTER_INFO_MEDIA_STATE *MediaInfo; > > + BOOLEAN MediaPresent; > > + UINTN DataSize; > > + EFI_STATUS TimerStatus; > > + EFI_EVENT Timer; > > + UINT64 TimeRemained; > > + > > + if (MediaState =3D=3D NULL) { > > + return EFI_INVALID_PARAMETER; > > + } > > + *MediaState =3D EFI_SUCCESS; > > + MediaInfo =3D NULL; > > + > > + // > > + // Get SNP handle > > + // > > + Snp =3D NULL; > > + SnpHandle =3D NetLibGetSnpHandle (ServiceHandle, &Snp); > > + if (SnpHandle =3D=3D NULL) { > > + return EFI_INVALID_PARAMETER; > > + } > > + > > + Status =3D gBS->HandleProtocol ( > > + SnpHandle, > > + &gEfiAdapterInformationProtocolGuid, > > + (VOID *) &Aip > > + ); > > + if (EFI_ERROR (Status)) { > > + > > + MediaPresent =3D TRUE; > > + Status =3D NetLibDetectMedia (ServiceHandle, &MediaPresent); > > + if (!EFI_ERROR (Status)) { > > + if (MediaPresent =3D=3D TRUE) { > > + *MediaState =3D EFI_SUCCESS; > > + } else { > > + *MediaState =3D EFI_NO_MEDIA; > > + } > > + } > > + > > + // > > + // NetLibDetectMedia doesn't support EFI_NOT_READY status, return > now! > > + // > > + return Status; > > + } > > + > > + Status =3D Aip->GetInformation ( > > + Aip, > > + &gEfiAdapterInfoMediaStateGuid, > > + (VOID **) &MediaInfo, > > + &DataSize > > + ); > > + if (!EFI_ERROR (Status)) { > > + > > + *MediaState =3D MediaInfo->MediaState; > > + FreePool (MediaInfo); > > + if (*MediaState !=3D EFI_NOT_READY || Timeout < > > MEDIA_STATE_DETECT_TIME_INTERVAL) { > > + > > + return EFI_SUCCESS; > > + } > > + } else { > > + > > + if (MediaInfo !=3D NULL) { > > + FreePool (MediaInfo); > > + } > > + return Status; > > + } > > + > > + // > > + // Loop to check media state > > + // > > + > > + Timer =3D NULL; > > + TimeRemained =3D Timeout; > > + Status =3D gBS->CreateEvent (EVT_TIMER, TPL_CALLBACK, NULL, NULL, > &Timer); > > + if (EFI_ERROR (Status)) { > > + return EFI_DEVICE_ERROR; > > + } > > + > > + do { > > + Status =3D gBS->SetTimer ( > > + Timer, > > + TimerRelative, > > + MEDIA_STATE_DETECT_TIME_INTERVAL > > + ); > > + if (EFI_ERROR (Status)) { > > + gBS->CloseEvent(Timer); > > + return EFI_DEVICE_ERROR; > > + } > > + > > + do { > > + TimerStatus =3D gBS->CheckEvent (Timer); > > + if (!EFI_ERROR (TimerStatus)) { > > + > > + TimeRemained -=3D MEDIA_STATE_DETECT_TIME_INTERVAL; > > + Status =3D Aip->GetInformation ( > > + Aip, > > + &gEfiAdapterInfoMediaStateGuid, > > + (VOID **) &MediaInfo, > > + &DataSize > > + ); > > + if (!EFI_ERROR (Status)) { > > + > > + *MediaState =3D MediaInfo->MediaState; > > + FreePool (MediaInfo); > > + } else { > > + > > + if (MediaInfo !=3D NULL) { > > + FreePool (MediaInfo); > > + } > > + gBS->CloseEvent(Timer); > > + return Status; > > + } > > + } > > + } while (TimerStatus =3D=3D EFI_NOT_READY); > > + } while (*MediaState =3D=3D EFI_NOT_READY && TimeRemained >=3D > > MEDIA_STATE_DETECT_TIME_INTERVAL); > > + > > + gBS->CloseEvent(Timer); > > + if (*MediaState =3D=3D EFI_NOT_READY && TimeRemained < > > MEDIA_STATE_DETECT_TIME_INTERVAL) { > > + return EFI_TIMEOUT; > > + } else { > > + return EFI_SUCCESS; > > + } > > +} > > + > > +/** > > Check the default address used by the IPv4 driver is static or dynam= ic > > (acquired > > from DHCP). > > > > If the controller handle does not have the EFI_IP4_CONFIG2_PROTOCOL > > installed, the > > default address is static. If failed to get the policy from Ip4 Conf= ig2 > > Protocol, > > diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf > > b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf > > index 1ff3a4f..ad0727c 100644 > > --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf > > +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf > > @@ -52,14 +52,16 @@ > > > > > > [Guids] > > gEfiSmbiosTableGuid ## SOMETIMES_CONSUMES = ## > > SystemTable > > gEfiSmbios3TableGuid ## SOMETIMES_CONSUMES = ## > > SystemTable > > + gEfiAdapterInfoMediaStateGuid ## SOMETIMES_CONSUMES > > > > > > [Protocols] > > gEfiSimpleNetworkProtocolGuid ## SOMETIMES_CONSUMES > > gEfiManagedNetworkProtocolGuid ## SOMETIMES_CONSUMES > > gEfiManagedNetworkServiceBindingProtocolGuid ## > SOMETIMES_CONSUMES > > gEfiIp4Config2ProtocolGuid ## SOMETIMES_CONSUMES > > gEfiComponentNameProtocolGuid ## SOMETIMES_CONSUMES > > gEfiComponentName2ProtocolGuid ## SOMETIMES_CONSUMES > > + gEfiAdapterInformationProtocolGuid ## SOMETIMES_CONSUMES > > \ No newline at end of file > > -- > > 1.9.5.msysgit.1