From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8B95C43381 for ; Sun, 3 Mar 2019 18:59:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 95F8220815 for ; Sun, 3 Mar 2019 18:59:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="k3FRH/C0"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U6zCjU0v" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 95F8220815 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Date:Message-ID:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=gZ1/iNGPfMoE0FfLPWvYH5jZ5xwYswBWSF6yGG3bGQo=; b=k3FRH/C0Lz6div Vlc0b2BG9DF0UsVEopyMOPSYefJtSHeYhpLJrHluLcEJginQPspkVCRRXEhROovqWhR+gaXLkB3bc OBUNpg5Z5rWwwG3bCmh2sEnT5FlQGYoGfm133e8siM40AiScEOkHtfXSb0SaWC6keohvxeZx6QBZL 58rukug3JUGWPJPi6uwACm7qW1EMp0iC2tQ9gzNKx/FzS9km+NdO3IsqhasAc0ULPRygno2BmKfsz vOJ7+Nj85pm3Kj9YjcG4z2iQSprDVbNKP/TQ7FJ+d1fdf613wUUcmxxJN3mJQePtdoY+0vZZNtm2B pjyUAQDCWPwT+GPRq1rQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0WKM-0005zE-77; Sun, 03 Mar 2019 18:59:10 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0WKH-0005yR-Rg; Sun, 03 Mar 2019 18:59:07 +0000 Received: by mail-wr1-x444.google.com with SMTP id i12so3166529wrw.0; Sun, 03 Mar 2019 10:59:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=TxZXRiKiMJ1B8lgyfF99G9ulqoODTYIAHoqbhaXi5Dk=; b=U6zCjU0vuwalJZ3RsTwGhGIEArkqnpv4BI7Gr6ycEUeEC95gDinLYc8VJbfdDL5Qoh +BumSsoNI3HFQWAzUIMw7RY/oo+Yjzinfkv8Z3Ps1JPZEUa9dsh7wkJcx9kTlCDw6KoP RhGG2o3e6HqbIkltS6TkubgD9McqCswtfe5OJHOjiphrjXf3rJLTyPY1ZkUfPG8w+Qch J2ZvCVb9Ye+EIvZw7NpQnV7LNQWHG8RXj0rQkmsWKp8g9tukhKrmhMvmQP/JiQ1dlUL1 JstJu8M4l69uztTQtT6N7HOLiARt/8rBEJWnJ8ewNtfbpuvGD7sNwAqrGVxgz5WMCgsQ 37zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=TxZXRiKiMJ1B8lgyfF99G9ulqoODTYIAHoqbhaXi5Dk=; b=AhVS6KCKxWqX7UOlDYSeVBfuuxE0zpB9OhIcabEzLPQAzrse7IEgg/XLKEmy4MjBan WDF7ch5/6aOFChkTu+WpqcIm0/VrBWsHHOgYfnWSLcOFlr2tpTlBOk5TFormsa2k2i1M lqIVMLPeQ0z3Ggzke+AoJjkCC1KTb8VALxvQPmbTcCvI+RlFHpGggi/dEgBxanvs/x76 eT5UqokHHUhRiRuGS8T4R72IdN1XIzuWhr4/Ybv28vL9e1rUeAezrzMe5yh0DhiRBcwz W+7FVnysMSHTc0zxjaf4I3J7OLG9kY8MwaIAc4Ld2yMX6MCc3uMLz2Cz1zFurlZJyOMI TMLQ== X-Gm-Message-State: APjAAAXKhOEFuVM0KUG8S9iX01ETPf/DmPF9Q+a2UcjJRIXZCki2vLFo 64HdhiJDLBWD6DuHk4nPcldi2xdd X-Google-Smtp-Source: APXvYqxr+Dc0IquwqCYMuCAe3pTmnQIPtoQHlVhplYpdtMdSAoRMGVMElgMNI7kchd46CHQOIQ+qzg== X-Received: by 2002:a5d:4412:: with SMTP id z18mr10201579wrq.111.1551639543407; Sun, 03 Mar 2019 10:59:03 -0800 (PST) Received: from ?IPv6:2003:ea:8bf1:e200:35a8:f48d:4b19:96c9? (p200300EA8BF1E20035A8F48D4B1996C9.dip0.t-ipconnect.de. [2003:ea:8bf1:e200:35a8:f48d:4b19:96c9]) by smtp.googlemail.com with ESMTPSA id d206sm11430840wmc.11.2019.03.03.10.59.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Mar 2019 10:59:02 -0800 (PST) From: Heiner Kallweit To: Andrew Lunn , Florian Fainelli , David Miller , Heiko Stuebner Subject: [PATCH net-next] net: phy: improve handling link_change_notify callback Message-ID: <411b1c33-a245-0706-8afd-c4bea1b90f68@gmail.com> Date: Sun, 3 Mar 2019 19:58:57 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190303_105905_924492_F0E744F3 X-CRM114-Status: GOOD ( 19.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "netdev@vger.kernel.org" , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently the Phy driver's link_change_notify callback is called whenever the state machine is run (every second if polling), no matter whether the state changed or not. This isn't needed and may confuse users considering the name of the callback. Therefore let's change the behavior and call this callback only in case of an actual state change. This requires changes to the at803x and rockchip drivers. at803x can be simplified so that it reacts on a state change to PHY_NOLINK only. The rockchip driver can also be much simplified. We simply re-init the AFE/DSP registers whenever we change to PHY_RUNNING and speed is 100Mbps. This causes very small overhead because we do this even if the speed was 100Mbps already. But this is neglectable and I think justified by the much simpler code. Changes are compile-tested only. Signed-off-by: Heiner Kallweit --- drivers/net/phy/at803x.c | 26 +++++++++----------------- drivers/net/phy/phy.c | 8 ++++---- drivers/net/phy/rockchip.c | 31 ++----------------------------- 3 files changed, 15 insertions(+), 50 deletions(-) diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c index f3e96191e..f315ab468 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -324,8 +324,6 @@ static int at803x_config_intr(struct phy_device *phydev) static void at803x_link_change_notify(struct phy_device *phydev) { - struct at803x_priv *priv = phydev->priv; - /* * Conduct a hardware reset for AT8030 every time a link loss is * signalled. This is necessary to circumvent a hardware bug that @@ -333,25 +331,19 @@ static void at803x_link_change_notify(struct phy_device *phydev) * in the FIFO. In such cases, the FIFO enters an error mode it * cannot recover from by software. */ - if (phydev->state == PHY_NOLINK) { - if (phydev->mdio.reset && !priv->phy_reset) { - struct at803x_context context; + if (phydev->state == PHY_NOLINK && phydev->mdio.reset) { + struct at803x_context context; - at803x_context_save(phydev, &context); + at803x_context_save(phydev, &context); - phy_device_reset(phydev, 1); - msleep(1); - phy_device_reset(phydev, 0); - msleep(1); + phy_device_reset(phydev, 1); + msleep(1); + phy_device_reset(phydev, 0); + msleep(1); - at803x_context_restore(phydev, &context); + at803x_context_restore(phydev, &context); - phydev_dbg(phydev, "%s(): phy was reset\n", - __func__); - priv->phy_reset = true; - } - } else { - priv->phy_reset = false; + phydev_dbg(phydev, "%s(): phy was reset\n", __func__); } } diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 3745220c5..5938c5acf 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -891,9 +891,6 @@ void phy_state_machine(struct work_struct *work) old_state = phydev->state; - if (phydev->drv && phydev->drv->link_change_notify) - phydev->drv->link_change_notify(phydev); - switch (phydev->state) { case PHY_DOWN: case PHY_READY: @@ -940,10 +937,13 @@ void phy_state_machine(struct work_struct *work) if (err < 0) phy_error(phydev); - if (old_state != phydev->state) + if (old_state != phydev->state) { phydev_dbg(phydev, "PHY state change %s -> %s\n", phy_state_to_str(old_state), phy_state_to_str(phydev->state)); + if (phydev->drv && phydev->drv->link_change_notify) + phydev->drv->link_change_notify(phydev); + } /* Only re-schedule a PHY state machine change if we are polling the * PHY, if PHY_IGNORE_INTERRUPT is set, then we will be moving diff --git a/drivers/net/phy/rockchip.c b/drivers/net/phy/rockchip.c index 95abf7072..9053b1d01 100644 --- a/drivers/net/phy/rockchip.c +++ b/drivers/net/phy/rockchip.c @@ -104,41 +104,14 @@ static int rockchip_integrated_phy_config_init(struct phy_device *phydev) static void rockchip_link_change_notify(struct phy_device *phydev) { - int speed = SPEED_10; - - if (phydev->autoneg == AUTONEG_ENABLE) { - int reg = phy_read(phydev, MII_SPECIAL_CONTROL_STATUS); - - if (reg < 0) { - phydev_err(phydev, "phy_read err: %d.\n", reg); - return; - } - - if (reg & MII_SPEED_100) - speed = SPEED_100; - else if (reg & MII_SPEED_10) - speed = SPEED_10; - } else { - int bmcr = phy_read(phydev, MII_BMCR); - - if (bmcr < 0) { - phydev_err(phydev, "phy_read err: %d.\n", bmcr); - return; - } - - if (bmcr & BMCR_SPEED100) - speed = SPEED_100; - else - speed = SPEED_10; - } - /* * If mode switch happens from 10BT to 100BT, all DSP/AFE * registers are set to default values. So any AFE/DSP * registers have to be re-initialized in this case. */ - if ((phydev->speed == SPEED_10) && (speed == SPEED_100)) { + if (phydev->state == PHY_RUNNING && phydev->speed == SPEED_100) { int ret = rockchip_integrated_phy_analog_init(phydev); + if (ret) phydev_err(phydev, "rockchip_integrated_phy_analog_init err: %d.\n", ret); -- 2.21.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel