[BPI-R2] internal Wifi/BT (MT6625L) - Kernel

I wish i had anyone who knows what the driver does and do a rewrite to a much smaller codebase. But there is nobody…and no documentation. I can only port by compile errors…

Dear @frank-w, @DeadMeat I remove sch_fq_codel module and it works as it should! :smile:

for the same reason, there was no outgoing traffic (I thought the problem was in iptables rules :man_facepalming:)

root@bpi-r2-ubuntu:~# tc qdisc show dev ap0
qdisc mq 0: root 
qdisc pfifo_fast 0: parent :4 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
qdisc pfifo_fast 0: parent :3 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
qdisc pfifo_fast 0: parent :2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
qdisc pfifo_fast 0: parent :1 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
root@bpi-r2-ubuntu:~# lsmod
Module                  Size  Used by
ipt_MASQUERADE         16384  5
iptable_nat            16384  1
nf_nat_ipv4            16384  2 ipt_MASQUERADE,iptable_nat
nf_nat                 36864  1 nf_nat_ipv4
nf_conntrack          147456  3 ipt_MASQUERADE,nf_nat_ipv4,nf_nat
nf_defrag_ipv6         20480  1 nf_conntrack
nf_defrag_ipv4         16384  1 nf_conntrack
mtk_pmic_keys          16384  0
mtk_thermal            16384  0
spi_mt65xx             20480  0
pwm_mediatek           16384  0
nvmem_mtk_efuse        16384  0
thermal_sys            61440  1 mtk_thermal
mt6577_auxadc          16384  0
ip_tables              24576  1 iptable_nat
x_tables               32768  2 ip_tables,ipt_MASQUERADE

But fq_codel is not an extra module, so now you need to configure it correctly…

Without ap0 (ethernet only)? Then it will be interesting if same problem is still in 5.9-rc4

What do you mean with configure correctly? Should do fq_codel it for you?

I didn’t test LAN, Ap0 only. banana Pi has Internet access via WAN.

To work with the module sch_fq_codel :nerd_face:

You have dropped it and it works right? Then it is problem with it. We need to know if it only affects ap0 (so it is wifi-driver incompatibility/bug) or network generic (then problem is in sch_fq_*)

@DeadMeat https://www.fw-web.de/dokuwiki/doku.php?id=en:bpi-r2:wlan#known_issues last subtopic

Hi! The sch_fq_codel module only causes problems with WiFi. The wired connection works fine.

sch_fq_codel Enable

Last login: Fri Sep 11 22:43:51 2020 from 192.168.0.13
root@bpi-r2-ubuntu:~# lsmod
Module                  Size  Used by
ipt_MASQUERADE         16384  7
iptable_nat            16384  1
nf_nat_ipv4            16384  2 ipt_MASQUERADE,iptable_nat
nf_nat                 36864  1 nf_nat_ipv4
nf_conntrack          147456  3 ipt_MASQUERADE,nf_nat_ipv4,nf_nat
nf_defrag_ipv6         20480  1 nf_conntrack
nf_defrag_ipv4         16384  1 nf_conntrack
mtk_thermal            16384  0
thermal_sys            61440  1 mtk_thermal
mt6577_auxadc          16384  0
mtk_pmic_keys          16384  0
spi_mt65xx             20480  0
pwm_mediatek           16384  0
nvmem_mtk_efuse        16384  0
sch_fq_codel           24576  7
ip_tables              24576  1 iptable_nat
x_tables               32768  2 ip_tables,ipt_MASQUERADE
root@bpi-r2-ubuntu:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 02:02:02:02:02:02 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::2:2ff:fe02:202/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 02:03:03:03:03:03 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::3:3ff:fe03:303/64 scope link 
       valid_lft forever preferred_lft forever
4: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
5: wan@eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 02:03:03:03:03:03 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.11/24 brd 192.168.0.255 scope global wan
       valid_lft forever preferred_lft forever
    inet6 fe80::3:3ff:fe03:303/64 scope link 
       valid_lft forever preferred_lft forever
6: lan0@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br0 state LOWERLAYERDOWN group default qlen 1000
    link/ether 02:02:02:02:02:02 brd ff:ff:ff:ff:ff:ff
