From nobody Tue Feb 10 03:38:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+44139+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+44139+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1563796671; cv=none; d=zoho.com; s=zohoarc; b=D8kN3B1LzkUvC0hDBJHf5izaJA/4Pecn8mzNaXj2ZW8LDtqi0go0Zv4ed245I+vHqdT7CVmO/TaA6KxiylCyqx1b7oYcFEkUno228k2A9SJjqtRgxpQ+yy73i5XEZNFQKMWDFTl4O0B32Qr31PwU1bBBtw/nBOLgEqD9kvxWF68= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563796671; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=JYTjUZK0NMOzflPmFlhmJoNmSRnj8JKG0G8leSg1ZqI=; b=FTDMvSD4Y7yqojOcPbhO9GHSYLOGpaL7tdvF0EaovAmCntE/6Wx8F6eP/arX3fc2huQXkY7Z9Pl/76WBAre0OIp35qr1HF58572YJL9iW5fIQkS/AKUeS4u0Phir2eozEsDe+rBn7PDgHC/cH9mk+cTuU1BtjHqtGTrL/pEeCwM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+44139+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1563796671847811.2986127381452; Mon, 22 Jul 2019 04:57:51 -0700 (PDT) Return-Path: X-Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by groups.io with SMTP; Mon, 22 Jul 2019 04:57:51 -0700 X-Received: by mail-pl1-f193.google.com with SMTP id m9so19040920pls.8 for ; Mon, 22 Jul 2019 04:57:50 -0700 (PDT) X-Gm-Message-State: APjAAAX6iRZBX/H2FXJMl3C0F0tNveMrLrqV6DPkiQS+PL5nUYSKGgID Gt+Wt5tldZ1bHvp5WrN/EHxOMu+xbUU= X-Google-Smtp-Source: APXvYqw8WMeck/hUMUPJcutUIMmR+2JiekIF0me7btNHytJkqgQr1XPbVZ+d2tPDUyjguzZDfR1Now== X-Received: by 2002:a17:902:4c88:: with SMTP id b8mr77552587ple.29.1563796670005; Mon, 22 Jul 2019 04:57:50 -0700 (PDT) X-Received: from localhost ([121.95.100.191]) by smtp.gmail.com with ESMTPSA id j15sm39316480pfr.146.2019.07.22.04.57.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Jul 2019 04:57:49 -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: [edk2-devel] [edk2-platforms PATCH v1 3/3] NetsecDxe: SnpInitialize() waits for media linking up Date: Mon, 22 Jul 2019 20:56:36 +0900 Message-Id: <20190722115636.3413-4-masahisa.kojima@linaro.org> In-Reply-To: <20190722115636.3413-1-masahisa.kojima@linaro.org> References: <20190722115636.3413-1-masahisa.kojima@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,masahisa.kojima@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1563796671; bh=oXhDfmYOx4lZYycu/uP5xIwHhlEcoxgrGNSI3fRlKiQ=; h=Cc:Date:From:Reply-To:Subject:To; b=s3wiNebgFFmRH8Du8k+ffrq9M6t/p6AkBzRM6eRTypTJGe/UEUDvGzIsT070eCfHnUL uLpvLwI41mrLFFaRyQ2SBxckrD8aSZD0+GdNcVW6EfpbdUSnAos3hPto5ADcz8jOarHGL oJ+SfrCn/zx6EWZkIeVx3Zbj1weWCQHCeyE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Satoru Okamoto --- .../Socionext/DeveloperBox/DeveloperBox.dsc | 1 + .../Drivers/Net/NetsecDxe/NetsecDxe.c | 232 ++++++++---------- .../Drivers/Net/NetsecDxe/NetsecDxe.dec | 1 + .../Drivers/Net/NetsecDxe/NetsecDxe.inf | 1 + 4 files changed, 110 insertions(+), 125 deletions(-) diff --git a/Platform/Socionext/DeveloperBox/DeveloperBox.dsc b/Platform/So= cionext/DeveloperBox/DeveloperBox.dsc index 97fb8c410c60..af149607f3ce 100644 --- a/Platform/Socionext/DeveloperBox/DeveloperBox.dsc +++ b/Platform/Socionext/DeveloperBox/DeveloperBox.dsc @@ -138,6 +138,7 @@ gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStartThreshold|36 gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStopThreshold|48 gNetsecDxeTokenSpaceGuid.PcdPauseTime|256 + gNetsecDxeTokenSpaceGuid.PcdMediaDetectTimeoutOnBoot|5 =20 gSynQuacerTokenSpaceGuid.PcdNetsecEepromBase|0x08080000 gSynQuacerTokenSpaceGuid.PcdNetsecPhyAddress|7 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; } =20 +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 =3D INSTANCE_FROM_SNP_THIS (Snp); + + // Update the media status + ogma_err =3D ogma_get_phy_link_status (LanDriver->Handle, + &phy_link_status); + if (ogma_err !=3D OGMA_ERR_OK) { + DEBUG ((DEBUG_ERROR, + "NETSEC: ogma_get_phy_link_status failed with error code: %d\n", + (INT32)ogma_err)); + ErrorStatus =3D EFI_DEVICE_ERROR; + goto Fail; + } + + // Update the GMAC status + ogma_err =3D ogma_get_gmac_status (LanDriver->Handle, &ValidFlag, &GmacM= ode, + &RxRunningFlag, &TxRunningFlag); + if (ogma_err !=3D OGMA_ERR_OK) { + DEBUG ((DEBUG_ERROR, + "NETSEC: ogma_get_gmac_status failed with error code: %d\n", + (INT32)ogma_err)); + ErrorStatus =3D 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 =3D ogma_stop_gmac (LanDriver->Handle, OGMA_TRUE, OGMA_TRUE); + if (ogma_err !=3D OGMA_ERR_OK) { + DEBUG ((DEBUG_ERROR, + "NETSEC: ogma_stop_gmac() failed with error status %d\n", + ogma_err)); + ErrorStatus =3D 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 =3D phy_link_status.link_speed; + ogma_gmac_mode.half_duplex_flag =3D (ogma_bool)phy_link_status.half_du= plex_flag; + if (!phy_link_status.half_duplex_flag && FixedPcdGet8 (PcdFlowCtrl)) { + ogma_gmac_mode.flow_ctrl_enable_flag =3D FixedPcdGet8 (PcdFlowCt= rl); + ogma_gmac_mode.flow_ctrl_start_threshold =3D FixedPcdGet16 (PcdFlowC= trlStartThreshold); + ogma_gmac_mode.flow_ctrl_stop_threshold =3D FixedPcdGet16 (PcdFlowC= trlStopThreshold); + ogma_gmac_mode.pause_time =3D FixedPcdGet16 (PcdPause= Time); + } + + ogma_err =3D ogma_set_gmac_mode (LanDriver->Handle, &ogma_gmac_mode); + if (ogma_err !=3D OGMA_ERR_OK) { + DEBUG ((DEBUG_ERROR, + "NETSEC: ogma_set_gmac() failed with error status %d\n", + (INT32)ogma_err)); + ErrorStatus =3D EFI_DEVICE_ERROR; + goto Fail; + } + + ogma_err =3D ogma_start_gmac (LanDriver->Handle, OGMA_TRUE, OGMA_TRUE); + if (ogma_err !=3D OGMA_ERR_OK) { + DEBUG ((DEBUG_ERROR, + "NETSEC: ogma_start_gmac() failed with error status %d\n", + (INT32)ogma_err)); + ErrorStatus =3D EFI_DEVICE_ERROR; + goto Fail; + } + } + + /* Updating link status for external guery */ + Snp->Mode->MediaPresent =3D phy_link_status.up_flag; + return EFI_SUCCESS; + +Fail: + Snp->Mode->MediaPresent =3D FALSE; + return ErrorStatus; +} + /* * UEFI Initialize() function */ @@ -185,9 +277,9 @@ SnpInitialize ( EFI_TPL SavedTpl; EFI_STATUS Status; =20 - ogma_phy_link_status_t phy_link_status; ogma_err_t ogma_err; - ogma_gmac_mode_t ogma_gmac_mode; + + UINT32 Index; =20 // Check Snp Instance if (Snp =3D=3D NULL) { @@ -271,48 +363,18 @@ SnpInitialize ( ogma_disable_desc_ring_irq (LanDriver->Handle, OGMA_DESC_RING_ID_NRM_TX, OGMA_CH_IRQ_REG_EMPTY); =20 - // Stop and restart the physical link - ogma_err =3D ogma_stop_gmac (LanDriver->Handle, OGMA_TRUE, OGMA_TRUE); - if (ogma_err !=3D OGMA_ERR_OK) { - DEBUG ((DEBUG_ERROR, - "NETSEC: ogma_stop_gmac() failed with error status %d\n", - ogma_err)); - ReturnUnlock (EFI_DEVICE_ERROR); - } - - ogma_err =3D ogma_get_phy_link_status (LanDriver->Handle, - &phy_link_status); - if (ogma_err !=3D 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 =3D phy_link_status.link_speed; - ogma_gmac_mode.half_duplex_flag =3D (ogma_bool)phy_link_status.half_dupl= ex_flag; - if ((!phy_link_status.half_duplex_flag) && FixedPcdGet8 (PcdFlowCtrl)) { - ogma_gmac_mode.flow_ctrl_enable_flag =3D FixedPcdGet8 (PcdFlowCtrl= ); - ogma_gmac_mode.flow_ctrl_start_threshold =3D FixedPcdGet16 (PcdFlowCtr= lStartThreshold); - ogma_gmac_mode.flow_ctrl_stop_threshold =3D FixedPcdGet16 (PcdFlowCtr= lStopThreshold); - ogma_gmac_mode.pause_time =3D FixedPcdGet16 (PcdPauseTi= me); - } - - ogma_err =3D ogma_set_gmac_mode (LanDriver->Handle, &ogma_gmac_mode); - if (ogma_err !=3D 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 =3D ogma_start_gmac (LanDriver->Handle, OGMA_TRUE, OGMA_TRUE); - if (ogma_err !=3D 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 =3D 0; Index < (UINT32)FixedPcdGet8 (PcdMediaDetectTimeoutOnB= oot) * 10; Index++) { + Status =3D NetsecUpdateLink (Snp); + if (Status !=3D EFI_SUCCESS) { + ReturnUnlock (EFI_DEVICE_ERROR); + } + + if (Snp->Mode->MediaPresent) { + break; + } + + MicroSecondDelay(100000); } =20 // 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; =20 Snp =3D (EFI_SIMPLE_NETWORK_PROTOCOL *)Context; if (Snp =3D=3D NULL) { @@ -435,66 +489,7 @@ NetsecPollPhyStatus ( return; } =20 - LanDriver =3D INSTANCE_FROM_SNP_THIS (Snp); - - // Update the media status - ogma_err =3D ogma_get_phy_link_status (LanDriver->Handle, - &phy_link_status); - if (ogma_err !=3D 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 =3D ogma_get_gmac_status (LanDriver->Handle, &ValidFlag, &GmacM= ode, - &RxRunningFlag, &TxRunningFlag); - if (ogma_err !=3D 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 =3D ogma_stop_gmac (LanDriver->Handle, OGMA_TRUE, OGMA_TRUE); - if (ogma_err !=3D 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 =3D phy_link_status.link_speed; - ogma_gmac_mode.half_duplex_flag =3D (ogma_bool)phy_link_status.half_du= plex_flag; - if (!phy_link_status.half_duplex_flag && FixedPcdGet8 (PcdFlowCtrl)) { - ogma_gmac_mode.flow_ctrl_enable_flag =3D FixedPcdGet8 (PcdFlowCt= rl); - ogma_gmac_mode.flow_ctrl_start_threshold =3D FixedPcdGet16 (PcdFlowC= trlStartThreshold); - ogma_gmac_mode.flow_ctrl_stop_threshold =3D FixedPcdGet16 (PcdFlowC= trlStopThreshold); - ogma_gmac_mode.pause_time =3D FixedPcdGet16 (PcdPause= Time); - } - - ogma_err =3D ogma_set_gmac_mode (LanDriver->Handle, &ogma_gmac_mode); - if (ogma_err !=3D OGMA_ERR_OK) { - DEBUG ((DEBUG_ERROR, - "NETSEC: ogma_set_gmac() failed with error status %d\n", - (INT32)ogma_err)); - return; - } - - ogma_err =3D ogma_start_gmac (LanDriver->Handle, OGMA_TRUE, OGMA_TRUE); - if (ogma_err !=3D OGMA_ERR_OK) { - DEBUG ((DEBUG_ERROR, - "NETSEC: ogma_start_gmac() failed with error status %d\n", - (INT32)ogma_err)); - } - } + NetsecUpdateLink (Snp); } =20 /* @@ -631,7 +626,6 @@ SnpGetStatus ( pfdep_pkt_handle_t pkt_handle; LIST_ENTRY *Link; =20 - ogma_phy_link_status_t phy_link_status; ogma_err_t ogma_err; =20 // Check preliminaries @@ -661,18 +655,6 @@ SnpGetStatus ( // Find the LanDriver structure LanDriver =3D INSTANCE_FROM_SNP_THIS (Snp); =20 - // Update the media status - ogma_err =3D ogma_get_phy_link_status (LanDriver->Handle, - &phy_link_status); - if (ogma_err !=3D 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 =3D phy_link_status.up_flag; - ogma_err =3D ogma_clean_tx_desc_ring (LanDriver->Handle, OGMA_DESC_RING_ID_NRM_TX); =20 diff --git a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.de= c b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.dec index 6b9f60293879..016eba5ef695 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.dec +++ b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.dec @@ -38,3 +38,4 @@ gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStartThreshold|0x0|UINT16|0x00000006 gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStopThreshold|0x0|UINT16|0x00000007 gNetsecDxeTokenSpaceGuid.PcdPauseTime|0x0|UINT16|0x00000008 + gNetsecDxeTokenSpaceGuid.PcdMediaDetectTimeoutOnBoot|0x0|UINT8|0x00000009 diff --git a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.in= f b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf index 49dd28efc65b..818014e6d257 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf +++ b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf @@ -62,3 +62,4 @@ gNetsecDxeTokenSpaceGuid.PcdFlowCtrlStopThreshold gNetsecDxeTokenSpaceGuid.PcdJumboPacket gNetsecDxeTokenSpaceGuid.PcdPauseTime + gNetsecDxeTokenSpaceGuid.PcdMediaDetectTimeoutOnBoot --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#44139): https://edk2.groups.io/g/devel/message/44139 Mute This Topic: https://groups.io/mt/32557833/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-