Mt7622 ethernet and mtk_soc_eth driver on BPI-R64

I’m trying to make work mt7622 onboard ethernet with nixos default kernel. Since it doesn’t have mtk-eth I compile it separately as module. However, after system boots I don’t see eth0. I have entry in device tree for onboard ethernet:

[root@nixos:~]# ls /sys/firmware/devicetree/base/ethernet@1b100000/
'#address-cells'   interrupts   mediatek,ethsys     reg
 clock-names	   mac@0        mediatek,sgmiisys  '#size-cells'
 clocks		   mac@1        name		    status
 compatible	   mdio-bus     power-domains

and this entry is compatible with mediatek,mt7622-eth:

[root@nixos:~]# cat /sys/firmware/devicetree/base/ethernet@1b100000/compatible
mediatek,mt7622-ethmediatek,mt2701-ethsyscon

I have a module that claims that it compatible with mediatek,mt7622-eth:

[root@nixos:~]# lsmod | grep mtk_eth
mtk_eth                69632  0
dsa_core               98304  1 mtk_eth
[root@nixos:~]# modinfo mtk_eth
filename:       /run/current-system/kernel-modules/lib/modules/5.15.3/extra/mtk_eth.ko.xz
description:    Ethernet driver for MediaTek SoC
author:         John Crispin <[email protected]>
license:        GPL
alias:          of:N*T*Cralink,rt5350-ethC*
alias:          of:N*T*Cralink,rt5350-eth
alias:          of:N*T*Cmediatek,mt7629-ethC*
alias:          of:N*T*Cmediatek,mt7629-eth
alias:          of:N*T*Cmediatek,mt7623-ethC*
alias:          of:N*T*Cmediatek,mt7623-eth
alias:          of:N*T*Cmediatek,mt7622-ethC*
alias:          of:N*T*Cmediatek,mt7622-eth
alias:          of:N*T*Cmediatek,mt7621-ethC*
alias:          of:N*T*Cmediatek,mt7621-eth
alias:          of:N*T*Cmediatek,mt2701-ethC*
alias:          of:N*T*Cmediatek,mt2701-eth
depends:        dsa_core
name:           mtk_eth
vermagic:       5.15.3 SMP mod_unload aarch64
parm:           msg_level:Message level (-1=defaults,0=none,...,16=all) (int)

But I didn’t see any network interfaces created:

[root@nixos:~]# ip l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
[root@nixos:~]# ls /sys/devices/platform/1b100000.ethernet/
driver_override
modalias
of_node
power
subsystem
supplier:platform:10006000.power-controller
supplier:platform:10209000.apmixedsys
supplier:platform:10210000.topckgen
supplier:platform:10211000.pinctrl
supplier:platform:1b000000.syscon
supplier:platform:1b128000.sgmiisys
uevent
waiting_for_supplier

What did I miss?

You should post full dmesg and complete dts node and/or compare node to mainline dts node for mt7622/r64 ethernet/gmac node. I guess you miss some pinctrl/gpio/clocks.

According to https://nixos.wiki/wiki/Linux_kernel nixos just uses mainline kernel… You could just use franks kernel instead?

He could try use my defconfig or compare with the one he using

What does this say?

cat /sys/devices/platform/1b100000.ethernet/waiting_for_supplier

dmesg - https://justpaste.it/444sb

device tree - https://justpaste.it/3m7e9

According to https://nixos.wiki/wiki/Linux_kernel nixos just uses mainline kernel… You could just use franks kernel instead?

Yes, I think I can, but I don’t want) I’ve manged to run onboard ethernet with mt7530 dsa switch on mainline compiled by myself, I’m pretty sure it is possible to run in nixos’s one.

He could try use my defconfig or compare with the one he using

Ok, I will try to compare our configs, but I’m pretty sure that difference will be huge, not sure that I will find where is problem without knowing what exactly gone wrong with onboard ethernet.

What does this say?

cat /sys/devices/platform/1b100000.ethernet/waiting_for_supplier

[root@nixos:~]# cat /sys/devices/platform/1b100000.ethernet/waiting_for_supplier
0

I would try adding debug messages in probe function and look if anything is printed and where it stops the binding

