blob: 1b2fbfdf60a516539f937f7dcf5b5c9a50a36ee6 [file] [log] [blame]
developerfd40db22021-04-29 10:08:25 +08001#!/bin/sh
2
3. /lib/functions.sh
4
5config_load mtkhnat
6config_get enable global enable 0
7config_get hqos global hqos 0
8config_get txq_num global txq_num 16
9config_get scheduling global scheduling "wrr"
10config_get sch0_bw global sch0_bw 100000
11config_get sch1_bw global sch1_bw 100000
12
developer04f0ec82021-12-30 13:59:10 +080013# disable bridge netfilter module to avoid high cpu usage
14echo 0 > /proc/sys/net/bridge/bridge-nf-call-arptables
15echo 0 > /proc/sys/net/bridge/bridge-nf-call-iptables
16echo 0 > /proc/sys/net/bridge/bridge-nf-call-ip6tables
17echo 0 > /proc/sys/net/bridge/bridge-nf-filter-pppoe-tagged
18echo 0 > /proc/sys/net/bridge/bridge-nf-filter-vlan-tagged
19echo 0 > /proc/sys/net/bridge/bridge-nf-pass-vlan-input-dev
20
developerfd40db22021-04-29 10:08:25 +080021#if enable=0, disable qdma_sch & qdma_txq
22[ "${enable}" -eq 1 ] || {
23 echo 0 ${scheduling} ${sch0_bw} > /sys/kernel/debug/hnat/qdma_sch0
24 echo 0 ${scheduling} ${sch1_bw} > /sys/kernel/debug/hnat/qdma_sch1
developer04f0ec82021-12-30 13:59:10 +080025 echo 0 0 0 0 0 0 4 > /sys/kernel/debug/hnat/qdma_txq0
developerfd40db22021-04-29 10:08:25 +080026 for i in $(seq 1 $((txq_num - 1)))
27 do
28 echo 0 0 0 0 0 0 0 > /sys/kernel/debug/hnat/qdma_txq$i
29 done
30
31 rmmod mtkhnat
32 exit 0
33}
34
35insmod mtkhnat
36
37#if hqos=0, disable qdma_sch & qdma_txq
38[ "${hqos}" -eq 1 ] || {
39 echo 0 ${scheduling} ${sch0_bw} > /sys/kernel/debug/hnat/qdma_sch0
40 echo 0 ${scheduling} ${sch1_bw} > /sys/kernel/debug/hnat/qdma_sch1
developer04f0ec82021-12-30 13:59:10 +080041
42 for i in $(seq 0 $((txq_num - 1)))
developerfd40db22021-04-29 10:08:25 +080043 do
developer04f0ec82021-12-30 13:59:10 +080044 if [ "${i}" -le $(((txq_num / 2) - 1)) ]; then
45 echo 0 0 0 0 0 0 4 > /sys/kernel/debug/hnat/qdma_txq$i
46 else
47 echo 1 0 0 0 0 0 4 > /sys/kernel/debug/hnat/qdma_txq$i
48 fi
developerfd40db22021-04-29 10:08:25 +080049 done
50
51 exit 0
52}
53
54# enable qdma_sch0 and qdma_sch1
55echo 1 ${scheduling} ${sch0_bw} > /sys/kernel/debug/hnat/qdma_sch0
56echo 1 ${scheduling} ${sch1_bw} > /sys/kernel/debug/hnat/qdma_sch1
57
developer04f0ec82021-12-30 13:59:10 +080058# enable bridge netfilter module to allow skb being marked
59echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
60echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables
61
developerfd40db22021-04-29 10:08:25 +080062setup_queue() {
63 local queue_id queue_scheduler queue_minebl queue_maxebl
64 local queue_minrate queue_maxrate queue_resv minrate maxrate queue_weight
65
66 config_get queue_id $1 id 0
67 config_get queue_minrate $1 minrate 0
68 config_get queue_maxrate $1 maxrate 0
69 config_get queue_resv $1 resv 4
70 config_get queue_weight $1 weight 4
71
72 # check qid < txq max num or not for loop condition
73 [ "${queue_id}" -gt $((txq_num - 1)) ] && return 0
74
75 # start to set per queue config
76 queue_minebl=1
77 queue_maxebl=1
78 queue_scheduler=0
79
80 # if min rate = 0, set min enable = 0
81 # if max rate = 0, set max enable = 0
82 [ "${queue_minrate}" -eq 0 ] && queue_minebl=0
83 [ "${queue_maxrate}" -eq 0 ] && queue_maxebl=0
84
85 # calculate min rate according to sch0_bw
86 minrate=$((sch0_bw * $queue_minrate))
87 minrate=$((minrate / 100))
88
89 # calculate max rate according to sch0_bw
90 maxrate=$((sch0_bw * $queue_maxrate))
91 maxrate=$((maxrate / 100))
92
93 # set the queue of sch0 group(the lower half of total queues)
94 [ "${queue_id}" -le $(((txq_num / 2) - 1)) ] && \
95 echo 0 ${queue_minebl} ${minrate} ${queue_maxebl} ${maxrate} ${queue_weight} \
96 ${queue_resv} > /sys/kernel/debug/hnat/qdma_txq${queue_id}
97
98 # calculate min rate according to sch1_bw
99 minrate=$((sch1_bw * $queue_minrate))
100 minrate=$((minrate / 100))
101
102 # calculate max rate according to sch1_bw
103 maxrate=$((sch1_bw * $queue_maxrate))
104 maxrate=$((maxrate / 100))
105
106 # set the queue of sch1 group(the upper half of total queues)
107 [ "${queue_id}" -gt $(((txq_num / 2) - 1)) ] && \
108 echo 1 ${queue_minebl} ${minrate} ${queue_maxebl} ${maxrate} ${queue_weight} \
109 ${queue_resv} > /sys/kernel/debug/hnat/qdma_txq${queue_id}
110}
111
112config_foreach setup_queue queue