7: lan1@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br0 state LOWERLAYERDOWN group default qlen 1000
    link/ether 02:02:02:02:02:02 brd ff:ff:ff:ff:ff:ff
8: lan2@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br0 state LOWERLAYERDOWN group default qlen 1000
    link/ether 02:02:02:02:02:02 brd ff:ff:ff:ff:ff:ff
9: lan3@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br0 state LOWERLAYERDOWN group default qlen 1000
    link/ether 02:02:02:02:02:02 brd ff:ff:ff:ff:ff:ff
10: br0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 02:02:02:02:02:02 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.1/24 brd 192.168.1.255 scope global br0
       valid_lft forever preferred_lft forever
11: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:08:22:86:c9:fb brd ff:ff:ff:ff:ff:ff
12: ap0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 02:08:22:86:c9:fb brd ff:ff:ff:ff:ff:ff
    inet 192.168.13.1/24 scope global ap0
       valid_lft forever preferred_lft forever
    inet6 fe80::8:22ff:fe86:c9fb/64 scope link 
       valid_lft forever preferred_lft forever
root@bpi-r2-ubuntu:~# tc qdisc show dev br0
qdisc noqueue 0: root refcnt 3069083204 
root@bpi-r2-ubuntu:~# tc qdisc show dev eth0
qdisc fq_codel 0: root refcnt 3068259908 limit 3068259908p flows 3068259908 quantum 3068259908 target 5.0ms interval 100.0ms memory_limit 32Mb ecn 
root@bpi-r2-ubuntu:~# tc qdisc show dev eth1
qdisc fq_codel 0: root refcnt 3068735044 limit 3068735044p flows 3068735044 quantum 3068735044 target 5.0ms interval 100.0ms memory_limit 32Mb ecn 
root@bpi-r2-ubuntu:~# tc qdisc show dev lan1
qdisc noqueue 0: root refcnt 3068444228 
root@bpi-r2-ubuntu:~# tc qdisc show dev ap0
qdisc mq 0: root 
qdisc fq_codel 0: parent :4 limit 3068993092p flows 3068993092 quantum 3068993092 target 5.0ms interval 100.0ms memory_limit 32Mb ecn 
qdisc fq_codel 0: parent :3 limit 3068993092p flows 3068993092 quantum 3068993092 target 5.0ms interval 100.0ms memory_limit 32Mb ecn 
qdisc fq_codel 0: parent :2 limit 3068993092p flows 3068993092 quantum 3068993092 target 5.0ms interval 100.0ms memory_limit 32Mb ecn 
qdisc fq_codel 0: parent :1 limit 3068993092p flows 3068993092 quantum 3068993092 target 5.0ms interval 100.0ms memory_limit 32Mb ecn 

sch_fq_codel Disable

root@bpi-r2-ubuntu:~# lsmod
Module                  Size  Used by
ipt_MASQUERADE         16384  7
iptable_nat            16384  1
nf_nat_ipv4            16384  2 ipt_MASQUERADE,iptable_nat
nf_nat                 36864  1 nf_nat_ipv4
nf_conntrack          147456  3 ipt_MASQUERADE,nf_nat_ipv4,nf_nat
nf_defrag_ipv6         20480  1 nf_conntrack
nf_defrag_ipv4         16384  1 nf_conntrack
mtk_thermal            16384  0
thermal_sys            61440  1 mtk_thermal
mtk_pmic_keys          16384  0
mt6577_auxadc          16384  0
spi_mt65xx             20480  0
pwm_mediatek           16384  0
nvmem_mtk_efuse        16384  0
ip_tables              24576  1 iptable_nat
x_tables               32768  2 ip_tables,ipt_MASQUERADE
root@bpi-r2-ubuntu:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 02:02:02:02:02:02 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::2:2ff:fe02:202/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 02:03:03:03:03:03 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::3:3ff:fe03:303/64 scope link 
       valid_lft forever preferred_lft forever
4: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
5: wan@eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 02:03:03:03:03:03 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.11/24 brd 192.168.0.255 scope global wan
       valid_lft forever preferred_lft forever
    inet6 fe80::3:3ff:fe03:303/64 scope link 
       valid_lft forever preferred_lft forever
6: lan0@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br0 state LOWERLAYERDOWN group default qlen 1000
    link/ether 02:02:02:02:02:02 brd ff:ff:ff:ff:ff:ff
