[U-Boot] Question: Information regarding MII and PHY

Andy Fleming afleming at gmail.com
Tue Sep 27 18:32:35 CEST 2011


On Thu, Sep 22, 2011 at 7:17 PM, Graeme Russ <graeme.russ at gmail.com> wrote:
> Hi Andy
>
> On Fri, Sep 23, 2011 at 9:36 AM, Andy Fleming <afleming at gmail.com> wrote:
>> On Thu, Sep 22, 2011 at 6:27 PM, Graeme Russ <graeme.russ at gmail.com> wrote:
>
> [snip]
>
>>> Is there any documentation on how I should build a new MAC and PHY driver
>>> from scratch (i.e. what is the official network driver API)
>>
>> There's not really any documentation for phylib at the moment, except
>> the header files. There aren't a lot of examples for mdio buses at the
>> moment, but it's straightforward:
>>
>> 1) Call mdio_alloc() to create a new bus object
>> 2) Fill in the name, then read, write, and reset functions, and set
>> bus->priv to whatever context structure you want
>> 3) Call mdio_register(bus)
>>
>> For an example, see drivers/net/fsl_mdio.c
>>
>> A PHY driver is not much more complicated, and there are many examples.
>>
>> Then, in the ethernet driver, you will need to call:
>>
>> phy_connect() to declare the connection between your MAC and the PHY
>> phy_config() to initialize the PHY
>>
>> When the MAC is ready to deal with traffic, you call phy_startup()
>>
>> When the MAC is being shut down (the close function), you call phy_shutdown()
>
> Thanks for the explanation - I'll have a look tonight
>
> A couple of quick questions regarding network drivers...
>
> 1) Was it the case that the Linux phylib was 'tight' enough to bring
>   straight into U-Boot, or was a new phylib written for U-Boot?


Much of the code was copied straight over. But the interface is
*slightly* different to account for the non-persistence of network
connections in u-boot. Basically, I merged "config_aneg" and
"config_init", and made "read_status" into "startup", and left out the
power saving and interrupt stuff. This was done for simplicity, but it
may make sense at this early stage to get closer to the Linux
interface.


> 2) The Linux network driver framework (at least now) is so
>   massive that porting a network driver over is practically impossible.
>   Is the U-Boot network driver framework similar in any way to the Linux
>   framework such that I can take relevant portions of code straight from
>   a Linux driver, or is it a case of carefully picking out the relevant
>   bits and stitching together a entirely new beast?

It's very different. And most Linux ethernet drivers are going to be
filled with Linux-specific things (like sk_buffs). The U-Boot API is
very simple (open, close, tx, rx, no interrupts). Any driver can serve
as a simple example. As Mike said, just use the Linux driver to get a
sense of what registers to write, and how to set up your rings.

Andy


More information about the U-Boot mailing list