Need help porting mt76-driver to R2-Kernel

Hi,

i’m trying to include mt76-driver from lede-Project to the bananapi-r2 kernel-repo lede includes somewhere compat-wireless since net-includes in 4.4.71 are too old.

here my current work (mt76 must be unpacked to linux-mt/drivers/net/wireless/mediatek/): https://www.file-upload.net/download-12740868/mt76.tgz.html

https://www.file-upload.net/download-12740874/compat-wireless.tar.gz.html

i’ve tried to replace the files (include/net/mac80211.h, net/mac80211/,include/uapi/linux/nl80211.h,include/net/cfg80211.h) from kernel with same from compat-wireless, but ran into “implicit declaration of function”-errors

i’ve found also a Patch (don’t know kernel-version) from march 2016 to add mt76-driver: https://patchwork.kernel.org/patch/8496171/ maybe this is more compatible

edit: last patch needed some more files ( https://www.spinics.net/lists/linux-wireless/msg154015.html ) but errors seems the same…

here the merged patches (bitfield.h [new] and bug.h [added 2 lines] and must be in linux-mt/include/linux/)

edit again:

  CC [M]  drivers/net/wireless/mediatek/mt76/mt76x2_core.o
In file included from drivers/net/wireless/mediatek/mt76/mt76x2.h:38:0,
                 from drivers/net/wireless/mediatek/mt76/mt76x2_init.c:15:
drivers/net/wireless/mediatek/mt76/mt76.h: In function ‘mt76_channel_state’:
drivers/net/wireless/mediatek/mt76/mt76.h:301:14: warning: comparison between ‘enum ieee80211_band’ and ‘enum nl80211_band’ [-Wenum-compare]
  if (c->band == NL80211_BAND_2GHZ)
              ^
drivers/net/wireless/mediatek/mt76/mt76x2_init.c: In function ‘mt76x2_register_device’:
drivers/net/wireless/mediatek/mt76/mt76x2_init.c:733:20: error: ‘struct mt76_sband’ has no member named ‘ht_cap’
  dev->mt76.sband_2g.ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
                    ^
drivers/net/wireless/mediatek/mt76/mt76x2_init.c:734:20: error: ‘struct mt76_sband’ has no member named ‘ht_cap’
  dev->mt76.sband_5g.ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;

mt76.diff.txt (16,4 KB) mt76_p.tar.gz (162,3 KB)

i’ve found no definition of 'struct mt76_sband’->‘ht_cap’

regards Frank

‘struct mt76_sband’ is defined in file mt76.h. You must backport the full driver not only parts of them. Additionally you must use the full wireless compat. Only the header files has no effect because you need the .c Source files too.

can i link the full wireless-compat without change the source in linux-mt (like it seems to be done in openwrt)?

currently working on 2nd version (patch-way,not the openwrt)…i have linked my sources (patches)…and go step-by-step

which c-files do you mean exactly? i have all c-files the mt76-patches created…i’ve also patched rx.c (and may some others i did not remember :slight_smile: )

have never ported an driver (extending a kernel-source) before…only changed options in kernels (menuconfig) and recompiled.

right, mt76_sband is defined in mt76.h…but not the ht_cap-member…google found also nothing.

struct mt76_sband {
    struct ieee80211_supported_band sband;
    struct mt76_channel_state *chan;
};

it not seems that ht_cap is a mt76_hw_cap, because it must have a member “cap”, which mt76_hw_cap doesn’t. maybe its a ieee80211_sta_ht_cap defined in include/net/cfg80211.h (compat wireless), but i don’t know exactly.

edit: found that: https://patchwork.kernel.org/patch/9561073/, so my supposition is right

tried this as first line of my mt76/Makefile:

ccflags-y := -I../compat-wireless-2017-01-31/include/ -I$(src)/include/

first include is to avoid changing tree from repository, second for including compat-wireless (put folder with this name in same dir as build.sh)

drivers/net/wireless/mediatek/mt76/mac80211.c: In function ‘mt76_register_device’:
drivers/net/wireless/mediatek/mt76/mac80211.c:223:4: error: ‘struct ieee80211_hw’ has no member named ‘max_tx_fragments’
  hw->max_tx_fragments = 16;
    ^

compat-wireless-2017-01-31/include/net/mac80211.h:2230: u8 max_tx_fragments;

it seems that Include is working, but not used at first so headers existing in linux-mt are loaded and in wireless they are skipped (or content not used because of indef-keyword)

how to use includes (compat-wireless and my own) BEFORE linux-mt-includes?? i have created a bug.h, but its using that from linux-mt/includes (where __BUILD_BUG_ON_NOT_POWER_OF_2 is missing)

looked in documentation https://github.com/torvalds/linux/blob/master/Documentation/kbuild/makefiles.txt but found no priorized include

changed mt76-source to that from openwrt (more needed definitions): mediatek.7z (232,2 KB)

it seems that there is an official way to include compat-wireless/backports to Kernel: https://backports.wiki.kernel.org/index.php/Documentation/integration where to get the the python-script for kernel-integration and how to use it if not using git (found only tarballs)

You have to build the compat-wireless.This implies building of the mt76 driver. You can not copy the mt76 files only because the struct members and maybe the functions calls are updated and not the same as included in the kernel.

Compat wireless is the full wireless network stack.

Or can you build a car without the engine and the car drives like other cars which has an engine? :wink:

how to buil compat-wireless and my driver without the kernel? does the module working if kernel is build without it (simply by copy the *.ko to /lib/…)?

You need the kernel too. All you have to do is change into the wireless compat source directory and call make as followed:

make M=/path/to/your/kernel menuconfig

Then configure it an call make as followed:

make M=/path/to/your/kernel modules make M=/path/to/your/kernel modules_install

thank you, build compat-drivers

make M=/media/data_ext/download/bpi-r2/linux-mt/ menuconfig

  MODPOST 3 modules
  CC      /media/data_ext/download/bpi-r2/compat-wireless-2017-01-31/compat/compat.mod.o
  LD [M]  /media/data_ext/download/bpi-r2/compat-wireless-2017-01-31/compat/compat.ko
  CC      /media/data_ext/download/bpi-r2/compat-wireless-2017-01-31/net/mac80211/mac80211.mod.o
  LD [M]  /media/data_ext/download/bpi-r2/compat-wireless-2017-01-31/net/mac80211/mac80211.ko
  CC      /media/data_ext/download/bpi-r2/compat-wireless-2017-01-31/net/wireless/cfg80211.mod.o
  LD [M]  /media/data_ext/download/bpi-r2/compat-wireless-2017-01-31/net/wireless/cfg80211.ko

as i see there are only the generic-modules…

had included mt76-driver in compat-wireless and selected…is it now in mac80211 included? seems that is not compiled…maybe an error in Makefile :frowning:

how to get mt76-module if not included?

make modules_install is failed (because it tries to create directory under /lib/modules/)…I’m not compiling on BPI-R2. i assume that i must replace modules created by the build.sh (4.4.70-repo)…but i have no mt76.ko, how to deal with compat.ko (not existing in current kernel) drivers/net/wireless/mediatek/mt76/Kconfig

config MT76
        tristate "MediaTek MT76x2 (pcie) support"
        depends on MAC80211
        ---help---
          This adds support for MT76-based wireless pcie modules.

drivers/net/wireless/mediatek/mt76/Makefile

EXTRA_CFLAGS += -Werror
EXTRA_CFLAGS += -Wno-enum-compare
EXTRA_CFLAGS += -Wno-implicit-function-declaration

obj-$(CONFIG_MT76)      += mt76.o
obj-$(CPTCFG_MT76)      += mt76.o

obj-m := mt76.o mt76x2e.o mt7603e.o

mt76-y := \
        mmio.o util.o trace.o dma.o mac80211.o debugfs.o eeprom.o tx.o

mt76x2e-y := \
        mt76x2_pci.o mt76x2_dma.o \
        mt76x2_main.o mt76x2_init.o mt76x2_debugfs.o mt76x2_tx.o \
        mt76x2_core.o mt76x2_mac.o mt76x2_eeprom.o mt76x2_mcu.o mt76x2_phy.o \
        mt76x2_dfs.o mt76x2_trace.o

mt7603e-y := \
        mt7603_pci.o mt7603_soc.o mt7603_main.o mt7603_init.o mt7603_mcu.o \
        mt7603_core.o mt7603_dma.o mt7603_mac.o mt7603_eeprom.o \
        mt7603_beacon.o mt7603_debugfs.o

CFLAGS_trace.o := -I$(src)

drivers/net/wireless/mediatek/Makefile

obj-$(CPTCFG_MT7601U) += mt7601u/ obj-$(CPTCFG_MT76) += mt76/

drivers/net/wireless/mediatek/Kconfig

menuconfig WL_MEDIATEK
        bool "Mediatek Wireless LAN support"
        ---help---
          Enable community drivers for MediaTek WiFi devices.
          Those drivers make use of the Linux mac80211 stack.


if WL_MEDIATEK
source "drivers/net/wireless/mediatek/mt7601u/Kconfig"
source "drivers/net/wireless/mediatek/mt76/Kconfig"
endif # WL_MEDIATEK

changed obj-$(CONFIG_MT76) to obj-$(CPTCFG_MT76) CPTCFG_MT76 is in .config and seems to be loaded…but no compile-process

i had to add obj-$(CPTCFG_WL_MEDIATEK) += mediatek/ to drivers/net/wireless/Makefile (or have to change WL_MEDIATEK in mediatek/Makefile to WLAN_VENDOR_MEDIATEK) now files are touched…

In file included from /media/data_ext/download/bpi-r2/compat-wireless-2017-01-31/drivers/net/wireless/mediatek/mt76/mt76x2_trace.h:144:0,
                 from /media/data_ext/download/bpi-r2/compat-wireless-2017-01-31/drivers/net/wireless/mediatek/mt76/mt76x2_trace.c:21:
include/trace/define_trace.h:83:43: fatal error: ./mt76x2_trace.h: Datei oder Verzeichnis nicht gefunden
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
                                           ^
compilation terminated.

added “CFLAGS_mt76x2_trace.o := -I$(src)” to mt76/Makefile

frank@Frank-Laptop:/media/data_ext/download/bpi-r2/compat-wireless-2017-01-31$ find . -name '*.ko'./drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.ko
./drivers/net/wireless/mediatek/mt76/mt7603e.ko
./drivers/net/wireless/mediatek/mt76/mt76x2e.ko
./drivers/net/wireless/mediatek/mt76/mt76.ko <<<<<<< seems to be working :)
./drivers/net/wireless/ath/ath5k/ath5k.ko
./drivers/net/wireless/ath/ath.ko
./drivers/net/wireless/ath/ath10k/ath10k_core.ko
./drivers/net/wireless/ath/ath10k/ath10k_pci.ko
...
./compat/compat.ko
./net/wireless/cfg80211.ko
./net/mac80211/mac80211.ko