7: lan1@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br0 state LOWERLAYERDOWN group default qlen 1000
    link/ether 02:02:02:02:02:02 brd ff:ff:ff:ff:ff:ff
8: lan2@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br0 state LOWERLAYERDOWN group default qlen 1000
    link/ether 02:02:02:02:02:02 brd ff:ff:ff:ff:ff:ff
9: lan3@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br0 state LOWERLAYERDOWN group default qlen 1000
    link/ether 02:02:02:02:02:02 brd ff:ff:ff:ff:ff:ff
10: br0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 02:02:02:02:02:02 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.1/24 brd 192.168.1.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::2:2ff:fe02:202/64 scope link 
       valid_lft forever preferred_lft forever
11: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:08:22:f0:cd:fb brd ff:ff:ff:ff:ff:ff
12: ap0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 02:08:22:f0:cd:fb brd ff:ff:ff:ff:ff:ff
    inet 192.168.13.1/24 scope global ap0
       valid_lft forever preferred_lft forever
    inet6 fe80::8:22ff:fef0:cdfb/64 scope link 
       valid_lft forever preferred_lft forever

Thanks for testing,than it seems to be a bug in wifi-driver,but the values are huge for eth0/lan1/br0 too…so this numbers do not indicating the error. I guess there is any callback function called that breaks functionality,but have no clue where to search

i tried starting ap-mode in 5.10, but it hangs (can login via ssh) and does not create the ap0 interface

root       436  0.0  0.1   6520  2368 ttyS0    Ss   11:57   0:00 /bin/login -p --
root       533  0.0  0.1   4440  2456 ttyS0    S    12:00   0:00  \_ -bash
root       538  0.0  0.1   4188  2336 ttyS0    R+   12:00   0:00      \_ /bin/bash /usr/local/sbin/wifi.sh
root       549  0.0  0.0   9764   456 ttyS0    T+   12:00   0:00          \_ /usr/bin/stp_uart_launcher -p /etc/firmware

in wifi driver-log i came till this point:

[  232.735911] [MTK-WIFI] WIFI_open: WIFI_open: major 155 minor 0 (pid 538)     
[  232.742773] [MTK-WIFI] WIFI_write: WIFI_write A                              
[  232.742773]                                                                  
[  232.791863] kalFirmwareImageMapping firmware size 225840                     
                                                                                
[  233.982856] [MTK-WIFI] register_set_p2p_mode_handler: (pid 544) register set1
[  233.992362] [MTK-WIFI] WIFI_write: WMT turn on WIFI success

i unloaded mt7615-module and it works…seems like any conflict :thinking: maybe because my mt7615 is named wlan0 and mt6625l tries also creating an wlan0 device (additional to the ap0)

correct, i rebooted, enabled dbdc on mt7615 (for other test) and renamed both interfaces

ip link set wlan0 name wlan_2g
ip link set wlan1 name wlan_5g

and then started wifi.sh for internal ap0, works and ip a show this:

9: wlan_2g: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000                                                                                  
    link/ether 00:0a:52:05:c9:e2 brd ff:ff:ff:ff:ff:ff                                                                                                                    
10: wlan_5g: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000                                                                                 
    link/ether 82:0a:52:05:c9:e2 brd ff:ff:ff:ff:ff:ff                                                                                                                    
11: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000                                                                                   
    link/ether 00:08:22:18:bc:03 brd ff:ff:ff:ff:ff:ff                                                                                                                    
12: ap0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000                                                                             
    link/ether 02:08:22:18:bc:03 brd ff:ff:ff:ff:ff:ff                                                                                                                    
    inet 192.168.18.1/24 scope global ap0                                                                                                                                 
       valid_lft forever preferred_lft forever                                                                                                                            
    inet6 fe80::8:22ff:fe18:bc03/64 scope link                                                                                                                            
       valid_lft forever preferred_lft forever    

so it looks like driver tries to create wlan0 (which failes if interface exists) and/or wait for its creation/driver own…

so if you want to use the internal wifi on r2 (like me), make sure, there is no wlan0 before starting wifi.sh

debugged so far…

rootcause is adding a handler to wrong netdev searched with hardcoded wlan0 in drivers/misc/mediatek/connectivity/common/conn_soc/linux/pub/wmt_chrdev_wifi.c

#define WLAN_IFACE_NAME "wlan0"
static INT8 *ifname = WLAN_IFACE_NAME;
netdev = dev_get_by_name(&init_net, ifname);
pf_set_p2p_mode(netdev, p2pmode);

Currently i have no idea how to pass the wifi-devicename created in gl_init.c to wmt_chrdev_wifi.c

I tried to write a get_netdev function which tries wifi9 down to 0,but i get still an error which i need to solve…maybe because i try to set ifname which is a int8 * and no char*

Good news, i tested vendors 4.14 for client mode and it works. Ap too…and the best: it seems to be based on my codebase,as i see my debugs,i’ve disabled later. That makes it easy to find possible fix for client-mode. I make some tests and apply the fix to all lts/main branches if ready

mhm, in 5.10.32-bpi-r2-hnat, client-mode is working

difference to ap-mode:

/etc/wpa_supplicant/wpa_supplicant.conf:

network={
        ssid="ssid"
        psk="12345678"
        priority=1
}

wmt_loader and stp_uart-launcher needs to be called before, and needed modules loaded (wifi/BT)

instead of echo A we do echo 1 here:

echo 1 >/dev/wmtWifi
wpa_supplicant -i mt6625_0 -c /etc/wpa_supplicant/wpa_supplicant.conf &
dhclient mt6625_0

i got ip-adress from my dhcp-server (dnsmasq) and can ping it (of course wan/lan-disconnected)

11: mt6625_0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group
 default qlen 1000                                                              
    link/ether 00:08:22:f6:5c:fd brd ff:ff:ff:ff:ff:ff                          
    inet 192.168.10.110/24 brd 192.168.10.255 scope global dynamic mt6625_0

root@bpi-r2:~# ping -c 1 192.168.10.1                                           
PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data.                          
64 bytes from 192.168.10.1: icmp_seq=1 ttl=64 time=4.12 ms                      
                                                                                
--- 192.168.10.1 ping statistics ---                                            
1 packets transmitted, 1 received, 0% packet loss, time 0ms                     
rtt min/avg/max/mdev = 4.118/4.118/4.118/0.000 ms                               
root@bpi-r2:~#

maybe anybody can tell me why this is changed in official 4.14?

wifi-fix.patch (1,4 KB)

@Jackzeng seems to be no more here :frowning: maybe @sinovoip have an idea?

1 Like

Hey, thanks to Franks wiki I got the internal WiFi working to connect to my main network. Unfortunately it seems that the internal WiFi also likes to change MAC address on boot. Is there a way to hardcode the MAC adress of the internal WiFi? I have seen the instructions for the Ethernet ports (though I am not sure if they currently work correctly), but because the way you have to bring up the mt6625_0 device, I have not found a way to set its MAC address.

Imho udev way should work for wifi too. For client mode match mt6625l_0 and for ap-mode ap0

You can write sh that can chnage mac on run/ boot. Just need to ifconfig ap0 down. Ifconfig ap0 hwadress MAC. And start the ap0.

Right…you can add it to the wifi.sh before doing anything with ap0…if using ap-mode

Currently I try to use it in client mode. I use the systemd script to start the device, which works:

root@bpi-r2:~# ip link show mt6625_0
9: mt6625_0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:08:22:60:d1:fb brd ff:ff:ff:ff:ff:ff

wpa_supplicant is setup and using dhclient mt6625_0 lets me connect to my home wifi successfully. I’m running kernel bpi-r2 5.4.134-bpi-r2-main

I have set following udev rule:

ACTION=="add", SUBSYSTEM=="net", KERNEL=="mt6625_0", RUN+="/sbin/ip link set dev %k address 00:00:00:00:13:37"

in file

/etc/udev/rules.d/00-static-mac-address.rules

This rule should work, as indicated by

root@bpi-r2:~# udevadm test /sys/class/net/mt6625_0
Load module index
Parsed configuration file /lib/systemd/network/99-default.link
Created link configuration context.
Reading rules file: /etc/udev/rules.d/00-static-mac-address.rules
[...]
Reading rules file: /lib/udev/rules.d/99-systemd.rules
Rules contain 24576 bytes tokens (2048 * 12 bytes), 12552 bytes strings
1781 strings (22159 bytes), 1171 de-duplicated (10218 bytes), 611 trie nodes used
Using default interface naming scheme 'v240'.
Config file /lib/systemd/network/99-default.link applies to device mt6625_0
link_config: autonegotiation is unset or enabled, the speed and duplex are not writable.
DEVPATH=/devices/platform/180f0000.wifi/net/mt6625_0
DEVTYPE=wlan
INTERFACE=mt6625_0
IFINDEX=9
ACTION=add
SUBSYSTEM=net
ID_NET_NAMING_SCHEME=v240
ID_NET_NAME_MAC=wlx00082260d1fb
ID_OUI_FROM_DATABASE=InPro Comm
ID_PATH=platform-180f0000.wifi
ID_PATH_TAG=platform-180f0000_wifi
ID_NET_DRIVER=mt-wifi
ID_NET_LINK_FILE=/lib/systemd/network/99-default.link
TAGS=:systemd:
SYSTEMD_ALIAS=/sys/subsystem/net/devices/mt6625_0
USEC_INITIALIZED=26118286
run: '/sbin/ip link set dev mt6625_0 address 00:00:00:00:13:37'
run: 'bridge-network-interface'
run: 'ifupdown-hotplug'
run: '/lib/systemd/systemd-sysctl --prefix=/net/ipv4/conf/mt6625_0 --prefix=/net/ipv4/neigh/mt6625_0 --prefix=/net/ipv6/conf/mt6625_0 --prefix=/net/ipv6/neigh/mt6625_0'
Unload module index
Unloaded link configuration context.

The command to set the mac address is found in the output here. Unfortunately, after a reboot, the mac address is not 00:00:00:00:13:37 .

Manually trying to change the mac yields this:

root@bpi-r2:~# ip link set dev mt6625_0 down
root@bpi-r2:~# ip link show mt6625_0         
9: mt6625_0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
link/ether 00:08:22:60:d1:fb brd ff:ff:ff:ff:ff:ff
root@bpi-r2:~# /sbin/ip link set dev mt6625_0 address 00:00:00:00:13:37
RTNETLINK answers: Operation not supported
root@bpi-r2:~# ip link show mt6625_0                                    
9: mt6625_0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
link/ether 00:08:22:60:d1:fb brd ff:ff:ff:ff:ff:ff

I hope I’m just making a stupid mistake. Thanks for your help in advance!

maybe this MAC is dropped because it is invalid? but wonder why it works the first time. maybe you should use INTERFACE instead of KERNEL

INTERFACE is not shown as an identifier here:

root@bpi-r2:~# udevadm info -a -p /sys/class/net/mt6625_0

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/platform/180f0000.wifi/net/mt6625_0':
    KERNEL=="mt6625_0"
    SUBSYSTEM=="net"
    DRIVER==""
    ATTR{dev_id}=="0x0"
    ATTR{carrier_changes}=="0"
    ATTR{name_assign_type}=="2"
    ATTR{addr_assign_type}=="0"
    ATTR{type}=="1"
    ATTR{carrier_down_count}=="0"
    ATTR{mtu}=="1500"
    ATTR{addr_len}=="6"
    ATTR{iflink}=="9"
    ATTR{gro_flush_timeout}=="0"
    ATTR{operstate}=="down"
    ATTR{proto_down}=="0"
    ATTR{carrier_up_count}=="0"
    ATTR{link_mode}=="0"
    ATTR{netdev_group}=="0"
    ATTR{address}=="00:08:22:00:d2:fb"
    ATTR{broadcast}=="ff:ff:ff:ff:ff:ff"
    ATTR{tx_queue_len}=="1000"
    ATTR{flags}=="0x1002"
    ATTR{dev_port}=="0"
    ATTR{ifalias}==""
    ATTR{ifindex}=="9"

  looking at parent device '/devices/platform/180f0000.wifi':
    KERNELS=="180f0000.wifi"
    SUBSYSTEMS=="platform"
    DRIVERS=="mt-wifi"
    ATTRS{driver_override}=="(null)"

  looking at parent device '/devices/platform':
    KERNELS=="platform"
    SUBSYSTEMS==""
    DRIVERS==""

but can be seen in my post above when running udevadm test /sys/class/net/mt6625_0

Trying ACTION=="add", SUBSYSTEM=="net", INTERFACE=="mt6625_0", RUN+="/sbin/ip link set dev %k address ba:de:af:fe:13:37" as udev rule does not seem to work:

root@bpi-r2:~# udevadm test /sys/class/net/mt6625_0
Rules contain 24576 bytes tokens (2048 * 12 bytes), 12673 bytes strings
1791 strings (22294 bytes), 1177 de-duplicated (10236 bytes), 615 trie nodes used
Using default interface naming scheme 'v240'.
Config file /lib/systemd/network/99-default.link applies to device mt6625_0
link_config: autonegotiation is unset or enabled, the speed and duplex are not writable.
DEVPATH=/devices/platform/180f0000.wifi/net/mt6625_0
DEVTYPE=wlan
INTERFACE=mt6625_0
IFINDEX=9
ACTION=add
SUBSYSTEM=net
ID_NET_NAMING_SCHEME=v240
ID_NET_NAME_MAC=wlx00082200d2fb
ID_OUI_FROM_DATABASE=InPro Comm
ID_PATH=platform-180f0000.wifi
ID_PATH_TAG=platform-180f0000_wifi
ID_NET_DRIVER=mt-wifi
ID_NET_LINK_FILE=/lib/systemd/network/99-default.link
TAGS=:systemd:
SYSTEMD_ALIAS=/sys/subsystem/net/devices/mt6625_0
USEC_INITIALIZED=26304977
run: 'bridge-network-interface'
run: 'ifupdown-hotplug'
run: '/lib/systemd/systemd-sysctl --prefix=/net/ipv4/conf/mt6625_0 --prefix=/net/ipv4/neigh/mt6625_0 --prefix=/net/ipv6/conf/mt6625_0 --prefix=/net/ipv6/neigh/mt6625_0'
Unload module index

The command to set the mac does not appear. I tried with a different mac instead: ACTION=="add", SUBSYSTEM=="net", KERNEL=="mt6625_0", RUN+="/sbin/ip link set dev %k address ba:de:af:fe:13:37" (this should be valid, it is not a multicast address and it is a local-only mac address) This does verify again with udevadm test, but does not set the mac.

Changing the mac addresses of the other ports does work just fine:

ACTION=="add", SUBSYSTEM=="net", KERNELS=="1b100000.ethernet", RUN+="/sbin/ip link set dev %k address ba:de:af:fe:ff:ff"
ACTION=="add", SUBSYSTEM=="net", KERNEL=="lan0", RUN+="/sbin/ip link set dev %k address ba:de:af:fe:00:00"
ACTION=="add", SUBSYSTEM=="net", KERNEL=="lan1", RUN+="/sbin/ip link set dev %k address ba:de:af:fe:00:01"

This gives every adapter connected to eth0 the address ba:de:af:fe:ff:ff and lan0 ba:de:af:fe:00:00 as well as lan1 ba:de:af:fe:00:01 :

root@bpi-r2:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1504 qdisc pfifo_fast state UP group default qlen 1000
    link/ether ba:de:af:fe:ff:ff brd ff:ff:ff:ff:ff:ff
    inet6 fe80::b8de:afff:fefe:ffff/64 scope link 
       valid_lft forever preferred_lft forever
3: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
4: wan@eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether ba:de:af:fe:ff:ff brd ff:ff:ff:ff:ff:ff
5: lan0@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether ba:de:af:fe:00:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.178.170/24 brd 192.168.178.255 scope global dynamic lan0
       valid_lft 863054sec preferred_lft 863054sec
    inet6 2001:16b8:a0f:6700:b8de:afff:fefe:0/64 scope global dynamic mngtmpaddr 
       valid_lft 6824sec preferred_lft 3224sec
    inet6 fe80::b8de:afff:fefe:0/64 scope link 
       valid_lft forever preferred_lft forever
6: lan1@eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether ba:de:af:fe:00:01 brd ff:ff:ff:ff:ff:ff
7: lan2@eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether ba:de:af:fe:ff:ff brd ff:ff:ff:ff:ff:ff
8: lan3@eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether ba:de:af:fe:ff:ff brd ff:ff:ff:ff:ff:ff
9: mt6625_0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:08:22:00:d2:fb brd ff:ff:ff:ff:ff:ff

