Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4050022rwb; Sun, 9 Oct 2022 16:51:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ZbSy4UJAdYJdFJ1+jjFxMqaK7Ztvx4h8yElad6iYrw97QxlVxZD/5TWEJy5p1AJkrlSHg X-Received: by 2002:a63:e211:0:b0:43b:f03e:3cc5 with SMTP id q17-20020a63e211000000b0043bf03e3cc5mr14454526pgh.256.1665359464418; Sun, 09 Oct 2022 16:51:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665359464; cv=none; d=google.com; s=arc-20160816; b=tJaHlxh4tM3qfvXsHqR4EDHa6dQtmBqQxByfcdQ76j8wP02W6v6XBNg3PzO+dU14er iBvGnjSuSMdUbnr1JyghnNnMtjtZ3PPcaWNpMIfYkQv7wzhy7pp00pXpbFrS4eQfBvFM nexS9qlqZnO9GP/AJWUGVo5cOQ1KFcCfhmi4ZmhczXv/7aT5jsNzylt92bYeJUeXYPnG PF/F+X9OvwABHfbKDmUikT+b6SVApPxjS/aIblOHxVjGKy29pi1TvMw1f5lLLk7EZaNS T07VFRY+jS1W+c4nlaolgfqLAg+6mneFJ2Dtya6zeJZo0je2XNJ7aYqJVgpPRHOQVTJ6 KhhQ== 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=AqQSR9Qo6YDatGhdzgXae672nLs1ndncJiUnneDOo4c=; b=QztcfG9vdM73Bxkuyj+wEMibQgkMLikMb004dTsO1CfGS+OFPXLQfoBHdP2skvbD57 Gsmn03kknZRsaYh9Z0qfivJuQm4kmVuCdRA3Cc6C5500jcrV9IWGHq7Uev2vXK9oDoKV nz3hoZSvQYMWy+Ig1lGBuWW+Z5bLaBtN6Y4QDEkL/i4abss+X18qQnFNVM+9Q9ZTDiX2 6IHQIvAk4AQVOoqsK4iNbAhP4CSi6VS9R9SXoVzGQ7HFu7XDlIBWKfuzTGtXxaMgSSFJ 17+8d3Lz//VST9T23CpkEYB883fzfUfbzrJgJYweSgwSem1Sa+X4JF9ayGecSfclovwd WzvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y7nFr7P1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f130-20020a636a88000000b0043961d06e6bsi10769790pgc.787.2022.10.09.16.50.53; Sun, 09 Oct 2022 16:51:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y7nFr7P1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232080AbiJIW1J (ORCPT + 99 others); Sun, 9 Oct 2022 18:27:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231819AbiJIWZW (ORCPT ); Sun, 9 Oct 2022 18:25:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B3053055D; Sun, 9 Oct 2022 15:18:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CE744B80DE1; Sun, 9 Oct 2022 22:12:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2FB52C433B5; Sun, 9 Oct 2022 22:12:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665353529; bh=49NXGqeSyT6CbiSBoQCNCv8DGcGSR3INQBaat4vue+I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y7nFr7P1UsMjstVmJh1sZyGdxtwCU0h9xYXaFwDtB7GnqcS+l3fVKRd0iGMdp7TwR oZ1N35mc6ypromUWTu+T/R0cRpDRVs78RYdPrdB1Z31WZBaPD50ceeTt5z+wUCUbMx nyppDp8ddZ9ccaIwaStMf7J+NjzQS6viIwgNtsHq5xDvBV95CONtUVSoh3DAREEBq6 cp0feTN4sA3ccjoigWJ031U0z8jhY4JMwcSeG6AJNie1wywmQKFXdqm6zJNztnX544 CKr+mOA8oSGy2tIxg7zbABnoZt0nJcCMx1897QIGD4tpELF893KCLljQTski3wQBOL nirfPESuPQ1kA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Russell King (Oracle)" , Jakub Kicinski , Sasha Levin , linux@armlinux.org.uk, andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 6.0 52/77] net: sfp: re-implement soft state polling setup Date: Sun, 9 Oct 2022 18:07:29 -0400 Message-Id: <20221009220754.1214186-52-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009220754.1214186-1-sashal@kernel.org> References: <20221009220754.1214186-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Russell King (Oracle)" [ Upstream commit 8475c4b70b040f9d8cbc308100f2c4d865f810b3 ] Re-implement the decision making for soft state polling. Instead of generating the soft state mask in sfp_soft_start_poll() by looking at which GPIOs are available, record their availability in sfp_sm_mod_probe() in sfp->state_hw_mask. This will then allow us to clear bits in sfp->state_hw_mask in module specific quirks when the hardware signals should not be used, thereby allowing us to switch to using the software state polling. Signed-off-by: Russell King (Oracle) Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/phy/sfp.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 63f90fe9a4d2..a38705cf192f 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -234,6 +234,7 @@ struct sfp { bool need_poll; struct mutex st_mutex; /* Protects state */ + unsigned int state_hw_mask; unsigned int state_soft_mask; unsigned int state; struct delayed_work poll; @@ -499,17 +500,18 @@ static void sfp_soft_set_state(struct sfp *sfp, unsigned int state) static void sfp_soft_start_poll(struct sfp *sfp) { const struct sfp_eeprom_id *id = &sfp->id; + unsigned int mask = 0; sfp->state_soft_mask = 0; - if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_DISABLE && - !sfp->gpio[GPIO_TX_DISABLE]) - sfp->state_soft_mask |= SFP_F_TX_DISABLE; - if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_FAULT && - !sfp->gpio[GPIO_TX_FAULT]) - sfp->state_soft_mask |= SFP_F_TX_FAULT; - if (id->ext.enhopts & SFP_ENHOPTS_SOFT_RX_LOS && - !sfp->gpio[GPIO_LOS]) - sfp->state_soft_mask |= SFP_F_LOS; + if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_DISABLE) + mask |= SFP_F_TX_DISABLE; + if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_FAULT) + mask |= SFP_F_TX_FAULT; + if (id->ext.enhopts & SFP_ENHOPTS_SOFT_RX_LOS) + mask |= SFP_F_LOS; + + // Poll the soft state for hardware pins we want to ignore + sfp->state_soft_mask = ~sfp->state_hw_mask & mask; if (sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT) && !sfp->need_poll) @@ -523,10 +525,11 @@ static void sfp_soft_stop_poll(struct sfp *sfp) static unsigned int sfp_get_state(struct sfp *sfp) { - unsigned int state = sfp->get_state(sfp); + unsigned int soft = sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT); + unsigned int state; - if (state & SFP_F_PRESENT && - sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT)) + state = sfp->get_state(sfp) & sfp->state_hw_mask; + if (state & SFP_F_PRESENT && soft) state |= sfp_soft_get_state(sfp); return state; @@ -1947,6 +1950,15 @@ static int sfp_sm_mod_probe(struct sfp *sfp, bool report) if (ret < 0) return ret; + /* Initialise state bits to use from hardware */ + sfp->state_hw_mask = SFP_F_PRESENT; + if (sfp->gpio[GPIO_TX_DISABLE]) + sfp->state_hw_mask |= SFP_F_TX_DISABLE; + if (sfp->gpio[GPIO_TX_FAULT]) + sfp->state_hw_mask |= SFP_F_TX_FAULT; + if (sfp->gpio[GPIO_LOS]) + sfp->state_hw_mask |= SFP_F_LOS; + if (!memcmp(id.base.vendor_name, "ALCATELLUCENT ", 16) && !memcmp(id.base.vendor_pn, "3FE46541AA ", 16)) sfp->module_t_start_up = T_START_UP_BAD_GPON; @@ -2573,6 +2585,8 @@ static int sfp_probe(struct platform_device *pdev) return PTR_ERR(sfp->gpio[i]); } + sfp->state_hw_mask = SFP_F_PRESENT; + sfp->get_state = sfp_gpio_get_state; sfp->set_state = sfp_gpio_set_state; -- 2.35.1