[BPI-R64] mt7622 mac80211 WiFi driver

i tried 5.8-main and there firmware is loaded the first time (no driver own issue)…so something is changed till 5.8 and 5.9 causing this issue

@skype which kernel did you use (5.9+)?

I am using linux 5.4.72, your branch.

Ah,ok, i got the driver own issue only on 5.9+,maybe the len-issue is also only there

in my 5.4 i see the semaphore-problem again (imho this was because bluetooth/rfkill)

root@bpi-r64:~# modprobe -r mt7622
root@bpi-r64:~# modprobe mt7622
[  100.778469] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[  100.787154] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[  100.794318] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
[  100.803989] cfg80211: failed to load regulatory.db
[  100.817743] mt7622_wmac 18000000.wmac: ASIC revision: 76220010
[  100.823808] mt7622_wmac 18000000.wmac: Invalid MAC address, using random address 42:de:fd:15:bb:52
[  100.832854] mt7622_wmac 18000000.wmac: MAC addr = 42:de:fd:15:bb:52
[  111.069495] mt7622_wmac 18000000.wmac: Message -16 (seq 1) timeout
[  111.075697] mt7622_wmac 18000000.wmac: Failed to get patch semaphore
[  111.083874] mt7622_wmac: probe of 18000000.wmac failed with error -11

with eeprom-patch it looks like this:

root@bpi-r64:~# modprobe -r mt7622
root@bpi-r64:~# modprobe rfkill
root@bpi-r64:~# modprobe mt7622
[   55.822252] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[   55.830948] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[   55.838025] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
[   55.847673] cfg80211: failed to load regulatory.db
[   55.860947] mt7622_wmac 18000000.wmac: ASIC revision: 76220010
[   55.866845] mt7622_wmac 18000000.wmac: Load firmware : /lib/firmware/mediatek/mt7622_wmac_rf.bin
[   55.875668] mt7622_wmac 18000000.wmac: Load firmware Failed : /lib/firmware/mediatek/mt7622_wmac_rf.bin
[   55.885127] mt7622_wmac 18000000.wmac: Invalid MAC address, using random address 46:c0:74:51:9a:d9
[   55.894111] mt7622_wmac 18000000.wmac: MAC addr = 46:c0:74:51:9a:d9
[   66.013328] mt7622_wmac 18000000.wmac: Message -16 (seq 1) timeout
[   66.019530] mt7622_wmac 18000000.wmac: Failed to get patch semaphore
[   66.027684] mt7622_wmac: probe of 18000000.wmac failed with error -11
root@bpi-r64:~#

mhm, failed is because file is named “mt7622-wmac_rf.bin” instead of “mt7622_wmac_rf.bin” (seems filename differs between 5.4 and 5.9)…modulename is in 5.4 (mt76_new) also mt7622 and not part of mt7615e

after removing the CONFIG_BT and copy the eeprom-file to other name:

root@bpi-r64:~# modprobe -r mt7622
root@bpi-r64:~# modprobe mt7622
[   84.258144] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[   84.266821] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[   84.273471] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
[   84.282212] cfg80211: failed to load regulatory.db
[   84.353538] mt7622_wmac 18000000.wmac: ASIC revision: 76220010
[   84.359422] mt7622_wmac 18000000.wmac: Load firmware : /lib/firmware/mediatek/mt7622_wmac_rf.bin
[   84.369517] mt7622_wmac 18000000.wmac: Load firmware OK, count 1024 byte
[   84.376288] mt7622_wmac 18000000.wmac: MAC addr = 00:0c:43:26:60:00
[   84.383543] mt7622_wmac 18000000.wmac: HW/SW Version: 0x8a108a10, Build Time: 20190801210006a
[   84.383543] 
[   84.406056] mt7622_wmac 18000000.wmac: N9 Firmware Version: _reserved_, Build Time: 20190801210351
[   84.461907] mt7622_wmac 18000000.wmac: Firmware init done
[   84.487375] mt7622_wmac 18000000.wmac: Driver own success
[   88.245589] ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
root@bpi-r64:~# 

