bricco1981 / MT7622-mtkwifi

21 stars 8 forks source link

How to enable Fast-NAT support(MTK_APSOC_WIFI_FAST_NAT_SUPPORT)? #3

Open hpx502766238 opened 5 months ago

hpx502766238 commented 5 months ago

I have tried to enable this function in menuconfig,but failed to build:"xxx is not defined".It seems to lack of some dependencies. Can you fix it? I guess the sourcecode from padavanonly may offer a help: package/mtk/mt7622/Makefile

bricco1981 commented 4 months ago

well,to do that you need other stuff in mediatek folder. here we have things missing. that is for DSA right? to do that you should be on old swconfig. i ll make a testing build before sharing the code.

hpx502766238 commented 4 months ago

well,to do that you need other stuff in mediatek folder. here we have things missing. that is for DSA right? to do that you should be on old swconfig. i ll make a testing build before sharing the code.

DSA+Openwrt NAT,or swconfig+ MTK NAT,which is faster?

hpx502766238 commented 4 months ago

In addition, I want the firmware to automatically "add ra0/rai0 to br-lan" during the device's first startup. How can I change the code to achieve this? I have tried setting "EAPifname=br-lan" in the file mt7615.1.dat located in package/mtk/luci-app-mtwifi/files/ before compiling the firmware. However, it doesn't take effect at startup. I still need to login to the web interface using a wired connection, then re-tick the option and manually reload the Wi-Fi settings.

bricco1981 commented 4 months ago

well i did alot changes, but i'm having problem with luci-lib-jquery-1-4 .how you did that? i compiled swconfig+ MTK NAT

hpx502766238 commented 4 months ago

well i did alot changes, but i'm having problem with luci-lib-jquery-1-4 .how you did that? i compiled swconfig+ MTK NAT

copy

well i did alot changes, but i'm having problem with luci-lib-jquery-1-4 .how you did that? i compiled swconfig+ MTK NAT

luci-lib-jquery-1-4 is from bmx6 just copy bmx6 from openwrt routing 21.02 https://github.com/openwrt/routing/tree/a9e43101bb726070cbf81b6225fc0625f4a4a5e5/bmx6 https://github.com/openwrt/routing/tree/a9e43101bb726070cbf81b6225fc0625f4a4a5e5/luci-app-bmx6

bricco1981 commented 4 months ago

I did, i can select it but it wont compile,and i get no error.very strange.

hpx502766238 commented 4 months ago

About auto-applying "add ra0/rai0 to br-lan", I have searched for a while. The conclusion is that to apply this configuration, the sbin/mtkwifi tool does not provide a direct function for it; instead, it relies on the "vif_enable" function from mtkwifi.lua. Therefore, I need to make an HTTP request at startup, for example, using curl -s http://127.0.0.1/cgi-bin/luci/admin/network/wifi/vif_enable/ra0. However, at present, there is an issue with authentication or logging in to perform this action.

bricco1981 commented 4 months ago

I add ra0 and rai0 to br-lan, but at first boot i like that the radios are down.today or tomorrow i'll share the firmware.

hpx502766238 commented 4 months ago

I add ra0 and rai0 to br-lan, but at first boot i like that the radios are down.today or tomorrow i'll share the firmware.

Thanks for your work.Remember to make a new branch for swconfig.

bricco1981 commented 4 months ago

hi @hpx502766238 can you test the build please? do not keep setting. in firewall select software and hardware offload or the device will not work at all on wan side. well you really need only hardware offloadind like this.

config defaults option input 'ACCEPT' option output 'ACCEPT' option forward 'REJECT' option synflood_protect '1'

option flow_offloading '1'

option flow_offloading_hw '1'
hpx502766238 commented 4 months ago

hi @hpx502766238 can you test the build please? do not keep setting. in firewall select software and hardware offload or the device will not work at all on wan side. well you really need only hardware offloadind like this.

config defaults option input 'ACCEPT' option output 'ACCEPT' option forward 'REJECT' option synflood_protect '1' #option flow_offloading '1' option flow_offloading_hw '1'

Ok,I will test later.

hpx502766238 commented 4 months ago

