[][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/Makefile b/feed/mtkhnat_util/Makefile
new file mode 100755
index 0000000..8ef168a
--- /dev/null
+++ b/feed/mtkhnat_util/Makefile
@@ -0,0 +1,48 @@
+#
+# MTK-factory read and write
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=mtkhnat_util
+PKG_VERSION:=1
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
+PKG_CONFIG_DEPENDS:=
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/mtkhnat_util
+ SECTION:=net
+ CATEGORY:=Network
+ TITLE:=mtk hnat utility
+ VERSION:=$(PKG_RELEASE)-$(REVISION)
+endef
+
+define Package/mtkhnat_util/description
+ mtk hnat util to init hnat module
+endef
+
+define Build/Prepare
+ mkdir -p $(PKG_BUILD_DIR)
+endef
+
+define Build/Compile/Default
+endef
+
+Build/Compile = $(Build/Compile/Default)
+
+define Package/mtkhnat_util/install
+ $(INSTALL_DIR) $(1)/sbin
+ $(INSTALL_DIR) $(1)/etc/config
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_DIR) $(1)/etc/uci-defaults
+
+ $(INSTALL_BIN) ./files/mtkhnat $(1)/sbin/
+ $(INSTALL_BIN) ./files/mtkhnat.config $(1)/etc/config/mtkhnat
+ $(INSTALL_BIN) ./files/mtkhnat.init $(1)/etc/init.d/mtkhnat
+ $(INSTALL_BIN) ./files/99-firewall $(1)/etc/uci-defaults
+endef
+
+$(eval $(call BuildPackage,mtkhnat_util))
diff --git a/feed/mtkhnat_util/files/99-firewall b/feed/mtkhnat_util/files/99-firewall
new file mode 100755
index 0000000..9c72762
--- /dev/null
+++ b/feed/mtkhnat_util/files/99-firewall
@@ -0,0 +1,6 @@
+echo "iptables -t mangle -A FORWARD -m dscp --dscp-class BE -j MARK --set-mark 0" >> /etc/firewall.user
+echo "iptables -t mangle -A FORWARD -m dscp --dscp-class CS2 -j MARK --set-mark 2" >> /etc/firewall.user
+echo "iptables -t mangle -A FORWARD -m dscp --dscp-class CS4 -j MARK --set-mark 4" >> /etc/firewall.user
+echo "iptables -t mangle -A FORWARD -m dscp --dscp-class CS6 -j MARK --set-mark 6" >> /etc/firewall.user
+
+exit 0
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
diff --git a/feed/mtkhnat_util/files/mtkhnat.config b/feed/mtkhnat_util/files/mtkhnat.config
new file mode 100755
index 0000000..f252a98
--- /dev/null
+++ b/feed/mtkhnat_util/files/mtkhnat.config
@@ -0,0 +1,921 @@
+####################################################################
+# hqos: 1:ON, 0:OFF #
+# txq_num: 16:default (only supports 64 queues for MT7622) #
+# scheduling: wrr: weighted round-robin, sp: strict priority #
+# sch0_bw: sch0 bandwidth (unit:Kbps) #
+# sch1_bw: sch1 bandwidth (unit:Kbps) #
+####################################################################
+config global global
+ option enable 1
+ option hqos 0
+ option txq_num 16
+ option scheduling 'wrr'
+ option sch0_bw 1000000
+ option sch1_bw 1000000
+
+####################################################################
+# id: queue id #
+# minrate: percentage of min rate limit #
+# maxrate: percentage of max rate limit #
+# weight: weight for queue schedule #
+# resv: buffer reserved for HW/SW path #
+####################################################################
+config queue
+ option id 0
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 1
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 2
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 3
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 4
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 5
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 6
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 7
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 8
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 9
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 10
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 11
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 12
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 13
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 14
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 15
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+####################################################################
+# Default setting supports 16 queues (id: 0~15) #
+# Only supports 64 queues for MT7622 #
+####################################################################
+config queue
+ option id 16
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 17
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 18
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 19
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 20
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 21
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 22
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 23
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 24
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 25
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 26
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 27
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 28
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 29
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 30
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 31
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 32
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 33
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 34
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 35
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 36
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 37
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 38
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 39
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 40
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 41
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 42
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 43
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 44
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 45
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 46
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 47
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 48
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 49
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 50
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 51
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 52
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 53
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 54
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 55
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 56
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 57
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 58
+ option minrate 30
+ option maxrate 100
+ option weight 2
+ option resv 4
+
+config queue
+ option id 59
+ option minrate 30
+ option maxrate 100
+ option weight 4
+ option resv 4
+
+config queue
+ option id 60
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 61
+ option minrate 30
+ option maxrate 100
+ option weight 6
+ option resv 4
+
+config queue
+ option id 62
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 63
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 64
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 65
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 66
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 67
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 68
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 69
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 70
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 71
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 72
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 73
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 74
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 75
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 76
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 77
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 78
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 79
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 80
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 81
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 82
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 83
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 84
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 85
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 86
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 87
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 88
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 89
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 90
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 91
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 92
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 93
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 94
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 95
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 96
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 97
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 98
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 99
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 100
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 101
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 102
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 103
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 104
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 105
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 106
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 107
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 108
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 109
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 110
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 111
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 112
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 113
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 114
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 115
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 116
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 117
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 118
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 119
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 120
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 121
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 122
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 123
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 124
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 125
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 126
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
+
+config queue
+ option id 127
+ option minrate 30
+ option maxrate 100
+ option weight 8
+ option resv 4
diff --git a/feed/mtkhnat_util/files/mtkhnat.init b/feed/mtkhnat_util/files/mtkhnat.init
new file mode 100755
index 0000000..528e62e
--- /dev/null
+++ b/feed/mtkhnat_util/files/mtkhnat.init
@@ -0,0 +1,17 @@
+#!/bin/sh /etc/rc.common
+
+START=19
+
+USE_PROCD=1
+NAME=mtkhnat
+PROG=/sbin/mtkhnat
+
+start_service() {
+ procd_open_instance
+ procd_set_param command "${PROG}"
+ procd_close_instance
+}
+
+service_triggers() {
+ procd_add_reload_trigger "mtkhnat"
+}