Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2314954rdd; Fri, 12 Jan 2024 06:08:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IEC7FIrUUpLY1pRU5CIOcQRrrXVNs83SNrg+YI1QfkdoN9Q1tabHqzv//Tf5dVqqgIy3ZWN X-Received: by 2002:a05:6a21:7893:b0:19a:55a7:6799 with SMTP id bf19-20020a056a21789300b0019a55a76799mr1076765pzc.41.1705068484582; Fri, 12 Jan 2024 06:08:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705068484; cv=none; d=google.com; s=arc-20160816; b=R8ixx06Uet3roXCtDSfr3j8HY0BM0j/EHSvMzwLKPIxuPV02lXw/4yayF2HCMZ0vd9 bgGMF/zceFdTIACh3ID+xHJjozpqeuK5OygIEUvscFDXdg+gDZEAIQrzVAbpO2R9P+Gy 5GMctl3NOx+mT+nDpv8H9KpqMjrYQ7jX/N7b6LP5zl0OetixFVbMn3gYp4PuyPrdv+wH 4z610qML3zns9EW5DozgSlu96qMjR3TDCWwOZkDvxdinoYFgyoUdhMexERUyhupxetWC LcuGFZ0fizapgz8A7WAbYWIQ68k8/dt0OlYmQo3n2lTD0Su2+/74XJjpI0bQQ/8hr+uC Mo1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=RiRrSSLr5SyfdyeLfkhsU+zqNg4/9eDfQmjqOYEinJI=; fh=kARw4Za9FSyMqdUPVbzOMy/882hiHHItvXRZJtJwrPg=; b=twSCgGhGiot0fRpWLD5PwoMDOC9KIMaIPxdijKQcV9iW44hBPRH8oOvmjqTt59/sM6 7/dj8Ns1XQkS4gYapERLhCPLT2Iojzx/aNE7ate6e+RBM72HD+SRfbKDxL1bZ6lo+eJK uSJCTaVdEMziwrXmCpQ0Y1brgVTkYVAYXfAdmNuvFFErr2eZJD2+ljiSD/KsL/YL6qK/ PVwqelssWnYvrlCaB+SguHk2hqSkrX6+nSrVrxcdUwpYK6mGnhJ5an2gMtrzB4p3po6x hkINQatQOwpEQU+4Paw0AJHJJAIiIwV6XVt69LIhFqjUjLE/W56n1a2Ewu0YJ98t5fjV yiEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-24726-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24726-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id by41-20020a056a0205a900b005ce19c68684si3733992pgb.495.2024.01.12.06.08.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 06:08:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24726-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-24726-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24726-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 44E65285781 for ; Fri, 12 Jan 2024 14:08:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5BE1D6DCF6; Fri, 12 Jan 2024 14:07:37 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73FD96D1C6 for ; Fri, 12 Jan 2024 14:07:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de 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 1rOIBr-0000z8-Hy; Fri, 12 Jan 2024 15:07:19 +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 1rOIBp-002AeW-VJ; Fri, 12 Jan 2024 15:07:17 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rOIBp-00BOU0-2r; Fri, 12 Jan 2024 15:07:17 +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 , Vladimir Oltean , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com Subject: [RFC net-next v3 2/3] net: dsa: microchip: Remove redundant optimization in ksz8_w_phy_bmcr Date: Fri, 12 Jan 2024 15:07:15 +0100 Message-Id: <20240112140716.2715664-3-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240112140716.2715664-1-o.rempel@pengutronix.de> References: <20240112140716.2715664-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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 Reviewed-by: Vladimir Oltean Acked-by: Arun Ramadoss --- drivers/net/dsa/microchip/ksz8795.c | 96 +++++++++-------------------- 1 file changed, 29 insertions(+), 67 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 1269dde832bd..51e0194453df 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -956,115 +956,77 @@ static int ksz8_w_phy_ctrl(struct ksz_device *dev, int port, u16 val) */ static int ksz8_w_phy_bmcr(struct ksz_device *dev, u16 port, u16 val) { + u8 restart, speed, ctrl, restart_mask; const u16 *regs = dev->info->regs; - u8 restart, ctrl, speed, data; 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; - - if (data != ctrl) { - ret = ksz_pwrite8(dev, port, regs[P_FORCE_CTRL], data); - if (ret) - return ret; - } + ctrl |= PORT_FORCE_FULL_DUPLEX; - 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; - - if (data != restart) { - ret = ksz_pwrite8(dev, port, regs[P_NEG_RESTART_CTRL], - data); - if (ret) - return ret; - } + restart |= PORT_PHY_LOOPBACK; - 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