Need help porting mt76-driver to R2-Kernel

using now VM with Ubuntu 16.4:

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 

installed toolchain:

$ ls /usr/bin/arm*
/usr/bin/arm2hpdl
/usr/bin/arm-linux-gnueabihf-addr2line
/usr/bin/arm-linux-gnueabihf-ar
/usr/bin/arm-linux-gnueabihf-as
/usr/bin/arm-linux-gnueabihf-c++filt
/usr/bin/arm-linux-gnueabihf-cpp
/usr/bin/arm-linux-gnueabihf-cpp-5
/usr/bin/arm-linux-gnueabihf-dwp
/usr/bin/arm-linux-gnueabihf-elfedit
/usr/bin/arm-linux-gnueabihf-gcc
/usr/bin/arm-linux-gnueabihf-gcc-5
/usr/bin/arm-linux-gnueabihf-gcc-ar
/usr/bin/arm-linux-gnueabihf-gcc-ar-5
/usr/bin/arm-linux-gnueabihf-gcc-nm
/usr/bin/arm-linux-gnueabihf-gcc-nm-5
/usr/bin/arm-linux-gnueabihf-gcc-ranlib
/usr/bin/arm-linux-gnueabihf-gcc-ranlib-5
/usr/bin/arm-linux-gnueabihf-gcov
/usr/bin/arm-linux-gnueabihf-gcov-5
/usr/bin/arm-linux-gnueabihf-gcov-tool
/usr/bin/arm-linux-gnueabihf-gcov-tool-5
/usr/bin/arm-linux-gnueabihf-gprof
/usr/bin/arm-linux-gnueabihf-ld
/usr/bin/arm-linux-gnueabihf-ld.bfd
/usr/bin/arm-linux-gnueabihf-ld.gold
/usr/bin/arm-linux-gnueabihf-nm
/usr/bin/arm-linux-gnueabihf-objcopy
/usr/bin/arm-linux-gnueabihf-objdump
/usr/bin/arm-linux-gnueabihf-ranlib
/usr/bin/arm-linux-gnueabihf-readelf
/usr/bin/arm-linux-gnueabihf-size
/usr/bin/arm-linux-gnueabihf-strings
/usr/bin/arm-linux-gnueabihf-strip

$ make M=/home/frank/bpi-r2/BPI-R2-bsp/linux-mt/ ARCH=arm CROSS-COMPILE=arm-linux-gnueabihf-gcc
...
Building backport-include/backport/autoconf.h ... done.
Makefile:702: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler
  CC [M]  /home/frank/bpi-r2/compat-wireless-2017-01-31/compat/main.o
gcc: error: unrecognized argument in option ā€˜-mabi=apcs-gnuā€™
gcc: note: valid arguments to ā€˜-mabi=ā€™ are: ms sysv
gcc: error: unrecognized command line option ā€˜-mlittle-endianā€™
gcc: error: unrecognized command line option ā€˜-mapcsā€™
gcc: error: unrecognized command line option ā€˜-mno-sched-prologā€™

Please post your Makefile

Makefile from compat wireless(not changed by me): Makefile (6,0 KB)

From linux-mt-folder: Makefile (54,1 KB)

had copied compat-wireless and mt76 driver from lede-build-dir after building lede

try now integrate https://github.com/openwrt/mt76/tree/mt7603_old into the 4.4-kernel compiles except of ampdu_action which seems differently

https://github.com/openwrt/mt76/blob/mt7603_old/main.c line 403 vs. https://github.com/BPI-SINOVOIP/BPI-R2-bsp/blob/master/linux-mt/include/net/mac80211.h line

working on itā€¦maybe i get that working :wink:

static int
mt76_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
//          enum ieee80211_ampdu_mlme_action action,
//          struct ieee80211_sta *sta,u16 tid, u16 *ssn, u8 buf_size,
//          bool amsdu
struct ieee80211_ampdu_params *params
)
{
  enum ieee80211_ampdu_mlme_action action=params->action;
  
  struct ieee80211_sta *sta=params->sta;
  u16 tid=params->tid;
  u16 *ssn = &params->ssn; //<< is that right? local pointer needed, params->ssn = u16

    struct mt76_dev *dev = hw->priv;
    struct mt76_sta *msta = (struct mt76_sta *) sta->drv_priv;
    struct ieee80211_txq *txq = sta->txq[tid];
    struct mt76_txq *mtxq = (struct mt76_txq *) txq->drv_priv;

  //*ssn=params->ssn;  //does not work

mt76.tar.gz (166,3 KB)

compiles fine (when copied to r2-kernel 4.4.70), needs no compat-wireless and create mt76pci.ko :slight_smile:

hope i have it changed right and itā€™s workingā€¦

You compare apples with bananas. The result will never equals. You compare an PCI hardware driver with with a network protocol driver.

You see the difference?

You should not copy the files to your kernel directory. It compiles, yes. But successfull compilation does not mean that it works. A PCI chipset btw PCI bus driver needs no wireless driver to work. But without the PCI driver you are not able to communicate with the wireless device through the PCI bus.

You see the difference between the drivers?

The PCI driver is required for PCI bus. The wireless driver is required to speak with the wireless device.

You mean wireless driver is missing in that mt76x2-old repo and i have only the pci-part?

How to do it the right way? Iā€™found nothing a step-by-step guide howto port a driver using backports/compat-wireless

Currently i try different thing with simple c/cpp knowledge but without knowing anything about driver structure or backporting. Simple try anything and try to fix the compiler-errors

Is it possible to compile that current tree

against the bpi-kernel in github?

Using that backport (newest iā€™ve found): https://backports.wiki.kernel.org/index.php/Main_Page / http://drvbp1.linux-foundation.org/~mcgrof/rel-html/backports/

Just for a clean startā€¦all 3 parts in separate folders or mt76 inside backports? maybe my previous sources from lede are not compatible with ā€œnormalā€ kernel (lede-specific patches)

This is the PCI Driver not the wireless driver. The wireless chipset is an MT6625L. This driver is the PCI Bridge driver.

All communications with the wireless Chipset, with the SATA Connectors, the IR device ā€¦ is done through the PCI bridge. The wireless driver communicates only with the wireless MT6625L Chip, e.g. loading binary firmware, channel selection, frequency ā€¦

The wireless chip is the city cologn, the cpu is berlin, the pci bridge is the highway cross wĆ¼rzburg. Without the the highway bridge wĆ¼rzburg, it is not possible that berlin (the cpu) communicates with cologn (wirless chip) but berlin can communicate with frankfurt the ethernet.

I hope it i explain a little bit understandable. :slight_smile:

I understand the difference between pci-wireless,but i cannot see that in code.

gary is working on the internal wireless-driver (Client mode is working as i read).

Here iā€™m trying to get a mt7612e wlan-pcie-card working. i see it using lspciā€¦so pci-driver seems working so far.

If you can write in german we can talk via pm an posting results here.

i have now the mt76 included in compat wireless and the following structure:

bpi-r2/compat-wireless
bpi-r2/linux-mt <<<kernel

https://www.file-upload.net/download-12766859/compat-wireless-2017-01-31mt76.tar.gz.html

compiles fine without ARCH=arm

export ARCH=arm export INSTALL_MOD_PATH=$(pwd)/mod/ export CROSS_COMPILE=arm-linux-gnueabihf-

/media/data_ext/download/bpi-r2/compat-wireless-2017-01-31$ make M=/media/data_ext/download/bpi-r2/linux-mt/

multiple files coming with warning

./arch/arm/include/asm/swab.h:20:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef]

at the end:

include/linux/preempt.h:59:25: fatal error: asm/preempt.h: Datei oder Verzeichnis nicht gefunden
 #include <asm/preempt.h>
                         ^
compilation terminated.

that Variable/Const is defined in linux-mt/arch/arm/Makefile, but seems not be used

# This selects which instruction set is used.
# Note that GCC does not numerically define an architecture version
# macro, but instead defines a whole series of macros which makes
# testing for a specific architecture or later rather impossible.
arch-$(CONFIG_CPU_32v7M)        =-D__LINUX_ARM_ARCH__=7 -march=armv7-m -Wa,-march=armv7-m
arch-$(CONFIG_CPU_32v7)         =-D__LINUX_ARM_ARCH__=7 $(call cc-option,-march=armv7-a,-march=armv5t -Wa$(comma)-march=armv7-a)
arch-$(CONFIG_CPU_32v6)         =-D__LINUX_ARM_ARCH__=6 $(call cc-option,-march=armv6,-march=armv5t -Wa$(comma)-march=armv6)
# Only override the compiler option if ARMv6. The ARMv6K extensions are
# always available in ARMv7
ifeq ($(CONFIG_CPU_32v6),y)
arch-$(CONFIG_CPU_32v6K)        =-D__LINUX_ARM_ARCH__=6 $(call cc-option,-march=armv6k,-march=armv5t -Wa$(comma)-march=armv6k)
endif
arch-$(CONFIG_CPU_32v5)         =-D__LINUX_ARM_ARCH__=5 $(call cc-option,-march=armv5te,-march=armv4t)
arch-$(CONFIG_CPU_32v4T)        =-D__LINUX_ARM_ARCH__=4 -march=armv4t
arch-$(CONFIG_CPU_32v4)         =-D__LINUX_ARM_ARCH__=4 -march=armv4
arch-$(CONFIG_CPU_32v3)         =-D__LINUX_ARM_ARCH__=3 -march=armv3

