blob: f407f1acbf597d7267e9b5477de90cbb47fd2755 [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 ] || {
developer492e2a52023-01-09 14:53:44 +080047 SOC=`cat /proc/device-tree/ethernet*/compatible | cut -c 10-15`
48 IS_NETSYS_V2=$(if [[ $SOC == "mt7986" || $SOC == "mt7981" ]]; then echo true; fi)
49
developerf1fcda92022-09-22 09:45:43 +080050 echo 0 ${scheduling} ${sch0_bw} > /sys/kernel/debug/${module}/qdma_sch0
51 echo 0 ${scheduling} ${sch1_bw} > /sys/kernel/debug/${module}/qdma_sch1
developer04f0ec82021-12-30 13:59:10 +080052
53 for i in $(seq 0 $((txq_num - 1)))
developerfd40db22021-04-29 10:08:25 +080054 do
developer492e2a52023-01-09 14:53:44 +080055 if [ "${i}" -le $(((txq_num / 2) - 1)) ] || [ ! $IS_NETSYS_V2 ]; then
developerf1fcda92022-09-22 09:45:43 +080056 echo 0 0 0 0 0 0 4 > /sys/kernel/debug/${module}/qdma_txq$i
developer04f0ec82021-12-30 13:59:10 +080057 else
developerf1fcda92022-09-22 09:45:43 +080058 echo 1 0 0 0 0 0 4 > /sys/kernel/debug/${module}/qdma_txq$i
developer04f0ec82021-12-30 13:59:10 +080059 fi
developerfd40db22021-04-29 10:08:25 +080060 done
61
62 exit 0
63}
64
65# enable qdma_sch0 and qdma_sch1
developerf1fcda92022-09-22 09:45:43 +080066echo 1 ${scheduling} ${sch0_bw} > /sys/kernel/debug/${module}/qdma_sch0
67echo 1 ${scheduling} ${sch1_bw} > /sys/kernel/debug/${module}/qdma_sch1
developerfd40db22021-04-29 10:08:25 +080068
developer04f0ec82021-12-30 13:59:10 +080069# enable bridge netfilter module to allow skb being marked
70echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
71echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables
72
developerfd40db22021-04-29 10:08:25 +080073setup_queue() {
74 local queue_id queue_scheduler queue_minebl queue_maxebl
75 local queue_minrate queue_maxrate queue_resv minrate maxrate queue_weight
76
77 config_get queue_id $1 id 0
78 config_get queue_minrate $1 minrate 0
79 config_get queue_maxrate $1 maxrate 0
80 config_get queue_resv $1 resv 4
81 config_get queue_weight $1 weight 4
82
83 # check qid < txq max num or not for loop condition
84 [ "${queue_id}" -gt $((txq_num - 1)) ] && return 0
85
86 # start to set per queue config
87 queue_minebl=1
88 queue_maxebl=1
89 queue_scheduler=0
90
91 # if min rate = 0, set min enable = 0
92 # if max rate = 0, set max enable = 0
93 [ "${queue_minrate}" -eq 0 ] && queue_minebl=0
94 [ "${queue_maxrate}" -eq 0 ] && queue_maxebl=0
95
96 # calculate min rate according to sch0_bw
97 minrate=$((sch0_bw * $queue_minrate))
98 minrate=$((minrate / 100))
99
100 # calculate max rate according to sch0_bw
101 maxrate=$((sch0_bw * $queue_maxrate))
102 maxrate=$((maxrate / 100))
103
104 # set the queue of sch0 group(the lower half of total queues)
105 [ "${queue_id}" -le $(((txq_num / 2) - 1)) ] && \
106 echo 0 ${queue_minebl} ${minrate} ${queue_maxebl} ${maxrate} ${queue_weight} \
developerf1fcda92022-09-22 09:45:43 +0800107 ${queue_resv} > /sys/kernel/debug/${module}/qdma_txq${queue_id}
developerfd40db22021-04-29 10:08:25 +0800108
109 # calculate min rate according to sch1_bw
110 minrate=$((sch1_bw * $queue_minrate))
111 minrate=$((minrate / 100))
112
113 # calculate max rate according to sch1_bw
114 maxrate=$((sch1_bw * $queue_maxrate))
115 maxrate=$((maxrate / 100))
116
117 # set the queue of sch1 group(the upper half of total queues)
118 [ "${queue_id}" -gt $(((txq_num / 2) - 1)) ] && \
119 echo 1 ${queue_minebl} ${minrate} ${queue_maxebl} ${maxrate} ${queue_weight} \
developerf1fcda92022-09-22 09:45:43 +0800120 ${queue_resv} > /sys/kernel/debug/${module}/qdma_txq${queue_id}
developerfd40db22021-04-29 10:08:25 +0800121}
122
123config_foreach setup_queue queue