blob: ea94f182b34b210cde2e0f58f70e4f849b10ee1a [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
developer69b0f422023-01-06 15:37:54 +080017module_param=/sys/module/mt7915e/parameters/wed_enable
developer10cbf2c2022-02-09 10:39:21 +080018get_if_info()
19{
20 # try to get all wifi and eth net interface.
21 dbg2 "try to get all wifi and eth net interface."
22 NET_IF_LIST=`ls /sys/class/net`
23 for vif in $NET_IF_LIST;
24 do
25 if [[ "$vif" == "eth0*" ]] || [[ "$vif" == "eth1" ]] || \
26 [[ "$vif" == "lan*" ]] || [[ "$vif" == "wan*" ]] || \
developer7273f5f2022-12-12 17:18:16 +080027 [[ "$vif" == "wlan*" ]] || [[ "$vif" == "phy*" ]]; then
developer10cbf2c2022-02-09 10:39:21 +080028 RPS_IF_LIST="$RPS_IF_LIST $vif"
29 fi
30 done;
31 dbg2 "RPS_IF_LIST = $RPS_IF_LIST"
32
33 # try to get wifi physical card num.
34 dbg2 "try to get wifi physical card num."
35 VIRTUAL_RADIO_LIST=`ls -l /sys/class/ieee80211/ | awk -F 'devices' '{print $2}' | awk -F 'phy' '{print $1}' | uniq`
36 for v in $VIRTUAL_RADIO_LIST;
37 do
38 NUM_WIFI_CARD=`expr $NUM_WIFI_CARD + 1`
39 dbg2 "physical raido $v"
40 if [[ $v == *"wmac"* ]]; then
41 WIFI_RADIO1=1
42 fi
developer69b0f422023-01-06 15:37:54 +080043
developer10cbf2c2022-02-09 10:39:21 +080044 if [[ $v == *"wbsys"* ]]; then
developer69b0f422023-01-06 15:37:54 +080045 WIFI_RADIO1=1
46 fi
developer10cbf2c2022-02-09 10:39:21 +080047
48 if [[ $v == *"pci0000"* ]]; then
49 WIFI_RADIO2=1
50 fi
51
52 if [[ $v == *"pci0001"* ]]; then
53 WIFI_RADIO3=1
54 fi
55 done;
56
developer69b0f422023-01-06 15:37:54 +080057 WED_ENABLE_LIST=
58 if [[ -f "$module_param" ]]; then
59 WED_ENABLE_LIST=`cat $module_param`
60 fi
developer10d32132022-07-05 15:12:10 +080061 for v in $WED_ENABLE_LIST;
62 do
63 dbg2 "wed enable ori info $v"
64 if [[ $v == "Y" ]]; then
65 WED_ENABLE=1
66 fi
67 done;
developer10cbf2c2022-02-09 10:39:21 +080068 dbg2 "NUM_WIFI_CARD = $NUM_WIFI_CARD"
69 dbg2 "platform wifi enable = $WIFI_RADIO1"
70 dbg2 "pcie1 wifi enable = $WIFI_RADIO2"
71 dbg2 "pcie2 wifi enable = $WIFI_RADIO3"
developer10d32132022-07-05 15:12:10 +080072 dbg2 "WED enable = $WED_ENABLE"
developer10cbf2c2022-02-09 10:39:21 +080073}
74
75# $1: CPU#
76# $2: irq list for added.
77CPU_AFFINITY_ADD()
78{
79 eval oval=\$CPU${1}_AFFINITY
80 eval CPU${1}_AFFINITY=\"\$CPU${1}_AFFINITY $2\"
81}
82
83# $1: CPU#
84# $2: Interface name for added.
85CPU_RPS_ADD()
86{
87 eval oval=\$CPU${1}_RPS
88 eval CPU${1}_RPS=\"\$CPU${1}_RPS $2\"
89 dbg2 "CPU${1}_RPS=\"\$CPU${1}_RPS $2\""
90}
91
developer69b0f422023-01-06 15:37:54 +080092MT7988()
93{
94 num_of_wifi=$1
95 DEFAULT_RPS=0
96
97 #Physical IRQ# setting
98 eth0_irq=229
99 eth1_irq=230
100 eth2_irq=231
101 wifi1_irq_pcie0=524288
102 wifi1_irq_pcie1=134742016
103 wifi2_irq_pcie0=
104 wifi2_irq_pcie1=
105
106 if [[ "$WED_ENABLE" -eq "1" ]]; then
107 dbg2 "WED_ENABLE ON irq/iptable setting"
108 #TCP Binding
109 iptables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
110 iptables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
111 ip6tables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
112 ip6tables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
113 #UDP Binding
114 iptables -D FORWARD -p udp -j FLOWOFFLOAD --hw
115 iptables -I FORWARD -p udp -j FLOWOFFLOAD --hw
116 ip6tables -D FORWARD -p udp -j FLOWOFFLOAD --hw
117 ip6tables -I FORWARD -p udp -j FLOWOFFLOAD --hw
118
119 else
120 dbg2 "WED_ENABLE OFF irq/iptable seting"
121 fi
122
123 for vif in $NET_IF_LIST;
124 do
125 if [[ "$vif" == "wlan*" ]] || [[ "$vif" == "phy*" ]]; then
126 WIFI_IF_LIST="$WIFI_IF_LIST $vif"
127 fi
128 done;
129 dbg2 "$WIFI_IF_LIST = $WIFI_IF_LIST"
130 # Please update the CPU binding in each cases.
131 # CPU#_AFFINITY="add binding irq number here"
132 # CPU#_RPS="add binding interface name here"
133 if [ "$num_of_wifi" = "0" ]; then
134 CPU0_AFFINITY="$eth0_irq"
135 CPU1_AFFINITY="$eth1_irq"
136 CPU2_AFFINITY="$eth2_irq"
137 CPU3_AFFINITY=""
138
139 CPU0_RPS="$RPS_IF_LIST"
140 CPU1_RPS="$RPS_IF_LIST"
141 CPU2_RPS="$RPS_IF_LIST"
142 CPU3_RPS="$RPS_IF_LIST"
143 else
144 #we bound all wifi card to cpu0 and bound eth to cpu
145 CPU0_AFFINITY=""
146 CPU1_AFFINITY=""
147 CPU2_AFFINITY="$eth1_irq"
148 CPU3_AFFINITY="$eth0_irq $eth2_irq"
149
150 CPU0_RPS="$WIFI_IF_LIST"
151 CPU1_RPS="$WIFI_IF_LIST"
152 CPU2_RPS="$WIFI_IF_LIST"
153 CPU3_RPS=""
154 fi
155 dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY"
156 dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY"
157 dbg2 "CPU2_AFFINITY = $CPU2_AFFINITY"
158 dbg2 "CPU3_AFFINITY = $CPU3_AFFINITY"
159}
160
developer10cbf2c2022-02-09 10:39:21 +0800161MT7986()
162{
163 num_of_wifi=$1
164 DEFAULT_RPS=0
165
166 #Physical IRQ# setting
167 eth0_irq=229
168 eth1_irq=230
169 wifi1_irq=
170 wifi2_irq=
171 wifi3_irq=
developer10d32132022-07-05 15:12:10 +0800172
173 if [[ "$WED_ENABLE" -eq "1" ]]; then
174 dbg2 "WED_ENABLE ON irq/iptable setting"
175 #TCP Binding
developer6adfa0e2022-07-06 16:25:53 +0800176 iptables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
177 iptables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
178 ip6tables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
179 ip6tables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw
developer10d32132022-07-05 15:12:10 +0800180 #UDP Binding
developer6adfa0e2022-07-06 16:25:53 +0800181 iptables -D FORWARD -p udp -j FLOWOFFLOAD --hw
182 iptables -I FORWARD -p udp -j FLOWOFFLOAD --hw
183 ip6tables -D FORWARD -p udp -j FLOWOFFLOAD --hw
184 ip6tables -I FORWARD -p udp -j FLOWOFFLOAD --hw
developer10d32132022-07-05 15:12:10 +0800185
186 #AX6000 AX7800 - SOC
187 if [[ "$WIFI_RADIO1" -eq "1" ]]; then
188 wifi1_irq=238
189 fi
190 #AX7800 - PCIE0
191 if [[ "$WIFI_RADIO2" -eq "1" ]]; then
192 wifi2_irq=237
193 fi
194 #AX7800 - PCIE1
195 #if [[ "$WIFI_RADIO3" -eq "1" ]]; then
196 # wifi3_irq=239
197 #fi
198 else
199 dbg2 "WED_ENABLE OFF irq/iptable seting"
200 #AX6000 AX7800 - SOC
201 if [[ "$WIFI_RADIO1" -eq "1" ]]; then
202 wifi1_irq=245
203 fi
204 #AX7800 - PCIE0
205 if [[ "$WIFI_RADIO2" -eq "1" ]]; then
206 wifi2_irq=246
207 fi
208 #AX7800 - PCIE1
209 #if [[ "$WIFI_RADIO3" -eq "1" ]]; then
210 # wifi3_irq=247
211 #fi
developer10cbf2c2022-02-09 10:39:21 +0800212 fi
213 # Please update the CPU binding in each cases.
214 # CPU#_AFFINITY="add binding irq number here"
215 # CPU#_RPS="add binding interface name here"
216 if [ "$num_of_wifi" = "0" ]; then
217 CPU0_AFFINITY="$eth0_irq"
218 CPU1_AFFINITY="$eth1_irq"
219 CPU2_AFFINITY=""
220 CPU3_AFFINITY=""
221
222 CPU0_RPS="$RPS_IF_LIST"
223 CPU1_RPS="$RPS_IF_LIST"
224 CPU2_RPS="$RPS_IF_LIST"
225 CPU3_RPS="$RPS_IF_LIST"
226 else
227 #we bound all wifi card to cpu1 and bound eth to cpu0
228 CPU0_AFFINITY="$eth0_irq"
229 CPU1_AFFINITY="$eth1_irq"
230 CPU2_AFFINITY="$wifi2_irq $wifi3_irq"
231 CPU3_AFFINITY="$wifi1_irq"
232
233 CPU0_RPS="$RPS_IF_LIST"
234 CPU1_RPS="$RPS_IF_LIST"
235 CPU2_RPS="$RPS_IF_LIST"
236 CPU3_RPS="$RPS_IF_LIST"
237 fi
238 dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY"
239 dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY"
240 dbg2 "CPU2_AFFINITY = $CPU2_AFFINITY"
241 dbg2 "CPU3_AFFINITY = $CPU3_AFFINITY"
242}
243
244MT7981()
245{
246 num_of_wifi=$1
247 DEFAULT_RPS=0
248
249 #Physical IRQ# setting
250 eth0_irq=229
251 eth1_irq=230
252 wifi1_irq=
253 wifi2_irq=
254 wifi3_irq=
255 #AX3000
256 if [[ "$WIFI_RADIO1" -eq "1" ]]; then
257 wifi1_irq=245
258 fi
259 # Please update the CPU binding in each cases.
260 # CPU#_AFFINITY="add binding irq number here"
261 # CPU#_RPS="add binding interface name here"
262 if [ "$num_of_wifi" = "0" ]; then
263 CPU0_AFFINITY="$eth0_irq"
264 CPU1_AFFINITY="$eth1_irq"
265
266 CPU0_RPS="$RPS_IF_LIST"
267 CPU1_RPS="$RPS_IF_LIST"
268 else
269 #we bound all wifi card to cpu0 and bound eth to cpu1
270 CPU0_AFFINITY="$wifi1_irq $wifi2_irq $wifi3_irq"
271 CPU1_AFFINITY="$eth0_irq $eth1_irq"
272
273 CPU0_RPS="$RPS_IF_LIST"
274 CPU1_RPS="$RPS_IF_LIST"
275 fi
276 dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY"
277 dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY"
278}
279
280MT7622()
281{
282 num_of_wifi=$1
283 DEFAULT_RPS=0
284
285 #Physical IRQ# setting
286 eth0_irq=224
287 eth1_irq=225
288 wifi1_irq=
289 wifi2_irq=
290 wifi3_irq=
291 #AX1200 AX3200
292 if [[ "$WIFI_RADIO1" -eq "1" ]]; then
293 wifi1_irq=211
294 fi
295 #AX1800 AX3200
296 if [[ "$WIFI_RADIO2" -eq "1" ]]; then
297 wifi2_irq=214
298 fi
299 #AX3600
300 if [[ "$WIFI_RADIO3" -eq "1" ]]; then
301 wifi3_irq=215
302 fi
303
304 # Please update the CPU binding in each cases.
305 # CPU#_AFFINITY="add binding irq number here"
306 # CPU#_RPS="add binding interface name here"
307 if [ "$num_of_wifi" == "0" ]; then
308 CPU0_AFFINITY="$eth0_irq"
309 CPU1_AFFINITY="$eth1_irq"
310
311 CPU0_RPS="$RPS_IF_LIST"
312 CPU1_RPS="$RPS_IF_LIST"
313 else
314 #we bound all wifi card to cpu0 and bound eth to cpu1
315 CPU0_AFFINITY="$wifi1_irq $wifi2_irq $wifi3_irq"
316 CPU1_AFFINITY="$eth0_irq $eth1_irq"
317
318 CPU0_RPS="$RPS_IF_LIST"
319 CPU1_RPS="$RPS_IF_LIST"
320 fi
321
322 dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY"
323 dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY"
324}
325
326setup_model()
327{
328 board=$(board_name)
329 num_of_wifi=$NUM_WIFI_CARD
330
developer69b0f422023-01-06 15:37:54 +0800331 if [[ $board == "*7988*" ]]; then
332 dbg "setup_model: MT7988 NUM_WIFI_CARD=$num_of_wifi"
333 MT7988 $num_of_wifi
334 elif [[ $board == "*7986*" ]]; then
developer10cbf2c2022-02-09 10:39:21 +0800335 dbg "setup_model: MT7986 NUM_WIFI_CARD=$num_of_wifi"
336 MT7986 $num_of_wifi
337 elif [[ $board == "*7981*" ]]; then
338 dbg "setup_model: MT7981 NUM_WIFI_CARD=$num_of_wifi"
339 MT7981 $num_of_wifi
340 elif [[ $board == "*7622*" ]]; then
341 dbg "setup_model: MT7622 NUM_WIFI_CARD=$num_of_wifi"
342 MT7622 $num_of_wifi
343 fi
344}
345
346get_virtual_irq()
347{
348 PHY_POS=`expr $NUM_OF_CPU + 3` #physical irq # position in /proc/interrups may vary with the number of CPU up
349 target_phy_irq=$1
350 cat /proc/interrupts | sed 's/:/ /g'| awk '$1 ~ /^[0-9]+$/' | while read line
351 do
352 set -- $line
353 phy_irq=$(eval "echo \$$PHY_POS")
354 if [ $phy_irq == $target_phy_irq ]; then
355 echo $1
356 return
357 fi
358 done
359}
360
361set_rps_cpu_bitmap()
362{
363 dbg2 "# Scan binding interfaces of each cpu"
364 # suppose the value of interface_var is null or hex
365 num=0
366 while [ "$num" -lt "$NUM_OF_CPU" ];do
367 cpu_bit=$((2 ** $num))
368 eval rps_list=\$CPU${num}_RPS
369 dbg2 "# CPU$num: rps_list=$rps_list"
370 for i in $rps_list; do
371 var=${VAR_PREFIX}_${i//-/_}
372 eval ifval=\$$var
373 dbg2 "[var val before] \$$var=$ifval"
374 if [ -z "$ifval" ]; then
375 eval $var=$cpu_bit
376 else
377 eval $var=`expr $ifval + $cpu_bit`
378 fi
379 eval ifval=\$$var
380 dbg2 "[rps val after]$i=$ifval"
381 done
382 num=`expr $num + 1`
383 done
384}
385
386# $1: The default rps value. If rps of the interface is not setup, set $1 to it
387set_rps_cpus()
388{
389 dbg2 "# Setup rps of the interfaces, $RPS_IF_LIST."
390 for i in $RPS_IF_LIST; do
391 var=${VAR_PREFIX}_${i//-/_}
392 eval cpu_map=\$$var
393 if [ -d /sys/class/net/$i ]; then
394 if [ ! -z $cpu_map ]; then
395 cpu_map=`printf '%x' $cpu_map`
396 dbg "echo $cpu_map > /sys/class/net/$i/queues/rx-0/rps_cpus"
397 echo $cpu_map > /sys/class/net/$i/queues/rx-0/rps_cpus
398 elif [ ! -z $1 ]; then
399 dbg "echo $1 > /sys/class/net/$i/queues/rx-0/rps_cpus"
400 echo $1 > /sys/class/net/$i/queues/rx-0/rps_cpus
401 fi
402 fi
403 done
404}
405
406set_smp_affinity()
407{
408 dbg2 "# Setup affinity of each physical irq."
409 num=0
410 while [ "$num" -lt "$NUM_OF_CPU" ];do
411 eval smp_list=\$CPU${num}_AFFINITY
412 for i in $smp_list; do
413 cpu_bit=$((2 ** $num))
414 virq=$(get_virtual_irq $i)
415 #virq=$i
416 dbg2 "irq p2v $i --> $virq"
417 if [ ! -z $virq ]; then
418 dbg "echo $cpu_bit > /proc/irq/$virq/smp_affinity"
419 echo $cpu_bit > /proc/irq/$virq/smp_affinity
420 fi
421 done
422 num=`expr $num + 1`
423 done
424}
425
426if [ "$1" = "dbg" ]; then
427 DBG=1
428elif [ "$1" = "dbg2" ]; then
429 DBG=2
430else
431 DBG=0
432fi
433
434# Usage: dbg "the output string"
435dbg()
436{
437 if [ "$DBG" -ge "1" ]; then
438 echo -e $1
439 fi
440}
441
442# Usage: dbg2 "the output string"
443dbg2()
444{
445 if [ "$DBG" -ge "2" ]; then
446 echo -e $1
447 fi
448}
449
450dbg "# RPS and AFFINITY Setting"
451dbg "# NUM_OF_CPU=$NUM_OF_CPU"
452VAR_PREFIX="autogen"
453get_if_info
454setup_model
455set_rps_cpu_bitmap
456set_rps_cpus $DEFAULT_RPS
457set_smp_affinity
458#end of file