From patchwork Fri Apr 27 11:37:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 134576 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp607986lji; Fri, 27 Apr 2018 04:37:59 -0700 (PDT) X-Google-Smtp-Source: AB8JxZowo6uT8JVrMwM854CNHy17xt/2b/Wg1ss7LQhqZGNyXCcjgqdeyoq2vStibmWGXJZ3sbHb X-Received: by 2002:a17:902:822:: with SMTP id 31-v6mr2036047plk.172.1524829079107; Fri, 27 Apr 2018 04:37:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524829079; cv=none; d=google.com; s=arc-20160816; b=C01U2AbrFnSobYSmU1qhhZBEXVvFRl2JL08BeaM+Cj5IlsMx2b37hSmApSNxzGJeo4 wF0xZ4ShMT5Tt0pVojGcTrVFdBonlWrw8osm/+A/hqrPbT9w76XDTgfVvjYV5SH5/DPC ipk8VAwXF5m6w5okjml1w8H+siHb9/mxC9K6kAu4k/4ZVMTAiHRJFRwAeFHyprjR8t1z wibVSITRPOQjeua1TOIl8jB2Keznu409OE+4fCsZilantPq9y60Wo2ytQGnbf9BrpvKb 9pJDFW2iU2QP3r6hj/AGZRYwqNOXflsOJ5qvdsxgIFX1lfwkVmiFT94p4OqLlQ6UXtAw SIiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=6T4zXHBC8HtjGbwvrgKriDIqEtpw6/wUnrA8PlOCdZo=; b=BwqGYMfRKSI8DRCkHgsPehDWEXn0KefxKmm0Dsb9YezM3wFuTO3ixW3XL5BGkEw0Tz B4ufM6IRa63tAy5QUIZAr27M0Z56wsHysTyeB2LAwJHY7mnfHNp8LvVVfYGAWfCR77b4 05Zw690GG407ShqggzrZ1onHI7ys8ypKtZrmCMe7kPE8J7avK0RLdrGUE2Y3imnX2EUM SZldWStN+4txt1AErPbjgCfgN/0A6Eb2h/UeKl0MHhdGPr6C5T8QO6zxi/z1o5km9b3Q BF5bG+lx1YyS2/IV5WaBcIFoqIRgY2xH4PZ/SeYmJ5ib6bDKIkj2pISE2n8LVbnLn/Q+ 1Y4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Jbm+oKJh; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id l15-v6si1105303pgu.659.2018.04.27.04.37.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Apr 2018 04:37:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Jbm+oKJh; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A9EC52283931E; Fri, 27 Apr 2018 04:37:58 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::243; helo=mail-wr0-x243.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id EA9692282E595 for ; Fri, 27 Apr 2018 04:37:55 -0700 (PDT) Received: by mail-wr0-x243.google.com with SMTP id d1-v6so1453736wrj.13 for ; Fri, 27 Apr 2018 04:37:55 -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=zjiXFvL854AbJ8rE7Xe5Z8PdtahEfYirwEQnl6oQZ8Y=; b=Jbm+oKJhBBCYb7065yJAXy/RP25wNYuvgdI54WHhFEXlS6jPIj0ZDYwlYuZvr+Muje If6R0aZhWcXRsPenOozHRO96vlei2qnyj4QOGrlSaqWAlW9LgwzL+mwXaDf+7rBjN5Ld goiiWymHJHuxvASBEiDPi9QLqm9GfNzjPC+Og= 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=zjiXFvL854AbJ8rE7Xe5Z8PdtahEfYirwEQnl6oQZ8Y=; b=afQen1p3DNxA9GXB8bpF6Jp+LqH/c5hUEoQX/bYda8z6zRT4vlDIf/oZi9vAvSDFRh jxWVBmlMCKozs3Q45Xt9o2QKBWxmPXl4QT/K0cHEf4/voGlmkKeVAgOqg6oZbQOjENoi oNOBOvsEoSVqHQC8t1cvU5cpM5Sl+dJSZJHQfZaWMAV1jS+uJdatIl0OTUJMcBJw02wK UMG3YGp48aFrlYwSjXuXp4uMh8hX5m/jxe7JoGgnqsUnZXoV1WqwAMLv71J2+b0y0L2I /yWac18iOZDaWJLKuVVIijB3bMBNleS7WWd7MBn4Ef8vQz0B2QX3qzudTsmctw/sgdEX eh3A== X-Gm-Message-State: ALQs6tAGMi2oYfxUMVzC9+fT47xX58Ssa7xnt4b0g0vsAK4xDHsNblhl YuiVHO8P6LF0MMDfaUoafOST5O7eHNM= X-Received: by 2002:adf:d1cc:: with SMTP id m12-v6mr1650716wri.214.1524829074097; Fri, 27 Apr 2018 04:37:54 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:3995:5470:200:1aff:fe1b:b328]) by smtp.gmail.com with ESMTPSA id k82sm869167wmf.17.2018.04.27.04.37.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Apr 2018 04:37:53 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Fri, 27 Apr 2018 13:37:44 +0200 Message-Id: <20180427113748.21663-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427113748.21663-1-ard.biesheuvel@linaro.org> References: <20180427113748.21663-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH edk2-platforms 1/5] Silicon/SynQuacer/NetsecDxe: Add polling function to reinitialize GMAC X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leif.lindholm@linaro.org MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" From: Masahisa KOJIMA GMAC is a Gigabit Ethernet MAC implemented in NETSEC. When the physical link is changed from DOWN to UP, GMAC should be reinitialized properly. We add polling function to check the physical link status and reinitialize GMAC: - when the GMAC is running and physical link is down, stop GMAC, - when the GMAC is stopped and physical link is up, start GMAC. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Masahisa KOJIMA Reviewed-by: Ard Biesheuvel --- Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c | 108 ++++++++++++++++++++ Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.h | 4 + 2 files changed, 112 insertions(+) -- 2.17.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c index 764c44bb3c87..fa8ae79da28e 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c +++ b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.c @@ -161,6 +161,10 @@ SnpStop ( gBS->CloseEvent (LanDriver->ExitBootEvent); + gBS->SetTimer (LanDriver->PhyStatusEvent, TimerCancel, 0); + gBS->CloseEvent (LanDriver->PhyStatusEvent); + LanDriver->PhyStatusEvent = NULL; + // Change the state Snp->Mode->State = EfiSimpleNetworkStopped; Status = EFI_SUCCESS; @@ -406,6 +410,99 @@ NotifyExitBoot ( gBS->CloseEvent (Event); } +/** + Polling function to check the physical link status with GMAC + + @param[in] Timer Event + @param[in] Context Pointer to the Snp structure + +**/ +STATIC +VOID +EFIAPI +NetsecPollPhyStatus ( + IN EFI_EVENT Timer, + IN VOID *Context + ) +{ + 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) { + DEBUG((DEBUG_ERROR, "NETSEC: PollPhyStatus() invalid Snp\n")); + return; + } + + LanDriver = INSTANCE_FROM_SNP_THIS (Snp); + + // Update the media status + ogma_err = ogma_get_phy_link_status (LanDriver->Handle, LanDriver->PhyAddress, + &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)); + } + } +} + /* * UEFI Start() function */ @@ -450,6 +547,17 @@ SnpStart ( NotifyExitBoot, Snp, &LanDriver->ExitBootEvent); ASSERT_EFI_ERROR (Status); + Status = gBS->CreateEvent (EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK, + NetsecPollPhyStatus, Snp, &LanDriver->PhyStatusEvent); + ASSERT_EFI_ERROR (Status); + + Status = gBS->SetTimer ( + LanDriver->PhyStatusEvent, + TimerPeriodic, + NETSEC_PHY_STATUS_POLL_INTERVAL + ); + ASSERT_EFI_ERROR (Status); + // Change state Mode->State = EfiSimpleNetworkStarted; Status = EFI_SUCCESS; diff --git a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.h b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.h index 6aa7f1a1d107..f09fb609ba5a 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.h +++ b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.h @@ -71,6 +71,8 @@ typedef struct { EFI_EVENT ExitBootEvent; + EFI_EVENT PhyStatusEvent; + NON_DISCOVERABLE_DEVICE *Dev; NETSEC_DEVICE_PATH DevicePath; @@ -115,4 +117,6 @@ NetsecRelease ( #define RXINT_TMR_CNT_US 0 #define RXINT_PKTCNT 1 +#define NETSEC_PHY_STATUS_POLL_INTERVAL (EFI_TIMER_PERIOD_MILLISECONDS (1000)) + #endif