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 | |
| 13 | #if enable=0, disable qdma_sch & qdma_txq |
| 14 | [ "${enable}" -eq 1 ] || { |
| 15 | echo 0 ${scheduling} ${sch0_bw} > /sys/kernel/debug/hnat/qdma_sch0 |
| 16 | echo 0 ${scheduling} ${sch1_bw} > /sys/kernel/debug/hnat/qdma_sch1 |
| 17 | echo 1 0 0 0 0 0 4 > /sys/kernel/debug/hnat/qdma_txq0 |
| 18 | for i in $(seq 1 $((txq_num - 1))) |
| 19 | do |
| 20 | echo 0 0 0 0 0 0 0 > /sys/kernel/debug/hnat/qdma_txq$i |
| 21 | done |
| 22 | |
| 23 | rmmod mtkhnat |
| 24 | exit 0 |
| 25 | } |
| 26 | |
| 27 | insmod mtkhnat |
| 28 | |
| 29 | #if hqos=0, disable qdma_sch & qdma_txq |
| 30 | [ "${hqos}" -eq 1 ] || { |
| 31 | echo 0 ${scheduling} ${sch0_bw} > /sys/kernel/debug/hnat/qdma_sch0 |
| 32 | echo 0 ${scheduling} ${sch1_bw} > /sys/kernel/debug/hnat/qdma_sch1 |
| 33 | echo 1 0 0 0 0 0 4 > /sys/kernel/debug/hnat/qdma_txq0 |
| 34 | for i in $(seq 1 $((txq_num - 1))) |
| 35 | do |
| 36 | echo 0 0 0 0 0 0 0 > /sys/kernel/debug/hnat/qdma_txq$i |
| 37 | done |
| 38 | |
| 39 | exit 0 |
| 40 | } |
| 41 | |
| 42 | # enable qdma_sch0 and qdma_sch1 |
| 43 | echo 1 ${scheduling} ${sch0_bw} > /sys/kernel/debug/hnat/qdma_sch0 |
| 44 | echo 1 ${scheduling} ${sch1_bw} > /sys/kernel/debug/hnat/qdma_sch1 |
| 45 | |
| 46 | setup_queue() { |
| 47 | local queue_id queue_scheduler queue_minebl queue_maxebl |
| 48 | local queue_minrate queue_maxrate queue_resv minrate maxrate queue_weight |
| 49 | |
| 50 | config_get queue_id $1 id 0 |
| 51 | config_get queue_minrate $1 minrate 0 |
| 52 | config_get queue_maxrate $1 maxrate 0 |
| 53 | config_get queue_resv $1 resv 4 |
| 54 | config_get queue_weight $1 weight 4 |
| 55 | |
| 56 | # check qid < txq max num or not for loop condition |
| 57 | [ "${queue_id}" -gt $((txq_num - 1)) ] && return 0 |
| 58 | |
| 59 | # start to set per queue config |
| 60 | queue_minebl=1 |
| 61 | queue_maxebl=1 |
| 62 | queue_scheduler=0 |
| 63 | |
| 64 | # if min rate = 0, set min enable = 0 |
| 65 | # if max rate = 0, set max enable = 0 |
| 66 | [ "${queue_minrate}" -eq 0 ] && queue_minebl=0 |
| 67 | [ "${queue_maxrate}" -eq 0 ] && queue_maxebl=0 |
| 68 | |
| 69 | # calculate min rate according to sch0_bw |
| 70 | minrate=$((sch0_bw * $queue_minrate)) |
| 71 | minrate=$((minrate / 100)) |
| 72 | |
| 73 | # calculate max rate according to sch0_bw |
| 74 | maxrate=$((sch0_bw * $queue_maxrate)) |
| 75 | maxrate=$((maxrate / 100)) |
| 76 | |
| 77 | # set the queue of sch0 group(the lower half of total queues) |
| 78 | [ "${queue_id}" -le $(((txq_num / 2) - 1)) ] && \ |
| 79 | echo 0 ${queue_minebl} ${minrate} ${queue_maxebl} ${maxrate} ${queue_weight} \ |
| 80 | ${queue_resv} > /sys/kernel/debug/hnat/qdma_txq${queue_id} |
| 81 | |
| 82 | # calculate min rate according to sch1_bw |
| 83 | minrate=$((sch1_bw * $queue_minrate)) |
| 84 | minrate=$((minrate / 100)) |
| 85 | |
| 86 | # calculate max rate according to sch1_bw |
| 87 | maxrate=$((sch1_bw * $queue_maxrate)) |
| 88 | maxrate=$((maxrate / 100)) |
| 89 | |
| 90 | # set the queue of sch1 group(the upper half of total queues) |
| 91 | [ "${queue_id}" -gt $(((txq_num / 2) - 1)) ] && \ |
| 92 | echo 1 ${queue_minebl} ${minrate} ${queue_maxebl} ${maxrate} ${queue_weight} \ |
| 93 | ${queue_resv} > /sys/kernel/debug/hnat/qdma_txq${queue_id} |
| 94 | } |
| 95 | |
| 96 | config_foreach setup_queue queue |