Subject: Re: Possibility of me mainlining Tehuti Networks 10GbE driver

From: Andrew Lunn <[email-masked]>
Date: Sun, 10 Nov 2019 19:50:48 +0100

> Could I please have more information / reading resources on the PHY 
> business? My understanding is that the NIC firmware would be dealing 
> with the PHY (this is the MII, right?) and the OS would have nothing to 
> do with it (it just sees a NIC which processes packets).

There are two different strategies boards can use:

1) The MAC firmware handles the PHY, and the firmware has all the PHY
   drivers needed.

2) Linux handles the PHY, and uses drivers from drivers/net/phy. The
   MAC driver then needs to export an MDIO bus, and use either phylink
   or phylib.

> Above you mentioned mii_bus for PHYs, but a driver like Aquantia 
> Atlantic does not have references to PHYs or MII. Why do some not need 
> the feature when others do?

The Aquantia MAC driver uses the firmware strategy. The PHY is
completely hidden from Linux with the firmware running on the MAC
handling the PHY.

But say look at the Marvell MAC drivers. They expose an MDIO bus, and
linux then drives the PHY. The MAC driver then uses the phylink_ API
to interact with the PHY via the phylink core code.

I also had a quick look at the code. It has the basic code you need to
export an MDIO bus, and let Linux control the PHYs.  bdx_mdio_read()
and bdx_mdio_write() would become the two functions you need for
struct mii_bus, and then pass it to mdiobus_register(). You would then
need to add phylink calls in the write place in the MAC driver.

If you think writing a new driver is too much work for you, then going
via staging is probably the better idea. You can slowly working on
improving the driver. One of the big chunks of work is going to be
swapping to the kernel PHY drivers, using PHYLINK, etc. And to do
that, you really do need to have hardware. You don't need all the
different variants the driver supports, but you should at least have
one. And i would suggest you get hardware which uses either the
Marvell or Aquantia PHY.

     Andrew