I feel like the issue must lie deeper, but the only info I get is

root@bpi-r2:~# ip link set mt6625_0 address ba:de:af:fe:13:37
RTNETLINK answers: Operation not supported

I do not know where to go from here.

ok, then KERNEL is right…maybe interface is not in down state when udev triggers? how do you run the wmt-commands? imho it’s easier to put your command there before set interface up

Right now I tried manually bringing up the device (I disabled the systemd script which I used so far):

root@bpi-r2:~# /usr/bin/wmt_loader 
init combo device
Opened combo device
get device id : 30243
set device id : 30243
do module init: 30243
failed to init module

root@bpi-r2:~# /usr/bin/stp_uart_launcher -p /etc/firmware/ &
[1] 413

root@bpi-r2:~# open device node succeed.(Node:/dev/stpwmt, fd:3) 
chip id is 0x7623
chiId:0x7623, setting to property(D�)
chiId:0x7623
run SOC chip flow
create pwr on thread ok
enter power on connsys flowpatch name pre-fix:ROMv2_lm_patch
fwVersion:0x8a00
/etc/firmware//ROMv2_lm_patch_1_0_hdr.bin
fw Ver in patch: 0x8a00
read patch info:0x22,0x00,0x06,0x00
gpatchnum = [2]
gdwonseq = [2]
/etc/firmware//ROMv2_lm_patch_1_1_hdr.bin
fw Ver in patch: 0x8a00
read patch info:0x21,0x00,0x0e,0xf0
gdwonseq = [1]
cmd(srh_patch) resp(ok)

root@bpi-r2:~# echo 1 > /dev/wmtWifi 
root@bpi-r2:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1504 qdisc pfifo_fast state UP group default qlen 1000
    link/ether ba:de:af:fe:ff:ff brd ff:ff:ff:ff:ff:ff
    inet6 fe80::b8de:afff:fefe:ffff/64 scope link 
       valid_lft forever preferred_lft forever
3: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
4: wan@eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether ba:de:af:fe:ff:ff brd ff:ff:ff:ff:ff:ff
5: lan0@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether ba:de:af:fe:00:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.178.170/24 brd 192.168.178.255 scope global dynamic lan0
       valid_lft 863694sec preferred_lft 863694sec
    inet6 2001:16b8:a0f:6700:b8de:afff:fefe:0/64 scope global dynamic mngtmpaddr 
       valid_lft 6905sec preferred_lft 3305sec
    inet6 fe80::b8de:afff:fefe:0/64 scope link 
       valid_lft forever preferred_lft forever
6: lan1@eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether ba:de:af:fe:00:01 brd ff:ff:ff:ff:ff:ff
7: lan2@eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether ba:de:af:fe:ff:ff brd ff:ff:ff:ff:ff:ff
8: lan3@eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether ba:de:af:fe:ff:ff brd ff:ff:ff:ff:ff:ff
9: mt6625_0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:08:22:a0:d7:00 brd ff:ff:ff:ff:ff:ff

root@bpi-r2:~# ip link set mt6625_0 address ba:de:af:fe:11:37
RTNETLINK answers: Operation not supported

The earliest the mt6625_0 device appears, is after executing echo 1 >/dev/wmtWifi.

It is a bit annoying, because I can use the internal WiFi for networking, but having a static mac address would save me a few headaches ^^

Do you really have random mac? Comment in nic_cmd_event.c means it is copied from firmware.

Maybe you can add some debug?

This looks related

It seems to me to be random, at least the last three octets change. After preparing the adapter with wmt_loader and stp_uart_tools, I have tried

echo 1 > /dev/wmtWifi
ip a
echo 0 > /dev/wmtWifi

a few times and everytime the mac changed:

00:08:22:22:40:fd
00:08:22:80:04:fe 
00:08:22:41:e9:fe 
00:08:22:c0:63:ff
After rebooting:
00:08:22:3e:25:fc
00:08:22:10:a8:fc

I will try to look into the code over the weekend, maybe your hint can help. I can also add dmesg output tomorrow. Thanks again for helping and looking into the issue!