From patchwork Fri Oct 21 15:10:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 13014899 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 107F9C4167D for ; Fri, 21 Oct 2022 15:11:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230170AbiJUPKw (ORCPT ); Fri, 21 Oct 2022 11:10:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230222AbiJUPKQ (ORCPT ); Fri, 21 Oct 2022 11:10:16 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01432A52F6; Fri, 21 Oct 2022 08:10:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=CdzXJYSUP5pe0nNmt5zqsj5UcWBs/9HSTXlHf2H/4oI=; b=GiavR2ITDiDNg5NwEgCNHOormm Z8V5P4kgoO1G8OGNPeoQVH+DphOJwJAElTnj7e8Ho9oNFlj7JtgV+L8m9SsrVx1mviOtbLtdO6C5E wo4rjTwFACduJ1M57u4ViY01uRMOK4G+lRDg3CXrLQ3GE7Z+b8fJAf1W+M8nORlMNpYX4lsFxySSO 0ALfmi0HEy3dmj+MTvubb5db6llK57KoDW1SKK7XdL4W/X5H9JWRmmtNKbXwEnRO/7Wnj5nQ2/+Vf 2DX6zL3Q5YoUpEoBIgQemcRACt8u87/VwHpnsWc5eLwDLB2D50hfkD/W+Kn8xoe3zq1a3oA1Okesa eRwha3GQ==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:42514 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oltev-0000NA-8r; Fri, 21 Oct 2022 16:10:05 +0100 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1olteu-00FwxH-J5; Fri, 21 Oct 2022 16:10:04 +0100 In-Reply-To: References: From: "Russell King (Oracle)" To: "David S. Miller" , Jakub Kicinski Cc: Andrew Lunn , devicetree@vger.kernel.org, Eric Dumazet , Heiner Kallweit , Krzysztof Kozlowski , netdev@vger.kernel.org, Paolo Abeni , Rob Herring Subject: [PATCH net-next 6/7] net: sfp: add sfp_modify_u8() helper MIME-Version: 1.0 Content-Disposition: inline Message-Id: Sender: Russell King Date: Fri, 21 Oct 2022 16:10:04 +0100 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add a helper to modify bits in a single byte in memory space, and use it when updating the soft tx-disable flag in the module. Signed-off-by: Russell King (Oracle) --- drivers/net/phy/sfp.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 16bce0ea68d9..921bbedd9b22 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -608,6 +608,22 @@ static int sfp_write(struct sfp *sfp, bool a2, u8 addr, void *buf, size_t len) return sfp->write(sfp, a2, addr, buf, len); } +static int sfp_modify_u8(struct sfp *sfp, bool a2, u8 addr, u8 mask, u8 val) +{ + int ret; + u8 old, v; + + ret = sfp_read(sfp, a2, addr, &old, sizeof(old)); + if (ret != sizeof(old)) + return ret; + + v = (old & ~mask) | (val & mask); + if (v == old) + return sizeof(v); + + return sfp_write(sfp, a2, addr, &v, sizeof(v)); +} + static unsigned int sfp_soft_get_state(struct sfp *sfp) { unsigned int state = 0; @@ -633,17 +649,14 @@ static unsigned int sfp_soft_get_state(struct sfp *sfp) static void sfp_soft_set_state(struct sfp *sfp, unsigned int state) { - u8 status; + u8 mask = SFP_STATUS_TX_DISABLE_FORCE; + u8 val = 0; - if (sfp_read(sfp, true, SFP_STATUS, &status, sizeof(status)) == - sizeof(status)) { - if (state & SFP_F_TX_DISABLE) - status |= SFP_STATUS_TX_DISABLE_FORCE; - else - status &= ~SFP_STATUS_TX_DISABLE_FORCE; + if (state & SFP_F_TX_DISABLE) + val |= SFP_STATUS_TX_DISABLE_FORCE; - sfp_write(sfp, true, SFP_STATUS, &status, sizeof(status)); - } + + sfp_modify_u8(sfp, true, SFP_STATUS, mask, val); } static void sfp_soft_start_poll(struct sfp *sfp)