From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=OqjYyTwb; spf=pass (domain: linaro.org, ip: 209.85.210.195, mailfrom: masahisa.kojima@linaro.org) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by groups.io with SMTP; Thu, 08 Aug 2019 05:24:00 -0700 Received: by mail-pf1-f195.google.com with SMTP id r7so44025362pfl.3 for ; Thu, 08 Aug 2019 05:24:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7PAPJyKahEIAuwe9dWSBwuaPv08mXzusvOpPdO6gI9A=; b=OqjYyTwb28FoScAW9R226oec46tYPTRK2/nskIgv7aB8PGZwkBKc5PbZWDWMPczkI8 0cNlVQefSYR623zKitQnrmLpJlsik3yNEDcqTXYwBzdDbUuz6dfcecmeTS12EZlyku+Z i14+qgHDe2G9qd/8rW4YH+HCqtWLawMc34b1Jzr3nKpCJS8FhjFHIPFJUQFPxxOvvNhc NpakYsY18J9JYFFt+jwppAHkzV/pCckuQmMh8/C7/+6BWT93vi5slNcTZ3RKJLg8/eSC QJmGM1K2jhq3dQ0yqR96w+UjC5BDK+QeNcMPa+iZNVPVN4Npyh5F9cZUTxWGlP3BEiXj s3TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7PAPJyKahEIAuwe9dWSBwuaPv08mXzusvOpPdO6gI9A=; b=hZ3NuvLBQKqIlX20vIHLWe6YD+iHMp5qtD4WfCABBFtCNp8eO3lgVOraVH8m3+Xk9g 3WnUW6VsdeGb5xEX9FIi1KX+d3ZUmeF2xIwJKqAqBphNLFxCr1bM3+/t0uPqIIY8I8Gr GX1VO+oYuP+QNEVr7mlRGc5TVdmohvcCZvEismCdP0+QeF/QJis0FX/aOS13DqBTpOlz +LpG3YdWcx1A5j2Uixws8iMjCLzCCsUO2wPkp3OAQHFr+kwcm50O1iXdiivVOythwt7p W86QIDBfpyv6Zc4LG6R4UAzXCa+xaLrpS330DzlDFRiouU9QcN6BSQDZhqkZ7CBYRQTs sbHQ== X-Gm-Message-State: APjAAAXOTkyRpfo4w8vEeb9UcZf3pt+/djLfgcuz4UA/V+NQ7SmZXgaa +Hh/ijVM4wZ73nBQUNrFtbUuFhyMZME= X-Google-Smtp-Source: APXvYqzcby6ugftDRkcsbu665OZmCa+XK3FnDJhPVsIxbKyip5JbMQ9afVwSXsZQj5gVd0Zy1+ybAA== X-Received: by 2002:a17:90a:ad86:: with SMTP id s6mr3897549pjq.42.1565267039421; Thu, 08 Aug 2019 05:23:59 -0700 (PDT) Return-Path: Received: from localhost ([121.95.100.191]) by smtp.gmail.com with ESMTPSA id z13sm96314905pfa.94.2019.08.08.05.23.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Aug 2019 05:23:58 -0700 (PDT) From: "Masahisa Kojima" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, okamoto.satoru@socionext.com, Masahisa Kojima Subject: [PATCH edk2-platforms v3 3/3] NetsecDxe: SnpInitialize() waits for media linking up Date: Thu, 8 Aug 2019 21:23:35 +0900 Message-Id: <20190808122335.11883-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190808122335.11883-1-masahisa.kojima@linaro.org> References: <20190808122335.11883-1-masahisa.kojima@linaro.org> From: Satoru Okamoto The latest NetsecDxe requires issueing phy reset at the last stage of initialization to safely exit loopback mode. However, as a result, it takes a couple of seconds for link state to get stable, which could cause auto-chosen pxeboot to fail due to MediaPresent check error. This patch adds link state check with 5s timeout in NetsecDxe initialization. The timeout value can be adjustable via configuration file. Signed-off-by: Masahisa Kojima --- Platform/Socionext/DeveloperBox/DeveloperBox.dsc | 1 + Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c | 232 +++++++++----------- Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.dec | 1 + Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf | 1 + 4 files changed, 110 insertions(+), 125 deletions(-) diff --git a/Platform/Socionext/DeveloperBox/DeveloperBox.dsc b/Platform/Socionext/DeveloperBox/DeveloperBox.dsc index 97fb8c410c60..9f8cb68cdd26 100644 --- a/Platform/Socionext/DeveloperBox/DeveloperBox.dsc +++ b/Platform/Socionext/DeveloperBox/DeveloperBox.dsc @@ -137,6 +137,7 @@ [PcdsFixedAtBuild] gNetsecDxeTokenSpaceGuid.PcdFlowCtrl|0 gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStartThreshold|36 gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStopThreshold|48 + gNetsecDxeTokenSpaceGuid.PcdMediaDetectTimeoutOnBoot|5 gNetsecDxeTokenSpaceGuid.PcdPauseTime|256 gSynQuacerTokenSpaceGuid.PcdNetsecEepromBase|0x08080000 diff --git a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c index 0b91d4af44a3..a304e02208fa 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c +++ b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c @@ -169,6 +169,98 @@ ExitUnlock: return Status; } +EFI_STATUS +EFIAPI +NetsecUpdateLink ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *Snp + ) +{ + NETSEC_DRIVER *LanDriver; + ogma_phy_link_status_t phy_link_status; + ogma_gmac_mode_t ogma_gmac_mode; + ogma_err_t ogma_err; + BOOLEAN ValidFlag; + ogma_gmac_mode_t GmacMode; + BOOLEAN RxRunningFlag; + BOOLEAN TxRunningFlag; + EFI_STATUS ErrorStatus; + + LanDriver = INSTANCE_FROM_SNP_THIS (Snp); + + // Update the media status + ogma_err = ogma_get_phy_link_status (LanDriver->Handle, + &phy_link_status); + if (ogma_err != OGMA_ERR_OK) { + DEBUG ((DEBUG_ERROR, + "NETSEC: ogma_get_phy_link_status failed with error code: %d\n", + (INT32)ogma_err)); + ErrorStatus = EFI_DEVICE_ERROR; + goto Fail; + } + + // Update the GMAC status + ogma_err = ogma_get_gmac_status (LanDriver->Handle, &ValidFlag, &GmacMode, + &RxRunningFlag, &TxRunningFlag); + if (ogma_err != OGMA_ERR_OK) { + DEBUG ((DEBUG_ERROR, + "NETSEC: ogma_get_gmac_status failed with error code: %d\n", + (INT32)ogma_err)); + ErrorStatus = EFI_DEVICE_ERROR; + goto Fail; + } + + // Stop GMAC when GMAC is running and physical link is down + if (RxRunningFlag && TxRunningFlag && !phy_link_status.up_flag) { + ogma_err = ogma_stop_gmac (LanDriver->Handle, OGMA_TRUE, OGMA_TRUE); + if (ogma_err != OGMA_ERR_OK) { + DEBUG ((DEBUG_ERROR, + "NETSEC: ogma_stop_gmac() failed with error status %d\n", + ogma_err)); + ErrorStatus = EFI_DEVICE_ERROR; + goto Fail; + } + } + + // Start GMAC when GMAC is stopped and physical link is up + if (!RxRunningFlag && !TxRunningFlag && phy_link_status.up_flag) { + ZeroMem (&ogma_gmac_mode, sizeof (ogma_gmac_mode_t)); + ogma_gmac_mode.link_speed = phy_link_status.link_speed; + ogma_gmac_mode.half_duplex_flag = (ogma_bool)phy_link_status.half_duplex_flag; + if (!phy_link_status.half_duplex_flag && FixedPcdGet8 (PcdFlowCtrl)) { + ogma_gmac_mode.flow_ctrl_enable_flag = FixedPcdGet8 (PcdFlowCtrl); + ogma_gmac_mode.flow_ctrl_start_threshold = FixedPcdGet16 (PcdFlowCtrlStartThreshold); + ogma_gmac_mode.flow_ctrl_stop_threshold = FixedPcdGet16 (PcdFlowCtrlStopThreshold); + ogma_gmac_mode.pause_time = FixedPcdGet16 (PcdPauseTime); + } + + ogma_err = ogma_set_gmac_mode (LanDriver->Handle, &ogma_gmac_mode); + if (ogma_err != OGMA_ERR_OK) { + DEBUG ((DEBUG_ERROR, + "NETSEC: ogma_set_gmac() failed with error status %d\n", + (INT32)ogma_err)); + ErrorStatus = EFI_DEVICE_ERROR; + goto Fail; + } + + ogma_err = ogma_start_gmac (LanDriver->Handle, OGMA_TRUE, OGMA_TRUE); + if (ogma_err != OGMA_ERR_OK) { + DEBUG ((DEBUG_ERROR, + "NETSEC: ogma_start_gmac() failed with error status %d\n", + (INT32)ogma_err)); + ErrorStatus = EFI_DEVICE_ERROR; + goto Fail; + } + } + + /* Updating link status for external guery */ + Snp->Mode->MediaPresent = phy_link_status.up_flag; + return EFI_SUCCESS; + +Fail: + Snp->Mode->MediaPresent = FALSE; + return ErrorStatus; +} + /* * UEFI Initialize() function */ @@ -185,9 +277,9 @@ SnpInitialize ( EFI_TPL SavedTpl; EFI_STATUS Status; - ogma_phy_link_status_t phy_link_status; ogma_err_t ogma_err; - ogma_gmac_mode_t ogma_gmac_mode; + + UINT32 Index; // Check Snp Instance if (Snp == NULL) { @@ -271,48 +363,18 @@ SnpInitialize ( ogma_disable_desc_ring_irq (LanDriver->Handle, OGMA_DESC_RING_ID_NRM_TX, OGMA_CH_IRQ_REG_EMPTY); - // Stop and restart the physical link - ogma_err = ogma_stop_gmac (LanDriver->Handle, OGMA_TRUE, OGMA_TRUE); - if (ogma_err != OGMA_ERR_OK) { - DEBUG ((DEBUG_ERROR, - "NETSEC: ogma_stop_gmac() failed with error status %d\n", - ogma_err)); - ReturnUnlock (EFI_DEVICE_ERROR); - } - - ogma_err = ogma_get_phy_link_status (LanDriver->Handle, - &phy_link_status); - if (ogma_err != OGMA_ERR_OK) { - DEBUG ((DEBUG_ERROR, - "NETSEC: ogma_get_phy_link_status() failed error code %d\n", - (INT32)ogma_err)); - ReturnUnlock (EFI_DEVICE_ERROR); - } - - SetMem (&ogma_gmac_mode, sizeof (ogma_gmac_mode_t), 0); - ogma_gmac_mode.link_speed = phy_link_status.link_speed; - ogma_gmac_mode.half_duplex_flag = (ogma_bool)phy_link_status.half_duplex_flag; - if ((!phy_link_status.half_duplex_flag) && FixedPcdGet8 (PcdFlowCtrl)) { - ogma_gmac_mode.flow_ctrl_enable_flag = FixedPcdGet8 (PcdFlowCtrl); - ogma_gmac_mode.flow_ctrl_start_threshold = FixedPcdGet16 (PcdFlowCtrlStartThreshold); - ogma_gmac_mode.flow_ctrl_stop_threshold = FixedPcdGet16 (PcdFlowCtrlStopThreshold); - ogma_gmac_mode.pause_time = FixedPcdGet16 (PcdPauseTime); - } - - ogma_err = ogma_set_gmac_mode (LanDriver->Handle, &ogma_gmac_mode); - if (ogma_err != OGMA_ERR_OK) { - DEBUG ((DEBUG_ERROR, - "NETSEC: ogma_set_gmac() failed with error status %d\n", - (INT32)ogma_err)); - ReturnUnlock (EFI_DEVICE_ERROR); - } - - ogma_err = ogma_start_gmac (LanDriver->Handle, OGMA_TRUE, OGMA_TRUE); - if (ogma_err != OGMA_ERR_OK) { - DEBUG ((DEBUG_ERROR, - "NETSEC: ogma_start_gmac() failed with error status %d\n", - (INT32)ogma_err)); - ReturnUnlock (EFI_DEVICE_ERROR); + // Wait for media linking up + for (Index = 0; Index < (UINT32)FixedPcdGet8 (PcdMediaDetectTimeoutOnBoot) * 10; Index++) { + Status = NetsecUpdateLink (Snp); + if (Status != EFI_SUCCESS) { + ReturnUnlock (EFI_DEVICE_ERROR); + } + + if (Snp->Mode->MediaPresent) { + break; + } + + MicroSecondDelay(100000); } // Declare the driver as initialized @@ -420,14 +482,6 @@ NetsecPollPhyStatus ( ) { EFI_SIMPLE_NETWORK_PROTOCOL *Snp; - NETSEC_DRIVER *LanDriver; - ogma_phy_link_status_t phy_link_status; - ogma_gmac_mode_t ogma_gmac_mode; - ogma_err_t ogma_err; - BOOLEAN ValidFlag; - ogma_gmac_mode_t GmacMode; - BOOLEAN RxRunningFlag; - BOOLEAN TxRunningFlag; Snp = (EFI_SIMPLE_NETWORK_PROTOCOL *)Context; if (Snp == NULL) { @@ -435,66 +489,7 @@ NetsecPollPhyStatus ( return; } - LanDriver = INSTANCE_FROM_SNP_THIS (Snp); - - // Update the media status - ogma_err = ogma_get_phy_link_status (LanDriver->Handle, - &phy_link_status); - if (ogma_err != OGMA_ERR_OK) { - DEBUG ((DEBUG_ERROR, - "NETSEC: ogma_get_phy_link_status failed with error code: %d\n", - (INT32)ogma_err)); - return; - } - - // Update the GMAC status - ogma_err = ogma_get_gmac_status (LanDriver->Handle, &ValidFlag, &GmacMode, - &RxRunningFlag, &TxRunningFlag); - if (ogma_err != OGMA_ERR_OK) { - DEBUG ((DEBUG_ERROR, - "NETSEC: ogma_get_gmac_status failed with error code: %d\n", - (INT32)ogma_err)); - return; - } - - // Stop GMAC when GMAC is running and physical link is down - if (RxRunningFlag && TxRunningFlag && !phy_link_status.up_flag) { - ogma_err = ogma_stop_gmac (LanDriver->Handle, OGMA_TRUE, OGMA_TRUE); - if (ogma_err != OGMA_ERR_OK) { - DEBUG ((DEBUG_ERROR, - "NETSEC: ogma_stop_gmac() failed with error status %d\n", - ogma_err)); - return; - } - } - - // Start GMAC when GMAC is stopped and physical link is up - if (!RxRunningFlag && !TxRunningFlag && phy_link_status.up_flag) { - ZeroMem (&ogma_gmac_mode, sizeof (ogma_gmac_mode_t)); - ogma_gmac_mode.link_speed = phy_link_status.link_speed; - ogma_gmac_mode.half_duplex_flag = (ogma_bool)phy_link_status.half_duplex_flag; - if (!phy_link_status.half_duplex_flag && FixedPcdGet8 (PcdFlowCtrl)) { - ogma_gmac_mode.flow_ctrl_enable_flag = FixedPcdGet8 (PcdFlowCtrl); - ogma_gmac_mode.flow_ctrl_start_threshold = FixedPcdGet16 (PcdFlowCtrlStartThreshold); - ogma_gmac_mode.flow_ctrl_stop_threshold = FixedPcdGet16 (PcdFlowCtrlStopThreshold); - ogma_gmac_mode.pause_time = FixedPcdGet16 (PcdPauseTime); - } - - ogma_err = ogma_set_gmac_mode (LanDriver->Handle, &ogma_gmac_mode); - if (ogma_err != OGMA_ERR_OK) { - DEBUG ((DEBUG_ERROR, - "NETSEC: ogma_set_gmac() failed with error status %d\n", - (INT32)ogma_err)); - return; - } - - ogma_err = ogma_start_gmac (LanDriver->Handle, OGMA_TRUE, OGMA_TRUE); - if (ogma_err != OGMA_ERR_OK) { - DEBUG ((DEBUG_ERROR, - "NETSEC: ogma_start_gmac() failed with error status %d\n", - (INT32)ogma_err)); - } - } + NetsecUpdateLink (Snp); } /* @@ -631,7 +626,6 @@ SnpGetStatus ( pfdep_pkt_handle_t pkt_handle; LIST_ENTRY *Link; - ogma_phy_link_status_t phy_link_status; ogma_err_t ogma_err; // Check preliminaries @@ -661,18 +655,6 @@ SnpGetStatus ( // Find the LanDriver structure LanDriver = INSTANCE_FROM_SNP_THIS (Snp); - // Update the media status - ogma_err = ogma_get_phy_link_status (LanDriver->Handle, - &phy_link_status); - if (ogma_err != OGMA_ERR_OK) { - DEBUG ((DEBUG_ERROR, - "NETSEC: ogma_get_phy_link_status failed with error code: %d\n", - (INT32)ogma_err)); - ReturnUnlock (EFI_DEVICE_ERROR); - } - - Snp->Mode->MediaPresent = phy_link_status.up_flag; - ogma_err = ogma_clean_tx_desc_ring (LanDriver->Handle, OGMA_DESC_RING_ID_NRM_TX); diff --git a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.dec b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.dec index 6b9f60293879..3b1de62c6e31 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.dec +++ b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.dec @@ -37,4 +37,5 @@ [PcdsFixedAtBuild.common] gNetsecDxeTokenSpaceGuid.PcdFlowCtrl|0x0|UINT8|0x00000005 gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStartThreshold|0x0|UINT16|0x00000006 gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStopThreshold|0x0|UINT16|0x00000007 + gNetsecDxeTokenSpaceGuid.PcdMediaDetectTimeoutOnBoot|0x0|UINT8|0x00000009 gNetsecDxeTokenSpaceGuid.PcdPauseTime|0x0|UINT16|0x00000008 diff --git a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf index 49dd28efc65b..0fb06ba80bf4 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf +++ b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf @@ -61,4 +61,5 @@ [FixedPcd] gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStartThreshold gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStopThreshold gNetsecDxeTokenSpaceGuid.PcdJumboPacket + gNetsecDxeTokenSpaceGuid.PcdMediaDetectTimeoutOnBoot gNetsecDxeTokenSpaceGuid.PcdPauseTime -- 2.17.1