hi @hpx502766238 can you test the build please? do not keep setting. in firewall select software and hardware offload or the device will not work at all on wan side. well you really need only hardware offloadind like this.

config defaults option input 'ACCEPT' option output 'ACCEPT' option forward 'REJECT' option synflood_protect '1' #option flow_offloading '1' option flow_offloading_hw '1'

At present, the wired speed test sometimes shows a sharp drop in throughput, but everything else is working normally. The wireless network is very stable without packet loss and delay.

bricco1981 commented 4 months ago

What speed do you get via Ethernet?

try to play with software and hardware nat in firewall.

hpx502766238 commented 4 months ago

What speed do you get via Ethernet?

I currently do not have a 1000Mbps broadband testing condition. I tested it under a 200Mbps broadband environment. Currently, the lowest speed during the sudden drop is around 50Mbps.

hpx502766238 commented 4 months ago

What speed do you get via Ethernet?

try to play with software and hardware nat in firewall.

Software and hardware nat are already enabled.

bricco1981 commented 4 months ago

something is wrong on your side i have 300Mbps and never fail. have you done just hardware offload like my config? config defaults option input 'ACCEPT' option output 'ACCEPT' option forward 'REJECT' option synflood_protect '1'

option flow_offloading '1'

option flow_offloading_hw '1' is the device using just lan or wan too? wan cable or wwan? or in repeter mode? like apclii0 on br-lan?

hpx502766238 commented 4 months ago

something is wrong on your side i have 300Mbps and never fail. have you done just hardware offload like my config? config defaults option input 'ACCEPT' option output 'ACCEPT' option forward 'REJECT' option synflood_protect '1' #option flow_offloading '1' option flow_offloading_hw '1' is the device using just lan or wan too? wan cable or wwan? or in repeter mode? like apclii0 on br-lan?

How can I apply the above settings? I don't know how to manually edit firewall rules.In addition, I did test it in the standard main router mode, where the LAN and wireless are in the same network segment, and the WAN port automatically obtains the address through DHCP. It is not in a mode such as wireless bridging or repeating.

hpx502766238 commented 4 months ago

something is wrong on your side i have 300Mbps and never fail. have you done just hardware offload like my config? config defaults option input 'ACCEPT' option output 'ACCEPT' option forward 'REJECT' option synflood_protect '1' #option flow_offloading '1' option flow_offloading_hw '1' is the device using just lan or wan too? wan cable or wwan? or in repeter mode? like apclii0 on br-lan?

How can I apply the above settings? I don't know how to manually edit firewall rules.In addition, I did test it in the standard main router mode, where the LAN and wireless are in the same network segment, and the WAN port automatically obtains the address through DHCP. It is not in a mode such as wireless bridging or repeating.

I plan to conduct a more thorough and professional test using iperf3 on Sunday, utilizing a 1000M ethernet connection.

bricco1981 commented 4 months ago

Yes thanks, will be good test at that speed,i never tested. Sftp to the router,go in etc/config/firewall

hpx502766238 commented 4 months ago

The test has been completed. Test environment: Terminal:Windows 11 Home,iperf3 v3.1.5 lan:192.168.31.1(wireless and switch) wan:192.168.1.2 server ip address:192.168.1.3, running in command "iperf3 -s & iperf3 -s -p 5001",(port 5201 and port 5001) client ip address:192.168.31.163 Firewall settings: 【config defaults option input 'ACCEPT' option output 'ACCEPT' option forward 'REJECT' option synflood_protect '1' option flow_offloading '1' option flow_offloading_hw '1'】

The results are as follows: 1.Single Wired Downlink Test: DL 2.Single Wired Uplink Test: UL

  1. Wired Uplink+Downlink Test: DL+UL The maximum throughput rate is approximately 1.3G, with 940M UL and 400M DL.
  2. Wireless 5G 160Mhz Downlink Test: 160MhzDL
  3. Wireless 5G 160MhzUplink Test: 160MhzUL 6.Wireless 5G 160Mhz UDP Test(test for packet loss rate): 5G_160Mhz_DL_UDP 5G_160MHz_UL_UDP

