Linux – Ethernet PHY loopback test coding

Ethernet PHY loopback test coding… here is a solution to the problem.

Ethernet PHY loopback test coding

I had to write an Ethernet PHY loopback test in Linux. I’ve never done it before and don’t know where to start. After some research, I came up with a test plan, and I don’t know if anyone can help me verify it and give me some pointers on the problem.

This is an external loopback setup. It connects TX+/- from each internal PHY on the Ethernet switch chip to the RX+/- pin.

So the loopback high-level package path is as follows:

CPU->PHY0(chip)-> internal PHY->PHY0(chip)-> CPU of the Ethernet switch (chip

).

For this test, I intend

  1. Configure the internal PHY on the Ethernet switch with a specific MAC address
  2. Use the MAC address of the CPU as the source address to package the Ethernet test package
    The first step configures the MAC address as the destination address
  3. Send and wait to receive the test package
  4. Compare data patterns sent and received.

Any suggestions? Also, I would like to know if there is a function in Linux that can be used to generate packets for step 2 and send packets for step 3.

Thank you so much.

Solution

Most PHYs can be switched to test mode. We use the bootloader to write directly
PHY and switch to test mode.

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

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

MII ioctl。 Note that this feature will completely mess up the state
Machines, if you write registers like BMCR, BMSR, ADVERTISE, etc. best
Only use it to write non-standard registers, do not detonate
Renegotiate.

Related Problems and Solutions