blob: 709e22828e677fd7fffc73a49d17424712409579 [file] [log] [blame]
developer10cbf2c2022-02-09 10:39:21 +08001#!/bin/sh
2
3OPTIMIZED_FOR="$1"
4CPU_LIST=`cat /proc/interrupts | sed -n '1p'`
5NUM_OF_CPU=0; for i in $CPU_LIST; do NUM_OF_CPU=`expr $NUM_OF_CPU + 1`; done;
6DEFAULT_RPS=0
7
8. /lib/functions.sh
9
10RPS_IF_LIST=""
11NUM_WIFI_CARD=0
12WIFI_RADIO1=0
13WIFI_RADIO2=0
14WIFI_RADIO3=0
developer10d32132022-07-05 15:12:10 +080015WED_ENABLE=0
developer10cbf2c2022-02-09 10:39:21 +080016
developer431102f2023-05-12 10:52:51 +080017WIFI_MODULE_LIST='mt7915e mt7996e'
18
developer10cbf2c2022-02-09 10:39:21 +080019get_if_info()
20{
21 # try to get all wifi and eth net interface.
22 dbg2 "try to get all wifi and eth net interface."
23 NET_IF_LIST=`ls /sys/class/net`
24 for vif in $NET_IF_LIST;
25 do
developerd88f9b62023-02-02 09:51:21 +080026 if [[ "$vif" == "eth"* ]] || \
27 [[ "$vif" == "lan"* ]] || [[ "$vif" == "wan"* ]] || \
28 [[ "$vif" == "wlan"* ]] || [[ "$vif" == "phy"* ]]; then
developer10cbf2c2022-02-09 10:39:21 +080029 RPS_IF_LIST="$RPS_IF_LIST $vif"
30 fi
31 done;
32 dbg2 "RPS_IF_LIST = $RPS_IF_LIST"
33
34 # try to get wifi physical card num.
35 dbg2 "try to get wifi physical card num."
36 VIRTUAL_RADIO_LIST=`ls -l /sys/class/ieee80211/ | awk -F 'devices' '{print $2}' | awk -F 'phy' '{print $1}' | uniq`
37 for v in $VIRTUAL_RADIO_LIST;
38 do
39 NUM_WIFI_CARD=`expr $NUM_WIFI_CARD + 1`
40 dbg2 "physical raido $v"
41 if [[ $v == *"wmac"* ]]; then
42 WIFI_RADIO1=1
43 fi
developer69b0f422023-01-06 15:37:54 +080044
developer10cbf2c2022-02-09 10:39:21 +080045 if [[ $v == *"wbsys"* ]]; then
developer69b0f422023-01-06 15:37:54 +080046 WIFI_RADIO1=1
47 fi
developer10cbf2c2022-02-09 10:39:21 +080048
49 if [[ $v == *"pci0000"* ]]; then
50 WIFI_RADIO2=1
51 fi
52
53 if [[ $v == *"pci0001"* ]]; then
54 WIFI_RADIO3=1
55 fi
56 done;
57
developer431102f2023-05-12 10:52:51 +080058
59 for v in $WIFI_MODULE_LIST;
developer10d32132022-07-05 15:12:10 +080060 do
developer431102f2023-05-12 10:52:51 +080061 if [[ -f "/sys/module/$v/parameters/wed_enable" ]]; then
62 WED_ENABLE_LIST=`cat /sys/module/$v/parameters/wed_enable`
63 dbg2 "wed enable ori info $v $WED_ENABLE_LIST"
64 if [[ $WED_ENABLE_LIST == "Y" ]]; then
65 WED_ENABLE=1
66 fi
developer10d32132022-07-05 15:12:10 +080067 fi
68 done;
developer10cbf2c2022-02-09 10:39:21 +080069 dbg2 "NUM_WIFI_CARD = $NUM_WIFI_CARD"
70 dbg2 "platform wifi enable = $WIFI_RADIO1"
71 dbg2 "pcie1 wifi enable = $WIFI_RADIO2"
72 dbg2 "pcie2 wifi enable = $WIFI_RADIO3"
developer10d32132022-07-05 15:12:10 +080073 dbg2 "WED enable = $WED_ENABLE"
developer10cbf2c2022-02-09 10:39:21 +080074}
75
76# $1: CPU#
77# $2: irq list for added.
78CPU_AFFINITY_ADD()
79{
80 eval oval=\$CPU${1}_AFFINITY
81 eval CPU${1}_AFFINITY=\"\$CPU${1}_AFFINITY $2\"
82}
83
84# $1: CPU#
85# $2: Interface name for added.
86CPU_RPS_ADD()
87{
88 eval oval=\$CPU${1}_RPS
89 eval CPU${1}_RPS=\"\$CPU${1}_RPS $2\"
90 dbg2 "CPU${1}_RPS=\"\$CPU${1}_RPS $2\""
91}
92
developer69b0f422023-01-06 15:37:54 +080093MT7988()
94{
95 num_of_wifi=$1
96 DEFAULT_RPS=0
97
98 #Physical IRQ# setting
developer260bb6d2023-05-24 13:59:37 +080099 #Ethernet RSS feature enables 4 Rx rings
100 eth_irq_rx0=221
101 eth_irq_rx1=222
102 eth_irq_rx2=223
103 eth_irq_rx3=224
104 eth_irq_tx=229
developer69b0f422023-01-06 15:37:54 +0800105 wifi1_irq_pcie0=524288
106 wifi1_irq_pcie1=134742016
107 wifi2_irq_pcie0=
108 wifi2_irq_pcie1=
109
110 if [[ "$WED_ENABLE" -eq "1" ]]; then
111 dbg2 "WED_ENABLE ON irq/iptable setting"
112 #TCP Binding
113 iptables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
114 iptables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
115 ip6tables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
116 ip6tables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
117 #UDP Binding
118 iptables -D FORWARD -p udp -j FLOWOFFLOAD --hw
119 iptables -I FORWARD -p udp -j FLOWOFFLOAD --hw
120 ip6tables -D FORWARD -p udp -j FLOWOFFLOAD --hw
121 ip6tables -I FORWARD -p udp -j FLOWOFFLOAD --hw
122
123 else
124 dbg2 "WED_ENABLE OFF irq/iptable seting"
125 fi
126
127 for vif in $NET_IF_LIST;
128 do
developerd88f9b62023-02-02 09:51:21 +0800129 if [[ "$vif" == "wlan"* ]] || [[ "$vif" == "phy"* ]]; then
developer69b0f422023-01-06 15:37:54 +0800130 WIFI_IF_LIST="$WIFI_IF_LIST $vif"
131 fi
132 done;
133 dbg2 "$WIFI_IF_LIST = $WIFI_IF_LIST"
134 # Please update the CPU binding in each cases.
135 # CPU#_AFFINITY="add binding irq number here"
136 # CPU#_RPS="add binding interface name here"
137 if [ "$num_of_wifi" = "0" ]; then
developer260bb6d2023-05-24 13:59:37 +0800138 CPU0_AFFINITY="$eth_irq_rx0 $eth_irq_tx"
139 CPU1_AFFINITY="$eth_irq_rx1"
140 CPU2_AFFINITY="$eth_irq_rx2"
141 CPU3_AFFINITY="$eth_irq_rx3"
developer69b0f422023-01-06 15:37:54 +0800142
143 CPU0_RPS="$RPS_IF_LIST"
144 CPU1_RPS="$RPS_IF_LIST"
145 CPU2_RPS="$RPS_IF_LIST"
146 CPU3_RPS="$RPS_IF_LIST"
147 else
148 #we bound all wifi card to cpu0 and bound eth to cpu
149 CPU0_AFFINITY=""
150 CPU1_AFFINITY=""
developer260bb6d2023-05-24 13:59:37 +0800151 CPU2_AFFINITY="$eth_irq_rx0 $eth_irq_rx1 $eth_irq_tx"
152 CPU3_AFFINITY="$eth_irq_rx2 $eth_irq_rx3"
developer69b0f422023-01-06 15:37:54 +0800153
154 CPU0_RPS="$WIFI_IF_LIST"
155 CPU1_RPS="$WIFI_IF_LIST"
developer6d638dd2023-02-21 13:46:21 +0800156 CPU2_RPS=""
developer69b0f422023-01-06 15:37:54 +0800157 CPU3_RPS=""
158 fi
159 dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY"
160 dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY"
161 dbg2 "CPU2_AFFINITY = $CPU2_AFFINITY"
162 dbg2 "CPU3_AFFINITY = $CPU3_AFFINITY"
163}
164
developer10cbf2c2022-02-09 10:39:21 +0800165MT7986()
166{
167 num_of_wifi=$1
168 DEFAULT_RPS=0
169
170 #Physical IRQ# setting
developer260bb6d2023-05-24 13:59:37 +0800171 eth_irq_rx=221
172 eth_irq_tx=229
developer10cbf2c2022-02-09 10:39:21 +0800173 wifi1_irq=
174 wifi2_irq=
175 wifi3_irq=
developer10d32132022-07-05 15:12:10 +0800176
177 if [[ "$WED_ENABLE" -eq "1" ]]; then
178 dbg2 "WED_ENABLE ON irq/iptable setting"
179 #TCP Binding
developer6adfa0e2022-07-06 16:25:53 +0800180 iptables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
181 iptables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
182 ip6tables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
183 ip6tables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
developer10d32132022-07-05 15:12:10 +0800184 #UDP Binding
developer6adfa0e2022-07-06 16:25:53 +0800185 iptables -D FORWARD -p udp -j FLOWOFFLOAD --hw
186 iptables -I FORWARD -p udp -j FLOWOFFLOAD --hw
187 ip6tables -D FORWARD -p udp -j FLOWOFFLOAD --hw
188 ip6tables -I FORWARD -p udp -j FLOWOFFLOAD --hw
developer10d32132022-07-05 15:12:10 +0800189
190 #AX6000 AX7800 - SOC
191 if [[ "$WIFI_RADIO1" -eq "1" ]]; then
192 wifi1_irq=238
193 fi
194 #AX7800 - PCIE0
195 if [[ "$WIFI_RADIO2" -eq "1" ]]; then
196 wifi2_irq=237
197 fi
198 #AX7800 - PCIE1
199 #if [[ "$WIFI_RADIO3" -eq "1" ]]; then
200 # wifi3_irq=239
201 #fi
202 else
203 dbg2 "WED_ENABLE OFF irq/iptable seting"
204 #AX6000 AX7800 - SOC
205 if [[ "$WIFI_RADIO1" -eq "1" ]]; then
206 wifi1_irq=245
207 fi
208 #AX7800 - PCIE0
209 if [[ "$WIFI_RADIO2" -eq "1" ]]; then
210 wifi2_irq=246
211 fi
212 #AX7800 - PCIE1
213 #if [[ "$WIFI_RADIO3" -eq "1" ]]; then
214 # wifi3_irq=247
215 #fi
developer10cbf2c2022-02-09 10:39:21 +0800216 fi
developera126cb42023-09-06 09:01:59 +0800217
218 for vif in $NET_IF_LIST;
219 do
220 if [[ "$vif" == "lan"* ]] || \
221 [[ "$vif" == "wlan"* ]] || [[ "$vif" == "phy"* ]]; then
222 LAN_IF_LIST="$LAN_IF_LIST $vif"
223 fi
224 done;
225 dbg2 "$LAN_IF_LIST = $LAN_IF_LIST"
developer10cbf2c2022-02-09 10:39:21 +0800226 # Please update the CPU binding in each cases.
227 # CPU#_AFFINITY="add binding irq number here"
228 # CPU#_RPS="add binding interface name here"
229 if [ "$num_of_wifi" = "0" ]; then
developer260bb6d2023-05-24 13:59:37 +0800230 CPU0_AFFINITY="$eth_irq_rx"
231 CPU1_AFFINITY="$eth_irq_tx"
developer10cbf2c2022-02-09 10:39:21 +0800232 CPU2_AFFINITY=""
233 CPU3_AFFINITY=""
234
235 CPU0_RPS="$RPS_IF_LIST"
236 CPU1_RPS="$RPS_IF_LIST"
237 CPU2_RPS="$RPS_IF_LIST"
238 CPU3_RPS="$RPS_IF_LIST"
239 else
240 #we bound all wifi card to cpu1 and bound eth to cpu0
developer260bb6d2023-05-24 13:59:37 +0800241 CPU0_AFFINITY="$eth_irq_rx"
242 CPU1_AFFINITY="$eth_irq_tx"
developer10cbf2c2022-02-09 10:39:21 +0800243 CPU2_AFFINITY="$wifi2_irq $wifi3_irq"
244 CPU3_AFFINITY="$wifi1_irq"
245
developera126cb42023-09-06 09:01:59 +0800246 CPU0_RPS="$LAN_IF_LIST"
247 CPU1_RPS="$LAN_IF_LIST"
developer10cbf2c2022-02-09 10:39:21 +0800248 CPU2_RPS="$RPS_IF_LIST"
249 CPU3_RPS="$RPS_IF_LIST"
250 fi
251 dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY"
252 dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY"
253 dbg2 "CPU2_AFFINITY = $CPU2_AFFINITY"
254 dbg2 "CPU3_AFFINITY = $CPU3_AFFINITY"
255}
256
257MT7981()
258{
259 num_of_wifi=$1
260 DEFAULT_RPS=0
261
262 #Physical IRQ# setting
developer260bb6d2023-05-24 13:59:37 +0800263 eth_irq_rx=221
264 eth_irq_tx=229
developer10cbf2c2022-02-09 10:39:21 +0800265 wifi1_irq=
266 wifi2_irq=
267 wifi3_irq=
268 #AX3000
269 if [[ "$WIFI_RADIO1" -eq "1" ]]; then
270 wifi1_irq=245
271 fi
272 # Please update the CPU binding in each cases.
273 # CPU#_AFFINITY="add binding irq number here"
274 # CPU#_RPS="add binding interface name here"
275 if [ "$num_of_wifi" = "0" ]; then
developer260bb6d2023-05-24 13:59:37 +0800276 CPU0_AFFINITY="$eth_irq_rx"
277 CPU1_AFFINITY="$eth_irq_tx"
developer10cbf2c2022-02-09 10:39:21 +0800278
279 CPU0_RPS="$RPS_IF_LIST"
280 CPU1_RPS="$RPS_IF_LIST"
281 else
282 #we bound all wifi card to cpu0 and bound eth to cpu1
283 CPU0_AFFINITY="$wifi1_irq $wifi2_irq $wifi3_irq"
developer260bb6d2023-05-24 13:59:37 +0800284 CPU1_AFFINITY="$eth_irq_rx $eth_irq_tx"
developer10cbf2c2022-02-09 10:39:21 +0800285
286 CPU0_RPS="$RPS_IF_LIST"
287 CPU1_RPS="$RPS_IF_LIST"
288 fi
289 dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY"
290 dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY"
291}
292
293MT7622()
294{
295 num_of_wifi=$1
296 DEFAULT_RPS=0
297
298 #Physical IRQ# setting
299 eth0_irq=224
300 eth1_irq=225
301 wifi1_irq=
302 wifi2_irq=
303 wifi3_irq=
304 #AX1200 AX3200
305 if [[ "$WIFI_RADIO1" -eq "1" ]]; then
306 wifi1_irq=211
307 fi
308 #AX1800 AX3200
309 if [[ "$WIFI_RADIO2" -eq "1" ]]; then
310 wifi2_irq=214
311 fi
312 #AX3600
313 if [[ "$WIFI_RADIO3" -eq "1" ]]; then
314 wifi3_irq=215
315 fi
316
317 # Please update the CPU binding in each cases.
318 # CPU#_AFFINITY="add binding irq number here"
319 # CPU#_RPS="add binding interface name here"
320 if [ "$num_of_wifi" == "0" ]; then
321 CPU0_AFFINITY="$eth0_irq"
322 CPU1_AFFINITY="$eth1_irq"
323
324 CPU0_RPS="$RPS_IF_LIST"
325 CPU1_RPS="$RPS_IF_LIST"
326 else
327 #we bound all wifi card to cpu0 and bound eth to cpu1
328 CPU0_AFFINITY="$wifi1_irq $wifi2_irq $wifi3_irq"
329 CPU1_AFFINITY="$eth0_irq $eth1_irq"
330
331 CPU0_RPS="$RPS_IF_LIST"
332 CPU1_RPS="$RPS_IF_LIST"
333 fi
334
335 dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY"
336 dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY"
337}
338
339setup_model()
340{
341 board=$(board_name)
342 num_of_wifi=$NUM_WIFI_CARD
343
developerd88f9b62023-02-02 09:51:21 +0800344 if [[ $board == *"7988"* ]]; then
developer69b0f422023-01-06 15:37:54 +0800345 dbg "setup_model: MT7988 NUM_WIFI_CARD=$num_of_wifi"
346 MT7988 $num_of_wifi
developerd88f9b62023-02-02 09:51:21 +0800347 elif [[ $board == *"7986"* ]]; then
developer10cbf2c2022-02-09 10:39:21 +0800348 dbg "setup_model: MT7986 NUM_WIFI_CARD=$num_of_wifi"
349 MT7986 $num_of_wifi
developerd88f9b62023-02-02 09:51:21 +0800350 elif [[ $board == *"7981"* ]]; then
developer10cbf2c2022-02-09 10:39:21 +0800351 dbg "setup_model: MT7981 NUM_WIFI_CARD=$num_of_wifi"
352 MT7981 $num_of_wifi
developerd88f9b62023-02-02 09:51:21 +0800353 elif [[ $board == *"7622"* ]]; then
developer10cbf2c2022-02-09 10:39:21 +0800354 dbg "setup_model: MT7622 NUM_WIFI_CARD=$num_of_wifi"
355 MT7622 $num_of_wifi
356 fi
357}
358
359get_virtual_irq()
360{
361 PHY_POS=`expr $NUM_OF_CPU + 3` #physical irq # position in /proc/interrups may vary with the number of CPU up
362 target_phy_irq=$1
363 cat /proc/interrupts | sed 's/:/ /g'| awk '$1 ~ /^[0-9]+$/' | while read line
364 do
365 set -- $line
366 phy_irq=$(eval "echo \$$PHY_POS")
367 if [ $phy_irq == $target_phy_irq ]; then
368 echo $1
369 return
370 fi
371 done
372}
373
374set_rps_cpu_bitmap()
375{
376 dbg2 "# Scan binding interfaces of each cpu"
377 # suppose the value of interface_var is null or hex
378 num=0
379 while [ "$num" -lt "$NUM_OF_CPU" ];do
380 cpu_bit=$((2 ** $num))
381 eval rps_list=\$CPU${num}_RPS
382 dbg2 "# CPU$num: rps_list=$rps_list"
383 for i in $rps_list; do
384 var=${VAR_PREFIX}_${i//-/_}
385 eval ifval=\$$var
386 dbg2 "[var val before] \$$var=$ifval"
387 if [ -z "$ifval" ]; then
388 eval $var=$cpu_bit
389 else
390 eval $var=`expr $ifval + $cpu_bit`
391 fi
392 eval ifval=\$$var
393 dbg2 "[rps val after]$i=$ifval"
394 done
395 num=`expr $num + 1`
396 done
397}
398
399# $1: The default rps value. If rps of the interface is not setup, set $1 to it
400set_rps_cpus()
401{
402 dbg2 "# Setup rps of the interfaces, $RPS_IF_LIST."
403 for i in $RPS_IF_LIST; do
404 var=${VAR_PREFIX}_${i//-/_}
405 eval cpu_map=\$$var
406 if [ -d /sys/class/net/$i ]; then
407 if [ ! -z $cpu_map ]; then
408 cpu_map=`printf '%x' $cpu_map`
409 dbg "echo $cpu_map > /sys/class/net/$i/queues/rx-0/rps_cpus"
410 echo $cpu_map > /sys/class/net/$i/queues/rx-0/rps_cpus
411 elif [ ! -z $1 ]; then
412 dbg "echo $1 > /sys/class/net/$i/queues/rx-0/rps_cpus"
413 echo $1 > /sys/class/net/$i/queues/rx-0/rps_cpus
414 fi
415 fi
416 done
417}
418
419set_smp_affinity()
420{
421 dbg2 "# Setup affinity of each physical irq."
422 num=0
423 while [ "$num" -lt "$NUM_OF_CPU" ];do
424 eval smp_list=\$CPU${num}_AFFINITY
425 for i in $smp_list; do
426 cpu_bit=$((2 ** $num))
427 virq=$(get_virtual_irq $i)
428 #virq=$i
429 dbg2 "irq p2v $i --> $virq"
430 if [ ! -z $virq ]; then
431 dbg "echo $cpu_bit > /proc/irq/$virq/smp_affinity"
432 echo $cpu_bit > /proc/irq/$virq/smp_affinity
433 fi
434 done
435 num=`expr $num + 1`
436 done
437}
438
439if [ "$1" = "dbg" ]; then
440 DBG=1
441elif [ "$1" = "dbg2" ]; then
442 DBG=2
443else
444 DBG=0
445fi
446
447# Usage: dbg "the output string"
448dbg()
449{
450 if [ "$DBG" -ge "1" ]; then
451 echo -e $1
452 fi
453}
454
455# Usage: dbg2 "the output string"
456dbg2()
457{
458 if [ "$DBG" -ge "2" ]; then
459 echo -e $1
460 fi
461}
462
463dbg "# RPS and AFFINITY Setting"
464dbg "# NUM_OF_CPU=$NUM_OF_CPU"
465VAR_PREFIX="autogen"
466get_if_info
467setup_model
468set_rps_cpu_bitmap
469set_rps_cpus $DEFAULT_RPS
470set_smp_affinity
471#end of file