blob: f70049a46de2659cc2656908383b5aa013fd10dd [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
developerf1fcda92022-09-22 09:45:43 +080021#if hnat is not exist, switch module to mtk_ppe
22module=hnat
23[ -d /sys/kernel/debug/${module} ] || {
24 module=mtk_ppe
developer45d02782022-10-14 10:33:40 +080025 echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
26 echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables
developerf1fcda92022-09-22 09:45:43 +080027}
28
developerfd40db22021-04-29 10:08:25 +080029#if enable=0, disable qdma_sch & qdma_txq
30[ "${enable}" -eq 1 ] || {
developerf1fcda92022-09-22 09:45:43 +080031 echo 0 ${scheduling} ${sch0_bw} > /sys/kernel/debug/${module}/qdma_sch0
32 echo 0 ${scheduling} ${sch1_bw} > /sys/kernel/debug/${module}/qdma_sch1
33 echo 0 0 0 0 0 0 4 > /sys/kernel/debug/${module}/qdma_txq0
developerfd40db22021-04-29 10:08:25 +080034 for i in $(seq 1 $((txq_num - 1)))
35 do
developerf1fcda92022-09-22 09:45:43 +080036 echo 0 0 0 0 0 0 0 > /sys/kernel/debug/${module}/qdma_txq$i
developerfd40db22021-04-29 10:08:25 +080037 done
38
39 rmmod mtkhnat
40 exit 0
41}
42
43insmod mtkhnat
44
45#if hqos=0, disable qdma_sch & qdma_txq
46[ "${hqos}" -eq 1 ] || {
developerf1fcda92022-09-22 09:45:43 +080047 echo 0 ${scheduling} ${sch0_bw} > /sys/kernel/debug/${module}/qdma_sch0
48 echo 0 ${scheduling} ${sch1_bw} > /sys/kernel/debug/${module}/qdma_sch1
developer04f0ec82021-12-30 13:59:10 +080049
50 for i in $(seq 0 $((txq_num - 1)))
developerfd40db22021-04-29 10:08:25 +080051 do
developer04f0ec82021-12-30 13:59:10 +080052 if [ "${i}" -le $(((txq_num / 2) - 1)) ]; then
developerf1fcda92022-09-22 09:45:43 +080053 echo 0 0 0 0 0 0 4 > /sys/kernel/debug/${module}/qdma_txq$i
developer04f0ec82021-12-30 13:59:10 +080054 else
developerf1fcda92022-09-22 09:45:43 +080055 echo 1 0 0 0 0 0 4 > /sys/kernel/debug/${module}/qdma_txq$i
developer04f0ec82021-12-30 13:59:10 +080056 fi
developerfd40db22021-04-29 10:08:25 +080057 done
58
59 exit 0
60}
61
62# enable qdma_sch0 and qdma_sch1
developerf1fcda92022-09-22 09:45:43 +080063echo 1 ${scheduling} ${sch0_bw} > /sys/kernel/debug/${module}/qdma_sch0
64echo 1 ${scheduling} ${sch1_bw} > /sys/kernel/debug/${module}/qdma_sch1
developerfd40db22021-04-29 10:08:25 +080065
developer04f0ec82021-12-30 13:59:10 +080066# enable bridge netfilter module to allow skb being marked
67echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
68echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables
69
developerfd40db22021-04-29 10:08:25 +080070setup_queue() {
71 local queue_id queue_scheduler queue_minebl queue_maxebl
72 local queue_minrate queue_maxrate queue_resv minrate maxrate queue_weight
73
74 config_get queue_id $1 id 0
75 config_get queue_minrate $1 minrate 0
76 config_get queue_maxrate $1 maxrate 0
77 config_get queue_resv $1 resv 4
78 config_get queue_weight $1 weight 4
79
80 # check qid < txq max num or not for loop condition
81 [ "${queue_id}" -gt $((txq_num - 1)) ] && return 0
82
83 # start to set per queue config
84 queue_minebl=1
85 queue_maxebl=1
86 queue_scheduler=0
87
88 # if min rate = 0, set min enable = 0
89 # if max rate = 0, set max enable = 0
90 [ "${queue_minrate}" -eq 0 ] && queue_minebl=0
91 [ "${queue_maxrate}" -eq 0 ] && queue_maxebl=0
92
93 # calculate min rate according to sch0_bw
94 minrate=$((sch0_bw * $queue_minrate))
95 minrate=$((minrate / 100))
96
97 # calculate max rate according to sch0_bw
98 maxrate=$((sch0_bw * $queue_maxrate))
99 maxrate=$((maxrate / 100))
100
101 # set the queue of sch0 group(the lower half of total queues)
102 [ "${queue_id}" -le $(((txq_num / 2) - 1)) ] && \
103 echo 0 ${queue_minebl} ${minrate} ${queue_maxebl} ${maxrate} ${queue_weight} \
developerf1fcda92022-09-22 09:45:43 +0800104 ${queue_resv} > /sys/kernel/debug/${module}/qdma_txq${queue_id}
developerfd40db22021-04-29 10:08:25 +0800105
106 # calculate min rate according to sch1_bw
107 minrate=$((sch1_bw * $queue_minrate))
108 minrate=$((minrate / 100))
109
110 # calculate max rate according to sch1_bw
111 maxrate=$((sch1_bw * $queue_maxrate))
112 maxrate=$((maxrate / 100))
113
114 # set the queue of sch1 group(the upper half of total queues)
115 [ "${queue_id}" -gt $(((txq_num / 2) - 1)) ] && \
116 echo 1 ${queue_minebl} ${minrate} ${queue_maxebl} ${maxrate} ${queue_weight} \
developerf1fcda92022-09-22 09:45:43 +0800117 ${queue_resv} > /sys/kernel/debug/${module}/qdma_txq${queue_id}
developerfd40db22021-04-29 10:08:25 +0800118}
119
120config_foreach setup_queue queue