I also tested with DSA+Openwrt HNAT, and I will only list the differences: 1.Wired Uplink+Downlink Test: DL+UL

  1. Wireless 5G 160Mhz Downlink Test: 160Mhz_DL 3.Wireless 5G 160MhzUplink Test: 160Mhz_UL

The conclusion is: 1.It seems work well,all results are normal. 2.The maximum throughput with wired UL+DL NAT works better than DSA+OP HNAT. 3.Although the wireless 5G downlink rate is 100M higher than DSA+OP NAT, the uplink rate is 50% lower than DSA+OP HNAT. 4.In the wired test, the uplink packets have higher priority than the downlink packets, contrary to the wireless test. 5.I must enable both the "option flow_offloading" and "option flow_offloading_hw", otherwise HWNAT will not function at all, and the network performance will be extremely poor.

hpx502766238 commented 4 months ago

Another issue is that the 5G signal is lost after the system reboot, and I must reload it manually.

hpx502766238 commented 4 months ago

The most crucial issue lies in the uplink speed of 5G at 160Mhz, which is only 200M. I have tested DSA+Op HWNAT and found that the highest average speed can reach 800M.

bricco1981 commented 4 months ago

Set the channel on 5ghz radio, do not leave auto.i know it's not perfect,but in the long run this firmware should be very stable. you miss the wwan test on 5ghz radio, that is the test i was waiting.

hpx502766238 commented 4 months ago

Set the channel on 5ghz radio, do not leave auto.i know it's not perfect,but in the long run this firmware should be very stable. you miss the wwan test on 5ghz radio, that is the test i was waiting.

Currently, it seems that I am unable to perform WWAN testing as the AX6S I am using is the standard version made in China and not a specially customized version. It does not come with a mobile broadband module. Additionally, I would appreciate it if you could share your code with me. I am very interested in studying the modifications you have made. Personally, I believe the ideal solution would be to use MTK HNAT+dsa in combination with the openwrt fork of lean lede for compilation. However, I am uncertain if this is achievable and whether swconfig is absolutely necessary.

bricco1981 commented 4 months ago

Wwan is client mode Create an interface wwan, set as device apclii0, scan on 5ghz and connect.here you ll see the difference, the radio in station mode should be able to do hardware nat. make sure that the new interface wwan is on wan firewall zone.

hpx502766238 commented 4 months ago

Wwan is client mode Create an interface wwan, set as device apclii0, scan on 5ghz and connect.here you ll see the difference, the radio in station mode should be able to do hardware nat. make sure that the new interface wwan is on wan firewall zone.

I understand now. It sounds like a wireless bridge operating in routing mode. However, before I proceed with the test in 15 days, can you share your code with me first? As I am currently away from home and do not have the test environment available, I would like to study your code in the meantime.

hpx502766238 commented 4 months ago

Wwan is client mode Create an interface wwan, set as device apclii0, scan on 5ghz and connect.here you ll see the difference, the radio in station mode should be able to do hardware nat. make sure that the new interface wwan is on wan firewall zone.

I may have misunderstood it before. After you mentioned wwan, it suddenly occurred to me today that does the wireless fast nat only apply to wireless nat? If I understand correctly now, it calls the hnat module in the wireless chip, while the wired nat calls another hardware, I guess it's the hnat module of the mt7622 processor. These two nat modules are completely unrelated, so after enabling the wireless fast nat, it actually has no impact on the throughput and delay of wired wan to lan or wired wan to wireless, right? I don't know much about hardware, I don't know if this understanding is correct. If there is any mistake, I hope you can help me understand. Actually, my intention is to speed up the forwarding speed from wireless to wired wan port after enabling the wireless fast nat. It seems that I have always misunderstood it.

hpx502766238 commented 3 months ago

Wwan is client mode Create an interface wwan, set as device apclii0, scan on 5ghz and connect.here you ll see the difference, the radio in station mode should be able to do hardware nat. make sure that the new interface wwan is on wan firewall zone.

I conducted a brand new test in WWAN networking mode,https://github.com/bricco1981/MT7622-mtkwifi/issues/8

bricco1981 commented 3 months ago

Hi, sorry for the delay in replying. I think we will have to do more tests. as soon as I have some free time we will try. I think one test to do is to try the 5.4.xx kernel. Could this nat hardware malfunction be due to nftables? the 5.4 kernel uses iptables. We will see.

