Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion NetworkPkg/Include/Library/NetLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ typedef UINT16 TCP_PORTNO;
//
// Number of times to attempt to detect network media through SNP
//
#define DETECT_NET_MEDIA_RETRY_ATTEMPTS 2
#define SNP_MEDIA_DETECT_RETRY_ATTEMPTS 0

//
// Amount of time to wait for network media to be detected through SNP, in 100ns units
//
#define SNP_MEDIA_DETECT_WAITING_TIME EFI_TIMER_PERIOD_SECONDS(2)

// MU_CHANGE [END] - Consider timeout for NetLibDetectMedia() calls in NetLibDetectMediaWaitTimeout()

Expand Down
17 changes: 9 additions & 8 deletions NetworkPkg/Library/DxeNetLib/DxeNetLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,7 @@ NetLibSnpWaitForMediaPresent (
}

Timer = NULL;
TimeRemaining = Timeout;
TimeRemaining = MIN (Timeout, MAX_INT64);
Status = gBS->CreateEvent (EVT_TIMER, TPL_CALLBACK, NULL, NULL, &Timer);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
Expand Down Expand Up @@ -2951,7 +2951,7 @@ NetLibAipWaitForMediaState (
EFI_STATUS Status;
EFI_STATUS TimerStatus;
EFI_EVENT Timer;
UINT64 TimeRemaining;
INT64 TimeRemaining;
UINTN DataSize;
EFI_ADAPTER_INFO_MEDIA_STATE *MediaInfo;

Expand All @@ -2962,7 +2962,7 @@ NetLibAipWaitForMediaState (
MediaInfo = NULL;

Timer = NULL;
TimeRemaining = Timeout;
TimeRemaining = MIN (Timeout, MAX_INT64);
Status = gBS->CreateEvent (EVT_TIMER, TPL_CALLBACK, NULL, NULL, &Timer);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
Expand Down Expand Up @@ -3021,13 +3021,14 @@ NetLibAipWaitForMediaState (
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.
call NetLibDetectSnpMediaWithRetry() and wait for media to be present with a retry mechanism
and a minimal timeout.

@param[in] ServiceHandle The 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.
is connecting using AIP. Zero value means detect once and
return immediately.
@param[out] MediaState The pointer to the detected media state.

@retval EFI_SUCCESS Media detection success.
Expand Down Expand Up @@ -3075,7 +3076,7 @@ NetLibDetectMediaWaitTimeout (
);
if (EFI_ERROR (Status)) {
return NetLibNormalizeMediaReturnStatus (
NetLibDetectSnpMediaWithRetry (ServiceHandle, Timeout, DETECT_NET_MEDIA_RETRY_ATTEMPTS, MediaState),
NetLibDetectSnpMediaWithRetry (ServiceHandle, SNP_MEDIA_DETECT_WAITING_TIME, SNP_MEDIA_DETECT_RETRY_ATTEMPTS, MediaState),
MediaState
);
}
Expand All @@ -3098,7 +3099,7 @@ NetLibDetectMediaWaitTimeout (
}

return NetLibNormalizeMediaReturnStatus (
NetLibDetectSnpMediaWithRetry (ServiceHandle, Timeout, DETECT_NET_MEDIA_RETRY_ATTEMPTS, MediaState),
NetLibDetectSnpMediaWithRetry (ServiceHandle, SNP_MEDIA_DETECT_WAITING_TIME, SNP_MEDIA_DETECT_RETRY_ATTEMPTS, MediaState),
MediaState
);
}
Expand Down
Loading