public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Cc: linus.walleij@linaro.org, alsi@bang-olufsen.dk, andrew@lunn.ch,
	f.fainelli@gmail.com, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
	arinc.unal@arinc9.com
Subject: Re: [PATCH net-next v2 5/7] net: dsa: realtek: Migrate user_mii_bus setup to realtek-dsa
Date: Thu, 21 Dec 2023 19:47:46 +0200	[thread overview]
Message-ID: <20231221174746.hylsmr3f7g5byrsi@skbuf> (raw)
In-Reply-To: <CAJq09z4OP6Djuv=HkntCqyLM1332pXzhW0qBd4fc-pfrSt+r1A@mail.gmail.com>

On Wed, Dec 20, 2023 at 01:51:01AM -0300, Luiz Angelo Daros de Luca wrote:
> Hello Vladimir,
> 
> I'm sorry to bother you again but I would like your attention for two
> points that I'm not completely sure about.

Ok. Please trim the quoted text from your replies to just what's relevant.
It's easy to scroll past the new bits.

> > +int realtek_common_setup_user_mdio(struct dsa_switch *ds)
> > +{
> > +       const char *compatible = "realtek,smi-mdio";
> > +       struct realtek_priv *priv =  ds->priv;
> > +       struct device_node *phy_node;
> > +       struct device_node *mdio_np;
> > +       struct dsa_port *dp;
> > +       int ret;
> > +
> > +       mdio_np = of_get_child_by_name(priv->dev->of_node, "mdio");
> > +       if (!mdio_np) {
> > +               mdio_np = of_get_compatible_child(priv->dev->of_node, compatible);
> > +               if (!mdio_np) {
> > +                       dev_err(priv->dev, "no MDIO bus node\n");
> > +                       return -ENODEV;
> > +               }
> > +       }
> 
> I just kept the code compatible with both realtek-smi and realtek-mdio
> (that was using the generic "DSA user mii"), even when it might
> violate the binding docs (for SMI with a node not named "mdio").
> 
> You suggested using two new compatible strings for this driver
> ("realtek,rtl8365mb-mdio" and "realtek,rtl8366rb-mdio"). However, it
> might still not be a good name as it is similar to the MDIO-connected
> subdriver of each variant. Anyway, if possible, I would like to keep
> it out of this series as it would first require a change in the
> bindings before any real code change and it might add some more path
> cycles.

I suppose what you don't want is to make the code inadvertently accept
an MDIO bus named "realtek,smi-mdio" on MDIO-controlled switches.

I think it's safe to write a separate commit which just exercises a part
of the dt-binding that the Linux driver hasn't used thus far: that the
node name must be "mdio". You don't need to fall back to the search by
compatible string if there is nothing broken to support, and it's all
just theoretical (and even then, the theory is not supported by the DT
binding).

> > +       priv->user_mii_bus = devm_mdiobus_alloc(priv->dev);
> > +       if (!priv->user_mii_bus) {
> > +               ret = -ENOMEM;
> > +               goto err_put_node;
> > +       }
> > +       priv->user_mii_bus->priv = priv;
> > +       priv->user_mii_bus->name = "Realtek user MII";
> > +       priv->user_mii_bus->read = realtek_common_user_mdio_read;
> > +       priv->user_mii_bus->write = realtek_common_user_mdio_write;
> > +       snprintf(priv->user_mii_bus->id, MII_BUS_ID_SIZE, "Realtek-%d",
> > +                ds->index);
> > +       priv->user_mii_bus->parent = priv->dev;
> > +
> > +       /* When OF describes the MDIO, connecting ports with phy-handle,
> > +        * ds->user_mii_bus should not be used *
> > +        */
> > +       dsa_switch_for_each_user_port(dp, ds) {
> > +               phy_node = of_parse_phandle(dp->dn, "phy-handle", 0);
> > +               of_node_put(phy_node);
> > +               if (phy_node)
> > +                       continue;
> > +
> > +               dev_warn(priv->dev,
> > +                        "DS user_mii_bus in use as '%s' is missing phy-handle",
> > +                        dp->name);
> > +               ds->user_mii_bus = priv->user_mii_bus;
> > +               break;
> > +       }
> 
> Does this check align with how should ds->user_mii_bus be used (in a
> first step for phasing it out, at least for this driver)?

No. Thanks for asking.

What I would like to see is a commit which removes the line assigning
ds->user_mii_bus completely, with the following justification:

ds->user_mii_bus helps when
(1) the switch probes with platform_data (not on OF), or
(2) the switch probes on OF but its MDIO bus is not described in OF

Case (1) is eliminated because this driver uses of_device_get_match_data()
and fails to probe if that returns NULL (which it will, with platform_data).
So this switch driver only probes on OF.

Case (2) is also eliminated because realtek_smi_setup_mdio() bails out
if it cannot find the "mdio" node described in OF. So the ds->user_mii_bus
assignment is only ever executed when the bus has an OF node, aka when
it is not useful.

Having the MDIO bus described in OF, but no phy-handle to its children
is a semantically broken device tree, we should make no effort whatsoever
to support it.

Thus, because the dsa_user_phy_connect() behavior given by the DSA core
through ds->user_mii_bus does not help in any valid circumstance, let's
deactivate that possible code path and simplify the interaction between
the driver and DSA.

And then go on with the driver cleanup as if ds->user_mii_bus didn't exist.

Makes sense? Parsing "phy-handle" is just absurdly complicated.

> > +
> > +       ret = devm_of_mdiobus_register(priv->dev, priv->user_mii_bus, mdio_np);
> > +       if (ret) {
> > +               dev_err(priv->dev, "unable to register MDIO bus %s\n",
> > +                       priv->user_mii_bus->id);
> > +               goto err_put_node;
> > +       }
> > +
> > +       return 0;
> > +
> > +err_put_node:
> > +       of_node_put(mdio_np);
> > +
> > +       return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(realtek_common_setup_user_mdio);

  reply	other threads:[~2023-12-21 17:47 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-20  4:24 [PATCH net-next v2 0/7] net: dsa: realtek: variants to drivers, interfaces to a common module Luiz Angelo Daros de Luca
2023-12-20  4:24 ` [PATCH net-next v2 1/7] net: dsa: realtek: drop cleanup from realtek_ops Luiz Angelo Daros de Luca
2023-12-20 13:57   ` Alvin Šipraga
2023-12-21 17:04     ` Vladimir Oltean
2023-12-21 20:05       ` Alvin Šipraga
2023-12-22 22:32         ` Luiz Angelo Daros de Luca
2023-12-20  4:24 ` [PATCH net-next v2 2/7] net: dsa: realtek: convert variants into real drivers Luiz Angelo Daros de Luca
2023-12-21 17:08   ` Vladimir Oltean
2023-12-20  4:24 ` [PATCH net-next v2 3/7] net: dsa: realtek: common realtek-dsa module Luiz Angelo Daros de Luca
2023-12-20 10:40   ` Alvin Šipraga
2023-12-20 15:50     ` Alvin Šipraga
2023-12-21  3:25       ` Luiz Angelo Daros de Luca
2023-12-21  3:11     ` Luiz Angelo Daros de Luca
2023-12-20  4:24 ` [PATCH net-next v2 4/7] net: dsa: realtek: merge common and interface modules into realtek-dsa Luiz Angelo Daros de Luca
2023-12-20  4:24 ` [PATCH net-next v2 5/7] net: dsa: realtek: Migrate user_mii_bus setup to realtek-dsa Luiz Angelo Daros de Luca
2023-12-20  4:51   ` Luiz Angelo Daros de Luca
2023-12-21 17:47     ` Vladimir Oltean [this message]
2023-12-21 18:34       ` Arınç ÜNAL
2023-12-22 10:48         ` Vladimir Oltean
2023-12-22 11:13           ` Alvin Šipraga
2023-12-22 17:04             ` Arınç ÜNAL
2023-12-22 20:28               ` Luiz Angelo Daros de Luca
2023-12-22 20:59                 ` Arınç ÜNAL
2023-12-22 16:56           ` Arınç ÜNAL
2024-01-03 18:44             ` Vladimir Oltean
2024-01-05 18:43               ` Arınç ÜNAL
2023-12-22 20:03       ` Luiz Angelo Daros de Luca
2023-12-22 22:09         ` Vladimir Oltean
2023-12-22 22:12           ` Luiz Angelo Daros de Luca
2023-12-20 13:17   ` Alvin Šipraga
2023-12-21  3:03     ` Luiz Angelo Daros de Luca
2023-12-20  4:24 ` [PATCH net-next v2 6/7] net: dsa: realtek: embed dsa_switch into realtek_priv Luiz Angelo Daros de Luca
2023-12-20  4:24 ` [PATCH net-next v2 7/7] Revert "net: dsa: OF-ware slave_mii_bus" Luiz Angelo Daros de Luca
2023-12-20 13:19   ` Alvin Šipraga
2023-12-21  3:45     ` Luiz Angelo Daros de Luca
2023-12-21  0:41   ` kernel test robot
2023-12-21 15:21 ` [PATCH net-next v2 0/7] net: dsa: realtek: variants to drivers, interfaces to a common module Vladimir Oltean
2023-12-22 21:32   ` Luiz Angelo Daros de Luca

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=20231221174746.hylsmr3f7g5byrsi@skbuf \
    --to=olteanv@gmail.com \
    --cc=alsi@bang-olufsen.dk \
    --cc=andrew@lunn.ch \
    --cc=arinc.unal@arinc9.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=luizluca@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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