hpx502766238 commented 3 months ago

Hi, sorry for the delay in replying. I think we will have to do more tests. as soon as I have some free time we will try. I think one test to do is to try the 5.4.xx kernel. Could this nat hardware malfunction be due to nftables? the 5.4 kernel uses iptables. We will see.

" Indeed, I also agree that iptables should be used due to its better compatibility. However, I don’t think changing the kernel version is a good idea, as it would render many new Luci plugins unusable. Moreover, OpenWrt 22.03 can also use iptables. I originally abandoned the Padavan-only source code with the 5.4 kernel to ensure compatibility with new Luci plugins. Later on, I chose to work with Lean’s LEDE integrated drivers because they use the 5.10 kernel, iptables, and Luci18, which offer the best plugin compatibility and performance. I believe this is the ultimate solution for the AX6S. Of course, starting with the official OpenWrt 22.03 and iptables for hardware testing is also an excellent transitional approach.”

hpx502766238 commented 2 months ago

Hi, sorry for the delay in replying. I think we will have to do more tests. as soon as I have some free time we will try. I think one test to do is to try the 5.4.xx kernel. Could this nat hardware malfunction be due to nftables? the 5.4 kernel uses iptables. We will see.

I have built a new firmware with "mtk-openwrt-feeds, kernel 5.4.273, and lede24.4.4", including mtkhnat, whnat, and fast nat. I have solved many kernel patch errors, and it has now been built successfully. However, the router did not launch normally as expected after flashing the new firmware. So, I connected to the router with TTL to get more debug information, and it seems to be a problem with whnat. A piece of kernel log: [ 19.264697] Call trace: [ 19.267138] whnat_hal_hif_init+0x1c/0xf0 [mt_whnat] [ 19.272094] whnat_hif_init+0x98/0xc0 [mt_whnat] [ 19.276705] init_module+0x11c/0x1000 [mt_whnat] [ 19.281315] do_one_initcall+0x4c/0x1c0 [ 19.285143] do_init_module+0x40/0x1dc [ 19.288882] load_module+0x1c44/0x22b4 [ 19.292620] __do_sys_init_module+0x124/0x1bc [ 19.296967] __arm64_sys_init_module+0x18/0x20 [ 19.301403] el0_svc_common.constprop.0+0x60/0x110 [ 19.306182] el0_svc_handler+0x1c/0x24 [ 19.309921] el0_svc+0x8/0x6c0 [ 19.312968] Code: aa0003f3 f90013f5 f9400014 91002294 (b9400294) [ 19.319051] ---[ end trace bd67a0e471c6f94d ]--- [ 19.323658] Kernel panic - not syncing: Fatal exception [ 19.328875] SMP: stopping secondary CPUs [ 19.332790] Kernel Offset: disabled [ 19.336269] CPU features: 0x00002,04002004

I have no idea how to fix it; can you give me some advice? The component versions I used are as follows: mtk-openwrt-feeds: commit 46ed9497ef84121792e72ee1e27f534b7dfdf495, mirror Kernel version: 5.4.273 LEDE version: R24.4.4 (some of the kernel patches are replaced from openwrt21.02 due to compile conflicts, such as NAPI) My dev repo: https://github.com/hpx502766238/lede-R24.4.4-MTK/tree/mtk-drivers The file I uploaded is the full kernel log from the time of launching.

hpx502766238 commented 2 months ago

MobaXterm_COM5USB-SERIALCH340COM5_20240501_024036.txt

bricco1981 commented 2 months ago

do you have the DTS of the device the right way?

hpx502766238 commented 2 months ago

do you have the DTS of the device the right way?

I just solved this problem. It was due to a DTS issue; I had lost the PCIe-mirror configuration in the DTS. Now the kernel can launch normally. (But I am currently still having other problems with the UCI network configuration,The system network config are in a mess,with both dsa and gsw at the same time)

bricco1981 commented 2 months ago

fiber will be in town soon, so i can test too. please let me know your discovery, so we can make this better.

hpx502766238 commented 2 months ago

fiber will be in town soon, so i can test too. please let me know your discovery, so we can make this better.

