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 | 2f08017 | 2023-09-19 22:42:09 +0800 | [diff] [blame] | 171 | #Ethernet RSS feature enables 4 Rx rings |
| 172 | eth_irq_rx0=221 |
| 173 | eth_irq_rx1=222 |
| 174 | eth_irq_rx2=223 |
| 175 | eth_irq_rx3=224 |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 176 | eth_irq_tx=229 |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 177 | wifi1_irq= |
| 178 | wifi2_irq= |
| 179 | wifi3_irq= |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 180 | |
| 181 | if [[ "$WED_ENABLE" -eq "1" ]]; then |
| 182 | dbg2 "WED_ENABLE ON irq/iptable setting" |
| 183 | #TCP Binding |
developer | 6adfa0e | 2022-07-06 16:25:53 +0800 | [diff] [blame] | 184 | iptables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
| 185 | iptables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
| 186 | ip6tables -D FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
| 187 | ip6tables -I FORWARD -p tcp -m conntrack --ctstate RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 188 | #UDP Binding |
developer | 6adfa0e | 2022-07-06 16:25:53 +0800 | [diff] [blame] | 189 | iptables -D FORWARD -p udp -j FLOWOFFLOAD --hw |
| 190 | iptables -I FORWARD -p udp -j FLOWOFFLOAD --hw |
| 191 | ip6tables -D FORWARD -p udp -j FLOWOFFLOAD --hw |
| 192 | ip6tables -I FORWARD -p udp -j FLOWOFFLOAD --hw |
developer | 10d3213 | 2022-07-05 15:12:10 +0800 | [diff] [blame] | 193 | |
| 194 | #AX6000 AX7800 - SOC |
| 195 | if [[ "$WIFI_RADIO1" -eq "1" ]]; then |
| 196 | wifi1_irq=238 |
| 197 | fi |
| 198 | #AX7800 - PCIE0 |
| 199 | if [[ "$WIFI_RADIO2" -eq "1" ]]; then |
| 200 | wifi2_irq=237 |
| 201 | fi |
| 202 | #AX7800 - PCIE1 |
| 203 | #if [[ "$WIFI_RADIO3" -eq "1" ]]; then |
| 204 | # wifi3_irq=239 |
| 205 | #fi |
| 206 | else |
| 207 | dbg2 "WED_ENABLE OFF irq/iptable seting" |
| 208 | #AX6000 AX7800 - SOC |
| 209 | if [[ "$WIFI_RADIO1" -eq "1" ]]; then |
| 210 | wifi1_irq=245 |
| 211 | fi |
| 212 | #AX7800 - PCIE0 |
| 213 | if [[ "$WIFI_RADIO2" -eq "1" ]]; then |
| 214 | wifi2_irq=246 |
| 215 | fi |
| 216 | #AX7800 - PCIE1 |
| 217 | #if [[ "$WIFI_RADIO3" -eq "1" ]]; then |
| 218 | # wifi3_irq=247 |
| 219 | #fi |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 220 | fi |
developer | a126cb4 | 2023-09-06 09:01:59 +0800 | [diff] [blame] | 221 | |
| 222 | for vif in $NET_IF_LIST; |
| 223 | do |
developer | 2f08017 | 2023-09-19 22:42:09 +0800 | [diff] [blame] | 224 | if [[ "$vif" == "wlan"* ]] || [[ "$vif" == "phy"* ]]; then |
| 225 | WIFI_IF_LIST="$WIFI_IF_LIST $vif" |
developer | a126cb4 | 2023-09-06 09:01:59 +0800 | [diff] [blame] | 226 | fi |
| 227 | done; |
developer | 2f08017 | 2023-09-19 22:42:09 +0800 | [diff] [blame] | 228 | dbg2 "$WIFI_IF_LIST = $WIFI_IF_LIST" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 229 | # Please update the CPU binding in each cases. |
| 230 | # CPU#_AFFINITY="add binding irq number here" |
| 231 | # CPU#_RPS="add binding interface name here" |
| 232 | if [ "$num_of_wifi" = "0" ]; then |
developer | 2f08017 | 2023-09-19 22:42:09 +0800 | [diff] [blame] | 233 | CPU0_AFFINITY="$eth_irq_rx0" |
| 234 | CPU1_AFFINITY="$eth_irq_rx1 $eth_irq_tx" |
| 235 | CPU2_AFFINITY="$eth_irq_rx2" |
| 236 | CPU3_AFFINITY="$eth_irq_rx3" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 237 | |
developer | 2f08017 | 2023-09-19 22:42:09 +0800 | [diff] [blame] | 238 | CPU0_RPS="" |
| 239 | CPU1_RPS="" |
| 240 | CPU2_RPS="" |
| 241 | CPU3_RPS="" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 242 | else |
| 243 | #we bound all wifi card to cpu1 and bound eth to cpu0 |
developer | 2f08017 | 2023-09-19 22:42:09 +0800 | [diff] [blame] | 244 | CPU0_AFFINITY="$eth_irq_rx0" |
| 245 | CPU1_AFFINITY="$eth_irq_rx1 $eth_irq_tx" |
| 246 | CPU2_AFFINITY="$eth_irq_rx2 $wifi2_irq $wifi3_irq" |
| 247 | CPU3_AFFINITY="$eth_irq_rx3 $wifi1_irq" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 248 | |
developer | 2f08017 | 2023-09-19 22:42:09 +0800 | [diff] [blame] | 249 | CPU0_RPS="$WIFI_IF_LIST" |
| 250 | CPU1_RPS="$WIFI_IF_LIST" |
| 251 | CPU2_RPS="$WIFI_IF_LIST" |
| 252 | CPU3_RPS="$WIFI_IF_LIST" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 253 | fi |
| 254 | dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY" |
| 255 | dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY" |
| 256 | dbg2 "CPU2_AFFINITY = $CPU2_AFFINITY" |
| 257 | dbg2 "CPU3_AFFINITY = $CPU3_AFFINITY" |
| 258 | } |
| 259 | |
| 260 | MT7981() |
| 261 | { |
| 262 | num_of_wifi=$1 |
| 263 | DEFAULT_RPS=0 |
| 264 | |
| 265 | #Physical IRQ# setting |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 266 | eth_irq_rx=221 |
| 267 | eth_irq_tx=229 |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 268 | wifi1_irq= |
| 269 | wifi2_irq= |
| 270 | wifi3_irq= |
developer | 4170321 | 2023-10-16 14:38:12 +0800 | [diff] [blame] | 271 | |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 272 | #AX3000 |
developer | 4170321 | 2023-10-16 14:38:12 +0800 | [diff] [blame] | 273 | if [[ "$WED_ENABLE" -eq "1" ]]; then |
| 274 | dbg2 "WED_ENABLE ON irq/iptable setting" |
| 275 | #TCP Binding |
| 276 | iptables -D FORWARD -p tcp -m conntrack --ctstate \ |
| 277 | RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
| 278 | iptables -I FORWARD -p tcp -m conntrack --ctstate \ |
| 279 | RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
| 280 | ip6tables -D FORWARD -p tcp -m conntrack --ctstate \ |
| 281 | RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
| 282 | ip6tables -I FORWARD -p tcp -m conntrack --ctstate \ |
| 283 | RELATED,ESTABLISHED -j FLOWOFFLOAD --hw |
| 284 | #UDP Binding |
| 285 | iptables -D FORWARD -p udp -j FLOWOFFLOAD --hw |
| 286 | iptables -I FORWARD -p udp -j FLOWOFFLOAD --hw |
| 287 | ip6tables -D FORWARD -p udp -j FLOWOFFLOAD --hw |
| 288 | ip6tables -I FORWARD -p udp -j FLOWOFFLOAD --hw |
| 289 | |
| 290 | if [[ "$WIFI_RADIO1" -eq "1" ]]; then |
| 291 | wifi1_irq=237 |
| 292 | fi |
| 293 | else |
| 294 | if [[ "$WIFI_RADIO1" -eq "1" ]]; then |
| 295 | wifi1_irq=245 |
| 296 | fi |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 297 | fi |
developer | 4170321 | 2023-10-16 14:38:12 +0800 | [diff] [blame] | 298 | |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 299 | # Please update the CPU binding in each cases. |
| 300 | # CPU#_AFFINITY="add binding irq number here" |
| 301 | # CPU#_RPS="add binding interface name here" |
| 302 | if [ "$num_of_wifi" = "0" ]; then |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 303 | CPU0_AFFINITY="$eth_irq_rx" |
| 304 | CPU1_AFFINITY="$eth_irq_tx" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 305 | |
| 306 | CPU0_RPS="$RPS_IF_LIST" |
| 307 | CPU1_RPS="$RPS_IF_LIST" |
| 308 | else |
| 309 | #we bound all wifi card to cpu0 and bound eth to cpu1 |
| 310 | CPU0_AFFINITY="$wifi1_irq $wifi2_irq $wifi3_irq" |
developer | 260bb6d | 2023-05-24 13:59:37 +0800 | [diff] [blame] | 311 | CPU1_AFFINITY="$eth_irq_rx $eth_irq_tx" |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 312 | |
| 313 | CPU0_RPS="$RPS_IF_LIST" |
| 314 | CPU1_RPS="$RPS_IF_LIST" |
| 315 | fi |
| 316 | dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY" |
| 317 | dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY" |
| 318 | } |
| 319 | |
| 320 | MT7622() |
| 321 | { |
| 322 | num_of_wifi=$1 |
| 323 | DEFAULT_RPS=0 |
| 324 | |
| 325 | #Physical IRQ# setting |
| 326 | eth0_irq=224 |
| 327 | eth1_irq=225 |
| 328 | wifi1_irq= |
| 329 | wifi2_irq= |
| 330 | wifi3_irq= |
| 331 | #AX1200 AX3200 |
| 332 | if [[ "$WIFI_RADIO1" -eq "1" ]]; then |
| 333 | wifi1_irq=211 |
| 334 | fi |
| 335 | #AX1800 AX3200 |
| 336 | if [[ "$WIFI_RADIO2" -eq "1" ]]; then |
| 337 | wifi2_irq=214 |
| 338 | fi |
| 339 | #AX3600 |
| 340 | if [[ "$WIFI_RADIO3" -eq "1" ]]; then |
| 341 | wifi3_irq=215 |
| 342 | fi |
| 343 | |
| 344 | # Please update the CPU binding in each cases. |
| 345 | # CPU#_AFFINITY="add binding irq number here" |
| 346 | # CPU#_RPS="add binding interface name here" |
| 347 | if [ "$num_of_wifi" == "0" ]; then |
| 348 | CPU0_AFFINITY="$eth0_irq" |
| 349 | CPU1_AFFINITY="$eth1_irq" |
| 350 | |
| 351 | CPU0_RPS="$RPS_IF_LIST" |
| 352 | CPU1_RPS="$RPS_IF_LIST" |
| 353 | else |
| 354 | #we bound all wifi card to cpu0 and bound eth to cpu1 |
| 355 | CPU0_AFFINITY="$wifi1_irq $wifi2_irq $wifi3_irq" |
| 356 | CPU1_AFFINITY="$eth0_irq $eth1_irq" |
| 357 | |
| 358 | CPU0_RPS="$RPS_IF_LIST" |
| 359 | CPU1_RPS="$RPS_IF_LIST" |
| 360 | fi |
| 361 | |
| 362 | dbg2 "CPU0_AFFINITY = $CPU0_AFFINITY" |
| 363 | dbg2 "CPU1_AFFINITY = $CPU1_AFFINITY" |
| 364 | } |
| 365 | |
| 366 | setup_model() |
| 367 | { |
| 368 | board=$(board_name) |
| 369 | num_of_wifi=$NUM_WIFI_CARD |
| 370 | |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 371 | if [[ $board == *"7988"* ]]; then |
developer | 69b0f42 | 2023-01-06 15:37:54 +0800 | [diff] [blame] | 372 | dbg "setup_model: MT7988 NUM_WIFI_CARD=$num_of_wifi" |
| 373 | MT7988 $num_of_wifi |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 374 | elif [[ $board == *"7986"* ]]; then |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 375 | dbg "setup_model: MT7986 NUM_WIFI_CARD=$num_of_wifi" |
| 376 | MT7986 $num_of_wifi |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 377 | elif [[ $board == *"7981"* ]]; then |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 378 | dbg "setup_model: MT7981 NUM_WIFI_CARD=$num_of_wifi" |
| 379 | MT7981 $num_of_wifi |
developer | d88f9b6 | 2023-02-02 09:51:21 +0800 | [diff] [blame] | 380 | elif [[ $board == *"7622"* ]]; then |
developer | 10cbf2c | 2022-02-09 10:39:21 +0800 | [diff] [blame] | 381 | dbg "setup_model: MT7622 NUM_WIFI_CARD=$num_of_wifi" |
| 382 | MT7622 $num_of_wifi |
| 383 | fi |
| 384 | } |
| 385 | |
| 386 | get_virtual_irq() |
| 387 | { |
| 388 | PHY_POS=`expr $NUM_OF_CPU + 3` #physical irq # position in /proc/interrups may vary with the number of CPU up |
| 389 | target_phy_irq=$1 |
| 390 | cat /proc/interrupts | sed 's/:/ /g'| awk '$1 ~ /^[0-9]+$/' | while read line |
| 391 | do |
| 392 | set -- $line |
| 393 | phy_irq=$(eval "echo \$$PHY_POS") |
| 394 | if [ $phy_irq == $target_phy_irq ]; then |
| 395 | echo $1 |
| 396 | return |
| 397 | fi |
| 398 | done |
| 399 | } |
| 400 | |
| 401 | set_rps_cpu_bitmap() |
| 402 | { |
| 403 | dbg2 "# Scan binding interfaces of each cpu" |
| 404 | # suppose the value of interface_var is null or hex |
| 405 | num=0 |
| 406 | while [ "$num" -lt "$NUM_OF_CPU" ];do |
| 407 | cpu_bit=$((2 ** $num)) |
| 408 | eval rps_list=\$CPU${num}_RPS |
| 409 | dbg2 "# CPU$num: rps_list=$rps_list" |
| 410 | for i in $rps_list; do |
| 411 | var=${VAR_PREFIX}_${i//-/_} |
| 412 | eval ifval=\$$var |
| 413 | dbg2 "[var val before] \$$var=$ifval" |
| 414 | if [ -z "$ifval" ]; then |
| 415 | eval $var=$cpu_bit |
| 416 | else |
| 417 | eval $var=`expr $ifval + $cpu_bit` |
| 418 | fi |
| 419 | eval ifval=\$$var |
| 420 | dbg2 "[rps val after]$i=$ifval" |
| 421 | done |
| 422 | num=`expr $num + 1` |
| 423 | done |
| 424 | } |
| 425 | |
| 426 | # $1: The default rps value. If rps of the interface is not setup, set $1 to it |
| 427 | set_rps_cpus() |
| 428 | { |
| 429 | dbg2 "# Setup rps of the interfaces, $RPS_IF_LIST." |
| 430 | for i in $RPS_IF_LIST; do |
| 431 | var=${VAR_PREFIX}_${i//-/_} |
| 432 | eval cpu_map=\$$var |
| 433 | if [ -d /sys/class/net/$i ]; then |
| 434 | if [ ! -z $cpu_map ]; then |
| 435 | cpu_map=`printf '%x' $cpu_map` |
| 436 | dbg "echo $cpu_map > /sys/class/net/$i/queues/rx-0/rps_cpus" |
| 437 | echo $cpu_map > /sys/class/net/$i/queues/rx-0/rps_cpus |
| 438 | elif [ ! -z $1 ]; then |
| 439 | dbg "echo $1 > /sys/class/net/$i/queues/rx-0/rps_cpus" |
| 440 | echo $1 > /sys/class/net/$i/queues/rx-0/rps_cpus |
| 441 | fi |
| 442 | fi |
| 443 | done |
| 444 | } |
| 445 | |
| 446 | set_smp_affinity() |
| 447 | { |
| 448 | dbg2 "# Setup affinity of each physical irq." |
| 449 | num=0 |
| 450 | while [ "$num" -lt "$NUM_OF_CPU" ];do |
| 451 | eval smp_list=\$CPU${num}_AFFINITY |
| 452 | for i in $smp_list; do |
| 453 | cpu_bit=$((2 ** $num)) |
| 454 | virq=$(get_virtual_irq $i) |
| 455 | #virq=$i |
| 456 | dbg2 "irq p2v $i --> $virq" |
| 457 | if [ ! -z $virq ]; then |
| 458 | dbg "echo $cpu_bit > /proc/irq/$virq/smp_affinity" |
| 459 | echo $cpu_bit > /proc/irq/$virq/smp_affinity |
| 460 | fi |
| 461 | done |
| 462 | num=`expr $num + 1` |
| 463 | done |
| 464 | } |
| 465 | |
| 466 | if [ "$1" = "dbg" ]; then |
| 467 | DBG=1 |
| 468 | elif [ "$1" = "dbg2" ]; then |
| 469 | DBG=2 |
| 470 | else |
| 471 | DBG=0 |
| 472 | fi |
| 473 | |
| 474 | # Usage: dbg "the output string" |
| 475 | dbg() |
| 476 | { |
| 477 | if [ "$DBG" -ge "1" ]; then |
| 478 | echo -e $1 |
| 479 | fi |
| 480 | } |
| 481 | |
| 482 | # Usage: dbg2 "the output string" |
| 483 | dbg2() |
| 484 | { |
| 485 | if [ "$DBG" -ge "2" ]; then |
| 486 | echo -e $1 |
| 487 | fi |
| 488 | } |
| 489 | |
| 490 | dbg "# RPS and AFFINITY Setting" |
| 491 | dbg "# NUM_OF_CPU=$NUM_OF_CPU" |
| 492 | VAR_PREFIX="autogen" |
| 493 | get_if_info |
| 494 | setup_model |
| 495 | set_rps_cpu_bitmap |
| 496 | set_rps_cpus $DEFAULT_RPS |
| 497 | set_smp_affinity |
| 498 | #end of file |