any hint?

Supposing youā€™ll be able to build this ( I was able to build backports-4.14-rc4 ) youā€™ll lose internal wifi driver as you cannot use both internal and backported mac80211 driver at the same time (also: mac80211 must be disabled or module)

how do you build this driver with kernel 4.4.70 and backports 4.14-rc4 (from where did you got it)? can you make a a step-by-step guide?

since internal wifi does not have AP-Mode currently i can test with my mt7612, maybe the internal driver will also be ported to 4.14 if itā€™s working

https://backports.wiki.kernel.org

cd /root
mkdir backports
cd /root/backports

git clone git://git.kernel.org/pub/scm/linux/kernel/git/backports/backports.git
git clone git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git

cd /root/backports/linux-next
git checkout v4.14-rc4

cd /root/backports/linux-backports
git checkout v4.14-rc4-1
./gentree.py --clean --gitdebug --git-revision v4.14-rc4 /root/backports/linux-next/ /root/backports/updates

# /root/backports/updates contains -backports sources
1 Like

Hi Frank, could you please test the following driver? It builds fine with the R2 kernel but I have not yet received the MT7612 I ordered so I cannot test it. https://github.com/dfiloni/mt76

To build it:

  • 1 - clone repository inside linux-mt/drivers/net/wireless/mediatek

  • 2 - apply patch inside kernel-patches directory to linux-mt/

  • 3 - add following line to linux-mt/drivers/net/wireless/mediatek/Makefile:

    obj-$(CONFIG_MT76) += mt76/

  • 4 - add following line to linux-mt/drivers/net/wireless/mediatek/Kconfig before endif # WL_MEDIATEK:

    source "drivers/net/wireless/mediatek/mt76/Kconfig"

  • 5 - enable CONFIG_MAC80211 and CONFIG_MT76 using build.sh

  • 6 - build the kernel using build.sh

1 Like

thank youā€¦compiled without errors, now testing:

[   13.937028] cfg80211: World regulatory domain updated:
[   13.937038] cfg80211:  DFS Master region: unset
[   13.937038] cfg80211:   (start_freq - end_freq @ bandwidth), (max_antenna_ga)
[   13.937048] cfg80211:   (2402000 KHz - 2472000 KHz @ 40000 KHz), (N/A, 2000 )
BPI-ROOT: fsck [   13.937054] cfg80211:   (2457000 KHz - 2482000 KHz @ 20000 KH)
[   13.937058] cfg80211:   (2474000 KHz - 2494000 KHz @ 20000 KHz), (N/A, 2000 )
[   13.937062] cfg80211:   (5170000 KHz - 5250000 KHz @ 80000 KHz, 160000 KHz A)
[   13.937067] cfg80211:   (5250000 KHz - 5330000 KHz @ 80000 KHz, 160000 KHz A)
BPI-ROOT: fsck [   13.937071] cfg80211:   (5490000 KHz - 5730000 KHz @ 160000 K)
[   13.937075] cfg80211:   (5735000 KHz - 5835000 KHz @ 80000 KHz), (N/A, 2000 )
[   13.937079] cfg80211:   (57240000 KHz - 63720000 KHz @ 2160000 KHz), (N/A, 0)
[   14.241708] pci 0000:00:00.0: enabling device (0140 -> 0142)
[   14.250870] mt76x2e 0000:01:00.0: enabling device (0140 -> 0142)
[   14.260438] mt76x2e 0000:01:00.0: ASIC revision: 76120044
[   14.284794] mt76x2e 0000:01:00.0: ROM patch ad
[   14.298542] mt76x2e 0000:01:00.0: Direct firmware load for mt7662.bin failed2
[   14.310413] mt76x2e: probe of 0000:01:00.0 failed with error -2

tries to load wrong firmwareā€¦i assume that firmware-folder must also be copied (/lib/firmware), right? added it and rebooted:

scp linux-mt/drivers/net/wireless/mediatek/mt76/firmware/* [email protected]:/lib/firmware/

[   12.277101] pci 0000:00:00.0: enabling device (0140 -) Volatile Files
[   12.286972] mt76x2e 0000:01:00.0: enabling device (0140 -> 0 and Directories.
[   12.298464] mt76x2e 0000:01:00.0: ASIC revision: 76120044

[   12.322607] mt76x2e 0000:01:00.0: ROM patch already applied
[   12.338694] mt76x2e 0000:01:00.0: Firmware Version: 0.0.00
[   12.344616] systemd-journald[244]: Received request to flush runtime journal1
[   12.360023] mt76x2e 0000:01:00.0: Build: 1
[   12.360028] mt76x2e 0000:01:00.0: Build Time: 201507311614____
[   12.511759] mt76x2e 0000:01:00.0 wlan2: renamed from wlan0
[   12.551141] systemd-udevd[253]: renamed network interface wlan0 to wlan2

[10:01] root@bpi-r2:~# lspci
00:00.0 PCI bridge: MEDIATEK Corp. Device 0801 (rev 01)
00:01.0 PCI bridge: MEDIATEK Corp. Device 0801 (rev 01)
01:00.0 Network controller: MEDIATEK Corp. Device 7612  <<<<<
02:00.0 IDE interface: ASMedia Technology Inc. ASM1061 SATA IDE Controller (rev)
[10:01] root@bpi-r2:~# ifconfig -a | grep Link
bond0     Link encap:Ethernet  HWaddr 96:fb:01:14:e5:68  
eth0      Link encap:Ethernet  HWaddr 08:00:00:00:00:00  
          inet6 addr: fe80::a00:ff:fe00:0/64 Scope:Link
eth1      Link encap:Ethernet  HWaddr 08:00:00:00:00:01  
          inet6 addr: fe80::a00:ff:fe00:1/64 Scope:Link
lo        Link encap:Local Loopback  
sit0      Link encap:IPv6-in-IPv4  
tunl0     Link encap:IPIP Tunnel  HWaddr   
wlan2     Link encap:Ethernet  HWaddr f8:62:aa:50:12:1d    <<<< wlan-device visible :)
1 Like

Oh, this is really good, thank you for the test! Could you please attach a iw phy output? I want to check what capabilities are supported by the card :slight_smile:

iw_phy_mt76.log (7,2 KB)

    Supported interface modes:
         * IBSS
         * managed
         * AP
         * AP/VLAN
         * monitor

should only be the mt7612-card (other card currently not active), but found nothing the wlanx / MAC

1 Like

Thank you! Please let me know if you have any issue :wink:

@garywang can you please add the mt76-driver to your github, too?

  • add contents of mt76-github
  • apply patch
  • patch for build.sh (same as github-issue), Makefile and Kconfig patch_fwu.diff (1,8 KB)

maybe adding contents of drivers/net/wireless/mediatek/mt76/firmware to BPI_ROOT/lib/firmware if CONFIG_MT76 is set, when packing

also hostapd seems to work fine with mt76-driverā€¦see ssid with hand and can connect (waiting for ip because i have no IP of wlan1 set and no dnsmasq running)

added current todo to my WIKIā€¦ http://www.fw-web.de/dokuwiki/doku.php?id=en/bpi-r2/wlan

had dnsmasq + local IP working, got an IP from dnsmasq and can ping the IP from R2 :wink:

seems to work so farā€¦also without antennas :stuck_out_tongue:

have you found a technical sheet for the card? i have 2 antenna connectors and want to know which is for 2.4G and which is for 5G

found a datasheet here, but its chip-only, not for the board: http://ftp.mqmaker.com/WiTi/Docs/Hardware/MT7612E_Data_Sheet.pdf if i read it right, then both connectors can be used for G/A (Page 6, WF0/WF1), on the board one connector is labeled ā€œmainā€, the other ā€œauxā€

i added an antenna to Main-Connector and it works for both bands (2.4 + 5GHz)

#5G-Support
country_code=DE
ieee80211n=1
ieee80211d=1
hw_mode=a
channel=48

seems to work in my short tests without problems

1 Like

added mt76-driver to my fork of kernel-4.4: https://github.com/frank-w/BPI-R2-4.4

1 Like