From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Google-Smtp-Source: AB8JxZpFnJaUlIxIuVt5HHXlt6tgJSk8Vo6uu63WhOgRDOoBOaSsIJs3J865seKFxIBhtCOSDfPCew== 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 Cc: leif.lindholm@linaro.org, Masahisa KOJIMA 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: [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: , X-List-Received-Date: Fri, 27 Apr 2018 11:37:56 -0000 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(+) 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 -- 2.17.0