Yes,of course.I will make a summary after some final experiments.

hpx502766238 commented 2 months ago

fiber will be in town soon, so i can test too. please let me know your discovery, so we can make this better.

At present,I still have some problems that cannot be solved by myself: Issue 1: Coexistence issue of using DSA or GSW Resolution steps:

  1. Testing revealed that in DSA mode, the mtkhnat kernel logs indicate that tx-offload cannot be enabled, only rx-offload is possible, so DSA was abandoned.
  2. The dts and 02-network configurations were amended to disable CONFIG_NET_DSA and related kernel options, and swconfig was enabled. After recompiling, the uci network configuration became normal.

Issue 2: The WAN port cannot obtain an IP address automatically, and it cannot access the internet after manually setting a static address and routing, although the WWAN can access the internet with high CPU usage. Resolution steps:

  1. After disabling the compilation of turboacc (kmod-ipt-offload), kmod-crypto, and retesting, the issue persists.
  2. The cause is unclear; I may remove the compilation of the wireless driver in the future to test the wired connection separately. Issue 3: The initial MAC addresses of WAN and LAN are the same. Resolution steps: None at the moment.
bricco1981 commented 2 months ago

i'll post another firmware to test, it's openwrt 22.03.2, i remember this version does not need software and hardware offload enable to work right, this problem is only present on 22.03.6. i'll post in 2 or 3 hours, when i'll be back home.

hpx502766238 commented 2 months ago

i'll post another firmware to test, it's openwrt 22.03.2, i remember this version does not need software and hardware offload enable to work right, this problem is only present on 22.03.6. i'll post in 2 or 3 hours, when i'll be back home.

Bless you to success. At present, my build is a failure. I checked the NIC status using ethtool, which indicates that rx-offload cannot be enabled with the current mtk drivers (2023.10). I plan to build with an older mtkhnat driver (2023.5).

bricco1981 commented 2 months ago

hi @hpx502766238 can you test last build please? you cat test it without enabling software and hardware offload. do not keep setting.

hpx502766238 commented 2 months ago

hi @hpx502766238 can you test last build please? you cat test it without enabling software and hardware offload. do not keep setting.


At present, your firmware is almost perfect except for the low speed with WWAN. Here is the test result summary: 【lan->wan】 Both uplink and downlink can reach speeds of 950M. CPU utilization is 5%.(no high-use processes) 【wlan(5G)->wan】 Uplink 300M, downlink 650M. CPU utilization is 15% (ksoftirqd -- 1%), (wed_task0 -- 1%) 【wlan(5G)->wwan(5G)】 Uplink 300M, downlink 180M, CPU utilization is 23% (no high-use processes) (ksoftirqd -- 1%) 【lan->wwan(5G)】 Both uplink and downlink are 120M. CPU utilization is 15% (no high-use processes) Yes, it is almost perfect because you solved the CPU utilization problem. However, the WWAN speed is still an issue. The WWAN speed of AX6S can reach a maximum of 800M in firmware without HNAT, which I have tested before. In addition, to get more functionality, I still want to build a new firmware by myself with your drivers. So I have some questions, can you help me?

  1. Which version of the MediaTek vendor driver do you use? I have tried mtk-openwrt-feeds, but I don’t know which version is best for MT7622. At present, I use mtkfeeds committed on 2022-08; it works fine in wired HNAT but has a lot of problems with wireless.
  2. To build a kernel with MediaTek HNAT drivers, which kernel patches do I need to choose? At present, I compiled with all kernel patches (about 100+, too many) from mtk-openwrt-feeds, wasting a lot of time. Too many kernel patches also made it difficult to migrate from 5.4 to kernel 5.10.
  3. By watching the kernel log, I noticed that the IRQ num in your firmware seems to be different from PadavanOnly. Is this the key to reducing CPU usage?

bricco1981 commented 2 months ago

hi please check at the end of the radio configuration if whnat is enable. do not warry i'll send you the code, but lets first understand how make it better.

bricco1981 commented 2 months ago

hi @hpx502766238 any new test? with WHNAT=1 ?

hpx502766238 commented 2 months ago

