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

can anybody explain me, how from_timer-function works and which-params (1st+3rd) are needed?

i found some patches like https://www.spinics.net/lists/raid/msg59618.html

but the params are not clear…first can be the same var like assigned to, second is the timer_list and the last??

include/linux/timer.h

#define from_timer(var, callback_timer, timer_fieldname) \
	container_of(callback_timer, typeof(*var), timer_fieldname)

here is the way i try to port:

having now problems with the from_timer-macro, have anyone an idea?

anyone here who can help? i guess it’s the last param i’ve set to from_timer…but also found no explaination of the from_timer-macro

Hi Frank, please apply attached patch to your 4.16-wifi branch, it does build but I don’t have an R2 board to test it.

patch.diff (3.8 KB)

1 Like

Hi Frank,

sorry didn’t look in detail about what you are trying to accomplish but this is just a simple trick to find an entry in the structure.

So second parameter is the pointer to the struct list that the timer uses and the third parameter is the name of the variable embedded in the structure that you are trying to pull.

Does that make sense?

Thanks

I just looked at the link you provided, that’s never going to work. You’re not initializing the structure correctly at the init time. Then you are trying to pull the wrong type and cast it.

This will either: crash, dump garbage or cause a memory corruption depending on what the rest of the code does with this variable.

What are you trying to do? Port something from 4.16 to 4.14?

I don’t have a ton of free time, but I do have about 24 years of linux kernel and drivers experience so maybe I can help here and there…

I try to port the wifi-driver of r2 from 4.14 to 4.16

@dfiloni thank you…will try it when i’m at home

@dfiloni’s patch seems better, let me know if you need help

there is a new problem:

drivers/misc/mediatek/connectivity/wlan/gen2/os/linux/include/gl_kal.h:851:53: error: 'memset' writing 6 bytes into a region of size 5 overflows the destination [-Werror=stringop-overflow=]
 #define kalMemZero(pvAddr, u4Size)                  memset(pvAddr, 0, u4Size)
                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/misc/mediatek/connectivity/wlan/gen2/nic/nic_rx.c:2084:5: note: in expansion of macro 'kalMemZero'
     kalMemZero(prBowLinkConnected->aucPeerAddress, MAC_ADDR_LEN); /* @FIXME */
     ^~~~~~~~~~

@frank-w can you post the structure definition for: prBowLinkConnected->aucPeerAddress

Full code is in 4.16-wifi branch in my github…

the wifi-driver is in drivers/misc/mediatek

I’m currently not @home

edit:

drivers/misc/mediatek/connectivity/wlan/gen2/common/wlan_bow.c:1262:	P_BOW_LINK_CONNECTED prBowLinkConnected;
drivers/misc/mediatek/connectivity/wlan/gen2/include/nic/bow.h:252:
typedef struct _BOW_LINK_CONNECTED {
        CHANNEL_DESC rChannel;
        UINT_8 aucReserved;
        UINT_8 aucPeerAddress[6];
} BOW_LINK_CONNECTED, *P_BOW_LINK_CONNECTED;

That’s a very interesting error. Can you paste output of “gcc -v” or whatever compiler you ran?

Thanks

He’s using GCC 7, that’s why I was able to build it.

Also as a quick test, can you try and change it to this:

kalMemZero(&prBowLinkConnected->aucPeerAddress[0], MAC_ADDR_LEN);

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.3.0-16ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --with-as=/usr/bin/x86_64-linux-gnu-as --with-ld=/usr/bin/x86_64-linux-gnu-ld --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --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 --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)

make crosscompile with gcc-arm-linux-gnueabihf, but this seems not to be a binary

find / -name '*-arm-linux-gnueabihf' 2>/dev/null
/usr/share/doc/binutils-arm-linux-gnueabihf
/usr/share/doc/gcc-7-arm-linux-gnueabihf
/usr/share/doc/cpp-arm-linux-gnueabihf
/usr/share/doc/gcc-arm-linux-gnueabihf
/usr/share/doc/cpp-7-arm-linux-gnueabihf
/usr/share/lintian/overrides/binutils-arm-linux-gnueabihf
/usr/share/lintian/overrides/gcc-7-arm-linux-gnueabihf
/usr/share/lintian/overrides/cpp-7-arm-linux-gnueabihf