can i simply replace the modules (mac80211,…) created by my kernel and add the new ones (mt76,…) or have i do some more (update module-symbols?)?

No you can not simply replace the modules due tue the module symbol versions and the dependencies to other modules. The safest way is using the make target modules_install it generate the modules.dep and do a little bit more stuff.

If you want to do it manually you have to copy the *.ko files, the module symbol versions and after that you must call

depmod -a

The manual step can be very tricky.

Can i do make install with defining target-dir (target of other modules created by build.sh)?

The make target modules_install is an alias for the install target. But you can try the following:

make INSTALL_MOD_PATH=/path/to/your/kernel/modules M=/path/to/your/kernel modules

make INSTALL_MOD_PATH=/path/to/your/kernel/modules M=/path/to/your/kernel modules_install

mhm, seems not working:

frank@Frank-Laptop:/media/data_ext/download/bpi-r2/compat-wireless-2017-01-31$ make  INSTALL_MOD_PATH=$(pwd)/mod/ M=/media/data_ext/download/bpi-r2/linux-mt/ modules_install
make[1]: »Kconfig.versions« ist bereits aktualisiert.
make[3]: »Kconfig.versions« ist bereits aktualisiert.
make[4]: »conf« ist bereits aktualisiert.
boolean symbol HWMON tested for 'm'? test forced to 'n'
boolean symbol HWMON tested for 'm'? test forced to 'n'
#
# configuration written to .config
#
Building backport-include/backport/autoconf.h ... done.
  Building modules, stage 2.
  MODPOST 25 modules
  INSTALL /media/data_ext/download/bpi-r2/compat-wireless-2017-01-31/compat/compat.ko
