From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Christian Marangi <ansuelsmth@gmail.com>
Cc: Andrew Lunn <andrew@lunn.ch>, Lee Jones <lee@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Vladimir Oltean <olteanv@gmail.com>,
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Heiner Kallweit <hkallweit1@gmail.com>,
Maxime Chevallier <maxime.chevallier@bootlin.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, netdev@vger.kernel.org,
upstream@airoha.com
Subject: Re: [net-next PATCH v12 07/13] net: mdio: regmap: add support for multiple valid addr
Date: Fri, 14 Mar 2025 22:25:22 +0000 [thread overview]
Message-ID: <Z9Ss0qrxCcEbyJY7@shell.armlinux.org.uk> (raw)
In-Reply-To: <67d49d64.050a0220.35694d.b7ab@mx.google.com>
On Fri, Mar 14, 2025 at 10:19:29PM +0100, Christian Marangi wrote:
> On Fri, Mar 14, 2025 at 09:01:56PM +0000, Russell King (Oracle) wrote:
> > I'd prefer we didn't bring that abomination back. The detail about how
> > things are stored in regmap should be internal within regmap, and I
> > think it would be better to have an API presented that takes sensible
> > parameters, rather than something that's been encoded.
>
> Well problem is that regmap_write and regmap_read will take max 2 value
> at the very end (reg and value) so it's really a matter of making the
> encoding part internal but encoding it can't be skipped.
>
> You are suggesting to introduce additional API like
>
> mdio_regmap_write(regmap, phy, addr, val);
> mdio_mmd_regmap_write(regmap, phy, mmd, addr, val);
>
> And the encoding is done internally?
Yes, because littering drivers with the details of the conversion is
unreasonable.
> My concern is the decoding part from the .write/read_bits regmap OPs.
> I guess for that also some helper should be exposed (to keep the
> decoding/encoding internal to the driver and not expose the
> _abomination_)
Sadly, I don't think that's something we can get away from, but we
should make it _easy_ for people to get it right.
From what I remember from the days of shoe-horning C45 into the C22
MDIO API, encoding and/or decoding addresses was buggy because people
would use the wrong encoders and decoders.
For example, we had MDIO drivers using mdio_phy_id_is_c45() to test
whether the access being requested was C45 - mdio_phy_id_is_c45() is
for the _userspace_ MII API encoding (struct mii_ioctl_data), not the
kernel space. Kernel space used:
-#define MII_ADDR_C45 (1<<30)
-#define MII_DEVADDR_C45_SHIFT 16
-#define MII_REGADDR_C45_MASK GENMASK(15, 0)
to encode into the register number argument vs the userspace encoding
into the phy_id member of struct mii_ioctl_data:
#define MDIO_PHY_ID_C45 0x8000
#define MDIO_PHY_ID_PRTAD 0x03e0
#define MDIO_PHY_ID_DEVAD 0x001f
which is what the mdio_phy_id_*() accessors are using. The two
approaches are incompatible, and using the userspace one in a MDIO
driver wasn't going to work correctly - but people did it.
This is one of the reasons I hated the old MDIO API, and why we now
have separate C22 and C45 interfaces in the driver code.
This is exactly why I don't like reintroducing a new set of "massage
the package, mmd and address into some single integer representation"
and "decode a single integer into their respective parts" - we've
been here before, it's lead to problems because driver authors can't
grasp what the right approach is, and it results in bugs.
Given the history here, my personal opinion would be... if regmap can't
cope with MDIO devices having a three-part address without requiring
callers to flatten it first, and then have various regmap drivers
unflatten it, then regmap is unsuitable to be used with MDIO and ought
not be used.
So, this encoding/decoding is a problem that should be solved entirely
within regmap, and not spread out into users of regmap and drivers
behind regmap. Anything else is, IMHO, insane.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
next prev parent reply other threads:[~2025-03-14 22:25 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-09 17:26 [net-next PATCH v12 00/13] net: dsa: Add Airoha AN8855 support Christian Marangi
2025-03-09 17:26 ` [net-next PATCH v12 01/13] dt-bindings: nvmem: Document support for Airoha AN8855 Switch EFUSE Christian Marangi
2025-03-09 17:26 ` [net-next PATCH v12 02/13] dt-bindings: net: Document support for Airoha AN8855 Switch Virtual MDIO Christian Marangi
2025-03-20 17:31 ` Simon Horman
2025-03-09 17:26 ` [net-next PATCH v12 03/13] dt-bindings: net: dsa: Document support for Airoha AN8855 DSA Switch Christian Marangi
2025-03-11 19:20 ` Rob Herring
2025-03-20 17:32 ` Simon Horman
2025-03-09 17:26 ` [net-next PATCH v12 04/13] dt-bindings: net: Document support for AN8855 Switch Internal PHY Christian Marangi
2025-03-11 19:25 ` Rob Herring
2025-03-09 17:26 ` [net-next PATCH v12 05/13] dt-bindings: mfd: Document support for Airoha AN8855 Switch SoC Christian Marangi
2025-03-09 18:50 ` Rob Herring (Arm)
2025-03-09 19:26 ` kernel test robot
2025-03-09 17:26 ` [net-next PATCH v12 06/13] net: mdio: regmap: prepare support for multiple valid addr Christian Marangi
2025-03-09 17:26 ` [net-next PATCH v12 07/13] net: mdio: regmap: add " Christian Marangi
2025-03-09 17:36 ` Russell King (Oracle)
2025-03-09 17:45 ` Christian Marangi
2025-03-14 19:41 ` Andrew Lunn
2025-03-14 21:01 ` Russell King (Oracle)
2025-03-14 21:19 ` Christian Marangi
2025-03-14 22:25 ` Russell King (Oracle) [this message]
2025-03-09 17:26 ` [net-next PATCH v12 08/13] net: mdio: regmap: add OF support Christian Marangi
2025-03-09 17:37 ` Russell King (Oracle)
2025-03-09 17:48 ` Christian Marangi
2025-03-09 17:26 ` [net-next PATCH v12 09/13] mfd: an8855: Add support for Airoha AN8855 Switch MFD Christian Marangi
2025-03-14 11:35 ` Lee Jones
2025-03-14 19:34 ` Andrew Lunn
2025-03-15 10:52 ` Christian Marangi
2025-03-14 19:16 ` Andrew Lunn
2025-03-09 17:26 ` [net-next PATCH v12 10/13] net: mdio: Add Airoha AN8855 Switch MDIO Passtrough Christian Marangi
2025-03-09 17:26 ` [net-next PATCH v12 11/13] nvmem: an8855: Add support for Airoha AN8855 Switch EFUSE Christian Marangi
2025-03-09 17:26 ` [net-next PATCH v12 12/13] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver Christian Marangi
2025-03-09 17:57 ` Russell King (Oracle)
2025-03-10 10:57 ` Christian Marangi
2025-03-10 11:05 ` Russell King (Oracle)
2025-03-09 17:26 ` [net-next PATCH v12 13/13] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY Christian Marangi
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=Z9Ss0qrxCcEbyJY7@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=angelogioacchino.delregno@collabora.com \
--cc=ansuelsmth@gmail.com \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=lee@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=robh@kernel.org \
--cc=srinivas.kandagatla@linaro.org \
--cc=upstream@airoha.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).