developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | . /lib/functions.sh |
| 4 | |
| 5 | config_load mtkhnat |
| 6 | config_get enable global enable 0 |
| 7 | config_get hqos global hqos 0 |
| 8 | config_get txq_num global txq_num 16 |
| 9 | config_get scheduling global scheduling "wrr" |
| 10 | config_get sch0_bw global sch0_bw 100000 |
| 11 | config_get sch1_bw global sch1_bw 100000 |
| 12 | |
developer | 04f0ec8 | 2021-12-30 13:59:10 +0800 | [diff] [blame] | 13 | # disable bridge netfilter module to avoid high cpu usage |
| 14 | echo 0 > /proc/sys/net/bridge/bridge-nf-call-arptables |
| 15 | echo 0 > /proc/sys/net/bridge/bridge-nf-call-iptables |
| 16 | echo 0 > /proc/sys/net/bridge/bridge-nf-call-ip6tables |
| 17 | echo 0 > /proc/sys/net/bridge/bridge-nf-filter-pppoe-tagged |
| 18 | echo 0 > /proc/sys/net/bridge/bridge-nf-filter-vlan-tagged |
| 19 | echo 0 > /proc/sys/net/bridge/bridge-nf-pass-vlan-input-dev |
| 20 | |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 21 | #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 |
developer | 04f0ec8 | 2021-12-30 13:59:10 +0800 | [diff] [blame] | 25 | echo 0 0 0 0 0 0 4 > /sys/kernel/debug/hnat/qdma_txq0 |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 26 | 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 | |
| 35 | insmod 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 |
developer | 04f0ec8 | 2021-12-30 13:59:10 +0800 | [diff] [blame] | 41 | |
| 42 | for i in $(seq 0 $((txq_num - 1))) |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 43 | do |
developer | 04f0ec8 | 2021-12-30 13:59:10 +0800 | [diff] [blame] | 44 | 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 |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 49 | done |
| 50 | |
| 51 | exit 0 |
| 52 | } |
| 53 | |
| 54 | # enable qdma_sch0 and qdma_sch1 |
| 55 | echo 1 ${scheduling} ${sch0_bw} > /sys/kernel/debug/hnat/qdma_sch0 |
| 56 | echo 1 ${scheduling} ${sch1_bw} > /sys/kernel/debug/hnat/qdma_sch1 |
| 57 | |
developer | 04f0ec8 | 2021-12-30 13:59:10 +0800 | [diff] [blame] | 58 | # enable bridge netfilter module to allow skb being marked |
| 59 | echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables |
| 60 | echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables |
| 61 | |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 62 | setup_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 | |
| 112 | config_foreach setup_queue queue |