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=sgsidFgX; spf=pass (domain: linaro.org, ip: 209.85.214.195, mailfrom: masahisa.kojima@linaro.org) Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by groups.io with SMTP; Wed, 24 Jul 2019 18:11:22 -0700 Received: by mail-pl1-f195.google.com with SMTP id c14so22622731plo.0 for ; Wed, 24 Jul 2019 18:11:22 -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=rJaOEWOmrXDNZ21lUmqsWeIpzfflrnYJWxZbsLcKfD8=; b=sgsidFgXA+4rKXE4uU8seWgi5v61uR/FdVMwu7RCg83qZG9YU+Gy7TNlnwsVl5Hi16 nSf4xzeUv252Lu3F3ubaJKDh9aNc38cBg2BztuACWBgbZJeoqT9srit9O7UH99SEXzve GfKkCpnJ1yURiKnj2+EIKCnhCzH1kkUPhR7IXPvglcBvhk2/gYkvj49ffcXuy+TWpL1d cqyMsWfNVMUfpBWBUalZv0rc9nD4s6W7XgCi1I6fZJZlQf00vbuAikPVoDKKB3qFB7hH ZJzrUQem3MvY5Q72hKirpRDcYhXyA/slV8rt3YLnIn3PAx3cN6in2wAHyEWfTni3lUio jvaQ== 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=rJaOEWOmrXDNZ21lUmqsWeIpzfflrnYJWxZbsLcKfD8=; b=sG6hXg8AVKEBad+f2q9Mhgc+aNyIcqdOqycHl9jqxld7wuN1Gt7hFfOtOH5Jbtw+Pd Rd1q6L3GidSzHZN2yuwL9vBeSNnBIJodDDumYR3gCzVn31DZ29WemtvJiXpUcDhkOZb3 4SBkHxBifhuff9B9gQakDU058z9rvFWoQ+4XJmhcsPtCb4iv3yBJoFa7Lzl/7Y+nJfjx 36OZ9sGcaqJjc7cBMzUzfN7QPcJ9jlTwv0xfo3mcxVsKKMcPZggZlAeqGxBUdDpFZ6wm HS4oxpyvDoW21u/Ki+E9TFKwatd0AzCA3QvAuUQ8fbDAHuDjAUK9xwAOz38juQJnwpqP d4uw== X-Gm-Message-State: APjAAAUnDlvqDSo71qsyQQYGf5pWmQyaJLxXbrG2KtgJhVSedRjQH1k+ UQd1wWNcVdfZem+HNmoV28tcqRpbRSM= X-Google-Smtp-Source: APXvYqyRUMr+jhB4WXgczpsVOT1cazHamNqDU0oRyaAYsqa8VzkQUYYe1TQP52Hr3fsBbtdo7D4UtQ== X-Received: by 2002:a17:902:2be6:: with SMTP id l93mr89108091plb.0.1564017081333; Wed, 24 Jul 2019 18:11:21 -0700 (PDT) Return-Path: Received: from localhost ([121.95.100.191]) by smtp.gmail.com with ESMTPSA id s3sm8755901pgq.17.2019.07.24.18.11.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jul 2019 18:11:20 -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 v2 2/3] NetsecDxe: put phy in loopback mode to guarantee stable RXCLK input Date: Thu, 25 Jul 2019 10:10:59 +0900 Message-Id: <20190725011100.10176-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190725011100.10176-1-masahisa.kojima@linaro.org> References: <20190725011100.10176-1-masahisa.kojima@linaro.org> NETSEC hardware requires stable RXCLK input upon initialization triggered with DISCORE = 0. However, RXCLK input could be unstable depending on phy chipset and deployed network environment, which could cause NETSEC to hang up during initialization. We solve this platform/environment dependent issue by temporarily putting phy in loopback mode, then we can expect the stable RXCLK input. Signed-off-by: Masahisa Kojima Signed-off-by: Satoru Okamoto --- Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/netsec_for_uefi/netsec_sdk/src/ogma_misc.c | 72 ++++++++++++++++++++ Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/netsec_for_uefi/netsec_sdk/src/ogma_reg.h | 4 ++ 2 files changed, 76 insertions(+) diff --git a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/netsec_for_uefi/netsec_sdk/src/ogma_misc.c b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/netsec_for_uefi/netsec_sdk/src/ogma_misc.c index 7481d2da2d24..5f6ddc0c745e 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/netsec_for_uefi/netsec_sdk/src/ogma_misc.c +++ b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/netsec_for_uefi/netsec_sdk/src/ogma_misc.c @@ -327,6 +327,60 @@ STATIC ogma_uint32 ogma_calc_pkt_ctrl_reg_param ( return param; } +STATIC +void +ogma_pre_init_microengine ( + ogma_handle_t ogma_handle + ) +{ + UINT16 Data; + + /* Remove dormant settings */ + Data = ogma_get_phy_reg (ogma_handle, OGMA_PHY_REG_ADDR_CONTROL) & + ~((1U << OGMA_PHY_CONTROL_REG_POWER_DOWN) | + (1U << OGMA_PHY_CONTROL_REG_ISOLATE)); + + ogma_set_phy_reg (ogma_handle, OGMA_PHY_REG_ADDR_CONTROL, Data); + + while ((ogma_get_phy_reg (ogma_handle, OGMA_PHY_REG_ADDR_CONTROL) & + ((1U << OGMA_PHY_CONTROL_REG_POWER_DOWN) | + (1U << OGMA_PHY_CONTROL_REG_ISOLATE))) != 0); + + /* Put phy in loopback mode to guarantee RXCLK input */ + Data |= (1U << OGMA_PHY_CONTROL_REG_LOOPBACK); + + ogma_set_phy_reg (ogma_handle, OGMA_PHY_REG_ADDR_CONTROL, Data); + + while ((ogma_get_phy_reg (ogma_handle, OGMA_PHY_REG_ADDR_CONTROL) & + (1U << OGMA_PHY_CONTROL_REG_LOOPBACK)) == 0); +} + +STATIC +void +ogma_post_init_microengine ( + IN ogma_handle_t ogma_handle + ) +{ + UINT16 Data; + + /* Get phy back to normal operation */ + Data = ogma_get_phy_reg (ogma_handle, OGMA_PHY_REG_ADDR_CONTROL) & + ~(1U << OGMA_PHY_CONTROL_REG_LOOPBACK); + + ogma_set_phy_reg (ogma_handle, OGMA_PHY_REG_ADDR_CONTROL, Data); + + while ((ogma_get_phy_reg (ogma_handle, OGMA_PHY_REG_ADDR_CONTROL) & + (1U << OGMA_PHY_CONTROL_REG_LOOPBACK)) != 0); + + Data |= (1U << OGMA_PHY_CONTROL_REG_RESET); + + /* Apply software reset */ + ogma_set_phy_reg (ogma_handle, OGMA_PHY_REG_ADDR_CONTROL, Data); + + while ((ogma_get_phy_reg (ogma_handle, OGMA_PHY_REG_ADDR_CONTROL) & + (1U << OGMA_PHY_CONTROL_REG_RESET)) != 0); +} + ogma_err_t ogma_init ( void *base_addr, pfdep_dev_handle_t dev_handle, @@ -551,6 +605,17 @@ ogma_err_t ogma_init ( ogma_write_reg( ctrl_p, OGMA_REG_ADDR_DMA_TMR_CTRL, ( ogma_uint32)( ( OGMA_CONFIG_CLK_HZ / OGMA_CLK_MHZ) - 1) ); + /* + * Do pre-initialization tasks for microengine + * + * In particular, we put phy in loopback mode + * in order to make sure RXCLK keeps provided to mac + * irrespective of phy link status, + * which is required for microengine intialization. + * This will be disabled once microengine initialization complete. + */ + ogma_pre_init_microengine (ctrl_p); + /* start microengines */ ogma_write_reg( ctrl_p, OGMA_REG_ADDR_DIS_CORE, 0); @@ -573,6 +638,13 @@ ogma_err_t ogma_init ( goto err; } + /* + * Do post-initialization tasks for microengine + * + * We put phy in normal mode and apply reset. + */ + ogma_post_init_microengine (ctrl_p); + /* clear microcode load end status */ ogma_write_reg( ctrl_p, OGMA_REG_ADDR_TOP_STATUS, OGMA_TOP_IRQ_REG_ME_START); diff --git a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/netsec_for_uefi/netsec_sdk/src/ogma_reg.h b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/netsec_for_uefi/netsec_sdk/src/ogma_reg.h index 30c716352b37..ca769084cb31 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/netsec_for_uefi/netsec_sdk/src/ogma_reg.h +++ b/Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/netsec_for_uefi/netsec_sdk/src/ogma_reg.h @@ -138,8 +138,12 @@ /* bit fields for PHY CONTROL Register */ #define OGMA_PHY_CONTROL_REG_SPEED_SELECTION_MSB (6) #define OGMA_PHY_CONTROL_REG_DUPLEX_MODE (8) +#define OGMA_PHY_CONTROL_REG_ISOLATE (10) +#define OGMA_PHY_CONTROL_REG_POWER_DOWN (11) #define OGMA_PHY_CONTROL_REG_AUTO_NEGO_ENABLE (12) #define OGMA_PHY_CONTROL_REG_SPEED_SELECTION_LSB (13) +#define OGMA_PHY_CONTROL_REG_LOOPBACK (14) +#define OGMA_PHY_CONTROL_REG_RESET (15) /* bit fields for PHY STATUS Register */ #define OGMA_PHY_STATUS_REG_LINK_STATUS (2) -- 2.17.1