3
votes

I have to write a Ethernet PHY loopback test in Linux. I've never done it before and had no clue where to start. After some researching, I came up with the plan for the test, and I wonder if anyone can help me to verify it and give me some pointers to my questions.

This is a external loopback setup. It connects the TX+/- to RX+/- pins for each internal PHY's on the Ethernet switch chip.

So the loopback high level packet path is as follow:

CPU->PHY0(chip)->Ethernet switch(chip)'s internal PHY->PHY0(chip)->CPU

For this test, I plan to

  1. configure the internal PHYs on the Ethernet switch with specific MAC addresses,
  2. pack the Ethernet test packet using CPU's MAC address as the source address and the
    MAC address configured in step 1. as the destination address,
  3. send and wait to receive the test packet,
  4. compare sent and received data pattern.

Any suggestions? Also, I wonder if there are functions in Linux that I can use to generate the packets for step 2, and send the packets for step 3.

Thank you very much.

1
which language do you want to use for this test?Mike Pennington
Hi, Did you eventually did the loopback test on linux or in bootloader ? Thanksransh
Wow, my rely is so late. Yes, I make it working in bootloader. Tim's answer came too late, but I found a similar approach elsewhere. Thanks.user903151

1 Answers

4
votes

Most Phys can be switched to a test mode. We used the bootloader to write directly to the Phy and switch to testing mode.

There is also an ioctl taken from documentation/networking/phy.txt Ethtool convenience functions.

int phy_mii_ioctl(struct phy_device *phydev, struct mii_ioctl_data *mii_data, int cmd);

The MII ioctl. Note that this function will completely screw up the state machine if you write registers like BMCR, BMSR, ADVERTISE, etc. Best to use this only to write registers which are not standard, and don't set off a renegotiation.