All of lore.kernel.org
 help / color / mirror / Atom feed
From: Colin Foster <colin.foster@in-advantage.com>
To: Maxime Chevallier <maxime.chevallier@bootlin.com>
Cc: Mark Brown <broonie@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	rafael@kernel.org, Vladimir Oltean <vladimir.oltean@nxp.com>,
	Lee Jones <lee@kernel.org>,
	davem@davemloft.net, Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	thomas.petazzoni@bootlin.com
Subject: Re: [RFC 2/7] regmap: check for alignment on translated register addresses
Date: Thu, 30 Mar 2023 09:39:07 -0700	[thread overview]
Message-ID: <ZCW7K/DWmGApVen9@colin-ia-desktop> (raw)
In-Reply-To: <20230330114546.13472135@pc-7.home>

Hi Maxime,

On Thu, Mar 30, 2023 at 11:45:46AM +0200, Maxime Chevallier wrote:
> Hello Mark,
> 
> On Fri, 24 Mar 2023 18:51:19 +0000
> Mark Brown <broonie@kernel.org> wrote:
> 
> > On Fri, Mar 24, 2023 at 10:36:39AM +0100, Maxime Chevallier wrote:
> > > With regmap->reg_base and regmap->reg_downshift, the actual register
> > > address that is going to be used for the next operation might not
> > > be the same as the one we have as an input. Addresses can be offset
> > > with reg_base and shifted, which will affect alignment.
> > > 
> > > Check for alignment on the real register address.  
> > 
> > It is not at all clear to me that the combination of stride and
> > downshift particularly makes sense, and especially not that the
> > stride should be applied after downshifting rather than to what
> > the user is passing in.
> 
> I agree on the part where the ordering of "adding and offset, then
> down/upshifting" isn't natural. This is the order in which operations
> are done today, and from what I could gather, only the ocelot-spi MFD
> driver uses both of these operations.
> 
> It would indeed make sense to first shift the register to have the
> proper spacing between register addresses, then adding the offset.
> 
> So maybe we should address that in ocelot-spi in the next iteration,
> Colin, would you agree ?

I'm curious what you mean by "proper spacing". The proper spacing of the
VSC7512 (ocelot-spi) is 4, and that's what the reg_stride is. All
registers can be accessed in many ways, as I described.

Consider the case I brought up, where we're trying to access a register
at 0x71070004. If you're on the processor internal to ocelot, this would
be

uint32 val = *(uint32 *)0x71070004;

Accesses to 0x71070001, 0x71070002, and 0x71070003 are not possible.
(Well maybe they are _possible_ on some architectures... you get the
point though)


Translate this to accessing the same register via SPI, where everything
is shifted down two bits. We're still accessing 0x71070004, but the way
this gets sent on the bus is 0x71070004 >> 2 = 0x1c41c001.

This patch set would have allowed accesses to 0x71070001 in the
ocelot-spi scenario, but not in the MMIO scenario. That wouldn't be
desired.


The result of all this is a consistent driver interface. "Give me
register 0x4 from a base address of 0x71070000" works in both MMIO and
SPI. Everything in /sys/kernel/debug/regmap should be the same in both
scenarios as well. All of these scenarios were the motivation behind
reg_shift.


Colin Foster


  parent reply	other threads:[~2023-03-30 16:39 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24  9:36 [RFC 0/7] Introduce a generic regmap-based MDIO driver Maxime Chevallier
2023-03-24  9:36 ` [RFC 1/7] regmap: add a helper to translate the register address Maxime Chevallier
2023-03-24  9:36 ` [RFC 2/7] regmap: check for alignment on translated register addresses Maxime Chevallier
2023-03-24 18:51   ` Mark Brown
2023-03-30  9:45     ` Maxime Chevallier
2023-03-30 14:06       ` Mark Brown
2023-03-30 16:39       ` Colin Foster [this message]
2023-03-24  9:36 ` [RFC 3/7] regmap: allow upshifting register addresses before performing operations Maxime Chevallier
2023-03-24 12:08   ` Andrew Lunn
2023-03-24  9:36 ` [RFC 4/7] mfd: ocelot-spi: Change the regmap stride to reflect the real one Maxime Chevallier
2023-03-24 12:11   ` Andrew Lunn
2023-03-24 12:48     ` Maxime Chevallier
2023-03-24 15:48       ` Colin Foster
2023-03-24 17:56         ` Colin Foster
2023-03-30  9:53           ` Maxime Chevallier
2023-03-27  0:02       ` Andrew Lunn
2023-03-30  9:46         ` Maxime Chevallier
2023-03-24  9:36 ` [RFC 5/7] net: mdio: Introduce a regmap-based mdio driver Maxime Chevallier
2023-03-24 12:48   ` kernel test robot
2023-04-01 13:41   ` Vladimir Oltean
2023-03-24  9:36 ` [RFC 6/7] net: ethernet: altera-tse: Convert to mdio-regmap and use PCS Lynx Maxime Chevallier
2023-03-24 16:45   ` kernel test robot
2023-03-24 17:06   ` kernel test robot
2023-03-24  9:36 ` [RFC 7/7] net: pcs: Drop the TSE PCS driver Maxime Chevallier
2023-05-15 11:48   ` Vladimir Oltean
2023-05-22  6:26     ` Maxime Chevallier
2023-03-24 20:37 ` (subset) [RFC 0/7] Introduce a generic regmap-based MDIO driver Mark Brown

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=ZCW7K/DWmGApVen9@colin-ia-desktop \
    --to=colin.foster@in-advantage.com \
    --cc=andrew@lunn.ch \
    --cc=broonie@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=maxime.chevallier@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rafael@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=vladimir.oltean@nxp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.