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 CE4F5C433FE for ; Tue, 1 Nov 2022 11:47:23 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 554D684FC0; Tue, 1 Nov 2022 12:47:04 +0100 (CET) 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="hM1DaBiS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2F13384D1B; Tue, 1 Nov 2022 04:58:14 +0100 (CET) Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (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 6103484D1B for ; Tue, 1 Nov 2022 04:58:11 +0100 (CET) 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-pf1-x42c.google.com with SMTP id 130so12424112pfu.8 for ; Mon, 31 Oct 2022 20:58:11 -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=s+xuzqC8ShpnjiW5hZGQvHywGdEJJG/oW1E8XZrbx4o=; b=hM1DaBiSw+5xki6xB+sxodJgwuwpd8VEV42xN5PE5cMZZ5AMU2MaJChMsP9tbKBqVY uxkkI3iFSWEg82IqcC4bnHyIIenU2HOwuJynoYDPCuxdfMo5nXSX0opUEm7xx0wBK6R8 vBro08TF9yOE0XJdc8FS5ZQT5INJyXnvB6SlxYUniAOkAkAdrx5rK1wI+vmOi/dEduwO 4xdeCYMhE66nHPA3q1SGwDdXEo1iHt+36nF0aOsRL0H3L6VTfxItmY5Vt/bMxaglQ0XT Pny1mO38F9vD1B/mNjaCHZLPWKHSuJ4yDThnfja/OGrpJ8UEDH6+vcNxxY3MHo/b5f0m iXoQ== 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=s+xuzqC8ShpnjiW5hZGQvHywGdEJJG/oW1E8XZrbx4o=; b=59IXr+tzY9l1MwiTARXCU7IxIUGavMxVZZEyBrVBfGIP0dZ1MiqBkOGQ0F7c0ZDVwR crhVRKOMpQUaPzWSDI4pWe9sx0t0QvWFd4pizpsiW4JqHdRmIbbUao8Ip3pbS4mja2cj 9jP7vNIHrowRckWbNV02YLgPOiddUgcnAyxqi4imLMdt/EaMGVVUOMCRFfdbmke9l6Gv bChS/1F5m7t6I7/HQWD3exV65hC0TJHgykl2CccVd+Vrkv7nucRQN57rgShxPfAyMJBl LLalqdfaUbxGdMB8xcBIlXRGqdXwyiog+M64taS/HZE8oDbJaKdueE3UQHdIOtD/xi3c /lcg== X-Gm-Message-State: ACrzQf2eWr3/9PHM7rtRCl8woWwk29jux8mnHxjQIQ2qrsRBD0VbOrDS j8zxDZUqSpIt8i7/Y9oZWdAPQg== X-Google-Smtp-Source: AMsMyM4xNyIcwkWzj6FhAz2gDeNT2PgxEg5HtvJvAiDUPba2XDqNSybvEVYhB0202Kl8kAPfZ9hnJA== X-Received: by 2002:a05:6a00:cc6:b0:56d:3028:23ea with SMTP id b6-20020a056a000cc600b0056d302823eamr14061466pfv.19.1667275089573; Mon, 31 Oct 2022 20:58:09 -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 y1-20020a17090a104100b00200a85fa777sm5088278pjd.1.2022.10.31.20.58.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 20:58:09 -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 v2 2/2] net: xilinx_axi: check PCS/PMA PHY status in setup_phy Date: Tue, 1 Nov 2022 11:58:00 +0800 Message-Id: <20221101035800.912644-3-andy.chiu@sifive.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20221101035800.912644-1-andy.chiu@sifive.com> References: <20221101035800.912644-1-andy.chiu@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Tue, 01 Nov 2022 12:46:58 +0100 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 | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/net/xilinx_axi_emac.c b/drivers/net/xilinx_axi_emac.c index cb5487c437..10204db79b 100644 --- a/drivers/net/xilinx_axi_emac.c +++ b/drivers/net/xilinx_axi_emac.c @@ -336,6 +336,45 @@ static int axiemac_phy_init(struct udevice *dev) return 0; } +static int pcs_pma_startup(struct axidma_priv *priv) +{ + u32 rc, 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 link between it + * and the external PHY is not obtained. + */ + debug("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) { + debug(".Done\n"); + return 0; + } + if ((retry_cnt++ % 10) == 0) + debug("."); + mdelay(10); + } + debug("\n"); + printf("axiemac: Warning, PCS/PMA PHY@%d is not ready, link is down\n", + priv->pcsaddr); + 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 +406,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