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 | f1fcda9 | 2022-09-22 09:45:43 +0800 | [diff] [blame] | 21 | #if hnat is not exist, switch module to mtk_ppe |
| 22 | module=hnat |
| 23 | [ -d /sys/kernel/debug/${module} ] || { |
| 24 | module=mtk_ppe |
developer | 45d0278 | 2022-10-14 10:33:40 +0800 | [diff] [blame] | 25 | echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables |
| 26 | echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables |
developer | f1fcda9 | 2022-09-22 09:45:43 +0800 | [diff] [blame] | 27 | } |
| 28 | |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 29 | #if enable=0, disable qdma_sch & qdma_txq |
| 30 | [ "${enable}" -eq 1 ] || { |
developer | f1fcda9 | 2022-09-22 09:45:43 +0800 | [diff] [blame] | 31 | 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 |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 34 | for i in $(seq 1 $((txq_num - 1))) |
| 35 | do |
developer | f1fcda9 | 2022-09-22 09:45:43 +0800 | [diff] [blame] | 36 | echo 0 0 0 0 0 0 0 > /sys/kernel/debug/${module}/qdma_txq$i |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 37 | done |
| 38 | |
| 39 | rmmod mtkhnat |
| 40 | exit 0 |
| 41 | } |
| 42 | |
| 43 | insmod mtkhnat |
| 44 | |
| 45 | #if hqos=0, disable qdma_sch & qdma_txq |
| 46 | [ "${hqos}" -eq 1 ] || { |
developer | 492e2a5 | 2023-01-09 14:53:44 +0800 | [diff] [blame] | 47 | 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 | |
developer | f1fcda9 | 2022-09-22 09:45:43 +0800 | [diff] [blame] | 50 | echo 0 ${scheduling} ${sch0_bw} > /sys/kernel/debug/${module}/qdma_sch0 |
| 51 | echo 0 ${scheduling} ${sch1_bw} > /sys/kernel/debug/${module}/qdma_sch1 |
developer | 04f0ec8 | 2021-12-30 13:59:10 +0800 | [diff] [blame] | 52 | |
| 53 | for i in $(seq 0 $((txq_num - 1))) |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 54 | do |
developer | 492e2a5 | 2023-01-09 14:53:44 +0800 | [diff] [blame] | 55 | if [ "${i}" -le $(((txq_num / 2) - 1)) ] || [ ! $IS_NETSYS_V2 ]; then |
developer | f1fcda9 | 2022-09-22 09:45:43 +0800 | [diff] [blame] | 56 | echo 0 0 0 0 0 0 4 > /sys/kernel/debug/${module}/qdma_txq$i |
developer | 04f0ec8 | 2021-12-30 13:59:10 +0800 | [diff] [blame] | 57 | else |
developer | f1fcda9 | 2022-09-22 09:45:43 +0800 | [diff] [blame] | 58 | echo 1 0 0 0 0 0 4 > /sys/kernel/debug/${module}/qdma_txq$i |
developer | 04f0ec8 | 2021-12-30 13:59:10 +0800 | [diff] [blame] | 59 | fi |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 60 | done |
| 61 | |
| 62 | exit 0 |
| 63 | } |
| 64 | |
| 65 | # enable qdma_sch0 and qdma_sch1 |
developer | f1fcda9 | 2022-09-22 09:45:43 +0800 | [diff] [blame] | 66 | echo 1 ${scheduling} ${sch0_bw} > /sys/kernel/debug/${module}/qdma_sch0 |
| 67 | echo 1 ${scheduling} ${sch1_bw} > /sys/kernel/debug/${module}/qdma_sch1 |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 68 | |
developer | 04f0ec8 | 2021-12-30 13:59:10 +0800 | [diff] [blame] | 69 | # enable bridge netfilter module to allow skb being marked |
| 70 | echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables |
| 71 | echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables |
| 72 | |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 73 | setup_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} \ |
developer | f1fcda9 | 2022-09-22 09:45:43 +0800 | [diff] [blame] | 107 | ${queue_resv} > /sys/kernel/debug/${module}/qdma_txq${queue_id} |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 108 | |
| 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} \ |
developer | f1fcda9 | 2022-09-22 09:45:43 +0800 | [diff] [blame] | 120 | ${queue_resv} > /sys/kernel/debug/${module}/qdma_txq${queue_id} |
developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | config_foreach setup_queue queue |