From patchwork Thu Feb 7 09:49:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 10800663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99C6517FB for ; Thu, 7 Feb 2019 09:50:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 870602CDD7 for ; Thu, 7 Feb 2019 09:50:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7830F2CDEE; Thu, 7 Feb 2019 09:50:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 07BC92CDD7 for ; Thu, 7 Feb 2019 09:50:27 +0000 (UTC) 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:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uXas6zjox66y8EG6R5/ZXnwum0FWmubvVj+gGoEG0ew=; b=Nl9XHziDBi0Abd wJpsGVholZGdGGW9oqfxCB7sQCJwrf4VrIzaDbA2BSEGE8SGrPH/zCs611X6m+fe09dlsGlwYhGzq OtihesIR66o14oNdXvUtCDvht/LrQcjf6pO9nSrZnDmvhOqxKgn+bSsy1iZEZnM9YH2t+Nr2TVXi0 7pQ2USHc4f4+xMNXWnISKHnF8d35PQkFhDNP4ebk1o2Tslf7x+I0mwOpI10E4U0WBMVuUgpZLMJOU xkfu6oFEHZu0gYE4yb3J3GmRr6D/T2dzc9bKhMA2gZFZku78miisakBX+KgCLv/5vZVswA18SrurQ zMM5ICZ3pF1qG5TMGbrQ==; 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 1grgK8-0006SP-C9; Thu, 07 Feb 2019 09:50:24 +0000 Received: from relay11.mail.gandi.net ([217.70.178.231]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1grgJl-00053p-7Q for linux-arm-kernel@lists.infradead.org; Thu, 07 Feb 2019 09:50:03 +0000 Received: from mc-bl-xps13.lan (aaubervilliers-681-1-80-177.w90-88.abo.wanadoo.fr [90.88.22.177]) (Authenticated sender: maxime.chevallier@bootlin.com) by relay11.mail.gandi.net (Postfix) with ESMTPSA id DD84510001C; Thu, 7 Feb 2019 09:49:56 +0000 (UTC) From: Maxime Chevallier To: davem@davemloft.net Subject: [PATCH net-next v2 01/10] net: phy: Update PHY linkmodes after config_init Date: Thu, 7 Feb 2019 10:49:30 +0100 Message-Id: <20190207094939.27369-2-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190207094939.27369-1-maxime.chevallier@bootlin.com> References: <20190207094939.27369-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190207_015001_594023_C3402016 X-CRM114-Status: GOOD ( 16.50 ) 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: Andrew Lunn , Florian Fainelli , mw@semihalf.com, Antoine Tenart , netdev@vger.kernel.org, gregory.clement@bootlin.com, linux-kernel@vger.kernel.org, Maxime Chevallier , nadavh@marvell.com, thomas.petazzoni@bootlin.com, miquel.raynal@bootlin.com, Russell King , stefanc@marvell.com, linux-arm-kernel@lists.infradead.org, Heiner Kallweit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We want to be able to update a PHY's supported list in the config_init callback, so move the Pause parameters settings from phydrv->features after calling config_init to make sure these parameters aren't overwritten. Signed-off-by: Maxime Chevallier --- drivers/net/phy/phy_device.c | 89 +++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 31 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 891e0178b97f..18a10565efd4 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1059,6 +1059,59 @@ static int phy_poll_reset(struct phy_device *phydev) return 0; } +/** + * phy_update_linkmodes - Update and sanitize linkmodes and pause parameters + * @phydev: The PHY device whose parameters we want to update. + * + * Description: The list of supported and advertised linkmodes is not + * straightforward to maintain, since PHYs and MACs are subject to quirks and + * erratas. This function re-builds the list of the supported pause parameters + * by taking into account the parameters expressed in the driver's features + * list. + */ +static void phy_update_linkmodes(struct phy_device *phydev) +{ + struct device_driver *drv = phydev->mdio.dev.driver; + struct phy_driver *phydrv = to_phy_driver(drv); + + mutex_lock(&phydev->lock); + + /* The Pause Frame bits indicate that the PHY can support passing + * pause frames. During autonegotiation, the PHYs will determine if + * they should allow pause frames to pass. The MAC driver should then + * use that result to determine whether to enable flow control via + * pause frames. + * + * Normally, PHY drivers should not set the Pause bits, and instead + * allow phylib to do that. However, there may be some situations + * (e.g. hardware erratum) where the driver wants to set only one + * of these bits. + */ + if (test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydrv->features) || + test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydrv->features)) { + linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT, + phydev->supported); + linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, + phydev->supported); + if (test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydrv->features)) + linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, + phydev->supported); + if (test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, + phydrv->features)) + linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, + phydev->supported); + } else { + linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, + phydev->supported); + linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, + phydev->supported); + } + + linkmode_copy(phydev->advertising, phydev->supported); + + mutex_unlock(&phydev->lock); +} + int phy_init_hw(struct phy_device *phydev) { int ret = 0; @@ -1082,6 +1135,11 @@ int phy_init_hw(struct phy_device *phydev) if (phydev->drv->config_init) ret = phydev->drv->config_init(phydev); + /* Update and sanitize the supported and advertised linkmodes, since + * they might have been changed in config_init + */ + phy_update_linkmodes(phydev); + return ret; } EXPORT_SYMBOL(phy_init_hw); @@ -2221,37 +2279,6 @@ static int phy_probe(struct device *dev) */ of_set_phy_eee_broken(phydev); - /* The Pause Frame bits indicate that the PHY can support passing - * pause frames. During autonegotiation, the PHYs will determine if - * they should allow pause frames to pass. The MAC driver should then - * use that result to determine whether to enable flow control via - * pause frames. - * - * Normally, PHY drivers should not set the Pause bits, and instead - * allow phylib to do that. However, there may be some situations - * (e.g. hardware erratum) where the driver wants to set only one - * of these bits. - */ - if (test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydrv->features) || - test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydrv->features)) { - linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT, - phydev->supported); - linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, - phydev->supported); - if (test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydrv->features)) - linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, - phydev->supported); - if (test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, - phydrv->features)) - linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, - phydev->supported); - } else { - linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, - phydev->supported); - linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, - phydev->supported); - } - /* Set the state to READY by default */ phydev->state = PHY_READY;