developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | OPTIMIZED_FOR="$1" |
| 4 | CPU_LIST=`cat /proc/interrupts | sed -n '1p'` |
| 5 | NUM_OF_CPU=0; for i in $CPU_LIST; do NUM_OF_CPU=`expr $NUM_OF_CPU + 1`; done; |
| 6 | DEFAULT_RPS=0 |
| 7 | |
| 8 | . /lib/functions.sh |
| 9 | |
| 10 | RPS_IF_LIST="" |
| 11 | NUM_WIFI_CARD=0 |
| 12 | WIFI_RADIO1=0 |
| 13 | WIFI_RADIO2=0 |
| 14 | WIFI_RADIO3=0 |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 15 | WED_ENABLE=0 |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 16 | |
developer | 431102f | 2023-05-12 10:52:51 +0800 | [diff] [blame] | 17 | WIFI_MODULE_LIST='mt7915e mt7996e' |
| 18 | |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 19 | get_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 |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 26 | if [[ "$vif" == "eth"* ]] || \ |
| 27 | [[ "$vif" == "lan"* ]] || [[ "$vif" == "wan"* ]] || \ |
| 28 | [[ "$vif" == "wlan"* ]] || [[ "$vif" == "phy"* ]]; then |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 29 | 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 |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 44 | |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 45 | if [[ $v == *"wbsys"* ]]; then |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 46 | WIFI_RADIO1=1 |
| 47 | fi |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 48 | |
| 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 | |
developer | 431102f | 2023-05-12 10:52:51 +0800 | [diff] [blame] | 58 | |
| 59 | for v in $WIFI_MODULE_LIST; |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 60 | do |
developer | 431102f | 2023-05-12 10:52:51 +0800 | [diff] [blame] | 61 | 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 |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 67 | fi |
| 68 | done; |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 69 | 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" |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 73 | dbg2 "WED enable = $WED_ENABLE" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | # $1: CPU# |
| 77 | # $2: irq list for added. |
| 78 | CPU_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. |
| 86 | CPU_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 | |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 93 | MT7988() |
| 94 | { |
| 95 | num_of_wifi=$1 |
| 96 | DEFAULT_RPS=0 |
| 97 | |
| 98 | #Physical IRQ# setting |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 99 | #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 |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 105 | 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 |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 129 | if [[ "$vif" == "wlan"* ]] || [[ "$vif" == "phy"* ]]; then |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 130 | 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 |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 138 | 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" |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 142 | |
| 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="" |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 151 | CPU2_AFFINITY="$eth_irq_rx0 $eth_irq_rx1 $eth_irq_tx" |
| 152 | CPU3_AFFINITY="$eth_irq_rx2 $eth_irq_rx3" |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 153 | |
| 154 | CPU0_RPS="$WIFI_IF_LIST" |
| 155 | CPU1_RPS="$WIFI_IF_LIST" |
developer | 6d638dd | 2023-02-21 13:46:21 +0800 | [diff] [blame] | 156 | CPU2_RPS="" |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 157 | 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 | |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 165 | MT7986() |
| 166 | { |
| 167 | num_of_wifi=$1 |
| 168 | DEFAULT_RPS=0 |
| 169 | |
| 170 | #Physical IRQ# setting |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 171 | eth_irq_rx=221 |
| 172 | eth_irq_tx=229 |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 173 | wifi1_irq= |
| 174 | wifi2_irq= |
| 175 | wifi3_irq= |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 176 | |
| 177 | if [[ "$WED_ENABLE" -eq "1" ]]; then |
| 178 | dbg2 "WED_ENABLE ON irq/iptable setting" |
| 179 | #TCP Binding |
developer | 6adfa0e | 2022-07-06 16:25:53 +0800 | [diff] [blame] | 180 | 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 |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 184 | #UDP Binding |
developer | 6adfa0e | 2022-07-06 16:25:53 +0800 | [diff] [blame] | 185 | 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 |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 189 | |
| 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 |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 216 | fi |
developer | a126cb4 | 2023-09-06 09:01:59 +0800 | [diff] [blame^] | 217 | |
| 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" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 226 | # 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 |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 230 | CPU0_AFFINITY="$eth_irq_rx" |
| 231 | CPU1_AFFINITY="$eth_irq_tx" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 232 | 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 |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 241 | CPU0_AFFINITY="$eth_irq_rx" |
| 242 | CPU1_AFFINITY="$eth_irq_tx" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 243 | CPU2_AFFINITY="$wifi2_irq $wifi3_irq" |
| 244 | CPU3_AFFINITY="$wifi1_irq" |
| 245 | |
developer | a126cb4 | 2023-09-06 09:01:59 +0800 | [diff] [blame^] | 246 | CPU0_RPS="$LAN_IF_LIST" |
| 247 | CPU1_RPS="$LAN_IF_LIST" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 248 | 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 | |
| 257 | MT7981() |
| 258 | { |
| 259 | num_of_wifi=$1 |
| 260 | DEFAULT_RPS=0 |
| 261 | |
| 262 | #Physical IRQ# setting |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 263 | eth_irq_rx=221 |
| 264 | eth_irq_tx=229 |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 265 | 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 |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 276 | CPU0_AFFINITY="$eth_irq_rx" |
| 277 | CPU1_AFFINITY="$eth_irq_tx" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 278 | |
| 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" |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 284 | CPU1_AFFINITY="$eth_irq_rx $eth_irq_tx" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 285 | |
| 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 | |
| 293 | MT7622() |
| 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 | |
| 339 | setup_model() |
| 340 | { |
| 341 | board=$(board_name) |
| 342 | num_of_wifi=$NUM_WIFI_CARD |
| 343 | |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 344 | if [[ $board == *"7988"* ]]; then |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 345 | dbg "setup_model: MT7988 NUM_WIFI_CARD=$num_of_wifi" |
| 346 | MT7988 $num_of_wifi |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 347 | elif [[ $board == *"7986"* ]]; then |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 348 | dbg "setup_model: MT7986 NUM_WIFI_CARD=$num_of_wifi" |
| 349 | MT7986 $num_of_wifi |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 350 | elif [[ $board == *"7981"* ]]; then |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 351 | dbg "setup_model: MT7981 NUM_WIFI_CARD=$num_of_wifi" |
| 352 | MT7981 $num_of_wifi |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 353 | elif [[ $board == *"7622"* ]]; then |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 354 | dbg "setup_model: MT7622 NUM_WIFI_CARD=$num_of_wifi" |
| 355 | MT7622 $num_of_wifi |
| 356 | fi |
| 357 | } |
| 358 | |
| 359 | get_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 | |
| 374 | set_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 |
| 400 | set_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 | |
| 419 | set_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 | |
| 439 | if [ "$1" = "dbg" ]; then |
| 440 | DBG=1 |
| 441 | elif [ "$1" = "dbg2" ]; then |
| 442 | DBG=2 |
| 443 | else |
| 444 | DBG=0 |
| 445 | fi |
| 446 | |
| 447 | # Usage: dbg "the output string" |
| 448 | dbg() |
| 449 | { |
| 450 | if [ "$DBG" -ge "1" ]; then |
| 451 | echo -e $1 |
| 452 | fi |
| 453 | } |
| 454 | |
| 455 | # Usage: dbg2 "the output string" |
| 456 | dbg2() |
| 457 | { |
| 458 | if [ "$DBG" -ge "2" ]; then |
| 459 | echo -e $1 |
| 460 | fi |
| 461 | } |
| 462 | |
| 463 | dbg "# RPS and AFFINITY Setting" |
| 464 | dbg "# NUM_OF_CPU=$NUM_OF_CPU" |
| 465 | VAR_PREFIX="autogen" |
| 466 | get_if_info |
| 467 | setup_model |
| 468 | set_rps_cpu_bitmap |
| 469 | set_rps_cpus $DEFAULT_RPS |
| 470 | set_smp_affinity |
| 471 | #end of file |