Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp480839imi; Fri, 22 Jul 2022 03:20:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tiGilUULB1cmyyVi8Sg/1ab/GqSwxpWnF8UphziUDVwJcZ1RgmTOolEou9q76UXQOTWzQ0 X-Received: by 2002:a05:6a00:a12:b0:527:dba9:c416 with SMTP id p18-20020a056a000a1200b00527dba9c416mr2745843pfh.33.1658485258846; Fri, 22 Jul 2022 03:20:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658485258; cv=none; d=google.com; s=arc-20160816; b=HGtDK1F55aVfYpZgGR5DMvnkE+8IIfoTNUC0haE3ElpHjZ3YJD/HIzNtN48rp/nvrp 9Vy7F0W2VFDc1z9rGqil6FERtHCZbISox2zU3DVYwzJM7A02ucIBtJzJdXPNNEAJdNyI Fa9IQ3+ROuxD4PsTDGFb578MCRLNwKy9tYHeinBCb/oag2tR5ldZ2vjxpNS+xx4eLYlz JOhWFZ14Omz2YQZG7bfucnq3VG2V16MvEiFm/DjsvmYbClmNoqKmbvVk0PT8Oeh6sZRz 872U5iecs1MSBIVqX3c54zIUGgKlqE3R2APnny6mOqMVLVT7LVSIItH5Un6Mm5wFP8J6 oRKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=I/TeU7vG/TCOeE+ZVogJWf8GrihqAvOKUnOuXWXxgFM=; b=cx8IaK8u86UEi2zTEgomTHdLsK88zx+ZQO1li4ZmlQySDWJ/epuqrc+zRjFIbJxVVO eY/SPVwEPcCOBObYF7Xqw9x0C+baPwTwnPtiWAEj69i4o08DVrYeaqrQK5ujI0ByhSf7 dUxttu4Bl1lJwqt37IkZL0c2DYcjjpBELU1YWfyBjHdpFaCVvvgaUxGQTfg9n3n+ZTuJ Mu61ttkvYhWHz5HKkY64XPWAvZMhOTSUzcBDLn3Y7tDJgTyiV5FKYB+KEo472hSwV7Cp kNVCeAOvvfnpZ169vlWJxLmPKQcHlE0PsCGJJ/gkyN9bVE8fNGdHOt7uoqCbMGxydCPp Hu5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=gpVqBUul; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y188-20020a6364c5000000b00411f660a8b0si5193747pgb.124.2022.07.22.03.20.43; Fri, 22 Jul 2022 03:20:58 -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=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=gpVqBUul; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235088AbiGVKKM (ORCPT + 99 others); Fri, 22 Jul 2022 06:10:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234772AbiGVKKI (ORCPT ); Fri, 22 Jul 2022 06:10:08 -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 ACFA3BC3; Fri, 22 Jul 2022 03:10:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding: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=I/TeU7vG/TCOeE+ZVogJWf8GrihqAvOKUnOuXWXxgFM=; b=gpVqBUulvPzgezoxNMRIKP2SGb drQsSP3WP7roNnSXfozLzw/HXwmUhHl6WR2lUaAps63KJzLx0TCnLASXZnAIJx5SMuck8cObaFgwM vzNPCbt4GJj5qOJ0FNb6uENG4gEuaeddmhI1bzhN8Qvm5XmcSt1pUYwjtTd9pY24AQqRo+ZlMWZ2G y99Xl5/V7lmuCggMcxw2zEVQ64M5+9T5f94ZWp5/hDP0Q+plfcZ+LTNEBZCf9z9divaWjTeC5pZq8 dBxbIZfpbkmwsfJuTRIfnH42EIveQsG7kzEO/AKy5VXUsmtfJxrEhfTupUaMsNT9hafFmCf91agHB hpDb90ng==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:33504) 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 1oEpbc-0006lj-R2; Fri, 22 Jul 2022 11:10:00 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1oEpba-0005k8-67; Fri, 22 Jul 2022 11:09:58 +0100 Date: Fri, 22 Jul 2022 11:09:58 +0100 From: "Russell King (Oracle)" To: Arun Ramadoss Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: Re: [Patch net-next v1 3/9] net: dsa: microchip: add common duplex and flow control function Message-ID: References: <20220722092459.18653-1-arun.ramadoss@microchip.com> <20220722092459.18653-4-arun.ramadoss@microchip.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220722092459.18653-4-arun.ramadoss@microchip.com> Sender: Russell King (Oracle) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE 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 Hi, On Fri, Jul 22, 2022 at 02:54:53PM +0530, Arun Ramadoss wrote: > +void ksz_set_fullduplex(struct ksz_device *dev, int port, bool val) > +{ > + const u8 *bitval = dev->info->xmii_ctrl0; > + const u16 *regs = dev->info->regs; > + u8 data8; > + > + ksz_pread8(dev, port, regs[P_XMII_CTRL_0], &data8); > + > + data8 &= ~P_MII_DUPLEX_M; > + > + if (val) > + data8 |= FIELD_PREP(P_MII_DUPLEX_M, > + bitval[P_MII_FULL_DUPLEX]); > + else > + data8 |= FIELD_PREP(P_MII_DUPLEX_M, > + bitval[P_MII_HALF_DUPLEX]); > + > + ksz_pwrite8(dev, port, regs[P_XMII_CTRL_0], data8); > +} > + > +void ksz_set_tx_pause(struct ksz_device *dev, int port, bool val) > +{ > + const u32 *masks = dev->info->masks; > + const u16 *regs = dev->info->regs; > + u8 data8; > + > + ksz_pread8(dev, port, regs[P_XMII_CTRL_0], &data8); > + > + if (val) > + data8 |= masks[P_MII_TX_FLOW_CTRL]; > + else > + data8 &= ~masks[P_MII_TX_FLOW_CTRL]; > + > + ksz_pwrite8(dev, port, regs[P_XMII_CTRL_0], data8); > +} > + > +void ksz_set_rx_pause(struct ksz_device *dev, int port, bool val) > +{ > + const u32 *masks = dev->info->masks; > + const u16 *regs = dev->info->regs; > + u8 data8; > + > + ksz_pread8(dev, port, regs[P_XMII_CTRL_0], &data8); > + > + if (val) > + data8 |= masks[P_MII_RX_FLOW_CTRL]; > + else > + data8 &= ~masks[P_MII_RX_FLOW_CTRL]; > + > + ksz_pwrite8(dev, port, regs[P_XMII_CTRL_0], data8); > +} > + Having looked through all the proposed patches and noticed that these three functions are always called serially. What is the reason to make these separate functions which all read the same register, modify a single bit, and then write it back. What we end up with is the following sequence: - read P_XMII_CTRL_0 - udpate P_MII_HALF_DUPLEX bit - write P_XMII_CTRL_0 - read P_XMII_CTRL_0 - update P_MII_TX_FLOW_CTRL bit - write P_XMII_CTRL_0 - read P_XMII_CTRL_0 - update P_MII_RX_FLOW_CTRL bit - write P_XMII_CTRL_0 whereas the original code did: - read P_XMII_CTRL_0 - udpate P_MII_HALF_DUPLEX, P_MII_TX_FLOW_CTRL and P_MII_RX_FLOW_CTRL bits - write P_XMII_CTRL_0 which was much more efficient, not only in terms of CPU cycles, but also IO cycles and code size. You could do this instead: u8 mask, val, ctrl0; mask = P_MII_DUPLEX_M | masks[P_MII_TX_FLOW_CTRL] | masks[P_MII_RX_FLOW_CTRL]; if (duplex == DUPLEX_FULL) val = FIELD_PREP(P_MII_DUPLEX_M, bitval[P_MII_FULL_DUPLEX]); else val = FIELD_PREP(P_MII_DUPLEX_M, bitval[P_MII_HALF_DUPLEX]); if (tx_pause) val |= masks[P_MII_TX_FLOW_CTRL]; if (rx_pause) val |= masks[P_MII_RX_FLOW_CTRL]; ksz_pread8(dev, port, REG_PORT_XMII_CTRL_0, &ctrl0); ctrl0 = (ctrl0 & ~mask) | val; ksz_pwrite8(dev, port, REG_PORT_XMII_CTRL_0, ctrl0); and maybe convert that last three lines into a helper, ksz_pmodify8() which could be useful in other parts of the driver where you do a read-modify-write operation on a register. Thanks. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!