Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4143706pxb; Mon, 27 Sep 2021 10:16:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKmRsb95Cno7mhnWaOJHxbHnfWGeRt106BSJvSQrU4Fhsy14+HojR24/WPkJWlnDu1p6ju X-Received: by 2002:a63:3648:: with SMTP id d69mr633580pga.295.1632762964777; Mon, 27 Sep 2021 10:16:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632762964; cv=none; d=google.com; s=arc-20160816; b=ktCK+zaLVtdC6Bok423K1gcBMHWDmFQ9NwKx02bXm2DmyIgIRCUXuJdK8XuU2G4xtC jN94uHJmsoCAwQgHAYyUG34bcu9DzfRRHK6jdn7cijkI83yA1sNmd2yNnZxVSAR4OvSA Yx1pnIRGxn/Y1MsQHzELzINg2FA3m5mJf4zaFJuyc25ISoCu3Ba/xwma/v/gk8S2Dfx+ j0b4PKeGv9/m40pqzQ8MIzc8jV+uMhLaomAdLn3VZrknyKOuaOtCPhHiNUpIranXlClM xBSYjpcyw5qwWhxMbzw6vNFjW5GQXUN6qME1X+s4nFjNeiCQhK6gkaTSf3dm8qUT8ZqU WRHA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qSMrTq5FbIxfQNKuDzbMQqETUhoKPDWyNxRT/q4QNMo=; b=kbhrtqktyUl7TfKjk1b9iNy3s7mXye3lduJq8HvS4FE54NyvAT6rWjtBTom99YFYWx d/uyCpezNDxTcjU8n51gPTD2GRCrwxPpE9oirFfM2vH/seSL7StbbsssgLW1aWrfcQCT 1qI6Ngd1HziRnrZvm5RMGB8miSgEXAV3cbnyPEJR8Nrz2x0YEcazAtr5u3HeDXH/D2Up /spgCbHw7LxOfalhfyJjSvf6buazoZlpO7y8VqcwZ9nS07KKU3Nhu0D3W/c23F+tON4B hyrZipx7Ka2999DVhnQU7fHcGDmP+US0NmAbyOM6QEu1RGWf336cuJ1CMNCIt1mkHvYI p6aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="io8X/lr7"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s2si23866921plk.381.2021.09.27.10.15.52; Mon, 27 Sep 2021 10:16:04 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b="io8X/lr7"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236017AbhI0RPv (ORCPT + 99 others); Mon, 27 Sep 2021 13:15:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:54500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237051AbhI0RNe (ORCPT ); Mon, 27 Sep 2021 13:13:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 85E4761352; Mon, 27 Sep 2021 17:09:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632762567; bh=nFrudeAt+LMiUk+f0kMB0bLd3J1yHNHQTkGU0Gw2CU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=io8X/lr767kheWHnl76ntv2ZlUz4w8/3AtW8euk1w9n58Q1vSRkSIJDab8N9wlBds mEUUm34ikROriFratQwt0ep3bS4xFaCzmxQSB7000RS7YWYfXrNZuDVlWNRZxJC+jS MTvcsCWMFBSzT7+A//fqZSFTmTyNDRhGn3qnLWps= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nathan Rossi , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 073/103] net: phylink: Update SFP selected interface on advertising changes Date: Mon, 27 Sep 2021 19:02:45 +0200 Message-Id: <20210927170228.289181570@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210927170225.702078779@linuxfoundation.org> References: <20210927170225.702078779@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nathan Rossi [ Upstream commit ea269a6f720782ed94171fb962b14ce07c372138 ] Currently changes to the advertising state via ethtool do not cause any reselection of the configured interface mode after the SFP is already inserted and initially configured. While it is not typical to change the advertised link modes for an interface using an SFP in certain use cases it is desirable. In the case of a SFP port that is capable of handling both SFP and SFP+ modules it will automatically select between 1G and 10G modes depending on the supported mode of the SFP. However if the SFP module is capable of working in multiple modes (e.g. a SFP+ DAC that can operate at 1G or 10G), one end of the cable may be attached to a SFP 1000base-x port thus the SFP+ end must be manually configured to the 1000base-x mode in order for the link to be established. This change causes the ethtool setting of advertised mode changes to reselect the interface mode so that the link can be established. Additionally when a module is inserted the advertising mode is reset to match the supported modes of the module. Signed-off-by: Nathan Rossi Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/phy/phylink.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 6072e87ed6c3..025c3246f339 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1493,6 +1493,32 @@ int phylink_ethtool_ksettings_set(struct phylink *pl, if (config.an_enabled && phylink_is_empty_linkmode(config.advertising)) return -EINVAL; + /* If this link is with an SFP, ensure that changes to advertised modes + * also cause the associated interface to be selected such that the + * link can be configured correctly. + */ + if (pl->sfp_port && pl->sfp_bus) { + config.interface = sfp_select_interface(pl->sfp_bus, + config.advertising); + if (config.interface == PHY_INTERFACE_MODE_NA) { + phylink_err(pl, + "selection of interface failed, advertisement %*pb\n", + __ETHTOOL_LINK_MODE_MASK_NBITS, + config.advertising); + return -EINVAL; + } + + /* Revalidate with the selected interface */ + linkmode_copy(support, pl->supported); + if (phylink_validate(pl, support, &config)) { + phylink_err(pl, "validation of %s/%s with support %*pb failed\n", + phylink_an_mode_str(pl->cur_link_an_mode), + phy_modes(config.interface), + __ETHTOOL_LINK_MODE_MASK_NBITS, support); + return -EINVAL; + } + } + mutex_lock(&pl->state_mutex); pl->link_config.speed = config.speed; pl->link_config.duplex = config.duplex; @@ -2072,7 +2098,9 @@ static int phylink_sfp_config(struct phylink *pl, u8 mode, if (phy_interface_mode_is_8023z(iface) && pl->phydev) return -EINVAL; - changed = !linkmode_equal(pl->supported, support); + changed = !linkmode_equal(pl->supported, support) || + !linkmode_equal(pl->link_config.advertising, + config.advertising); if (changed) { linkmode_copy(pl->supported, support); linkmode_copy(pl->link_config.advertising, config.advertising); -- 2.33.0