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 82FFDC433F5 for ; Mon, 15 Nov 2021 10:46:50 +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 050B061AAD for ; Mon, 15 Nov 2021 10:46:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 050B061AAD 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 4A7BD83124; Mon, 15 Nov 2021 11:46:48 +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="XFOAyI2k"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CD30283518; Mon, 15 Nov 2021 11:46:45 +0100 (CET) Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (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 BA49B82D95 for ; Mon, 15 Nov 2021 11:46:41 +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=59535927f8=patrice.chotard@foss.st.com Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1AFA1Fkt013989 for ; Mon, 15 Nov 2021 11:46:41 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=subject : to : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=dJbRLN9A026CnDlRlQ/75bUjJm5Z8z8dkZjGK+DrdW8=; b=XFOAyI2ke7mH0AqSJU6lKwlCMbdi73xYA2os9kqPJcpZMc/+yekj7wyAIBi835vv7VPG mTuJPqJzOG+UzsVMoBoqYWjT+tDmiUuptbasmgTWRQYLaxYDoYwUSu5VRpKH6AlKhJcl cOST09Go4sdHzgHRqpBvl/RoF31K0iH9A49Ewuw1eu9UGIezFLdSldB97lIkCQfH60u7 l5JSK8tJqst+RiVsd5mDM4bBkfZJIQcAGmZm96q8SUNIF+Dxt6nqdYTPI8LD9rJf0Lug CENEe45QG8IY8RkrGgCzKx0sAy6CzUMbKVFhkNj+APLysOScWgAhJJTR78sd3pB+Lxe2 Wg== 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 3cben335x7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 15 Nov 2021 11:46:41 +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 BE405100034 for ; Mon, 15 Nov 2021 11:46:35 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id B6F3722A6D1 for ; Mon, 15 Nov 2021 11:46:35 +0100 (CET) Received: from lmecxl0573.lme.st.com (10.75.127.47) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Mon, 15 Nov 2021 11:46:34 +0100 Subject: Re: [PATCH] net: eqos: connect and config PHY from probe stage instead of starting EQOS To: References: <20211110054200.13371-1-qiangqing.zhang@nxp.com> <9d92d81b-6395-cc38-55be-5489ec1593ea@foss.st.com> From: Patrice CHOTARD Message-ID: <511612be-69aa-3d21-3a05-4efeb589e755@foss.st.com> Date: Mon, 15 Nov 2021 11:46:34 +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: <9d92d81b-6395-cc38-55be-5489ec1593ea@foss.st.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG1NODE3.st.com (10.75.127.3) 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 All For information Another patch from Marek will collide with this one => https://patchwork.ozlabs.org/project/uboot/patch/20211113022352.231762-1-marex@denx.de/ Patrice On 11/15/21 11:41 AM, Patrick DELAUNAY wrote: > 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 >