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 08620C54EBC for ; Tue, 10 Jan 2023 10:38:51 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 125C082A0A; Tue, 10 Jan 2023 11:38:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1673347130; bh=MlSgtGQC9ub3stucrCl+mBLkHtmDKAanNBGnCl/q9P8=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=HhnY+CKKm1xWKN4hdArA0XLyCU151DO0XWoKXPI5XnJW7+R10z5FuDTTMEBpyIKOz TbQaW8HFOqM31etvtKT/yoAkZcjw2W9QxZv2mStwdrrr8qjTtq9oU1n2d3Si9uNom9 1yaALTXsEyeIF2WmP1aMOdTqGbcl6seNINOkfZBpN3mHbDwHGnzkedbw0YsjRaN4rc Lp2ViL/3DDq40makV5ASxIYs4/+TI6Vz4QtgyTJkJy9J0RkO3UYRazNo0cU0cCeW4A Y9Eil9Aw75KuA7Nl+2E6gq1au3E3THNX4vy5juk2lJIf3KqPHplGJNOxUC8+frC02G p6eyzz9p/eRbQ== Received: by phobos.denx.de (Postfix, from userid 109) id 14DC5852A0; Tue, 10 Jan 2023 11:38:48 +0100 (CET) Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [80.241.59.204]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E555782131 for ; Tue, 10 Jan 2023 11:38:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4NrnNM44Khz9sb6; Tue, 10 Jan 2023 11:38:43 +0100 (CET) From: Stefan Roese To: u-boot@lists.denx.de Cc: Michal Simek , T Karthik Reddy , Ramon Fried Subject: [PATCH] net: zynq_gem: Wait for SGMII PCS link in zynq_gem_init() Date: Tue, 10 Jan 2023 11:38:42 +0100 Message-Id: <20230110103842.390061-1-sr@denx.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 In our system using ZynqMP with an external SGMII PHY it's necessary to wait for the PCS link and auto negotiation to finish before the xfer starts. Otherwise the first packet(s) might get dropped, resulting in a delay at the start of the ethernet transfers. This patch adds the necessary code at the end of zynq_gem_init() including a minimal delay of 10ms which fixes problems of dropped first packages. Signed-off-by: Stefan Roese Cc: Michal Simek Cc: T Karthik Reddy Cc: Ramon Fried --- drivers/net/zynq_gem.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/net/zynq_gem.c b/drivers/net/zynq_gem.c index 507b19b75975..625b0303d6e2 100644 --- a/drivers/net/zynq_gem.c +++ b/drivers/net/zynq_gem.c @@ -125,6 +125,10 @@ */ #define PHY_DETECT_MASK 0x1808 +/* PCS (SGMII) Link Status */ +#define ZYNQ_GEM_PCSSTATUS_LINK BIT(2) +#define ZYNQ_GEM_PCSSTATUS_ANEG_COMPL BIT(5) + /* TX BD status masks */ #define ZYNQ_GEM_TXBUF_FRMLEN_MASK 0x000007ff #define ZYNQ_GEM_TXBUF_EXHAUSTED 0x08000000 @@ -164,7 +168,8 @@ struct zynq_gem_regs { u32 stat[STAT_SIZE]; /* 0x100 - Octects transmitted Low reg */ u32 reserved9[20]; u32 pcscntrl; - u32 rserved12[36]; + u32 pcsstatus; + u32 rserved12[35]; u32 dcfg6; /* 0x294 Design config reg6 */ u32 reserved7[106]; u32 transmit_q1_ptr; /* 0x440 - Transmit priority queue 1 */ @@ -522,6 +527,31 @@ static int zynq_gem_init(struct udevice *dev) return ret; } } + + /* Wait for SGMII link */ + if (priv->interface == PHY_INTERFACE_MODE_SGMII && priv->int_pcs) { + u32 pcsstatus; + + if (priv->phydev->phy_id == PHY_FIXED_ID) + pcsstatus = ZYNQ_GEM_PCSSTATUS_LINK; + else + pcsstatus = ZYNQ_GEM_PCSSTATUS_LINK | + ZYNQ_GEM_PCSSTATUS_ANEG_COMPL; + + ret = wait_for_bit_le32(®s->pcsstatus, pcsstatus, + true, 5000, true); + if (ret) { + dev_err(dev, "no PCS (SGMII) link detected\n"); + return ret; + } + + /* + * Some additional minimal delay seems to be needed so that + * the first packet will be sent correctly + */ + mdelay(10); + } + setbits_le32(®s->nwctrl, ZYNQ_GEM_NWCTRL_RXEN_MASK | ZYNQ_GEM_NWCTRL_TXEN_MASK); -- 2.39.0