Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp915505pxu; Wed, 6 Jan 2021 07:42:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJyu6t7b2USsMQ+aBiupXq2ckkecGNcvRSQGGc9E3htdKpPmEwH+7adVjsgKNQxHXOJUfdGe X-Received: by 2002:a05:6402:30ac:: with SMTP id df12mr4529357edb.175.1609947738615; Wed, 06 Jan 2021 07:42:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609947738; cv=none; d=google.com; s=arc-20160816; b=M8Fv8inh05lMVMeX0WFBfhAFP5+uT12XFCSN9h1U/1YQdnvdiWWu2mVl4cFmjRi7fB TV+iinmQ5lu5cIyY4GOf8klu86hgsFmuAgdAOavEZRiKgY1x+WtE046Afzh0V/nar/3A uI7TwRZdqs3BnwNRcyXiFhQ9jIBP33bQSX9YZfZl+5j034qR9uupQGCs6CLf81jE+JKb m8uds6R7f1wHBHUbFCwO7nBbRcrVPp9O0CB/w0v8Ek/XcKE6ckjlooizO2DpyhlkASTB kgiuZvDWRXGQPRn7G1cQc+SuLvWlgAv7ic/MOGut3QcB/YxO7z47VaTZi4auUUXciM1R /poA== 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=1VL5lbP5ieT6c9B8AURse4A+ERvhdqVbRaeJJOBEw/c=; b=DFHuQcurXFElXjldGT9nva/TCa1kGMh9kQvDvVnfgd4ITQ60iR7qLYK4r+ht/CsP8h rQd4N82ivplC48+Tsr2c7sOmEPt5KzZArAtXI1kZ2KV+j37c/oDgN5ruwjrSVget4IgE 50NbgYedZXzhm/xsxHRvNSiPq5+w8IZKqsDQWG19KfixzZBPlOzHeK+oWKyEgltqNrSv 2daBjo/E4cbQ5rmLLRDkMBh39Q5VqqIazoX20CfVGPxFEvk+ZmI9UxOR7bWYsq7/rrBH nW8tZMi3uexk6xSCNmbLNZ8ZelvSAHPkosecKfCtop2u8a0LuB2t4+49gLUTOJSDiPi/ KKHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CAs0zfHQ; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y7si1098542edp.7.2021.01.06.07.41.54; Wed, 06 Jan 2021 07:42:18 -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=@kernel.org header.s=k20201202 header.b=CAs0zfHQ; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727177AbhAFPj0 (ORCPT + 99 others); Wed, 6 Jan 2021 10:39:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:41898 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726165AbhAFPjY (ORCPT ); Wed, 6 Jan 2021 10:39:24 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C8FEE23120; Wed, 6 Jan 2021 15:38:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609947523; bh=ULOW1MbfEc92miB+HDwds4nm4ZJaMXzTrInSe+HvzKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CAs0zfHQS07/sykdHjoDmwuenSHb4Mnpegxhgh+jstmG7kUdThulfvo5t/V/oXHA8 0N5/6+UlLtHYRwVt+eHuQO2NzMe+T2bvAxDDTgfqZlMnniL3+1EFqVRXG8/FW0wwbW LvVbM8jLUMvWOhUxasjbzMDsezn4zbacWcz9GN+b35kCRAnmNR7BJnUUgbcMPVjetH 1SxEUThBhpvYIAU+/8SDctSdTGR1V5sC8XJTG9w7WgqeUmzOHEYWSXPqUO8h/Cg2Ce iupE+oyiZdTIttjmvhW2qtP8LDSeJ5+2ilGWLAWwAfKhzQaiNep5CNK63OI+XjJeD/ Z9DwZZVJYzOog== Received: by pali.im (Postfix) id 112D944E; Wed, 6 Jan 2021 16:38:42 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Russell King - ARM Linux admin , Andrew Lunn , "David S. Miller" , Jakub Kicinski Cc: Thomas Schreiber , Heiner Kallweit , =?UTF-8?q?Marek=20Beh=C3=BAn?= , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] net: sfp: assume that LOS is not implemented if both LOS normal and inverted is set Date: Wed, 6 Jan 2021 16:37:48 +0100 Message-Id: <20210106153749.6748-3-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210106153749.6748-1-pali@kernel.org> References: <20201230154755.14746-1-pali@kernel.org> <20210106153749.6748-1-pali@kernel.org> 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: Russell King Some GPON SFP modules (e.g. Ubiquiti U-Fiber Instant) have set both SFP_OPTIONS_LOS_INVERTED and SFP_OPTIONS_LOS_NORMAL bits in their EEPROM. Such combination of bits is meaningless so assume that LOS signal is not implemented. This patch fixes link carrier for GPON SFP module Ubiquiti U-Fiber Instant. Signed-off-by: Russell King Signed-off-by: Pali Rohár --- Changes in v2: * Fix author/signed-off-by lines --- drivers/net/phy/sfp.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index c0a891cdcd73..15fb8f7dfe5b 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -1488,15 +1488,19 @@ static void sfp_sm_link_down(struct sfp *sfp) static void sfp_sm_link_check_los(struct sfp *sfp) { - unsigned int los = sfp->state & SFP_F_LOS; + const __be16 los_inverted = cpu_to_be16(SFP_OPTIONS_LOS_INVERTED); + const __be16 los_normal = cpu_to_be16(SFP_OPTIONS_LOS_NORMAL); + __be16 los_options = sfp->id.ext.options & (los_inverted | los_normal); + bool los = false; /* If neither SFP_OPTIONS_LOS_INVERTED nor SFP_OPTIONS_LOS_NORMAL - * are set, we assume that no LOS signal is available. + * are set, we assume that no LOS signal is available. If both are + * set, we assume LOS is not implemented (and is meaningless.) */ - if (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_INVERTED)) - los ^= SFP_F_LOS; - else if (!(sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_NORMAL))) - los = 0; + if (los_options == los_inverted) + los = !(sfp->state & SFP_F_LOS); + else if (los_options == los_normal) + los = !!(sfp->state & SFP_F_LOS); if (los) sfp_sm_next(sfp, SFP_S_WAIT_LOS, 0); @@ -1506,18 +1510,22 @@ static void sfp_sm_link_check_los(struct sfp *sfp) static bool sfp_los_event_active(struct sfp *sfp, unsigned int event) { - return (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_INVERTED) && - event == SFP_E_LOS_LOW) || - (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_NORMAL) && - event == SFP_E_LOS_HIGH); + const __be16 los_inverted = cpu_to_be16(SFP_OPTIONS_LOS_INVERTED); + const __be16 los_normal = cpu_to_be16(SFP_OPTIONS_LOS_NORMAL); + __be16 los_options = sfp->id.ext.options & (los_inverted | los_normal); + + return (los_options == los_inverted && event == SFP_E_LOS_LOW) || + (los_options == los_normal && event == SFP_E_LOS_HIGH); } static bool sfp_los_event_inactive(struct sfp *sfp, unsigned int event) { - return (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_INVERTED) && - event == SFP_E_LOS_HIGH) || - (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_LOS_NORMAL) && - event == SFP_E_LOS_LOW); + const __be16 los_inverted = cpu_to_be16(SFP_OPTIONS_LOS_INVERTED); + const __be16 los_normal = cpu_to_be16(SFP_OPTIONS_LOS_NORMAL); + __be16 los_options = sfp->id.ext.options & (los_inverted | los_normal); + + return (los_options == los_inverted && event == SFP_E_LOS_HIGH) || + (los_options == los_normal && event == SFP_E_LOS_LOW); } static void sfp_sm_fault(struct sfp *sfp, unsigned int next_state, bool warn) -- 2.20.1