[][Add initial mtk feed for OpenWRT v21.02]
[Description]
Add initial mtk feed for OpenWRT v21.02
[Release-log]
N/A
Change-Id: I8051c6ba87f1ccf26c02fdd88a17d66f63c0b101
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/4495320
diff --git a/feed/mtkhnat_util/files/mtkhnat b/feed/mtkhnat_util/files/mtkhnat
new file mode 100755
index 0000000..ce3ef9a
--- /dev/null
+++ b/feed/mtkhnat_util/files/mtkhnat
@@ -0,0 +1,96 @@
+#!/bin/sh
+
+. /lib/functions.sh
+
+config_load mtkhnat
+config_get enable global enable 0
+config_get hqos global hqos 0
+config_get txq_num global txq_num 16
+config_get scheduling global scheduling "wrr"
+config_get sch0_bw global sch0_bw 100000
+config_get sch1_bw global sch1_bw 100000
+
+#if enable=0, disable qdma_sch & qdma_txq
+[ "${enable}" -eq 1 ] || {
+ echo 0 ${scheduling} ${sch0_bw} > /sys/kernel/debug/hnat/qdma_sch0
+ echo 0 ${scheduling} ${sch1_bw} > /sys/kernel/debug/hnat/qdma_sch1
+ echo 1 0 0 0 0 0 4 > /sys/kernel/debug/hnat/qdma_txq0
+ for i in $(seq 1 $((txq_num - 1)))
+ do
+ echo 0 0 0 0 0 0 0 > /sys/kernel/debug/hnat/qdma_txq$i
+ done
+
+ rmmod mtkhnat
+ exit 0
+}
+
+insmod mtkhnat
+
+#if hqos=0, disable qdma_sch & qdma_txq
+[ "${hqos}" -eq 1 ] || {
+ echo 0 ${scheduling} ${sch0_bw} > /sys/kernel/debug/hnat/qdma_sch0
+ echo 0 ${scheduling} ${sch1_bw} > /sys/kernel/debug/hnat/qdma_sch1
+ echo 1 0 0 0 0 0 4 > /sys/kernel/debug/hnat/qdma_txq0
+ for i in $(seq 1 $((txq_num - 1)))
+ do
+ echo 0 0 0 0 0 0 0 > /sys/kernel/debug/hnat/qdma_txq$i
+ done
+
+ exit 0
+}
+
+# enable qdma_sch0 and qdma_sch1
+echo 1 ${scheduling} ${sch0_bw} > /sys/kernel/debug/hnat/qdma_sch0
+echo 1 ${scheduling} ${sch1_bw} > /sys/kernel/debug/hnat/qdma_sch1
+
+setup_queue() {
+ local queue_id queue_scheduler queue_minebl queue_maxebl
+ local queue_minrate queue_maxrate queue_resv minrate maxrate queue_weight
+
+ config_get queue_id $1 id 0
+ config_get queue_minrate $1 minrate 0
+ config_get queue_maxrate $1 maxrate 0
+ config_get queue_resv $1 resv 4
+ config_get queue_weight $1 weight 4
+
+ # check qid < txq max num or not for loop condition
+ [ "${queue_id}" -gt $((txq_num - 1)) ] && return 0
+
+ # start to set per queue config
+ queue_minebl=1
+ queue_maxebl=1
+ queue_scheduler=0
+
+ # if min rate = 0, set min enable = 0
+ # if max rate = 0, set max enable = 0
+ [ "${queue_minrate}" -eq 0 ] && queue_minebl=0
+ [ "${queue_maxrate}" -eq 0 ] && queue_maxebl=0
+
+ # calculate min rate according to sch0_bw
+ minrate=$((sch0_bw * $queue_minrate))
+ minrate=$((minrate / 100))
+
+ # calculate max rate according to sch0_bw
+ maxrate=$((sch0_bw * $queue_maxrate))
+ maxrate=$((maxrate / 100))
+
+ # set the queue of sch0 group(the lower half of total queues)
+ [ "${queue_id}" -le $(((txq_num / 2) - 1)) ] && \
+ echo 0 ${queue_minebl} ${minrate} ${queue_maxebl} ${maxrate} ${queue_weight} \
+ ${queue_resv} > /sys/kernel/debug/hnat/qdma_txq${queue_id}
+
+ # calculate min rate according to sch1_bw
+ minrate=$((sch1_bw * $queue_minrate))
+ minrate=$((minrate / 100))
+
+ # calculate max rate according to sch1_bw
+ maxrate=$((sch1_bw * $queue_maxrate))
+ maxrate=$((maxrate / 100))
+
+ # set the queue of sch1 group(the upper half of total queues)
+ [ "${queue_id}" -gt $(((txq_num / 2) - 1)) ] && \
+ echo 1 ${queue_minebl} ${minrate} ${queue_maxebl} ${maxrate} ${queue_weight} \
+ ${queue_resv} > /sys/kernel/debug/hnat/qdma_txq${queue_id}
+}
+
+config_foreach setup_queue queue