so eeprom-load on 5.4 works if CONFIG_BT is disabled…else i got the semaphore-error. on 5.9+ i got the driver-own issue and eeprom load failed because len is too big (eeprom-size differently in eeprom_init)

@nagi have you an idea about the driver own issue? It seems not related to bluetooth (like semaphore issue on 5.4).

Mhm,found this https://github.com/openwrt/mt76/issues/438#issuecomment-688114445, but it’s not compatible with my 5.9 source…seems there are Patches missing. but it looks like 5.9.3 has the patch already… => driver own issue fixed in 5.9.3…still have the different len problem…

drivers/net/wireless/mediatek/mt76/mt7615/eeprom.c:75:	ret = mt76_eeprom_init(&dev->mt76, MT7615_EEPROM_FULL_SIZE);
drivers/net/wireless/mediatek/mt76/mt7615/eeprom.h:20:#define MT7615_EEPROM_FULL_SIZE			(MT7615_EEPROM_TXDPD_OFFSET + \
drivers/net/wireless/mediatek/mt76/mt7615/eeprom.h-21-						 MT7615_EEPROM_TXDPD_COUNT * \
drivers/net/wireless/mediatek/mt76/mt7615/eeprom.h-22-						 MT7615_EEPROM_TXDPD_SIZE)

it looks like this calculation has changed a bit with dc7bd30b97aa (mt76: mt7615: fix EEPROM buffer size), but was also larger than 1k

drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h:54:#define MT7615_EEPROM_SIZE		1024
drivers/net/wireless/mediatek/mt76/mt7615/eeprom.h:14:#define MT7615_EEPROM_TXDPD_OFFSET		(MT7615_EEPROM_SIZE + \
drivers/net/wireless/mediatek/mt76/mt7615/eeprom.h-15-						 MT7615_EEPROM_DCOC_COUNT * \
drivers/net/wireless/mediatek/mt76/mt7615/eeprom.h-16-						 MT7615_EEPROM_DCOC_SIZE)
drivers/net/wireless/mediatek/mt76/mt7615/eeprom.h:11:#define MT7615_EEPROM_DCOC_SIZE			256
drivers/net/wireless/mediatek/mt76/mt7615/eeprom.h-12-#define MT7615_EEPROM_DCOC_COUNT		34

on entering the mt76_eeprom_init-function i have a len of 19880, so we cannot check again the len…maybe it’s better to check for filesize after read and then fill eeprom-buffer with 0x00

DEBUG: Passed mt76_eeprom_init 127 len:19880

the ret=len imho only works for mtd, if the mtd-partition has same size as eeprom

added a filesize-function and compared the loaded bytes with its return-value…now i got read ok

root@bpi-r64:~# modprobe mt7615e
[  957.477558] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[  957.630999] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[  957.638469] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
[  957.649409] cfg80211: failed to load regulatory.db
[  957.821120] DEBUG: Passed mt76_eeprom_init 150 len:19880 
[  957.827020] mt7622-wmac 18000000.wmac: Load firmware : /lib/firmware/mediatek/mt7622-wmac_rf.bin
[  957.841716] DEBUG: Passed mt76_get_of_file 51 fsize:1024 
[  957.853486] mt7622-wmac 18000000.wmac: Load firmware OK, count 1024 byte
[  957.875826] ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
root@bpi-r64:~# [  957.955821] mt7622-wmac 18000000.wmac: N9 Firmware Version: _reserved_, Build Time: 20190801210351

and it looks like mac is correctly read from eeprom-file

10: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:0c:43:26:60:00 brd ff:ff:ff:ff:ff:ff
root@bpi-r64:~# hd /lib/firmware/mediatek/mt7622-wmac_rf.bin |less
00000000  22 76 05 00 00 0c 43 26  60 00...
1 Like

as i see all have 4 bytes (first 54Mbit,channel1-6,7-10,11-14 as delta). i guess i need to set only the position you’ve mentioned…with delta-bytes=0 all should have same tx-power,right?

is the value directly the dBM (like comment mentiones)?

