From 52f554b84d3451224c19441b4a525f2eecbbd1cd Mon Sep 17 00:00:00 2001 From: Mohd Husaam Mehdi Date: Mon, 9 Dec 2024 16:51:11 +0530 Subject: [PATCH] qosmgr: add support for wan ingress and egress rate control --- qosmngr/files/airoha/lib/qos/airoha.sh | 72 +++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 7 deletions(-) diff --git a/qosmngr/files/airoha/lib/qos/airoha.sh b/qosmngr/files/airoha/lib/qos/airoha.sh index 4c1ba2c00..6f7e626a3 100755 --- a/qosmngr/files/airoha/lib/qos/airoha.sh +++ b/qosmngr/files/airoha/lib/qos/airoha.sh @@ -6,6 +6,19 @@ readonly ETHWAN="$(jsonfilter -i /etc/board.json -e @.network.wan.device)" readonly LANPORTS="$(jsonfilter -i /etc/board.json -e @.network.lan.ports[*] -e @.network.lan.device | xargs)" readonly OFFSET=32 +get_wan_type_idx() { + case "$(cat "/proc/tc3162/${ETHWAN}_switch_hsgmii_lan")" in + pon) echo "3" ;; + usb) echo "2" ;; + pcie0) echo "0" ;; + pcie1) echo "1" ;; + eth) echo "4" ;; + *) echo "-1" ;; + esac +} + +readonly WAN_TYPE_IDX="$(get_wan_type_idx)" + errmsg() { echo "$@" >&2 return 0 @@ -53,6 +66,43 @@ hw_intf_init() { return 0 } +set_wan_ingress_rate() { + local ingress_rate="$1" + local pkt_type + local wanchannel="$(cat /proc/tc3162/eth_portmap | head -n1)" + wanchannel=$((wanchannel)) + + rm -rf "/tmp/qos/wan_ingress_shape_speed" + if [ "$wanchannel" = "-1" ]; then + [ "$WAN_TYPE_IDX" = "-1" -o -z "$ingress_rate" ] && return + + echo "$ingress_rate" > "/tmp/qos/wan_ingress_shape_speed" + + for pkt_type in $(seq 0 3); do + echo "$WAN_TYPE_IDX $pkt_type $ingress_rate 0" > "/proc/tc3162/${ETHWAN}_ratelimit" + done + fi +} + +set_wan_egress_rate() { + local rate="$1" + local burstsize="$2" + local wanchannel="$(cat /proc/tc3162/eth_portmap | head -n1)" + wanchannel=$((wanchannel)) + [ "$wanchannel" = "-1" ] && wanchannel=0 + + if [ "$rate" -gt 0 ]; then + /userfs/bin/qdmamgr_wan set general_tx_trtcm config "$wanchannel" enable byte slow enable byte fast + /userfs/bin/qdmamgr_wan set general_tx_trtcm value "$wanchannel" "$rate" "$rate" + + if [ "$burstsize" -gt 1000 ]; then + /userfs/bin/qdmamgr_wan set general_tx_trtcm bsize "$wanchannel" "$burstsize" "$burstsize" + fi + else + /userfs/bin/qdmamgr_wan set general_tx_trtcm config "$wanchannel" disable byte slow disable byte fast + fi +} + # Initialize the hardware setup library hw_init_all() { local tc=0 @@ -70,6 +120,7 @@ hw_init_all() { /userfs/bin/qdmamgr_lan set general_rx_init enable trtcm 8 125 /userfs/bin/qdmamgr_wan set general_rx_init enable trtcm 8 125 + /userfs/bin/qdmamgr_wan set general_tx_init enable trtcm 40 25 for channel in $(seq 0 30); do tsid=$((OFFSET+channel)) @@ -77,6 +128,9 @@ hw_init_all() { /userfs/bin/qdmamgr_wan set general_rx_trtcm config "$tsid" disable byte slow disable byte fast done + # set_wan_ingress_rate "0" - Not needed + set_wan_egress_rate "0" "0" + return 0 } @@ -209,7 +263,7 @@ hw_policer_set_ingress_rate() { local in_burst_size="$3" if [ "$ifname" = "$ETHWAN" ]; then - errmsg "cannot set policer for wan interface ${ifname}" + set_wan_ingress_rate "$ingress_rate" else set_lan_rate "$ifname" "$ingress_rate" "$in_burst_size" "0" fi @@ -226,7 +280,7 @@ hw_shaper_set() { add) if [ "$ifname" = "$ETHWAN" ]; then export TMP_HW_SHAPE_RATE="$rate" - export TMP_HW_SHAPE_BURSTSIZE="$burstsize" + set_wan_egress_rate "$rate" "$burstsize" else set_lan_rate "$ifname" "$rate" "$burstsize" "1" fi @@ -234,7 +288,7 @@ hw_shaper_set() { del) if [ "$ifname" = "$ETHWAN" ]; then export TMP_HW_SHAPE_RATE="" - export TMP_HW_SHAPE_BURSTSIZE="" + set_wan_egress_rate "0" "0" else set_lan_rate "$ifname" "0" "0" "1" fi @@ -309,20 +363,24 @@ hw_commit_all() { weight_list="$weight_list 1" q_count=$((q_count + 1)) done + + echo ${mac_qos_flag} > /proc/qdma_wan/mac_qos_flag + echo "1 ${weight_list}" > /proc/qdma_wan/mac_qos ;; SP) mac_qos_flag="8QPQ" q_count="8" + + echo ${mac_qos_flag} > /proc/qdma_wan/mac_qos_flag + echo "0 0 0 0 0 0 0 0 0" > /proc/qdma_wan/mac_qos ;; esac + echo 255 > /proc/qdma_wan/mac_default_queuemask + rm -f "/tmp/qos/wan_link_shape_rate" rm -f "/tmp/qos/wan_link_speed" if [ "${glob_alg}" != "" ] ; then - /userfs/bin/qosrule discpline $(hw_sc_alg2str ${glob_alg}) ${weight_list} \ - uplink-bandwidth ${shape_rate:-10000000} \ - queuemask "$(((1 << q_count) - 1))" - echo ${mac_qos_flag} > /proc/qdma_wan/mac_qos_flag if [ -n "${shape_rate}" ]; then echo "${shape_rate}" > "/tmp/qos/wan_link_shape_rate" else