Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3987220pxb; Sat, 13 Feb 2021 17:08:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJxIJZghh5Sy34AN+R6JWIu3SoyrPailf2TC6CpbYCxsxwBD145kG6toUhnnBGpTUNrOCYkG X-Received: by 2002:a17:906:c448:: with SMTP id ck8mr9555075ejb.55.1613264934594; Sat, 13 Feb 2021 17:08:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613264934; cv=none; d=google.com; s=arc-20160816; b=btU2dmm5QCjMn9eajNidKDxqLQi675gi98mtJ8CbYvlpow9UCd1r9IS2rpp11+BIT4 z3CFNgcr65W9on7WrEsnMivdu09JnJo/3VJMMJdYX4bBH3hHl8OE7kSn5YE0OP4Pznc5 5pqDbujn6iEnTnC+7QXs6Wx27z8vBSSF0eULZjMvHbz8bGSDTnHweY96AeO0BURnoubw rvTA303efUHxWuwLSh9eZlM1WXEVNLg4LI0Q8EFQBBr9mHUpGluHLhKzEzTKMFmzCaIR EHnGWmOyjJSBsoKjT3v8Z+VPdGlMquSPHvS6oSTQzUauTWgPa6FNFJtPp4ZhZzUv+oTO FfSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6eWXt0pmqIuh7EZysx1TvDwVH9UcTFdMs2NIAS8KTVQ=; b=Z+I1h1++MDSZSk2nov9InK38t9UjRVa79WpRspzvdW/qUjE4sXxZKjCXVOeXHBaDKh vaUCzZk48u7EyAg1vdSxk1o+0s7XmF9ViDJs1ItbLk8yoK1uNMSCwp0HUU6pMrwfmSDo b39/D73TS/AAYaGr4e3SikStOJb6W3xivYlrAiJ0Q9FKjxm9Ky/1pdoI+OuTt9jBt8OB 1uCnpXqwmKgyZZ+otKM0AoB6eXgrFgDu/pJxliENbcaIKnxY0g/1u8FzHvb6IoKRuyg3 UvF0k5fcm+cnwWx/MBx7MhBE6nw3IewJ+fPHmb22ldGd0X0FyYXu1wPh1LkTvRjrKiO2 wsmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=K7sRVqY3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e6si11723886edz.361.2021.02.13.17.08.31; Sat, 13 Feb 2021 17:08:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=K7sRVqY3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229787AbhBNBFI (ORCPT + 99 others); Sat, 13 Feb 2021 20:05:08 -0500 Received: from ssl.serverraum.org ([176.9.125.105]:52673 "EHLO ssl.serverraum.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229702AbhBNBFD (ORCPT ); Sat, 13 Feb 2021 20:05:03 -0500 Received: from mwalle01.fritz.box (unknown [IPv6:2a02:810c:c200:2e91:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 3483F23E65; Sun, 14 Feb 2021 02:04:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1613264661; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6eWXt0pmqIuh7EZysx1TvDwVH9UcTFdMs2NIAS8KTVQ=; b=K7sRVqY3UhenvOpyGj4M2qmIc9WxpPHunDr42cygwiElGEBRYSY5bKI2a+2DZdljF/sThw nEmBh06tEmaunVaCMDAdKaIFKvs4t8C0L+T/rM7W2B39XypOLPtMjvVq7wbMtS6vRWkDhe UOi0517kxP8GLA5TIJawKVGUZyKrruk= From: Michael Walle To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andrew Lunn , Heiner Kallweit , Russell King , "David S . Miller" , Jakub Kicinski , Michael Walle Subject: [PATCH net-next 2/2] net: phy: at803x: use proper locking in at803x_aneg_done() Date: Sun, 14 Feb 2021 02:04:05 +0100 Message-Id: <20210214010405.32019-3-michael@walle.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210214010405.32019-1-michael@walle.cc> References: <20210214010405.32019-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org at803x_aneg_done() checks if auto-negotiation is completed on the SGMII side. This doesn't take the mdio bus lock and the page switching is open-coded. Now that we have proper page support, just use phy_read_paged(). Also use phydev->interface to check if we have an SGMII link instead of reading the mode register and be a bit more precise on the warning message. Signed-off-by: Michael Walle --- drivers/net/phy/at803x.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c index a3aa10f14638..8abaea7ae6bd 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -756,32 +756,27 @@ static void at803x_link_change_notify(struct phy_device *phydev) static int at803x_aneg_done(struct phy_device *phydev) { - int ccr; - - int aneg_done = genphy_aneg_done(phydev); - if (aneg_done != BMSR_ANEGCOMPLETE) - return aneg_done; + int ret, val; - /* - * in SGMII mode, if copper side autoneg is successful, - * also check SGMII side autoneg result - */ - ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG); - if ((ccr & AT803X_MODE_CFG_MASK) != AT803X_MODE_CFG_SGMII) - return aneg_done; - /* switch to SGMII/fiber page */ - phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr & ~AT803X_BT_BX_REG_SEL); + ret = genphy_aneg_done(phydev); - /* check if the SGMII link is OK. */ - if (!(phy_read(phydev, AT803X_PSSR) & AT803X_PSSR_MR_AN_COMPLETE)) { - phydev_warn(phydev, "803x_aneg_done: SGMII link is not ok\n"); - aneg_done = 0; + /* In SGMII mode, if copper side autoneg is successful, also check + * SGMII side autoneg result. + */ + if (phydev->interface == PHY_INTERFACE_MODE_SGMII && + ret == BMSR_ANEGCOMPLETE) { + val = phy_read_paged(phydev, AT803X_FIBER_PAGE, AT803X_PSSR); + if (val < 0) + return val; + + if (!(val & AT803X_PSSR_MR_AN_COMPLETE)) { + phydev_warn(phydev, "SGMII autoneg isn't completed\n"); + return 0; + } } - /* switch back to copper page */ - phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr | AT803X_BT_BX_REG_SEL); - return aneg_done; + return ret; } static int at803x_read_status(struct phy_device *phydev) -- 2.20.1