[BPI-R2] internal Wifi/BT (MT6625L) - 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!

mhm, i guess the hook, triggered by ip link address is not implemented…but i do not know more…but still wondering why i has worked one time

I assume client-mode also works for 5.10.76, correct?

i guess too, as there were no changes…i use only ap-mode

UPDATE: Several hours later (and a complete work shift), I finally got around to trying it on 5.10.76. It does appear to work on the onboard wifi. Thanks!

EDIT: Apologees for not being brave enough to try it first before asking questions. It was right before my work shift started and I needed to leave in a few minutes. Thought I’d ask before trying it. Wanna save my hair from being pulled out! :stuck_out_tongue:

You could try on 5.15-main too :slight_smile:

I just compiled 5.15-main branch on my computer and tried it on my R2. It appears to work, as I can get a DHCP address from my primary router. I can aslo ping my primary router, as well. However, pinging my computer that I’m SSH’ing from doesn’t work, nor does any internet site… (Sigh…)

I need to do more investigation to see what the problem with my configuration is… I’ll update once I figure out how to fix the problem…

Without knowing your network topology and what works exactly and what not we can’t help here.

Do you try pinging over r2 (e.g. client on wifi - traffic over wan)? Then your main-router needs to know subnet of wifi to be reached over r2.

Okay, I figured out what was going on. I forgot I needed a firewall rule to masquerade to the wifi internet connection… Had one for the WAN port, not the wireless interface… Also had to rewrite some of my firewall script in order to deal with lack of pings and masquerading interfaces, so this is a plus…

I also figured out how to bring the mt6625_0 and ap0 interfaces up before the networking services starts. In this way, those interfaces can be correctly configured by the networking services.

My /sbin/networking-helper.sh script:

#!/bin/bash
#############################################################################
# Bring the "eth0" interface up if not already up:
#############################################################################
ifconfig eth0 2> /dev/null | grep "UP," &> /dev/null || /sbin/ifup eth0 >& /dev/null
ifconfig eth1 2> /dev/null | grep "UP," &> /dev/null || /sbin/ifup eth1 >& /dev/null

#############################################################################
# Enable DBDC on any MT76xx wifi card that supports it:
#############################################################################
for file in /sys/kernel/debug/ieee80211/*; do
	test -e $file/mt76/dbdc && echo 1 > $file/mt76/dbdc
done

#############################################################################
# Load support files for R2's onboard Wifi/BT hardware and set WiFi mode:
#############################################################################
if [[ ! -e /dev/wmtWifi ]]; then
	/usr/bin/wmt_loader &> /var/log/wmtloader.log
	sleep 3
fi
if [[ -c /dev/stpwmt ]]; then
	if ! ps aux | grep stp_uart_launcher | grep -v grep >& /dev/null; then
		/usr/bin/stp_uart_launcher -p /etc/firmware &> /var/log/stp_launcher.log &
		sleep 5
	fi
fi
modprobe wlan_gen2
[[ -f /var/run/wmtWifi ]] && echo 0 > /dev/wmtWifi && sleep 3
echo $([[ "${ONBOARD_WIFI:-"A"}" == "A" ]] && echo A || echo 1) | tee /var/run/wmtWifi > /dev/wmtWifi

#############################################################################
# Rename the WiFi interfaces on the MT76xx wifi card:
#############################################################################
cd /sys/class/net
LIST=($(ls -l | grep pcie | awk '{print $9}'))
if [[ ! -z "${LIST[@]}" ]]; then
	for IFACE in ${LIST[@]}; do
		DEV="$(lspci -s $(basename $(ls -l ${IFACE}/device | awk '{print $NF}')) | grep MEDIATEK | awk '{print $NF}')"
		if [[ ! -z "${DEV}" ]]; then
			[[ -f /sys/kernel/debug/ieee80211/$(basename $(ls -l ${IFACE}/phy80211 | awk '{print $NF}'))/mt76/dbdc ]] && POST=24g || POST=5g
			NEW=mt${DEV}_${POST}
			ip link set ${IFACE} name ${NEW}
			iw dev ${NEW} interface add ${NEW}_0 type managed
			REN=$(dmesg | grep ${NEW}_0 | head -1 | awk '{print $5}' | sed 's|:||g')
			[[ "$REN" != "${NEW}_0" ]] && ip link set ${REN} name ${NEW}_0
		fi
	done
fi

#############################################################################
# Return error code 0 to the caller:
#############################################################################
exit 0

My /lib/systemd/system/networking.service.d/changes.conf:

[Service]
ExecStartPre=/sbin/networking-helper.sh
ExecStart=
ExecStart=/sbin/ifup -a --read-environment --exclude=eth0

Hopefully this will help someone…

These changes will allow the networking service to be restarted without the errors concerning the eth0 and/or eth1 interfaces… Speaking of which, eth1 and aux showed up while running kernel 5.15.11, while it didn’t on 5.10.76… Any insights to this?

Yes with masquerading you hide your wifi subnet…wifi clients reach your mainrouter with the subnet it knows.

It should be eth0 and aux and eth0/1 on older kernels (eth1 may be missing). Eth1/aux is same port but it needs some work to can use it. You can make a vlan-aware bridge to map wan-port to it an use both gmacs. This is becauae dsa core (which does the wan/lanX) only support 1 upstream/cpu port and the other cannot be used that easy

I assume using both gmacs would increase performance, right? If so, I’m interested in learning how…

It reduces traffic on eth0 by routing wan - traffic over eth1/aux

See second ethernet lane here: https://www.fw-web.de/dokuwiki/doku.php?id=en:bpi-r2:network:start#permanent

When booting from emmc the eth1 GMAC only works with bootswitch in 0 position…

On r2 too? I thought this was only r64. But imho bootswitch makes only sense in 1 position (try sdcard first than emmc). But cannot try it on r2 as my version (1.1) has no bootswitch (non working bat connector)

Ah forgot we’re writing about the R2… I do not own one so I also cannot test it. It is bootrom related so it could be in that rom too…

I’m waiting to buy an R2 pro. Just got an old rk3288 board out if the dustpile to get to know the rockchip boot process a little.

I tried this tip on my copy of Debian 10 running kernel 5.15.11 and I saw a definite improvement. Also, if anybody is interested, I want to note that while the onboard wifi is in AP mode, you CAN create a client connection, but not both AP and client at the same time. Must be one or the other…

EDIT: I can create a DHCP client connection only on the mt6625_0 interface. Apparently, I cannot do so on the ap0 interface, even though iw list says that I should be able to (it supports managed mode).

2nd EDIT: Cannot get bluetooth up and running… Maybe you can do client and AP, haven’t tested the combination…