At main.c:222:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:169
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:172
sign-file: certs/signing_key.pem: No such file or directory

don’t know why ssl-error is there with bss_file.c

also DEPMOD 4.4.0-96-generic

depmod uses my local kernel, not the target-kernel

build.sh uses also INSTALL_MOD_PATH modules are put in this dir (but with wrong kernel-version as directory), but i have no idea about the ssl-error and depmod

frank@Frank-Laptop:/media/data_ext/download/bpi-r2/compat-wireless-2017-01-31$ ls -lR mod
mod:
insgesamt 4
drwxrwxr-x 3 frank frank 4096 Okt  9 19:19 lib

mod/lib:
insgesamt 4
drwxrwxr-x 3 frank frank 4096 Okt  9 19:19 modules

mod/lib/modules:
insgesamt 4
drwxrwxr-x 3 frank frank 4096 Okt  9 19:19 4.4.0-96-generic

mod/lib/modules/4.4.0-96-generic:
insgesamt 4
drwxrwxr-x 5 frank frank 4096 Okt  9 19:19 updates

mod/lib/modules/4.4.0-96-generic/updates:
insgesamt 12
drwxrwxr-x 2 frank frank 4096 Okt  9 19:19 compat
drwxrwxr-x 3 frank frank 4096 Okt  9 19:19 drivers
drwxrwxr-x 4 frank frank 4096 Okt  9 19:19 net