I’ve tried to rmmod mtk_eth && modprobe mtk_eth msg_level=16 but did’nt see anything interesting, kernel even didn’t print mtk_eth: loading out-of-tree module taints kernel. again.

I’m not sure mtk eth supports to be compiled as module.

Well, I think I can just try to recompile nixos’s kernel with extra CONFIG_NET_MEDIATEK_SOC=y and check this theory (I think it will take about an 8-10 hours)

For now I will try to add more printk to the module to understant why can’t it create network interfaces.

Well, I think I can just try to recompile nixos’s kernel with extra CONFIG_NET_MEDIATEK_SOC=y and check this theory (I think it will take about an 8-10 hours)

I’ve recompiled kernel with new config and now CONFIG_NET_MEDIATEK_SOC=y:

[root@nixos:~]# zgrep CONFIG_NET_MEDIATEK_SOC /proc/config.gz
CONFIG_NET_MEDIATEK_SOC=y

But the issue is the same. Moreover, when I’m trying to bind driver and device manually, I get this error:

[root@nixos:~]# echo '1b100000.ethernet' > /sys/bus/platform/drivers/mtk_soc_eth/bind
-bash: echo: write error: Resource temporarily unavailable

So I think main problem is with binding platform driver to platform device. The only idea I have for now - read the binding code and try to understand why it can return Resource temporarily unavailable error.

Could you try using my kernel in nixos? I guess you need more options,maybe nixos patches break mtk ethernet driver somehow

Well, I’ve tried to load nixos with almost your kernel - just mainline kernel with your config for 5.15, and ethernet did work in this case. But I don’t know how it will help me.

you can compare your config with mine and dts(i) and there is not hardware fault :wink:

Well, it seems that I figured out where is the problem. It seems that linux kernel have rich debug options) I’ve enabled dynamic debug to track which happens inside __driver_probe_device https://github.com/torvalds/linux/blob/master/drivers/base/dd.c#L730 function:

[root@nixos:~]# echo 'file dd.c +p'>/sys/kernel/debug/dynamic_debug/control
[root@nixos:~]# echo 'file core.c +p'>/sys/kernel/debug/dynamic_debug/control

And then tried to bind device driver and device:

[root@nixos:~]# echo '1b100000.ethernet' >/sys/bus/platform/drivers/mtk_soc_eth/bind
-bash: echo: write error: Resource temporarily unavailable
[root@nixos:~]# dmesg -T | tail
...
[Sat Jan  1 00:03:27 2000] bus: 'platform': __driver_probe_device: matched device 1b100000.ethernet with driver mtk_soc_eth
[Sat Jan  1 00:03:27 2000] platform 1b100000.ethernet: error -EPROBE_DEFER: supplier 1b000000.syscon not ready

It seems that one of the dependent devices (1b000000.syscon) is not ready (at the same time /sys/bus/platform/devices/1b100000.ethernet/waiting_for_supplier was still 0 for some reason). I think that I need clk-mt7622-eth driver as well. Will try to compile it as module.

UPD: It seems it is impossible to build it as module) https://github.com/torvalds/linux/blob/master/drivers/clk/mediatek/clk-mt7622-eth.c#L148 so it will take another 8-10 hours to recompile kernel and check it.

you are building on the r64?? why not building on x86?

No, actually I’m building on 12-core i7-7800X, but using user-mode qemu. I still didn’t figured out how to compile nixos’s kernel natively without emulation.

If you have a linux os like ubuntu you can use crosscompile toolchain

Prefix each make command with

ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

Of course you need to install cross-compiler before

And add more threads to make via -j switch

Yes I know, but in nixos world everything is a bit different. You don’t actually compile it by yourself - you just specify which kernel you want (and optionally which patches you want) like that: https://github.com/BenSchZA/nixos-configuration/blob/a300c7716ca60dfeaa6b2c160f24db0400bdbec2/hardware/base.nix and run full system rebuild. For some reason nixpkg decides that it is good idea to compile kernel with qemu.

I’ve figured out how to compile kernel faster. After enabling COMMON_CLK_MT7622_ETHSYS, NET_VENDOR_MEDIATEK, NET_MEDIATEK_SOC onboard eth and mt7530 dsa switch works fine.

Good to read your problem is solved :slight_smile: