From: Andrew Lunn <andrew@lunn.ch>
To: Grant Edwards <grant.b.edwards@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: net: macb: fail when there's no PHY
Date: Thu, 3 Dec 2020 03:39:04 +0100 [thread overview]
Message-ID: <20201203023904.GA2333853@lunn.ch> (raw)
In-Reply-To: <rq90ks$mjq$1@ciao.gmane.io>
On Wed, Dec 02, 2020 at 09:23:40PM -0000, Grant Edwards wrote:
> On 2020-12-02, Andrew Lunn <andrew@lunn.ch> wrote:
> >> > So it will access the MDIO bus of the PHY that is attached to the
> >> > MAC.
> >>
> >> If that's the case, wouldn't the ioctl() calls "just work" even when
> >> only the fixed-phy mdio bus and fake PHY are declared in the device
> >> tree?
> >
> > The fixed-link PHY is connected to the MAC. So the IOCTL calls will be
> > made to the fixed-link fake MDIO bus.
>
> So how do you control which of the two mdio buses is connected to
> the MAC?
The bus is not connected to the MAC. The PHY is.
https://elixir.bootlin.com/linux/HEAD/source/drivers/net/ethernet/cadence/macb_main.c#L699
if (dn)
ret = phylink_of_phy_connect(bp->phylink, dn, 0);
if (!dn || (ret && !macb_phy_handle_exists(dn))) {
phydev = phy_find_first(bp->mii_bus);
if (!phydev) {
netdev_err(dev, "no PHY found\n");
return -ENXIO;
}
/* attach the mac to the phy */
ret = phylink_connect_phy(bp->phylink, phydev);
}
The call to phylink_of_phy_connect() will go looking in device tree to
find the phy-handle. If it exists, it follows it to the PHY, and the
PHY is connected to the MAC. This code also handles fixed link. But in
this case, because it is using phylink, not phylib, the emulation is
different. The phylib fixed-link has the limitation of only emulating
C22 PHYs upto 1Gbps. 2.5G, 10G etc is becoming more popular, so
Russell King implemented fixed-link in phylink differently. phylib has
emulated MDIO registers which the generic PHY driver uses. phylink
however incorporates fixed-link into the core code, there is no
emulation. And IOCTL is a stub.
Back to the code. If there is no PHY via device tree, it searches its
own MDIO bus for the first PHY, and connects that to the MAC. This is
obviously not ideal when you have multiple devices on the bus, so
using a phy-handle is best practice. This code is here for backwards
compatibility. macb has some funky backwards compatibility code with
respect to its MDIO bus. So you might be hitting a corner case which
is not handled correct.
> > There are plenty of examples to follow.
>
> That's true, but knowing which ones do what you're trying to do is the
> hard part. If you already know how to do it, it's easy to find
> examples showing it. :)
Feel free to ask.
Andrew
next prev parent reply other threads:[~2020-12-03 2:39 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-21 19:59 net: macb: fail when there's no PHY Grant Edwards
2017-09-21 20:05 ` Florian Fainelli
2017-09-21 20:36 ` Grant Edwards
2017-09-21 21:35 ` Brandon Streiff
2017-09-29 7:05 ` Harini Katakam
[not found] ` <CAK=1mW6Gti0QpUjirB6PfMCiQvnDjkbb56pVKkQmpCSkRU6wtA@mail.gmail.com>
2020-12-02 18:10 ` Florian Fainelli
2020-12-02 18:24 ` Grant Edwards
2020-12-02 18:35 ` Andrew Lunn
2020-12-02 19:16 ` Grant Edwards
2020-12-02 21:11 ` Andrew Lunn
2020-12-02 21:23 ` Grant Edwards
2020-12-03 2:39 ` Andrew Lunn [this message]
2020-12-03 3:03 ` Grant Edwards
2020-12-03 3:42 ` Florian Fainelli
2020-12-03 3:54 ` Grant Edwards
2020-12-03 4:07 ` Andrew Lunn
2020-12-03 15:07 ` Grant Edwards
2020-12-03 21:17 ` Andrew Lunn
2020-12-03 21:39 ` Grant Edwards
2020-12-03 21:49 ` Andrew Lunn
2020-12-03 22:20 ` Grant Edwards
2020-12-04 8:28 ` Alexander Dahl
2020-12-04 17:36 ` Andrew Lunn
2020-12-04 16:47 ` Florian Fainelli
2020-12-05 2:52 ` Grant Edwards
2020-12-05 3:06 ` Florian Fainelli
2020-12-03 4:00 ` Andrew Lunn
2020-12-02 18:10 ` Grant Edwards
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=20201203023904.GA2333853@lunn.ch \
--to=andrew@lunn.ch \
--cc=grant.b.edwards@gmail.com \
--cc=netdev@vger.kernel.org \
/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).