mod/lib/modules/4.4.0-96-generic/updates/compat:
insgesamt 32
-rw-rw-r-- 1 frank frank 30869 Okt  9 19:25 compat.ko

mod/lib/modules/4.4.0-96-generic/updates/drivers:
insgesamt 4
drwxrwxr-x 3 frank frank 4096 Okt  9 19:19 net

mod/lib/modules/4.4.0-96-generic/updates/drivers/net:
insgesamt 4
drwxrwxr-x 6 frank frank 4096 Okt  9 19:19 wireless

mod/lib/modules/4.4.0-96-generic/updates/drivers/net/wireless:
insgesamt 16
drwxrwxr-x 5 frank frank 4096 Okt  9 19:19 ath
drwxrwxr-x 3 frank frank 4096 Okt  9 19:19 mediatek
drwxrwxr-x 3 frank frank 4096 Okt  9 19:19 ralink
drwxrwxr-x 3 frank frank 4096 Okt  9 19:19 realtek

mod/lib/modules/4.4.0-96-generic/updates/drivers/net/wireless/ath:
insgesamt 60
drwxrwxr-x 2 frank frank  4096 Okt  9 19:19 ar5523
drwxrwxr-x 2 frank frank  4096 Okt  9 19:19 ath10k
drwxrwxr-x 2 frank frank  4096 Okt  9 19:19 ath5k
-rw-rw-r-- 1 frank frank 45954 Okt  9 19:25 ath.ko

mod/lib/modules/4.4.0-96-generic/updates/drivers/net/wireless/ath/ar5523:
insgesamt 72
-rw-rw-r-- 1 frank frank 70499 Okt  9 19:25 ar5523.ko

mod/lib/modules/4.4.0-96-generic/updates/drivers/net/wireless/ath/ath10k:
insgesamt 684
-rw-rw-r-- 1 frank frank 620463 Okt  9 19:25 ath10k_core.ko
-rw-rw-r-- 1 frank frank  77196 Okt  9 19:25 ath10k_pci.ko

mod/lib/modules/4.4.0-96-generic/updates/drivers/net/wireless/ath/ath5k:
insgesamt 212
-rw-rw-r-- 1 frank frank 214955 Okt  9 19:25 ath5k.ko