hi @hpx502766238 any new test? with WHNAT=1 ?

The WHNAT had been already enabled.Both seen in wireless config and kernel log on the last test I performed.

bricco1981 commented 2 months ago

are you sure in /etc/wireless/mt7615/mt7615.2.dat is enabled? mine was not

Wds3Key= WdsEnable=0 WdsEncrypType=NONE WdsList= WdsPhyMode=0 WEP1Type1=0 WEP2Type1=0 WEP3Type1=0 WEP4Type1=0 WHNAT=1 WiFiTest=0

hpx502766238 commented 2 months ago

are you sure in /etc/wireless/mt7615/mt7615.2.dat is enabled? mine was not

Wds3Key= WdsEnable=0 WdsEncrypType=NONE WdsList= WdsPhyMode=0 WEP1Type1=0 WEP2Type1=0 WEP3Type1=0 WEP4Type1=0 WHNAT=1 WiFiTest=0

yes,I am sure it is enabled by default even if I restore to factory settings: WEP1Type1=0 WEP2Type1=0 WEP3Type1=0 WEP4Type1=0 WHNAT=1 WiFiTest=0 WirelessMode=17 WmmCapable=1 WNMEnable=1 .I can also see whnat init info in kernel log. Fri Oct 14 22:47:45 2022 kern.info kernel: [ 26.385225] whnat_cap_support(): chip_id=7915 is in WHNAT support list Fri Oct 14 22:47:45 2022 kern.info kernel: [ 26.391821] wifi_slot_get(): bus name=PCI Bus 0000:01, funid=0, get slot id=0 Fri Oct 14 22:47:45 2022 kern.info kernel: [ 26.399051] whnat_entry_acquire(): PCIE SLOT:0, hook to WHNAT,entry id=0 Fri Oct 14 22:47:45 2022 kern.info kernel: [ 26.405908] wed_init(0): irq=20,base_addr=0xffffffc010dd5000 Fri Oct 14 22:47:45 2022 kern.info kernel: [ 26.412471] wed_ring_init(): wed ring init result = 0 Fri Oct 14 22:47:45 2022 kern.info kernel: [ 26.433249] create wed ok!!! Fri Oct 14 22:47:45 2022 kern.info kernel: [ 26.436274] wdma_init(): wdma(0) base addr=ffffffc010dd7800 Fri Oct 14 22:47:45 2022 kern.info kernel: [ 26.441996] wdma_init(): wdma(0) irq[0]=33 Fri Oct 14 22:47:45 2022 kern.info kernel: [ 26.446091] wdma_init(): wdma(0) irq[1]=34 Fri Oct 14 22:47:45 2022 kern.info kernel: [ 26.450262] wdma_init(): wdma(0) irq[2]=35 Fri Oct 14 22:47:45 2022 kern.info kernel: [ 26.454877] wifi_chip_probe(): Chang CHIP IRQ: 144 to WHNAT IRQ: 20

bricco1981 commented 2 months ago

So you said that wireless side is working better on non hardware nat drivers?

hpx502766238 commented 2 months ago

So you said that wireless side is working better on non hardware nat drivers?

Yes,the throughput is much higher on non-hardware NAT drivers, but CPU usage is much higher, too. (Only for wwan situation.)

bricco1981 commented 2 months ago

and if you enable hardware and software offload in firewall? no difference on wireless side?

very strange situation.

if you tell me how i can sent you this stuff i'll sent you. so we will have two eyes on that.

hpx502766238 commented 2 months ago

and if you enable hardware and software offload in firewall? no difference on wireless side?

very strange situation.

if you tell me how i can sent you this stuff i'll sent you. so we will have two eyes on that.

1.I didn't enable linux offload in firewall when tested your firmware. 2.In fact,there are some other difference on wireless side between your firmware and my [mtwifi+ linux offload] firmware(without mtkhnat). https://github.com/hpx502766238/lede-R24.4.4-MTK/tree/213f2713358060901860fb1201e30b8991cca7f9/package/mtk/mt7915 This is my repo I had tested before.I changed some default options such as fast uprate in n config.in and 7615.2.dat to improve performance,referring to profile from padavanonly and official miwifi firmware.You can compare the difference between them.