Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E4343C4332F for ; Mon, 17 Oct 2022 12:01:54 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E997F84F00; Mon, 17 Oct 2022 14:01:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="EXfDp6LT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8B86284E4B; Mon, 17 Oct 2022 13:19:45 +0200 (CEST) Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1048C8020A for ; Mon, 17 Oct 2022 13:19:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andy.chiu@sifive.com Received: by mail-pg1-x531.google.com with SMTP id e129so10145866pgc.9 for ; Mon, 17 Oct 2022 04:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=f7yIPSBV8W/bFX6Sg7GFVLnfP4OYV9pwErwMuvl80Rc=; b=EXfDp6LTPt6fjRwjAyGfS9diVEj84tMVz4eVDNR/hWwSx630UMnx/3RfnXsr4dRaxQ itLL4LZB6N0jmIBgmYmoKvgiVQj4fY2wg7K3jihRQOfJLo19L86HblLVpDXYjsYbLx0p PQdDPBam6ysUaRwmgXl4+i8YS6yVUbFTayQ87GAkPX75fciYAeXc3PAu6SOaWXnfBLIO 22G29uTaMyqgykau+hERv5tFXe5bF3Opp6hfCt9G9nLT2mINhKtRBIGNAsUsGFHQZLoi F6++7A3Y0FL5AM9u4sl68E+4TQSKw8OdQTszb2bxCXpcPGKYonX6o3D3sQlTaD4s0EeW GjeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f7yIPSBV8W/bFX6Sg7GFVLnfP4OYV9pwErwMuvl80Rc=; b=LnRTHmCn5RZCqjoJ5CAf95YLemKfwcWyIutOv5vDOjWYEThYTnM7uXWquAYReD50rX 3PNDLyXwOeEaZ7nFldxixhhzyN+AXO1v7fphtSAVp3tnFoyy8uD8lewSU/KrDQ4xYGxI 5yurLHllwFbigIE/wLu1OqtooNdBdUmO+zd/AeZWHL5BY5SH52EiAKaRI5aH3WuesUdB n9GMbtaD9c5fV4ef8HQVgIgeP5AopVp7V2Cgh0fkrrN7CSt7bqwZ7jqCoC5bUcUNsRoE LKvPwB5+VDhaFNLYLSD9IvH5un95jNSku/4vcBuA3qrp1SPGZUo+ccfB0ayDqV4A9WNm 045w== X-Gm-Message-State: ACrzQf1EyH1jZzp/fiXaPjdzqaJPPJPpkU+Ge1ZOZ4B9NlPCiXGXcadR CVqigkMNFdOH5QLPKc7chMBPpA== X-Google-Smtp-Source: AMsMyM5DiyUBholGozmbgASWmnmd9QrN4+OXQTqZWbGgmY1DtUE/8dNl68+8S4VBRMHZgkmfFlTi4w== X-Received: by 2002:a63:f91e:0:b0:456:ccc4:85c2 with SMTP id h30-20020a63f91e000000b00456ccc485c2mr10154680pgi.624.1666005580373; Mon, 17 Oct 2022 04:19:40 -0700 (PDT) Received: from archlinux.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id r12-20020a632b0c000000b004582e25a595sm5983582pgr.41.2022.10.17.04.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 04:19:39 -0700 (PDT) From: Andy Chiu To: michal.simek@amd.com Cc: rfried.dev@gmail.com, joe.hershberger@ni.com, u-boot@lists.denx.de, andy.chiu@sifive.com, greentime.hu@sifive.com Subject: [PATCH 2/2] net:xilinx_axi: check PCS/PMA PHY status in setup_phy Date: Mon, 17 Oct 2022 19:19:28 +0800 Message-Id: <20221017111928.462866-3-andy.chiu@sifive.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20221017111928.462866-1-andy.chiu@sifive.com> References: <20221017111928.462866-1-andy.chiu@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 17 Oct 2022 14:01:22 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Both PCS/PMA PHY and the external PHY need to have a valid link status in order to have Ethernet traffic. Check and wait this status at setup_phy() so that we could diagnose if there is a PHY issue. Signed-off-by: Andy Chiu Reviewed-by: Greentime Hu --- drivers/net/xilinx_axi_emac.c | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/net/xilinx_axi_emac.c b/drivers/net/xilinx_axi_emac.c index 447e1d4c9c..257ab4661e 100644 --- a/drivers/net/xilinx_axi_emac.c +++ b/drivers/net/xilinx_axi_emac.c @@ -336,6 +336,44 @@ static int axiemac_phy_init(struct udevice *dev) return 0; } +static int pcs_pma_startup(struct axidma_priv *priv) +{ + u32 rc; + u32 retry_cnt = 0; + u16 mii_reg; + + rc = phyread(priv, priv->pcsaddr, MII_BMCR, &mii_reg); + if (rc) + goto failed_mdio; + + if (!(mii_reg & BMCR_ANENABLE)) { + mii_reg |= BMCR_ANENABLE; + if (phywrite(priv, priv->pcsaddr, MII_BMCR, mii_reg)) + goto failed_mdio; + } + + /* Check the internal PHY status and warn user if the internal PHY is + * not resetted + */ + printf("axiemac: waiting for link status of the PCS/PMA PHY"); + while (retry_cnt * 10 < PHY_ANEG_TIMEOUT) { + rc = phyread(priv, priv->pcsaddr, MII_BMSR, &mii_reg); + if ((mii_reg & BMSR_LSTATUS) && mii_reg != 0xffff && !rc) { + printf(".Done\n"); + return 0; + } + + printf("."); + retry_cnt++; + mdelay(10); + } + printf("\n\tWarning, PCS/PMA PHY is not ready, link is down\n"); + return 1; +failed_mdio: + printf("axiemac: MDIO to the PCS/PMA PHY has failed\n"); + return 1; +} + /* Setting axi emac and phy to proper setting */ static int setup_phy(struct udevice *dev) { @@ -367,6 +405,11 @@ static int setup_phy(struct udevice *dev) phydev->dev->name); return 0; } + if (priv->interface == PHY_INTERFACE_MODE_SGMII || + priv->interface == PHY_INTERFACE_MODE_1000BASEX) { + if (pcs_pma_startup(priv)) + return 0; + } if (!phydev->link) { printf("%s: No link.\n", phydev->dev->name); return 0; -- 2.36.0