mod/lib/modules/4.4.0-96-generic/updates/drivers/net/wireless/mediatek:
insgesamt 4
drwxrwxr-x 2 frank frank 4096 Okt  9 19:19 mt76

mod/lib/modules/4.4.0-96-generic/updates/drivers/net/wireless/mediatek/mt76:
insgesamt 204
-rw-rw-r-- 1 frank frank 61894 Okt  9 19:25 mt7603e.ko
-rw-rw-r-- 1 frank frank 46871 Okt  9 19:25 mt76.ko
-rw-rw-r-- 1 frank frank 93876 Okt  9 19:25 mt76x2e.ko
...

how can i check if target-arch is same as kernel (will it be read from kernel-config?) or do i have to set it via param…arch from compile-pc is x86_64 and not arm…since make install uses my local kernel, modules may be compiled also with local arch

You do not use an ARM- Toolchain that matches your Target CPU like toolchain-arm_cortex-a7+neon-vfpv4_gcc-5.4.0_musl_eabi.

Therefore the Host GCC- Compiler and Tools are used. But this can never work due rctue the different CPU architecture.

So you have to install an already build toolchaiWith this toolchain n or you build one from source. The software for the target including kernel are then compiled with this toolchain.

Thats your error. Cross Compiling works only with extra compiled toolchain for the target architecture

Is it enough using param ARCH=arm CROSS-COMPILE=arm-linux-gnueabihf- ?

But this fixes not the depmod-issue

When the toolchain gcc and tools are used it is a beginning. Additionally you should use the following compiler optimizations:

-Os -pipe -mcpu=cortex-a7 -mfpu=neon-vfpv4

The depmod issue exists until you have compiled it with the toolchain and then using it.

now it seems makefile from other repo is used:

frank@Frank-Laptop:/media/data_ext/download/bpi-r2/compat-wireless-2017-01-31$ make  INSTALL_MOD_PATH=$(pwd)/mod/ M=/media/data_ext/download/bpi-r2/linux-mt/ ARCH=arm CROSS-COMPILE=arm-linux-gnueabihf-
make[2]: »Kconfig.versions« ist bereits aktualisiert.
make[4]: »Kconfig.versions« ist bereits aktualisiert.
make[5]: »conf« ist bereits aktualisiert.
boolean symbol HWMON tested for 'm'? test forced to 'n'
boolean symbol HWMON tested for 'm'? test forced to 'n'
#
# configuration written to .config
#
Building backport-include/backport/autoconf.h ... done.
Makefile:695: Cannot use CONFIG_CC_STACKPROTECTOR_REGULAR: -fstack-protector not supported by compiler
  CC [M]  /media/data_ext/download/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’

Have you done a make distclean before you compile it again?

distclean is not known, after make clean same, with optimization more errors

frank@Frank-Laptop:/media/data_ext/download/bpi-r2/compat-wireless-2017-01-31$ make  INSTALL_MOD_PATH=$(pwd)/mod/ M=/media/data_ext/download/bpi-r2/linux-mt/ ARCH=arm CROSS-COMPILE=arm-linux-gnueabihf

...

Makefile:695: Cannot use CONFIG_CC_STACKPROTECTOR_REGULAR: -fstack-protector not supported by compiler
  CC [M]  /media/data_ext/download/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’

i think, i must get a new kernel (4.13/4.14) working, to get wlan-driver running

Which gcc Version do you use?

4.8.4 ubuntu 14.4.3…

Your GCC does not support the regular stack protection. This is not good.

This error is confusing me a little. With -mabi you give machine dependent options to the compiler. The option value “apcs-gnu” tells me that you are not using any toolchain for cross compiling.

Some posts before, i told you that cross compiling requires a toolchain because you build it for an different architecture and therefore it s an requirement.

Before you start any further tries to get the driver working i recommend to do the following steps first:

  1. Do an release upgrade from Ubuntu 14.04 to minimum 16.04.
  2. Install the required toolchain via apt-get install.
  3. Add the toolchain bin directory to your PATH variable
  4. Then compile the required tools depmod etc. with the toolchain.
  5. Now you can compile the driver.

If problems occurs then post your questions and i am going to help you.