cancel
Showing results for 
Search instead for 
Did you mean: 

Ethernet fails if cable plugged in during boot. If plugged in after boot, works.

BillR
Associate III

This is an STM32MP157c based board design with Micrel KSZ9021GN PHY in 100 MII mode.

Have you ever seen this situation before?

Here are the relevant parts of the boot, the early kernel part looks normal and the LEDs are on.

...
[    2.507568] stm32-dwmac 5800a000.ethernet: PTP uses main clock
[    2.512079] stm32-dwmac 5800a000.ethernet: no reset control found
[    2.518073] stm32-dwmac 5800a000.ethernet: No phy clock provided...
[    2.524955] stm32-dwmac 5800a000.ethernet: User ID: 0x40, Synopsys ID: 0x42
[    2.531304] stm32-dwmac 5800a000.ethernet:   DWMAC4/5
[    2.536191] stm32-dwmac 5800a000.ethernet: DMA HW capability register supported
[    2.543532] stm32-dwmac 5800a000.ethernet: RX Checksum Offload Engine supported
[    2.550811] stm32-dwmac 5800a000.ethernet: TX Checksum insertion supported
[    2.557657] stm32-dwmac 5800a000.ethernet: Wake-Up On Lan supported
[    2.563937] stm32-dwmac 5800a000.ethernet: TSO supported
[    2.569235] stm32-dwmac 5800a000.ethernet: Enable RX Mitigation via HW Watchdog Timer
[    2.577041] stm32-dwmac 5800a000.ethernet: TSO feature enabled
[    2.583203] libphy: stmmac: probed
...

Then later on, I see the error and the driver asserts reset permanently and lights turn off.

[   10.557559] stm32-dwmac 5800a000.ethernet eth0: PHY [stmmac-0:03] driver [Generic PHY]
...
[   13.376644] stm32-dwmac 5800a000.ethernet: Failed to reset the dma
[   13.388797] stm32-dwmac 5800a000.ethernet eth0: stmmac_hw_setup: DMA engine initialization failed
/dev/mmcblk2p4: fsck 0.0% compl[   13.399390] stm32-dwmac 5800a000.ethernet eth0: stmmac_open: Hw setup failed
...

The board must be (re)booted with the cable unplugged.

The other odd thing that might be a clue? is that when the ethernet IS working, I have to plug->unplug->plug the cable to light up and work. If then unpluged I have to always replug it twice to come up again.

Thanks in advance! BillR.

1 ACCEPTED SOLUTION

Accepted Solutions
BillR
Associate III

Better yet, after noticing it wouldn't link in an old 10/100 hub, I realized this was a better idea:

	phy_write(phydev,0x09, 0x0000);  // PHY register 9 - advertise only  10/100BaseT capable

View solution in original post

3 REPLIES 3
BillR
Associate III

So I have found out a bit about this. It strikes me as a kernel bug. 

Even though I have configured for 100/MII in device tree, the PHY driver does not attempt to configure

the PHY for 10/100 and it stays in 125Mhz, failing the init due to bad clocks (expecting 25mhz).

If I just don't have the cable plugged in during this time, it says at 25Mhz and works fine later. (except for the 2x replug issue)

If I use an old 10/100 hub, no problems whatsoever. No need to replug the cable 2x either. 

So I am going to have to understand why the kernel does not force the PHY to 10/100. 

BillR
Associate III

After failing to find other device tree binding options that might deal with this, for now I ended up having to just force the PHY to 100Mbit mode as I needed a solution. I may look into the "right way" to handle this better in the future.

In drivers/net/phy/phy_device.c:

int phy_device_register(struct phy_device *phydev)
{
	int err;
 
	err = mdiobus_register_device(&phydev->mdio);
	if (err)
		return err;
 
	/* Deassert the reset signal */
	phy_device_reset(phydev, 0);
 
	/* HACK force to autoneg. off, 100Mbit. */
	phy_write(phydev,0, 0x2000);  
	
	...
}

BillR
Associate III

Better yet, after noticing it wouldn't link in an old 10/100 hub, I realized this was a better idea:

	phy_write(phydev,0x09, 0x0000);  // PHY register 9 - advertise only  10/100BaseT capable