blob: cc5b46b27229c5961ebfe101fd9ef50e7296398c [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
99 eth0_irq=229
100 eth1_irq=230
101 eth2_irq=231
102 wifi1_irq_pcie0=524288
103 wifi1_irq_pcie1=134742016
104 wifi2_irq_pcie0=
105 wifi2_irq_pcie1=
106
107 if [[ "$WED_ENABLE" -eq "1" ]]; then
108 dbg2 "WED_ENABLE ON irq/iptable setting"
109 #TCP Binding
110 iptables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
111 iptables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
112 ip6tables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
113 ip6tables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
114 #UDP Binding
115 iptables -D FORWARD -p udp -j FLOWOFFLOAD --hw
116 iptables -I FORWARD -p udp -j FLOWOFFLOAD --hw
117 ip6tables -D FORWARD -p udp -j FLOWOFFLOAD --hw
118 ip6tables -I FORWARD -p udp -j FLOWOFFLOAD --hw
119
120 else
121 dbg2 "WED_ENABLE OFF irq/iptable seting"
122 fi
123
124 for vif in $NET_IF_LIST;
125 do
developerd88f9b62023-02-02 09:51:21 +0800126 if [[ "$vif" == "wlan"* ]] || [[ "$vif" == "phy"* ]]; then
developer69b0f422023-01-06 15:37:54 +0800127 WIFI_IF_LIST="$WIFI_IF_LIST $vif"
128 fi
129 done;
130 dbg2 "$WIFI_IF_LIST = $WIFI_IF_LIST"
131 # Please update the CPU binding in each cases.
132 # CPU#_AFFINITY="add binding irq number here"
133 # CPU#_RPS="add binding interface name here"
134 if [ "$num_of_wifi" = "0" ]; then
135 CPU0_AFFINITY="$eth0_irq"
136 CPU1_AFFINITY="$eth1_irq"
137 CPU2_AFFINITY="$eth2_irq"
138 CPU3_AFFINITY=""
139
140 CPU0_RPS="$RPS_IF_LIST"
141 CPU1_RPS="$RPS_IF_LIST"
142 CPU2_RPS="$RPS_IF_LIST"
143 CPU3_RPS="$RPS_IF_LIST"
144 else
145 #we bound all wifi card to cpu0 and bound eth to cpu
146 CPU0_AFFINITY=""
147 CPU1_AFFINITY=""
148 CPU2_AFFINITY="$eth1_irq"
149 CPU3_AFFINITY="$eth0_irq $eth2_irq"
150
151 CPU0_RPS="$WIFI_IF_LIST"
152 CPU1_RPS="$WIFI_IF_LIST"
developer6d638dd2023-02-21 13:46:21 +0800153 CPU2_RPS=""
developer69b0f422023-01-06 15:37:54 +0800154 CPU3_RPS=""
155 fi
156 dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY"
157 dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY"
158 dbg2 "CPU2_AFFINITY = $CPU2_AFFINITY"
159 dbg2 "CPU3_AFFINITY = $CPU3_AFFINITY"
160}
161
developer10cbf2c2022-02-09 10:39:21 +0800162MT7986()
163{
164 num_of_wifi=$1
165 DEFAULT_RPS=0
166
167 #Physical IRQ# setting
168 eth0_irq=229
169 eth1_irq=230
170 wifi1_irq=
171 wifi2_irq=
172 wifi3_irq=
developer10d32132022-07-05 15:12:10 +0800173
174 if [[ "$WED_ENABLE" -eq "1" ]]; then
175 dbg2 "WED_ENABLE ON irq/iptable setting"
176 #TCP Binding
developer6adfa0e2022-07-06 16:25:53 +0800177 iptables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
178 iptables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
179 ip6tables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
180 ip6tables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
developer10d32132022-07-05 15:12:10 +0800181 #UDP Binding
developer6adfa0e2022-07-06 16:25:53 +0800182 iptables -D FORWARD -p udp -j FLOWOFFLOAD --hw
183 iptables -I FORWARD -p udp -j FLOWOFFLOAD --hw
184 ip6tables -D FORWARD -p udp -j FLOWOFFLOAD --hw
185 ip6tables -I FORWARD -p udp -j FLOWOFFLOAD --hw
developer10d32132022-07-05 15:12:10 +0800186
187 #AX6000 AX7800 - SOC
188 if [[ "$WIFI_RADIO1" -eq "1" ]]; then
189 wifi1_irq=238
190 fi
191 #AX7800 - PCIE0
192 if [[ "$WIFI_RADIO2" -eq "1" ]]; then
193 wifi2_irq=237
194 fi
195 #AX7800 - PCIE1
196 #if [[ "$WIFI_RADIO3" -eq "1" ]]; then
197 # wifi3_irq=239
198 #fi
199 else
200 dbg2 "WED_ENABLE OFF irq/iptable seting"
201 #AX6000 AX7800 - SOC
202 if [[ "$WIFI_RADIO1" -eq "1" ]]; then
203 wifi1_irq=245
204 fi
205 #AX7800 - PCIE0
206 if [[ "$WIFI_RADIO2" -eq "1" ]]; then
207 wifi2_irq=246
208 fi
209 #AX7800 - PCIE1
210 #if [[ "$WIFI_RADIO3" -eq "1" ]]; then
211 # wifi3_irq=247
212 #fi
developer10cbf2c2022-02-09 10:39:21 +0800213 fi
214 # Please update the CPU binding in each cases.
215 # CPU#_AFFINITY="add binding irq number here"
216 # CPU#_RPS="add binding interface name here"
217 if [ "$num_of_wifi" = "0" ]; then
218 CPU0_AFFINITY="$eth0_irq"
219 CPU1_AFFINITY="$eth1_irq"
220 CPU2_AFFINITY=""
221 CPU3_AFFINITY=""
222
223 CPU0_RPS="$RPS_IF_LIST"
224 CPU1_RPS="$RPS_IF_LIST"
225 CPU2_RPS="$RPS_IF_LIST"
226 CPU3_RPS="$RPS_IF_LIST"
227 else
228 #we bound all wifi card to cpu1 and bound eth to cpu0
229 CPU0_AFFINITY="$eth0_irq"
230 CPU1_AFFINITY="$eth1_irq"
231 CPU2_AFFINITY="$wifi2_irq $wifi3_irq"
232 CPU3_AFFINITY="$wifi1_irq"
233
234 CPU0_RPS="$RPS_IF_LIST"
235 CPU1_RPS="$RPS_IF_LIST"
236 CPU2_RPS="$RPS_IF_LIST"
237 CPU3_RPS="$RPS_IF_LIST"
238 fi
239 dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY"
240 dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY"
241 dbg2 "CPU2_AFFINITY = $CPU2_AFFINITY"
242 dbg2 "CPU3_AFFINITY = $CPU3_AFFINITY"
243}
244
245MT7981()
246{
247 num_of_wifi=$1
248 DEFAULT_RPS=0
249
250 #Physical IRQ# setting
251 eth0_irq=229
252 eth1_irq=230
253 wifi1_irq=
254 wifi2_irq=
255 wifi3_irq=
256 #AX3000
257 if [[ "$WIFI_RADIO1" -eq "1" ]]; then
258 wifi1_irq=245
259 fi
260 # Please update the CPU binding in each cases.
261 # CPU#_AFFINITY="add binding irq number here"
262 # CPU#_RPS="add binding interface name here"
263 if [ "$num_of_wifi" = "0" ]; then
264 CPU0_AFFINITY="$eth0_irq"
265 CPU1_AFFINITY="$eth1_irq"
266
267 CPU0_RPS="$RPS_IF_LIST"
268 CPU1_RPS="$RPS_IF_LIST"
269 else
270 #we bound all wifi card to cpu0 and bound eth to cpu1
271 CPU0_AFFINITY="$wifi1_irq $wifi2_irq $wifi3_irq"
272 CPU1_AFFINITY="$eth0_irq $eth1_irq"
273
274 CPU0_RPS="$RPS_IF_LIST"
275 CPU1_RPS="$RPS_IF_LIST"
276 fi
277 dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY"
278 dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY"
279}
280
281MT7622()
282{
283 num_of_wifi=$1
284 DEFAULT_RPS=0
285
286 #Physical IRQ# setting
287 eth0_irq=224
288 eth1_irq=225
289 wifi1_irq=
290 wifi2_irq=
291 wifi3_irq=
292 #AX1200 AX3200
293 if [[ "$WIFI_RADIO1" -eq "1" ]]; then
294 wifi1_irq=211
295 fi
296 #AX1800 AX3200
297 if [[ "$WIFI_RADIO2" -eq "1" ]]; then
298 wifi2_irq=214
299 fi
300 #AX3600
301 if [[ "$WIFI_RADIO3" -eq "1" ]]; then
302 wifi3_irq=215
303 fi
304
305 # Please update the CPU binding in each cases.
306 # CPU#_AFFINITY="add binding irq number here"
307 # CPU#_RPS="add binding interface name here"
308 if [ "$num_of_wifi" == "0" ]; then
309 CPU0_AFFINITY="$eth0_irq"
310 CPU1_AFFINITY="$eth1_irq"
311
312 CPU0_RPS="$RPS_IF_LIST"
313 CPU1_RPS="$RPS_IF_LIST"
314 else
315 #we bound all wifi card to cpu0 and bound eth to cpu1
316 CPU0_AFFINITY="$wifi1_irq $wifi2_irq $wifi3_irq"
317 CPU1_AFFINITY="$eth0_irq $eth1_irq"
318
319 CPU0_RPS="$RPS_IF_LIST"
320 CPU1_RPS="$RPS_IF_LIST"
321 fi
322
323 dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY"
324 dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY"
325}
326
327setup_model()
328{
329 board=$(board_name)
330 num_of_wifi=$NUM_WIFI_CARD
331
developerd88f9b62023-02-02 09:51:21 +0800332 if [[ $board == *"7988"* ]]; then
developer69b0f422023-01-06 15:37:54 +0800333 dbg "setup_model: MT7988 NUM_WIFI_CARD=$num_of_wifi"
334 MT7988 $num_of_wifi
developerd88f9b62023-02-02 09:51:21 +0800335 elif [[ $board == *"7986"* ]]; then
developer10cbf2c2022-02-09 10:39:21 +0800336 dbg "setup_model: MT7986 NUM_WIFI_CARD=$num_of_wifi"
337 MT7986 $num_of_wifi
developerd88f9b62023-02-02 09:51:21 +0800338 elif [[ $board == *"7981"* ]]; then
developer10cbf2c2022-02-09 10:39:21 +0800339 dbg "setup_model: MT7981 NUM_WIFI_CARD=$num_of_wifi"
340 MT7981 $num_of_wifi
developerd88f9b62023-02-02 09:51:21 +0800341 elif [[ $board == *"7622"* ]]; then
developer10cbf2c2022-02-09 10:39:21 +0800342 dbg "setup_model: MT7622 NUM_WIFI_CARD=$num_of_wifi"
343 MT7622 $num_of_wifi
344 fi
345}
346
347get_virtual_irq()
348{
349 PHY_POS=`expr $NUM_OF_CPU + 3` #physical irq # position in /proc/interrups may vary with the number of CPU up
350 target_phy_irq=$1
351 cat /proc/interrupts | sed 's/:/ /g'| awk '$1 ~ /^[0-9]+$/' | while read line
352 do
353 set -- $line
354 phy_irq=$(eval "echo \$$PHY_POS")
355 if [ $phy_irq == $target_phy_irq ]; then
356 echo $1
357 return
358 fi
359 done
360}
361
362set_rps_cpu_bitmap()
363{
364 dbg2 "# Scan binding interfaces of each cpu"
365 # suppose the value of interface_var is null or hex
366 num=0
367 while [ "$num" -lt "$NUM_OF_CPU" ];do
368 cpu_bit=$((2 ** $num))
369 eval rps_list=\$CPU${num}_RPS
370 dbg2 "# CPU$num: rps_list=$rps_list"
371 for i in $rps_list; do
372 var=${VAR_PREFIX}_${i//-/_}
373 eval ifval=\$$var
374 dbg2 "[var val before] \$$var=$ifval"
375 if [ -z "$ifval" ]; then
376 eval $var=$cpu_bit
377 else
378 eval $var=`expr $ifval + $cpu_bit`
379 fi
380 eval ifval=\$$var
381 dbg2 "[rps val after]$i=$ifval"
382 done
383 num=`expr $num + 1`
384 done
385}
386
387# $1: The default rps value. If rps of the interface is not setup, set $1 to it
388set_rps_cpus()
389{
390 dbg2 "# Setup rps of the interfaces, $RPS_IF_LIST."
391 for i in $RPS_IF_LIST; do
392 var=${VAR_PREFIX}_${i//-/_}
393 eval cpu_map=\$$var
394 if [ -d /sys/class/net/$i ]; then
395 if [ ! -z $cpu_map ]; then
396 cpu_map=`printf '%x' $cpu_map`
397 dbg "echo $cpu_map > /sys/class/net/$i/queues/rx-0/rps_cpus"
398 echo $cpu_map > /sys/class/net/$i/queues/rx-0/rps_cpus
399 elif [ ! -z $1 ]; then
400 dbg "echo $1 > /sys/class/net/$i/queues/rx-0/rps_cpus"
401 echo $1 > /sys/class/net/$i/queues/rx-0/rps_cpus
402 fi
403 fi
404 done
405}
406
407set_smp_affinity()
408{
409 dbg2 "# Setup affinity of each physical irq."
410 num=0
411 while [ "$num" -lt "$NUM_OF_CPU" ];do
412 eval smp_list=\$CPU${num}_AFFINITY
413 for i in $smp_list; do
414 cpu_bit=$((2 ** $num))
415 virq=$(get_virtual_irq $i)
416 #virq=$i
417 dbg2 "irq p2v $i --> $virq"
418 if [ ! -z $virq ]; then
419 dbg "echo $cpu_bit > /proc/irq/$virq/smp_affinity"
420 echo $cpu_bit > /proc/irq/$virq/smp_affinity
421 fi
422 done
423 num=`expr $num + 1`
424 done
425}
426
427if [ "$1" = "dbg" ]; then
428 DBG=1
429elif [ "$1" = "dbg2" ]; then
430 DBG=2
431else
432 DBG=0
433fi
434
435# Usage: dbg "the output string"
436dbg()
437{
438 if [ "$DBG" -ge "1" ]; then
439 echo -e $1
440 fi
441}
442
443# Usage: dbg2 "the output string"
444dbg2()
445{
446 if [ "$DBG" -ge "2" ]; then
447 echo -e $1
448 fi
449}
450
451dbg "# RPS and AFFINITY Setting"
452dbg "# NUM_OF_CPU=$NUM_OF_CPU"
453VAR_PREFIX="autogen"
454get_if_info
455setup_model
456set_rps_cpu_bitmap
457set_rps_cpus $DEFAULT_RPS
458set_smp_affinity
459#end of file