the defined value 00100110 is then 38dB (in eeprom-file too for all 4 antennas) which seems wrong to me…(26 in front of the line is hexadecimal representation). what is suggested (imho ~21dB) or max value?

also it looks like the eeprom also contain MACs for BT and both ethernet-ports (full mt7622 eeprom)

0x26 decimal is 38, I guess it should be: 38 * 0.5 = 19dBm, the other three parameters should be fine-tuned, so just leave it alone.

I think there should be a Bluetooth address set. I haven’t debugged Bluetooth there. I am not familiar with it. I think I still need to ask you for advice in the future.

why this calculation? or did you get -19dB with the value of 38?

is there an easier way to get the filesize? see my repo i linked before for my current implementation

for bluetooth i did not much except adding some patches, installed bluez and made some basic tests with bluetoothctl

@nagi is there a way to fix the semaphore-issue on (my) 5.4 without disabling CONFIG_BT? i have still the modprobe-config which loads rfkill before mt7622

why this calculation? or did you get -19dB with the value of 38?

The power values are in unit of 0.5dBm in registers.

@nagi is there a way to fix the semaphore-issue on (my) 5.4 without disabling CONFIG_BT? i have still the modprobe-config which loads rfkill before mt7622

This happens because both wifi and bt share some parts in the wbsys, I haven’t dived into this issue yet.

1 Like

could you try kernel from my tree? change in build.conf board to bpi-r64 (remove # ), run

  • ./build.sh importconfig
  • ./build.sh

in mainline-kernel bluetooth is not working, at least because the scpsys and tty-patch is missing

or use kernels compiled from travis (github-releases)

Btw. I read that set_fs will be limited in 5.10 for some architectures because it can be a security hole. Is there any way to get the filesize without it?

1 Like

Hi frank,

Could you try this patch and see if patch semaphore problem fixes in mt7622? (With BT subsystem enabled)

It also tries to init again as you did, but merged into the code.

1 Like

thanks, this seems to fix it (need to patch manually, but it’s small patch) :slight_smile:

 root@bpi-r64:~# uname -a                                                        
Linux bpi-r64 5.4.72-bpi-r64-main #1 SMP PREEMPT Wed Nov 11 10:53:44 CET 2020 ax
root@bpi-r64:~# dmesg | grep hci0                                               
[    6.578465] Bluetooth: hci0: Device setup in 242847 usecs                    
root@bpi-r64:~# dmesg | grep mt7622                                             
[    0.000000] Kernel command line: board=bpi-r64 console=ttyS0,115200n1 earlyp2
[    1.191837] rtc_mt7622 10212800.rtc: registered as rtc0                      
[    1.931814] rtc_mt7622 10212800.rtc: setting system clock to 2000-01-01T00:0)
[    6.366853] mt7622_wmac 18000000.wmac: ASIC revision: 76220010               
[    6.410250] mt7622_wmac 18000000.wmac: Load firmware : /lib/firmware/mediaten
[    6.466927] mt7622_wmac 18000000.wmac: Load firmware OK, count 1024 byte     
[    6.497514] mt7622_wmac 18000000.wmac: MAC addr = 00:0c:43:26:60:00          
[    6.536181] mt7622_wmac 18000000.wmac: N9 Firmware Version: _reserved_, Buil1
[    6.633222] mt7622_wmac 18000000.wmac: Firmware init done                    
[    6.657449] mt7622_wmac 18000000.wmac: Driver own success                    
root@bpi-r64:~#
1 Like

@nagi: it seems we have a side-effect for the semaphore-fix: [R2] Need help with Debian 10 and MT7615 PCIe card

on missing firmware-file it tries again too…this should not be done…but it seems semaphore-issue happens before loading any firmware-file

@skype i think i’ve found another way to get filesize of eeprom-file without the set_fs function:

Maybe we can use

struct inode			*inode = NULL;
loff_t				size;

inode = file_inode(filp);
size = i_size_read(inode->i_mapping->host);

Like it’s done here: https://elixir.bootlin.com/linux/v5.10-rc1/source/drivers/usb/gadget/function/storage_common.c#L224