From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Arun Ramadoss <arun.ramadoss@microchip.com>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
Woojung Huh <woojung.huh@microchip.com>,
UNGLinuxDriver@microchip.com, Andrew Lunn <andrew@lunn.ch>,
Vivien Didelot <vivien.didelot@gmail.com>,
Florian Fainelli <f.fainelli@gmail.com>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Subject: Re: [Patch net-next v1 3/9] net: dsa: microchip: add common duplex and flow control function
Date: Fri, 22 Jul 2022 11:09:58 +0100 [thread overview]
Message-ID: <Ytp3dl5l9jkp94lU@shell.armlinux.org.uk> (raw)
In-Reply-To: <20220722092459.18653-4-arun.ramadoss@microchip.com>
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!
next prev parent reply other threads:[~2022-07-22 10:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-22 9:24 [Patch net-next v1 0/9] net: dsa: microchip: add support for phylink mac config and link up Arun Ramadoss
2022-07-22 9:24 ` [Patch net-next v1 1/9] net: dsa: microchip: add common gigabit set and get function Arun Ramadoss
2022-07-22 9:24 ` [Patch net-next v1 2/9] net: dsa: microchip: add common ksz port xmii speed selection function Arun Ramadoss
2022-07-22 9:24 ` [Patch net-next v1 3/9] net: dsa: microchip: add common duplex and flow control function Arun Ramadoss
2022-07-22 10:09 ` Russell King (Oracle) [this message]
2022-07-22 9:24 ` [Patch net-next v1 4/9] net: dsa: microchip: add support for common phylink mac link up Arun Ramadoss
2022-07-22 9:24 ` [Patch net-next v1 5/9] net: dsa: microchip: lan937x: add support for configuing xMII register Arun Ramadoss
2022-07-22 9:24 ` [Patch net-next v1 6/9] net: dsa: microchip: apply rgmii tx and rx delay in phylink mac config Arun Ramadoss
2022-07-22 9:24 ` [Patch net-next v1 7/9] net: dsa: microchip: ksz9477: use common xmii function Arun Ramadoss
2022-07-22 9:24 ` [Patch net-next v1 8/9] net: dsa: microchip: ksz8795: " Arun Ramadoss
2022-07-22 9:24 ` [Patch net-next v1 9/9] net: dsa: microchip: add support for phylink mac config Arun Ramadoss
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Ytp3dl5l9jkp94lU@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew@lunn.ch \
--cc=arun.ramadoss@microchip.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=vivien.didelot@gmail.com \
--cc=woojung.huh@microchip.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).