November 15, 2024

An ethernet driver for Zynq on Kyu - Round 1 -- collecting information

This will be my first driver for gigabit ethernet, which may present some differences.

One nice thing is that the Xilinx documentation for Zynq is excellent, as was the documentation from Texas Instruments for the BBB. Chapter 16 (page 484) in the TRM covers the ethernet controller. Appendix B has register details (page 1267).

The Zynq has two ethernet interfaces! My boards all just use one, so I am just ignoring the second one. Somebody someday could generalize the driver to support both, but doing it now would just be a waste of time and energy.

The controller is 10/100/1000 - and of course we also need to deal with a physical interface (Phy) chip -- and find a datasheet for it. Different boards use different Phy chips as follows:

Antminer S9 - Broadcom B50612E - 10/100/1000
Ebaz - IC plus electronics IP101GA - 10/100
Zybo - Realtek 8211E - 10/100/1000
Zedboard - Marvell M-88E1518-NNB2 - 10/100/1000
So, four different boards and four different Phy chips. It will be beneficial to keep the ability in mind to easily switch Phy chip support in software. To start I just want to support the Antminer, but I will definitely want to support the Ebaz sooner rather than later.

All 4 chips have datasheets available online and I have placed copies in /u1/Projects/Zynq/Manuals.

Broadcom is always a nightmare as far as documentation. There seems to be no datasheet for the B50612E available online. I do find a datasheet for the B50612D chip, and I am hopeful that it will be useful (if not identical) but who knows.

Learn from U-Boot

This has always been immensely helpful for other projects. Linux drivers tend to be overly complex and written in a "linux-C dialect" and further complicated by the tangle of include files that are part of the linux kernel code. Dealing with linux kernel code is a unique specialty, even for veteran C programmers. Something to be engaged with only when there is no other option. U-Boot has plenty of its own complexity, but it is managable -- also U-Boot avoids using interrupts.

I have a local copy of "u-boot-xlnx" in /u1/Projects/Zynq and will refer to that. My first trick with resspect to U-boot is to build it for the desired target. This leaves xxx.o files for only those files included in the build. These serve as invaluable "bread crumbs).

For example, the directory drivers/net has 86 different source files, but I only see 3 object files, one of which is for "zynq_gem.c". This is 1025 lines of code and the register names and offsets match the Zynq datasheet, so this looks good. A comment says that it is based on the Xilinx "gmac" driver (for what that might be worth).

The Phy drivers are in "drivers/net/phy".

I don't see support for the Broadcom 50612 (but see below on the BCM54xx). I also don't see support for the "IC plus" IP101GA -- which is not entirely surprising as the Antminer and Ebaz are not actual Xilinx products.

Linux has a driver for the IP101GA in drivers/net/phy/icplus.c

Linux has a driver for the Broadcom 50610 in drivers/net/phy/broadcom.c
The comment says it is for BCM54xx chips, but code later checks for PHY_ID_BCM50610.

I only found a miserable 2 page "product brief" for the BCM5461S.

I found a decent 90 page datasheet for the BCM5221, which is only a 10/100 device, but maybe we can get an idea of how Broadcom does things using it. The date on this is 2002.

The Kyu driver for the internal Phy in the Orange Pi

This uses the first 6 standard MDIO registers and ought to be a good starting point for the Zynq Phy driver for any of the chips that are not insane.

Run U-boot

U-boot announces:
Net:   Gem.e000b000
So that confirms the zynq_gem.c driver and the address is for the first of the two ethernet interfaces. We also see this in bdinfo:
ethaddr     = 00:0a:35:00:01:22
There are two commands which could be useful: "mii" "mdio".
zynq-uboot> mdio list
Gem.e000b000:
1 - Broadcom BCM5461S <--> Gem.e000b000
Now this is interesting. There are no such markings on the actual chip. Searching only yields a 2 page "data brief".
Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org