Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp465222rdf; Tue, 21 Nov 2023 07:27:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyxrfTG8MfmVr7smcbnukU0nM6pyMi3dI9c4Oe32xQGmQz9fcVx+3Nr1N5OO+x5vm0Ifkj X-Received: by 2002:a17:902:dad1:b0:1cf:56e1:ba98 with SMTP id q17-20020a170902dad100b001cf56e1ba98mr10639989plx.18.1700580469237; Tue, 21 Nov 2023 07:27:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700580469; cv=none; d=google.com; s=arc-20160816; b=LpQy75TERj5eDkuYsWhnqRUqk7kaYjhOMjEjNd18wrZ+KQ1bPdvKoimQcV8SrMmFS3 1lsPN7AxvmRhWWAU0cvbBhXcxHBzjXPU/4sVJVGiQfCmQRDjQmT6s9Ez9rdjUxlFE96d RnmK6CmFknAANHQ4VLTFBFz7V0mWEzXOPlLEssHI7GgwO5aBl7aYCvdDKxvG7NPmfgNf N9eetUvT0p2djXMEEc1zdc8/zNUkfHmNDlwzsV7Rbo3WVYhNXUE54wP4Y90DJIm+AATh lkZSyyT6d87vnUvnSzbwBlHN8g6lJ+Q+gQ5/9ykl4Td/G1FovKGzbu/Mq1wHGWBjAdiY dsBQ== 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; bh=2pNST/XYOY9xlsze7vhjq8JDuva8PkwxQyz4lFygRXs=; fh=M1qfrahb/qW7n6G/0kHpmUybK+Ky3Jq5+sps382+aZ4=; b=MpUPTv0851eeY8s+MEsmuJ4jSoO4khcdzcVOOoTPyPqIFo0zvIhm5MfNQ4GnHRvEWp t/2EyokU3D49J0Y4P4vQVbrvMysesX0Byg5np+6Cr2u8OiRpIlceeeglSBtD1gUxiq4L sfPrAtHrI0tf8WcFhzKhCIM6b3fur2Clu8k1wi06I1Hw8Um9IDXWYqidp71NRHCT2YJ/ wvdAcLgx6k4LAKoFF33PIrbin9ku+ESjteCf9mbPgj/qRRlHKbjtZNmsjgonoYIz7xic /HM3HxmsgN3JXyMJeXruhqTcV3cGyglBEkBVaDqttpzPj6LHEcN7UoDpkw6ESu+1ZBpb KcBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id p11-20020a170902e74b00b001cf6aae59c0si2729203plf.564.2023.11.21.07.27.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 07:27:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id C392480289C7; Tue, 21 Nov 2023 07:25:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234320AbjKUPYo (ORCPT + 99 others); Tue, 21 Nov 2023 10:24:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234325AbjKUPYm (ORCPT ); Tue, 21 Nov 2023 10:24:42 -0500 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F154134 for ; Tue, 21 Nov 2023 07:24:37 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r5Sc0-000608-I4; Tue, 21 Nov 2023 16:24:28 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r5Sbz-00Ac94-Dd; Tue, 21 Nov 2023 16:24:27 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1r5Sbz-00HZfu-1B; Tue, 21 Nov 2023 16:24:27 +0100 From: Oleksij Rempel To: "David S. Miller" , Andrew Lunn , Eric Dumazet , Florian Fainelli , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , Woojung Huh , Arun Ramadoss Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com Subject: [PATCH net-next v1 2/3] net: dsa: microchip: Remove redundant optimization in ksz8_w_phy_bmcr Date: Tue, 21 Nov 2023 16:24:25 +0100 Message-Id: <20231121152426.4188456-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231121152426.4188456-1-o.rempel@pengutronix.de> References: <20231121152426.4188456-1-o.rempel@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 21 Nov 2023 07:25:06 -0800 (PST) Remove the manual checks for register value changes in the ksz8_w_phy_bmcr function. Instead, rely on regmap_update_bits() for optimizing register updates. Signed-off-by: Oleksij Rempel --- drivers/net/dsa/microchip/ksz8795.c | 95 +++++++++-------------------- 1 file changed, 28 insertions(+), 67 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 835157815937..4c1e21fd87da 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -951,107 +951,68 @@ static int ksz8_w_phy_ctrl(struct ksz_device *dev, int port, u16 val) static int ksz8_w_phy_bmcr(struct ksz_device *dev, int port, u16 val) { const u16 *regs = dev->info->regs; - u8 restart, ctrl, speed, data; + u8 restart, speed, ctrl, restart_mask; int ret; /* Do not support PHY reset function. */ if (val & BMCR_RESET) return 0; - ret = ksz_pread8(dev, port, regs[P_SPEED_STATUS], &speed); - if (ret) - return ret; - - data = speed; + speed = 0; if (val & KSZ886X_BMCR_HP_MDIX) - data |= PORT_HP_MDIX; - else - data &= ~PORT_HP_MDIX; - - if (data != speed) { - ret = ksz_pwrite8(dev, port, regs[P_SPEED_STATUS], data); - if (ret) - return ret; - } + speed |= PORT_HP_MDIX; - ret = ksz_pread8(dev, port, regs[P_FORCE_CTRL], &ctrl); + ret = ksz_prmw8(dev, port, regs[P_SPEED_STATUS], PORT_HP_MDIX, speed); if (ret) return ret; - data = ctrl; + ctrl = 0; if (ksz_is_ksz88x3(dev)) { if ((val & BMCR_ANENABLE)) - data |= PORT_AUTO_NEG_ENABLE; - else - data &= ~PORT_AUTO_NEG_ENABLE; + ctrl |= PORT_AUTO_NEG_ENABLE; } else { if (!(val & BMCR_ANENABLE)) - data |= PORT_AUTO_NEG_DISABLE; - else - data &= ~PORT_AUTO_NEG_DISABLE; + ctrl |= PORT_AUTO_NEG_DISABLE; /* Fiber port does not support auto-negotiation. */ if (dev->ports[port].fiber) - data |= PORT_AUTO_NEG_DISABLE; + ctrl |= PORT_AUTO_NEG_DISABLE; } if (val & BMCR_SPEED100) - data |= PORT_FORCE_100_MBIT; - else - data &= ~PORT_FORCE_100_MBIT; + ctrl |= PORT_FORCE_100_MBIT; if (val & BMCR_FULLDPLX) - data |= PORT_FORCE_FULL_DUPLEX; - else - data &= ~PORT_FORCE_FULL_DUPLEX; + ctrl |= PORT_FORCE_FULL_DUPLEX; - if (data != ctrl) { - ret = ksz_pwrite8(dev, port, regs[P_FORCE_CTRL], data); - if (ret) - return ret; - } - - ret = ksz_pread8(dev, port, regs[P_NEG_RESTART_CTRL], &restart); + ret = ksz_prmw8(dev, port, regs[P_FORCE_CTRL], PORT_FORCE_100_MBIT | + /* PORT_AUTO_NEG_ENABLE and PORT_AUTO_NEG_DISABLE are the same + * bits + */ + PORT_FORCE_FULL_DUPLEX | PORT_AUTO_NEG_ENABLE, ctrl); if (ret) return ret; - data = restart; + restart = 0; + restart_mask = PORT_LED_OFF | PORT_TX_DISABLE | PORT_AUTO_NEG_RESTART | + PORT_POWER_DOWN | PORT_AUTO_MDIX_DISABLE | PORT_FORCE_MDIX | + PORT_PHY_LOOPBACK; if (val & KSZ886X_BMCR_DISABLE_LED) - data |= PORT_LED_OFF; - else - data &= ~PORT_LED_OFF; + restart |= PORT_LED_OFF; if (val & KSZ886X_BMCR_DISABLE_TRANSMIT) - data |= PORT_TX_DISABLE; - else - data &= ~PORT_TX_DISABLE; + restart |= PORT_TX_DISABLE; if (val & BMCR_ANRESTART) - data |= PORT_AUTO_NEG_RESTART; - else - data &= ~(PORT_AUTO_NEG_RESTART); + restart |= PORT_AUTO_NEG_RESTART; if (val & BMCR_PDOWN) - data |= PORT_POWER_DOWN; - else - data &= ~PORT_POWER_DOWN; + restart |= PORT_POWER_DOWN; if (val & KSZ886X_BMCR_DISABLE_AUTO_MDIX) - data |= PORT_AUTO_MDIX_DISABLE; - else - data &= ~PORT_AUTO_MDIX_DISABLE; + restart |= PORT_AUTO_MDIX_DISABLE; if (val & KSZ886X_BMCR_FORCE_MDI) - data |= PORT_FORCE_MDIX; - else - data &= ~PORT_FORCE_MDIX; + restart |= PORT_FORCE_MDIX; if (val & BMCR_LOOPBACK) - data |= PORT_PHY_LOOPBACK; - else - data &= ~PORT_PHY_LOOPBACK; + restart |= PORT_PHY_LOOPBACK; - if (data != restart) { - ret = ksz_pwrite8(dev, port, regs[P_NEG_RESTART_CTRL], - data); - if (ret) - return ret; - } - - return 0; + return ksz_prmw8(dev, port, regs[P_NEG_RESTART_CTRL], restart_mask, + restart); } int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val) -- 2.39.2