netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Golle <daniel@makrotopia.org>
To: Chris Packham <chris.packham@alliedtelesis.co.nz>
Cc: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, sander@svanheule.net,
	markus.stockhausen@gmx.de, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org
Subject: Re: [PATCH net-next v9] net: mdio: Add RTL9300 MDIO driver
Date: Mon, 10 Mar 2025 01:31:35 +0000	[thread overview]
Message-ID: <Z85A9_Li_4n9vcEG@pidgin.makrotopia.org> (raw)
In-Reply-To: <20250309232536.19141-1-chris.packham@alliedtelesis.co.nz>

Hi Chris,

On Mon, Mar 10, 2025 at 12:25:36PM +1300, Chris Packham wrote:
> Add a driver for the MDIO controller on the RTL9300 family of Ethernet
> switches with integrated SoC. There are 4 physical SMI interfaces on the
> RTL9300 however access is done using the switch ports. The driver takes
> the MDIO bus hierarchy from the DTS and uses this to configure the
> switch ports so they are associated with the correct PHY. This mapping
> is also used when dealing with software requests from phylib.
> 
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---

> ...
> +static int rtl9300_mdio_read_c22(struct mii_bus *bus, int phy_id, int regnum)
> +{
> +	struct rtl9300_mdio_chan *chan = bus->priv;
> +	struct rtl9300_mdio_priv *priv;
> +	struct regmap *regmap;
> +	int port;
> +	u32 val;
> +	int err;
> +
> +	priv = chan->priv;
> +	regmap = priv->regmap;
> +
> +	port = rtl9300_mdio_phy_to_port(bus, phy_id);
> +	if (port < 0)
> +		return port;
> +
> +	mutex_lock(&priv->lock);
> +	err = rtl9300_mdio_wait_ready(priv);
> +	if (err)
> +		goto out_err;
> +
> +	err = regmap_write(regmap, SMI_ACCESS_PHY_CTRL_2, FIELD_PREP(PHY_CTRL_INDATA, port));
> +	if (err)
> +		goto out_err;
> +
> +	val = FIELD_PREP(PHY_CTRL_REG_ADDR, regnum) |
> +	      FIELD_PREP(PHY_CTRL_PARK_PAGE, 0x1f) |
> +	      FIELD_PREP(PHY_CTRL_MAIN_PAGE, 0xfff) |
> +	      PHY_CTRL_READ | PHY_CTRL_TYPE_C22 | PHY_CTRL_CMD;

Using "raw" access to the PHY and thereby bypassing the MDIO
controller's support for hardware-assisted page access is problematic.
The MDIO controller also polls all PHYs status in hardware and hence
be aware of the currently selected page. Using raw access to switch
the page of a PHY "behind the back" of the hardware polling mechanism
results in in occassional havoc on link status changes in case Linux'
reading the phy status overlaps with the hardware polling.
This is esp. when using RealTek's 2.5GBit/s PHYs which require using
paged access in their read_status() function.

Markus Stockhausen (already in Cc) has implemented a nice solution to
this problem, including documentation, see
https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=target/linux/realtek/files-6.6/drivers/net/ethernet/rtl838x_eth.c;h=4b79090696e341ed1e432a7ec5c0f7f92776f0e1;hb=HEAD#l1631

Including a similar mechanism in this driver for C22 read and write
operations would be my advise, so hardware-assisted access to the PHY
pages is always used, and hence the hardware polling mechanism is aware
of the currently selected page.

Other than that the driver looks really good now, and will allow using
existing RealTek PHY drivers independently of whether they are used with
RealTek's switch SoCs or with non-RealTek systems -- this has always
been a big issue with OpenWrt's current implementation and I look
forward to use this driver instead asap ;)


  reply	other threads:[~2025-03-10  1:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-09 23:25 [PATCH net-next v9] net: mdio: Add RTL9300 MDIO driver Chris Packham
2025-03-10  1:31 ` Daniel Golle [this message]
2025-03-10  2:07   ` Chris Packham
2025-03-10 15:28     ` Daniel Golle
2025-03-13  1:04       ` Chris Packham
2025-03-13 13:05         ` Andrew Lunn
2025-03-10 16:32     ` Andrew Lunn
2025-03-10 16:34     ` Russell King (Oracle)
2025-03-10 16:27   ` Andrew Lunn
2025-03-10 18:06 ` Christophe JAILLET
2025-03-10 18:15   ` Russell King (Oracle)

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=Z85A9_Li_4n9vcEG@pidgin.makrotopia.org \
    --to=daniel@makrotopia.org \
    --cc=andrew@lunn.ch \
    --cc=chris.packham@alliedtelesis.co.nz \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=markus.stockhausen@gmx.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sander@svanheule.net \
    /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).