openwrt-ipq-breeze303/package/kernel/mac80211/files/qca-nss-pbuf.init

150 lines
4.9 KiB
Bash
Executable File

#!/bin/sh /etc/rc.common
#
# Copyright (c) 2021 The Linux Foundation. All rights reserved.
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
START=71
apply_sysctl() {
[ "$(sysctl -n -e dev.nss.general.redirect)" -eq 0 ] && /etc/init.d/qca-nss-ecm start
# Running this script multiple times is useless, as extra_pbuf_core0
# can't be changed if it is allocated, assume it's already been run.
if [ "$(sysctl -n -e dev.nss.n2hcfg.extra_pbuf_core0)" -eq 0 ]; then
logger -t ath11k_nss "$board - setting dev.nss.n2hcfg.extra_pbuf_core0=$extra_pbuf_core0"
sysctl -w dev.nss.n2hcfg.extra_pbuf_core0="$extra_pbuf_core0" > /dev/null 2> /dev/null
else
logger -t ath11k_nss "Sysctl key 'extra_pbuf_core0' already set to '""$extra_pbuf_core0""'. Skipping applying wifi nss configs"
fi
sysctl -w dev.nss.n2hcfg.n2h_high_water_core0="$n2h_high_water_core0" > /dev/null 2>/dev/null
logger -t ath11k_nss "$board - setting dev.nss.n2hcfg.n2h_wifi_pool_buf=$n2h_wifi_pool_buf"
sysctl -w dev.nss.n2hcfg.n2h_wifi_pool_buf="$n2h_wifi_pool_buf"
logger -t ath11k_nss "$board - setting dev.nss.n2hcfg.n2h_high_water_core0=$n2h_high_water_core0"
sysctl -w dev.nss.n2hcfg.n2h_high_water_core0="$n2h_high_water_core0"
}
apply_nss_config() {
if [ ! -r /sys/module/ath11k/parameters/nss_offload ]; then
logger -t ath11k_nss "Module parameter '/sys/module/ath11k/parameters/nss_offload' does NOT exist. Skipping applying wifi nss configs"
exit 1
fi
enable_nss_offload=$(cat /sys/module/ath11k/parameters/nss_offload)
if [ "$enable_nss_offload" -ne "1" ]; then
logger -t ath11k_nss -s user.warn "Module parameter 'nss_offload=0'. Skipping applying wifi nss configs"
exit 1
fi
[ ! -d "/proc/sys/dev/nss/rps" ] && {
logger -s -t ath11k_nss -p user.error "NSS driver not loaded or disabled! Exiting... "
exit 1
}
# Lock NSS clock to highest setting
sysctl -w dev.nss.clock.auto_scale=0 > /dev/null 2> /dev/null
sysctl -w dev.nss.n2hcfg.n2h_queue_limit_core0=2048 > /dev/null 2> /dev/null
sysctl -w dev.nss.n2hcfg.n2h_queue_limit_core1=2048 > /dev/null 2> /dev/null
sysctl -w dev.nss.rps.hash_bitmap=15 > /dev/null 2> /dev/null
local memory_profile
if memory_profile=$(uci_get pbuf.opt.memory_profile); then
case "$memory_profile" in
1g*|512m*|256m*)
board=$memory_profile
logger -t ath11k_nss "Using custom memory profile - $board"
;;
off*|false*|disable*|0)
logger -s -t ath11k_nss -p user.warn "NSS pbuf option 'memory_profile=off'. Not running. Enable if you have issues connecting more than 65 clients"
exit 0
;;
auto)
board=$(board_name)
logger -t ath11k_nss "Setting n2hcfg values for board: $board"
;;
*)
logger -s -t ath11k_nss -p user.error "Unknown profile $memory_profile. Choose auto, 1gb, 512mb, or 256mb"
exit 1
;;
esac
else
exit 0
fi
case "$board" in
# 1GB+ profile
arcadyan,aw1000 | \
buffalo,wxr-5950ax12 | \
dynalink,dl-wrx36 | \
edgecore,eap102 | \
linksys,mx4200v2 | \
linksys,mx5300 | \
netgear,rax120v2 | \
netgear,wax620 | \
netgear,wax630 | \
prpl,haze | \
qnap,301w | \
xiaomi,ax9000 | \
yuncore,ax880 | \
zyxel,nbg7815 | \
1g*)
extra_pbuf_core0=9000000 n2h_high_water_core0=67392 n2h_wifi_pool_buf=40960 apply_sysctl
;;
# 512MB profile
edimax,cax1800 | \
compex,wpq873 | \
linksys,mx4200v1 | \
redmi,ax6 | \
xiaomi,ax3600 | \
zte,mf269 | \
512m*)
extra_pbuf_core0=3100000 n2h_high_water_core0=30624 n2h_wifi_pool_buf=8192 apply_sysctl
;;
# 256MB profile
netgear,wax218 | \
256m*)
extra_pbuf_core0=3100000 n2h_high_water_core0=30258 n2h_wifi_pool_buf=4096 apply_sysctl
;;
esac
}
boost_performance() {
find /sys/kernel/debug/ath11k -name stats_disable| while read -r stats_disable; do
echo 1 > "$stats_disable"
done
ubus call iwinfo devices | jsonfilter -e "@.devices[*]"| while read -r device; do
tc qdisc replace dev "${device}" root noqueue
done
for num in 0 1 2 3; do
echo "performance" > /sys/devices/system/cpu/cpu${num}/cpufreq/scaling_governor
done
}
start() {
boost_performance
apply_nss_config
}