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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F3E6C433EF for ; Mon, 15 Nov 2021 10:41:47 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 087E2630EF for ; Mon, 15 Nov 2021 10:41:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 087E2630EF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=foss.st.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 58EFD83571; Mon, 15 Nov 2021 11:41:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.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=foss.st.com header.i=@foss.st.com header.b="dcebaOzL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 63B9982E67; Mon, 15 Nov 2021 11:41:43 +0100 (CET) Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1C4DF836BC for ; Mon, 15 Nov 2021 11:41:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=595306832a=patrick.delaunay@foss.st.com Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1AF8sjfU006661; Mon, 15 Nov 2021 11:41:32 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=MtPGCDs2ZxC+NwiXzBhRWEpoRiHdln3ro0FHND9NL9I=; b=dcebaOzLClm/vPMhPZcIRQRa1WQKmDKTixWSbe40eA3w430sZJCwOm8cjYxxRSASBU+Y x9ZkFbLSN1fAHwfIxIyuxyZpMRXcqXHwzwrso57zmMsbmx7+5cBQYEoIuotRNpYakgGy G12jpc+ASUUFBSevgq1D/x8VvBP1NaivVlFNCDNuBolW/9Z+4oSmA4TeIwEbQM9VfS3d haf+ByY1Xi7IctvKkC2ZMjJV9e1YebUSu4aTqW/t+val7kjAVRuTNxgQ4qv+93EHcHIY ikNMFDWcz+MYMQu0ai2B+pda0AzWY4qMw0SqUVndLHHONpAdKZoc3LljtgxbLrYdP13V PA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3cbmf40pbc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 15 Nov 2021 11:41:32 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id CFD2610002A; Mon, 15 Nov 2021 11:41:31 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id BB92A229A83; Mon, 15 Nov 2021 11:41:31 +0100 (CET) Received: from lmecxl0994.lme.st.com (10.75.127.49) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Mon, 15 Nov 2021 11:41:31 +0100 Subject: Re: [PATCH] net: eqos: connect and config PHY from probe stage instead of starting EQOS To: Joakim Zhang , , CC: , , , , Christophe ROULLIER , Marek Vasut References: <20211110054200.13371-1-qiangqing.zhang@nxp.com> From: Patrick DELAUNAY Message-ID: <9d92d81b-6395-cc38-55be-5489ec1593ea@foss.st.com> Date: Mon, 15 Nov 2021 11:41:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20211110054200.13371-1-qiangqing.zhang@nxp.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-15_10,2021-11-12_01,2020-04-07_01 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.35 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.2 at phobos.denx.de X-Virus-Status: Clean Hi, On 11/10/21 6:42 AM, Joakim Zhang wrote: > For EQOS ethernet, it will do phy_connect() and phy_config() when start > the ethernet (eqos_srart()), users need wait seconds for PHY auto negotiation s/eqos_srart()/eqos_start()/ > to complete when do tftp boot. > phy_config() > -> board_phy_config() > -> phydev->drv->config() // i.MX8MP/DXL use realtek PHY > -> rtl8211f_config() > -> genphy_config_aneg() > -> genphy_restart_aneg() // restart auto-nego, then need seconds to complete > > To avoid wasting time, we can move PHY connection and configuration from > eqos_start() to eqos_probe(). This patch also moves clock setting from > eqos_start() to eqos_probe() as MDIO access need CSR clock, there is no > function change. > > Tested-on: i.MX8MP & i.MX8DXL > > Before: > u-boot=> run netboot > Booting from net ... > ethernet@30bf0000 Waiting for PHY auto negotiation to complete....... done > BOOTP broadcast 1 > DHCP client bound to address 10.193.102.192 (313 ms) > Using ethernet@30bf0000 device > TFTP from server 10.193.108.176; our IP address is 10.193.102.192; sending through gateway 10.193.102.254 > After: > u-boot=> run netboot > Booting from net ... > BOOTP broadcast 1 > DHCP client bound to address 10.193.102.192 (454 ms) > Using ethernet@30bf0000 device > TFTP from server 10.193.108.176; our IP address is 10.193.102.192; sending through gateway 10.193.102.254 > > Signed-off-by: Joakim Zhang > --- > drivers/net/dwc_eth_qos.c | 132 +++++++++++++++++++------------------- > 1 file changed, 67 insertions(+), 65 deletions(-) > > diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c > index 585101804d..c1923fbe6b 100644 > --- a/drivers/net/dwc_eth_qos.c > +++ b/drivers/net/dwc_eth_qos.c > @@ -1045,20 +1045,6 @@ static int eqos_start(struct udevice *dev) > eqos->tx_desc_idx = 0; > eqos->rx_desc_idx = 0; > > - ret = eqos->config->ops->eqos_start_clks(dev); > - if (ret < 0) { > - pr_err("eqos_start_clks() failed: %d", ret); > - goto err; > - } > - > - ret = eqos->config->ops->eqos_start_resets(dev); > - if (ret < 0) { > - pr_err("eqos_start_resets() failed: %d", ret); > - goto err_stop_clks; > - } > - > - udelay(10); > - > eqos->reg_access_ok = true; => as clock is moved in probe... the line eqos->reg_access_ok = true should be also moved I think or reg_access_ok can be removed, as reg_access_ok is always one when eqos_write_hwaddr is called > > ret = wait_for_bit_le32(&eqos->dma_regs->mode, > @@ -1066,68 +1052,34 @@ static int eqos_start(struct udevice *dev) > eqos->config->swr_wait, false); > if (ret) { > pr_err("EQOS_DMA_MODE_SWR stuck"); > - goto err_stop_resets; > + goto err; > } > > ret = eqos->config->ops->eqos_calibrate_pads(dev); > if (ret < 0) { > pr_err("eqos_calibrate_pads() failed: %d", ret); > - goto err_stop_resets; > + goto err; > } > rate = eqos->config->ops->eqos_get_tick_clk_rate(dev); > > val = (rate / 1000000) - 1; > writel(val, &eqos->mac_regs->us_tic_counter); > > - /* > - * if PHY was already connected and configured, > - * don't need to reconnect/reconfigure again > - */ > - if (!eqos->phy) { > - int addr = -1; > -#ifdef CONFIG_DM_ETH_PHY > - addr = eth_phy_get_addr(dev); > -#endif > -#ifdef DWC_NET_PHYADDR > - addr = DWC_NET_PHYADDR; > -#endif > - eqos->phy = phy_connect(eqos->mii, addr, dev, > - eqos->config->interface(dev)); > - if (!eqos->phy) { > - pr_err("phy_connect() failed"); > - goto err_stop_resets; > - } > - > - if (eqos->max_speed) { > - ret = phy_set_supported(eqos->phy, eqos->max_speed); > - if (ret) { > - pr_err("phy_set_supported() failed: %d", ret); > - goto err_shutdown_phy; > - } > - } > - > - ret = phy_config(eqos->phy); > - if (ret < 0) { > - pr_err("phy_config() failed: %d", ret); > - goto err_shutdown_phy; > - } > - } > - > ret = phy_startup(eqos->phy); > if (ret < 0) { > pr_err("phy_startup() failed: %d", ret); > - goto err_shutdown_phy; > + goto err; > } > > if (!eqos->phy->link) { > pr_err("No link"); > - goto err_shutdown_phy; > + goto err; > } > > ret = eqos_adjust_link(dev); > if (ret < 0) { > pr_err("eqos_adjust_link() failed: %d", ret); > - goto err_shutdown_phy; > + goto err; > } > > /* Configure MTL */ > @@ -1356,12 +1308,6 @@ static int eqos_start(struct udevice *dev) > debug("%s: OK\n", __func__); > return 0; > > -err_shutdown_phy: > - phy_shutdown(eqos->phy); > -err_stop_resets: > - eqos->config->ops->eqos_stop_resets(dev); > -err_stop_clks: > - eqos->config->ops->eqos_stop_clks(dev); > err: > pr_err("FAILED: %d", ret); > return ret; > @@ -1412,12 +1358,6 @@ static void eqos_stop(struct udevice *dev) > clrbits_le32(&eqos->dma_regs->ch0_rx_control, > EQOS_DMA_CH0_RX_CONTROL_SR); > > - if (eqos->phy) { > - phy_shutdown(eqos->phy); > - } > - eqos->config->ops->eqos_stop_resets(dev); > - eqos->config->ops->eqos_stop_clks(dev); > - > debug("%s: OK\n", __func__); > } > > @@ -1888,9 +1828,65 @@ static int eqos_probe(struct udevice *dev) > eth_phy_set_mdio_bus(dev, eqos->mii); > #endif > > + ret = eqos->config->ops->eqos_start_clks(dev); > + if (ret < 0) { > + pr_err("eqos_start_clks() failed: %d", ret); > + goto err_unregister_mdio; > + } > + > + ret = eqos->config->ops->eqos_start_resets(dev); > + if (ret < 0) { > + pr_err("eqos_start_resets() failed: %d", ret); > + goto err_stop_clks; > + } > + > + udelay(10); > + > + /* > + * if PHY was already connected and configured, > + * don't need to reconnect/reconfigure again > + */ > + if (!eqos->phy) { this test can be remove I think because we have always eqos->phy = NULL in probe, PHY was can't be configured before probe and it should be done again after a remove... > + int addr = -1; > +#ifdef CONFIG_DM_ETH_PHY > + addr = eth_phy_get_addr(dev); > +#endif > +#ifdef DWC_NET_PHYADDR > + addr = DWC_NET_PHYADDR; > +#endif > + eqos->phy = phy_connect(eqos->mii, addr, dev, > + eqos->config->interface(dev)); > + if (!eqos->phy) { > + pr_err("phy_connect() failed"); > + goto err_stop_resets; > + } > + > + if (eqos->max_speed) { > + ret = phy_set_supported(eqos->phy, eqos->max_speed); > + if (ret) { > + pr_err("phy_set_supported() failed: %d", ret); > + goto err_shutdown_phy; > + } > + } > + > + ret = phy_config(eqos->phy); > + if (ret < 0) { > + pr_err("phy_config() failed: %d", ret); > + goto err_shutdown_phy; > + } > + } > + > debug("%s: OK\n", __func__); > return 0; > > +err_shutdown_phy: > + phy_shutdown(eqos->phy); > +err_stop_resets: > + eqos->config->ops->eqos_stop_resets(dev); > +err_stop_clks: > + eqos->config->ops->eqos_stop_clks(dev); > +err_unregister_mdio: > + mdio_unregister(eqos->mii); > err_free_mdio: > mdio_free(eqos->mii); > err_remove_resources_tegra: > @@ -1908,6 +1904,12 @@ static int eqos_remove(struct udevice *dev) > > debug("%s(dev=%p):\n", __func__, dev); > > + if (eqos->phy) { > + phy_shutdown(eqos->phy); > + } > + eqos->config->ops->eqos_stop_resets(dev); > + eqos->config->ops->eqos_stop_clks(dev); > + > mdio_unregister(eqos->mii); > mdio_free(eqos->mii); > eqos->config->ops->eqos_remove_resources(dev); Regards Patrick