Re: connect a "loose" device to a OFW/FDT node (and then use mii_fdt)?

From: Warner Losh <imp_at_bsdimp.com>
Date: Tue, 27 Feb 2024 21:01:28 UTC
On Tue, Feb 27, 2024 at 1:40 PM Bjoern A. Zeeb <
bzeeb-lists@lists.zabbadoz.net> wrote:

> Hi,
>
> I have a device which has its own ivars and is not created from OFW/FDT.
>

How does it get this knowledge then?


> The parent(parent(dev)) was but FDT does not fully represent the logic
> of it and we need to create the intermediate device *sigh*
>

FDT just describes hardware, which is often non-linear where a driver would
need to speak to two different devices to accomplish its needs. A common
example of this has been NIC drivers that don't have any access to the mii
bus to talk to the PHY that controls it, so has to do what's normally a
parent/child relationship in add-in cards via a proxy. From what you
described below, it looks like that's what's going on here, but I could be
mistaken.


> I tried to put ASCII art below (try a plain text view if needed).
>
> Is there any way to connect this "mac" device to its relevant node in FDT
> (continuing the "tree" there) and then use mii_fdt to attach (doing
> all the PHY stuff and references)?
>

You'd likely have to proxy the miibus that the phy is connected to so that
the NIC can talk to its PHY via this intermediary.

So looks something like this:
>
>   X (ofw/fdt/simplebus node/device)
>   |
>   +--- interim dev (not in FDT created by X)
>

If there's no hardware, why is this device created?

However, assuming that there's a good reason, this X device is just another
bus. It will have whatever children are proper for that bus to have. It's
up to it to make that determination.


>        |
>        +----- mac dev (in FDT but created as child of 'interim dev' and
> not out of ofw/fdt/simplebus)
>

Wouldn't there be a PHANDLE or similar reference then pointing to this node
in the tree?

But regardless, you could create any device you want as a child of X,
though in this case it is a little weird if the mac doesn't belong to
something else that would be a simple bus or a simple bus super class.


>                 |
>                 +---- miibus(_fdt if possible)
>                          |
>                          +------ PHY


Usually the non-linear references to PHYs that live on a MIIBUS not
directly connected to the mac are done through cooperation between the PHY
driver and the MAC driver. One could model it the way you are saying, but
that's not a requirement. We've had several of these come up over the years
since many SoCs have direct control of the MII bus not through resources
owned by the NIC as is often the case with add-in cards.

So the question would become, is that the real situation here (in which
case you'd need to proxie messages between the NIC and PHY) or is it
something else?

I can't recall if we have drivers in the tree that do this today. I did
this years ago with some stuff that never made it into the tree on a
consulting basis and it was relatively simple to write the wrappers that
forwarded all the relevant newbus methods called on behalf of driver A to
driver B and vice versa. Though I do recall it was a pain in some spots
since simple operations couldn't be directly coded.

Warner