Ah OK, so you are on Bionic (18.04), I don’t see the problem on xenial. I did see a couple of issues on gcc bug reports related to this flag.

But to just clarify, the cross compilation is the one that fails?

Also can you try changing the line as mentioned in my previous post.

If you are cross compiling for example in openwrt you’d have the compiler here:

staging_dir/toolchain-arm_cortex-a7+neon-vfpv4_gcc-5.4.0_musl_eabi/bin/arm-openwrt-linux-muslgnueabi-gcc

with the change you’ve mentioned:

from drivers/misc/mediatek/connectivity/wlan/gen2/nic/nic_rx.c:812:
./arch/arm/include/asm/string.h:26:15: note: expected 'void *' but argument is of type 'UINT_8 {aka unsigned char}'
 extern void * memset(void *, int, __kernel_size_t);
           ^~~~~~

diff --git a/drivers/misc/mediatek/connectivity/wlan/gen2/nic/nic_rx.c b/drivers/misc/mediatek/connectivity/wlan/gen2/nic/nic_rx.c
index ba4840414da8..24337520f79d 100644
--- a/drivers/misc/mediatek/connectivity/wlan/gen2/nic/nic_rx.c
+++ b/drivers/misc/mediatek/connectivity/wlan/gen2/nic/nic_rx.c
@@ -2081,7 +2081,7 @@ VOID nicRxProcessEventPacket(IN P_ADAPTER_T prAdapter, IN OUT P_SW_RFB_T prSwRfb
                                /* fill event body */
                                prBowLinkConnected = (P_BOW_LINK_CONNECTED) (prBowEvent->aucPayload);
                                prBowLinkConnected->rChannel.ucChannelNum = prEventBtOverWifi->ucSelectedChannel;
-                               kalMemZero(prBowLinkConnected->aucPeerAddress, MAC_ADDR_LEN);   /* @FIXME */
+                               kalMemZero(prBowLinkConnected->aucPeerAddress[0], MAC_ADDR_LEN);        /* @FIXME */
 
                                kalIndicateBOWEvent(prAdapter->prGlueInfo, prBowEvent);
                        } else {
@@ -2093,7 +2093,7 @@ VOID nicRxProcessEventPacket(IN P_ADAPTER_T prAdapter, IN OUT P_SW_RFB_T prSwRfb
                                /* fill event body */
                                prBowLinkDisconnected = (P_BOW_LINK_DISCONNECTED) (prBowEvent->aucPayload);
                                prBowLinkDisconnected->ucReason = 0;    /* @FIXME */
-                               kalMemZero(prBowLinkDisconnected->aucPeerAddress, MAC_ADDR_LEN);        /* @FIXME */
+                               kalMemZero(prBowLinkDisconnected->aucPeerAddress[0], MAC_ADDR_LEN);     /* @FIXME */
 
                                kalIndicateBOWEvent(prAdapter->prGlueInfo, prBowEvent);
                        }

openwrt builds its own toolchain…have it not downloaded/built

Argh! OK then type cast it:

kalMemZero((void*)(&prBowLinkConnected->aucPeerAddress[0]), MAC_ADDR_LEN);

seems cast is not easy this way:

drivers/misc/mediatek/connectivity/wlan/gen2/nic/nic_rx.c:2084:16: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
     kalMemZero((void*)(prBowLinkConnected->aucPeerAddress[0]), MAC_ADDR_LEN); /* @FIXME */
                ^
drivers/misc/mediatek/connectivity/wlan/gen2/os/linux/include/gl_kal.h:851:60: note: in definition of macro 'kalMemZero'
 #define kalMemZero(pvAddr, u4Size)                  memset(pvAddr, 0, u4Size)
                                                            ^~~~~~
drivers/misc/mediatek/connectivity/wlan/gen2/nic/nic_rx.c:2096:16: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
     kalMemZero((void*)(prBowLinkDisconnected->aucPeerAddress[0]), MAC_ADDR_LEN); /* @FIXME */
                ^
drivers/misc/mediatek/connectivity/wlan/gen2/os/linux/include/gl_kal.h:851:60: note: in definition of macro 'kalMemZero'
 #define kalMemZero(pvAddr, u4Size)                  memset(pvAddr, 0, u4Size)
                                                            ^~~~~~