Use mtk sdk HWNAT driver to replace hw flow offload

Considering some problems with openwrt flow offload now, I try to use the hwnat driver of mtk sdk. Compared with flow offload, it is more stable and supports wifi offload. This is the sdk driver source code published by mtk https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/

Based on the above source code, I modified the hwnat driver that can run stably under linux 5.10. It supports offload of ipv4, ipv6 and wifi. For some reason I'm using the switch driver instead of the dsa driver. The steps to use this driver are as follows

  1. https://github.com/padavanonly/openwrt/tree/master/target/linux/ramips

Replace ramips folder of your openwrt source directory with the folder corresponding to the link

  1. This folder is only adapted to wr1200js, newifi d1, and k2p now. If you are on other models, you should refer to these two commits to modify the source code to adapt to your router.
    https://github.com/padavanonly/openwrt/commit/8a99f52a38e302a35acc31a8155d3b5243a3d7ad
    https://github.com/padavanonly/openwrt/commit/419d4efc0ee4f74d7c4151f5c3310e16c0cb870d

  2. Run rm .config. In theory, after re-make menuconfig, kmod-ramips_hnat will be automatically added to .config. Flash the compiled firmware, when you see the following log, it means hwnat is running successfully. To avoid conflicts, you should disable flow offload.

4 Likes

For the second step, the wan of 7621 has two cases. If your wan is port4, it should be

mediatek,portmap = "llllw";

ucidef_add_switch "switch0" \
  "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6u@eth0" "5u@eth1"
  ;;

And if your wan is port0, it should be

  mediatek,portmap = "wllll";

ucidef_add_switch "switch0" \
 "1:lan" "2:lan" "3:lan" "4:lan"   "0:wan" "6u@eth0" "5u@eth1"
  ;;

You can see whether your wan is port0 or port4 from the switch0 node in the original dts

3 Likes

But there are some mt7621 routers that only support one gmac, such as newifi3 d2, so the above steps are not suitable for these routers. I don't have time to adapt this kind of router, I hope people with energy can study it.

Can use on coolwolfsnow lede?

Any openwrt could use this driver if the kernel version is 5.10. But I haven't test firewall4.

Really appreciate your guidance

I'm curious how hard it would be to port this to DSA and kernel 5.15.x. Exciting that you have it up and running with 5.10 and the older switch code. Anything that helps out these little chipsets is a good thing. Thanks for digging into it. Hopefully people can pile on and get this into a usable PR.

In theory 5.15 can be used directly. As for dsa, mtk sdk lacks related patches, and I have the need to use switch myself, so I have no motivation to test dsa.