blob: a4257f1c65555a9a1daf0e53b1501e9632325ef5 [file] [log] [blame]
developerb9b4cd12022-10-11 13:18:59 +08001#!/bin/ash
2
3interface=$1 # phy0/phy1/ra0
developer13655da2023-01-10 19:53:25 +08004cmd_type=$2 # set/show/e2p/mac/dump
developerb9b4cd12022-10-11 13:18:59 +08005full_cmd=$3
6interface_ori=${interface}
developer13655da2023-01-10 19:53:25 +08007SOC_start_idx="0"
developer3f784572023-01-31 15:21:28 +08008SOC_end_idx="0"
developerc8796032023-08-09 10:28:15 +08009is_connac3="0"
developerb9b4cd12022-10-11 13:18:59 +080010
11work_mode="RUN" # RUN/PRINT/DEBUG
12iwpriv_file="/tmp/iwpriv_wrapper"
13interface_file="/tmp/interface"
14phy_idx=$(echo ${interface} | tr -dc '0-9')
developer9237f442024-06-14 17:13:04 +080015main_phy_idx=0
developerb9b4cd12022-10-11 13:18:59 +080016
17function do_cmd() {
18 case ${work_mode} in
19 "RUN")
20 eval "$1"
21 ;;
22 "PRINT")
23 echo "$1"
24 ;;
25 "DEBUG")
developerb9b4cd12022-10-11 13:18:59 +080026 echo "$1"
developerb403ad02022-11-08 10:16:29 +080027 eval "$1"
developerb9b4cd12022-10-11 13:18:59 +080028 ;;
29 esac
30}
31
32function print_debug() {
33 if [ "${work_mode}" = "DEBUG" ]; then
34 echo "$1"
35 fi
36}
37
38function write_dmesg() {
39 echo "$1" > /dev/kmsg
40}
41
42function record_config() {
43 local config=$1
44 local tmp_file=$3
45
developer9237f442024-06-14 17:13:04 +080046 # check it is SOC(mt7986)/Eagle/Kite or PCIE card (mt7915/7916), and write its config
developer3f784572023-01-31 15:21:28 +080047 if [ ${tmp_file} != ${interface_file} ]; then
developer13655da2023-01-10 19:53:25 +080048 if [ $phy_idx -lt $SOC_start_idx ]; then
developerb9b4cd12022-10-11 13:18:59 +080049 config="${config}_PCIE"
developer13655da2023-01-10 19:53:25 +080050 elif [ $phy_idx -ge $SOC_start_idx ]; then
51 config="${config}_SOC"
developerb9b4cd12022-10-11 13:18:59 +080052 fi
53 fi
54
55 if [ -f ${tmp_file} ]; then
56 if grep -q ${config} ${tmp_file}; then
57 sed -i "/${config}/c\\${config}=$2" ${tmp_file}
58 else
59 echo "${config}=$2" >> ${tmp_file}
60 fi
61 else
62 echo "${config}=$2" >> ${tmp_file}
63 fi
64}
65
66function get_config() {
67 local config=$1
68 local tmp_file=$2
69
70 if [ ! -f ${tmp_file} ]; then
71 echo ""
72 return
73 fi
74
developer9237f442024-06-14 17:13:04 +080075 # check it is SOC(mt7986)/Eagle/Kite or PCIE card (mt7915/7916), and write its config
developer3f784572023-01-31 15:21:28 +080076 if [ ${tmp_file} != ${interface_file} ]; then
developer13655da2023-01-10 19:53:25 +080077 if [ $phy_idx -lt $SOC_start_idx ]; then
developerb9b4cd12022-10-11 13:18:59 +080078 config="${config}_PCIE"
developer13655da2023-01-10 19:53:25 +080079 elif [ $phy_idx -ge $SOC_start_idx ]; then
80 config="${config}_SOC"
developerb9b4cd12022-10-11 13:18:59 +080081 fi
82 fi
83
84 if grep -q ${config} ${tmp_file}; then
85 echo "$(cat ${tmp_file} | grep ${config} | sed s/=/' '/g | cut -d " " -f 2)"
86 else
87 echo ""
88 fi
89}
90
developer3f784572023-01-31 15:21:28 +080091function parse_sku {
developer13655da2023-01-10 19:53:25 +080092 SOC_start_idx=$(get_config "STARTIDX" ${interface_file})
developer3f784572023-01-31 15:21:28 +080093 SOC_end_idx=$(get_config "ENDIDX" ${interface_file})
developerc8796032023-08-09 10:28:15 +080094 is_connac3=$(get_config "IS_CONNAC3" ${interface_file})
developerb9b4cd12022-10-11 13:18:59 +080095 local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom
developerc8796032023-08-09 10:28:15 +080096 if [ -z "${SOC_start_idx}" ] || [ -z "${SOC_end_idx}" ] || [ -z "${is_connac3}" ]; then
developerb9b4cd12022-10-11 13:18:59 +080097 if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then
developer13655da2023-01-10 19:53:25 +080098 SOC_start_idx="2"
developer3f784572023-01-31 15:21:28 +080099 SOC_end_idx="3"
developerc8796032023-08-09 10:28:15 +0800100 is_connac3="0"
developerb9b4cd12022-10-11 13:18:59 +0800101 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then
developer13655da2023-01-10 19:53:25 +0800102 SOC_start_idx="1"
developer3f784572023-01-31 15:21:28 +0800103 SOC_end_idx="2"
developerc8796032023-08-09 10:28:15 +0800104 is_connac3="0"
developer70180b02023-11-14 17:01:47 +0800105 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7981")" ]; then
106 SOC_start_idx="0"
107 SOC_end_idx="1"
108 is_connac3="0"
developerb9b4cd12022-10-11 13:18:59 +0800109 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then
developer13655da2023-01-10 19:53:25 +0800110 SOC_start_idx="0"
developer3f784572023-01-31 15:21:28 +0800111 SOC_end_idx="1"
developerc8796032023-08-09 10:28:15 +0800112 is_connac3="0"
developer13655da2023-01-10 19:53:25 +0800113 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7990")" ]; then
114 SOC_start_idx="0"
developer3f784572023-01-31 15:21:28 +0800115 SOC_end_idx="2"
developerc8796032023-08-09 10:28:15 +0800116 is_connac3="1"
117 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7992")" ]; then
118 SOC_start_idx="0"
119 SOC_end_idx="1"
120 is_connac3="1"
developerb9b4cd12022-10-11 13:18:59 +0800121 else
122 echo "Interface Conversion Failed!"
123 echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands"
developer70180b02023-11-14 17:01:47 +0800124 echo "For AX3000/AX6000:"
developer3f784572023-01-31 15:21:28 +0800125 echo " echo STARTIDX=0 >> ${interface_file}"
126 echo " echo ENDIDX=1 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800127 echo " echo IS_CONNAC3=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800128 echo "For AX7800:"
129 echo " echo STARTIDX=2 >> ${interface_file}"
130 echo " echo ENDIDX=3 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800131 echo " echo IS_CONNAC3=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800132 echo "For AX8400:"
133 echo " echo STARTIDX=1 >> ${interface_file}"
134 echo " echo ENDIDX=2 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800135 echo " echo IS_CONNAC3=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800136 echo "For Eagle:"
developerc8796032023-08-09 10:28:15 +0800137 echo " echo STARTIDX=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800138 echo " echo ENDIDX=2 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800139 echo " echo IS_CONNAC3=1 >> ${interface_file}"
140 echo "For Kite:"
141 echo " echo STARTIDX=0 >> ${interface_file}"
142 echo " echo ENDIDX=1 >> ${interface_file}"
143 echo " echo IS_CONNAC3=1 >> ${interface_file}"
developerb9b4cd12022-10-11 13:18:59 +0800144 exit 0
145 fi
developer13655da2023-01-10 19:53:25 +0800146 record_config "STARTIDX" ${SOC_start_idx} ${interface_file}
developer3f784572023-01-31 15:21:28 +0800147 record_config "ENDIDX" ${SOC_end_idx} ${interface_file}
developerc8796032023-08-09 10:28:15 +0800148 record_config "IS_CONNAC3" ${is_connac3} ${interface_file}
developerb9b4cd12022-10-11 13:18:59 +0800149 fi
developer3f784572023-01-31 15:21:28 +0800150}
developerb9b4cd12022-10-11 13:18:59 +0800151
developer3f784572023-01-31 15:21:28 +0800152function convert_interface {
developerc8796032023-08-09 10:28:15 +0800153 if [ ${is_connac3} == "0" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800154 if [[ $1 == "raix"* ]]; then
developer13655da2023-01-10 19:53:25 +0800155 phy_idx=1
156 elif [[ $1 == "rai"* ]]; then
developerb9b4cd12022-10-11 13:18:59 +0800157 phy_idx=0
158 elif [[ $1 == "rax"* ]]; then
developer13655da2023-01-10 19:53:25 +0800159 phy_idx=$((SOC_start_idx+1))
160 else
161 phy_idx=$SOC_start_idx
developerb9b4cd12022-10-11 13:18:59 +0800162 fi
developer13655da2023-01-10 19:53:25 +0800163
164 # convert phy index according to band idx
165 local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
166 if [ "${band_idx}" = "0" ]; then
167 if [[ $1 == "raix"* ]]; then
168 phy_idx=0
169 elif [[ $1 == "rax"* ]]; then
170 phy_idx=$SOC_start_idx
171 fi
172 elif [ "${band_idx}" = "1" ]; then
173 if [[ $1 == "rai"* ]]; then
174 # AX8400: mt7915 remain phy0
175 # AX7800: mt7916 becomes phy1
176 phy_idx=$((SOC_start_idx-1))
177 elif [[ $1 == "ra"* ]]; then
178 phy_idx=$((SOC_start_idx+1))
179 fi
180 fi
181 else
developer9237f442024-06-14 17:13:04 +0800182 # Connac 3 chips has different mapping method
developer13655da2023-01-10 19:53:25 +0800183 # phy0: ra0
184 # phy1: rai0
185 # phy2: rax0
developerb9b4cd12022-10-11 13:18:59 +0800186 if [[ $1 == "rai"* ]]; then
developer13655da2023-01-10 19:53:25 +0800187 phy_idx=1
188 elif [[ $1 == "rax"* ]]; then
189 phy_idx=2
190 else
191 phy_idx=0
developerb9b4cd12022-10-11 13:18:59 +0800192 fi
193 fi
194
195 interface="phy${phy_idx}"
196}
197
198function change_band_idx {
199 local new_idx=$1
200 local new_phy_idx=$phy_idx
201
202 local old_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
203
204
205 if [[ ${interface_ori} == "ra"* ]]; then
206 if [ -z "${old_idx}" ] || [ "${old_idx}" != "${new_idx}" ]; then
207 if [ "${new_idx}" = "0" ]; then
208 # raix0 & rai0 becomes rai0
209 if [[ $interface_ori == "rai"* ]]; then
210 new_phy_idx=0
211 # rax0 & ra0 becomes ra0
212 elif [[ $interface_ori == "ra"* ]]; then
developer13655da2023-01-10 19:53:25 +0800213 new_phy_idx=$SOC_start_idx
developerb9b4cd12022-10-11 13:18:59 +0800214 fi
215 elif [ "${new_idx}" = "1" ]; then
216 # raix0 & rai0 becomes raix0
217 if [[ $interface_ori == "rai"* ]]; then
developerc5ce7502022-12-19 11:33:22 +0800218 # For AX8400 => don't change phy idx
developer13655da2023-01-10 19:53:25 +0800219 if [ ${SOC_start_idx} != "1" ]; then
developerc5ce7502022-12-19 11:33:22 +0800220 new_phy_idx=1
221 fi
developerb9b4cd12022-10-11 13:18:59 +0800222 # rax0 & ra0 becomes rax0
223 elif [[ $interface_ori == "ra"* ]]; then
developer13655da2023-01-10 19:53:25 +0800224 new_phy_idx=$((SOC_start_idx+1))
developerb9b4cd12022-10-11 13:18:59 +0800225 fi
226 fi
227 fi
228
229 if [ ${new_phy_idx} != ${phy_idx} ]; then
230 do_ate_work "ATESTOP"
231 phy_idx=$new_phy_idx
232 interface="phy${phy_idx}"
233 do_ate_work "ATESTART"
234 fi
235 fi
236 record_config "ATECTRLBANDIDX" ${new_idx} ${iwpriv_file}
237}
238
239function simple_convert() {
240 if [ "$1" = "ATETXCNT" ]; then
241 echo "tx_count"
242 elif [ "$1" = "ATETXLEN" ]; then
243 echo "tx_length"
244 elif [ "$1" = "ATETXMCS" ]; then
245 echo "tx_rate_idx"
246 elif [ "$1" = "ATEVHTNSS" ]; then
247 echo "tx_rate_nss"
248 elif [ "$1" = "ATETXLDPC" ]; then
249 echo "tx_rate_ldpc"
250 elif [ "$1" = "ATETXSTBC" ]; then
251 echo "tx_rate_stbc"
252 elif [ "$1" = "ATEPKTTXTIME" ]; then
253 echo "tx_time"
254 elif [ "$1" = "ATEIPG" ]; then
255 echo "tx_ipg"
256 elif [ "$1" = "ATEDUTYCYCLE" ]; then
257 echo "tx_duty_cycle"
258 elif [ "$1" = "ATETXFREQOFFSET" ]; then
259 echo "freq_offset"
260 else
261 echo "undefined"
262 fi
263}
264
265function convert_tx_mode() {
developerc5ce7502022-12-19 11:33:22 +0800266 # Remove leading zeros
developer3f784572023-01-31 15:21:28 +0800267 local tx_mode=$(echo $1 | sed -r 's/0+([0-9]+)/\1/g')
developerc5ce7502022-12-19 11:33:22 +0800268
269 if [ "$tx_mode" = "0" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800270 echo "cck"
developerc5ce7502022-12-19 11:33:22 +0800271 elif [ "$tx_mode" = "1" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800272 echo "ofdm"
developerc5ce7502022-12-19 11:33:22 +0800273 elif [ "$tx_mode" = "2" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800274 echo "ht"
developerc5ce7502022-12-19 11:33:22 +0800275 elif [ "$tx_mode" = "4" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800276 echo "vht"
developerc5ce7502022-12-19 11:33:22 +0800277 elif [ "$tx_mode" = "8" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800278 echo "he_su"
developerc5ce7502022-12-19 11:33:22 +0800279 elif [ "$tx_mode" = "9" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800280 echo "he_er"
developerc5ce7502022-12-19 11:33:22 +0800281 elif [ "$tx_mode" = "10" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800282 echo "he_tb"
developerc5ce7502022-12-19 11:33:22 +0800283 elif [ "$tx_mode" = "11" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800284 echo "he_mu"
developerbb6ddff2023-03-08 17:22:32 +0800285 elif [ "$tx_mode" = "13" ]; then
286 echo "eht_su"
287 elif [ "$tx_mode" = "14" ]; then
288 echo "eht_tb"
289 elif [ "$tx_mode" = "15" ]; then
290 echo "eht_mu"
developerb9b4cd12022-10-11 13:18:59 +0800291 else
292 echo "undefined"
293 fi
294}
295
296function convert_gi {
297 local tx_mode=$1
298 local val=$2
299 local sgi="0"
300 local he_ltf="0"
301
302 case ${tx_mode} in
303 "ht"|"vht")
304 sgi=${val}
305 ;;
306 "he_su"|"he_er")
307 case ${val} in
308 "0")
309 ;;
310 "1")
311 he_ltf="1"
312 ;;
313 "2")
314 sgi="1"
315 he_ltf="1"
316 ;;
317 "3")
318 sgi="2"
319 he_ltf="2"
320 ;;
321 "4")
322 he_ltf="2"
323 ;;
324 *)
325 echo "unknown gi"
326 esac
327 ;;
328 "he_mu")
329 case ${val} in
330 "0")
331 he_ltf="2"
332 ;;
333 "1")
334 he_ltf="1"
335 ;;
336 "2")
337 sgi="1"
338 he_ltf="1"
339 ;;
340 "3")
341 sgi="2"
342 he_ltf="2"
343 ;;
344 *)
345 echo "unknown gi"
346 esac
347 ;;
348 "he_tb")
349 case ${val} in
350 "0")
351 sgi="1"
352 ;;
353 "1")
354 sgi="1"
355 he_ltf="1"
356 ;;
357 "2")
358 sgi="2"
359 he_ltf="2"
360 ;;
361 *)
362 echo "unknown gi"
363 esac
364 ;;
365 *)
366 print_debug "legacy mode no need gi"
367 esac
368
369 do_cmd "mt76-test ${interface} set tx_rate_sgi=${sgi} tx_ltf=${he_ltf}"
370}
371
developer05f3b2b2024-08-19 19:17:34 +0800372function convert_tm_cbw_to_nl {
373 local cbw=$1
374 local bw="NOHT"
375
376 case ${cbw} in
377 # TM_CBW_20MHZ
378 "0")
379 bw="20"
380 ;;
381 # TM_CBW_40MHZ
382 "1")
383 bw="40"
384 ;;
385 # TM_CBW_80MHZ
386 "2")
387 bw="80"
388 ;;
389 # TM_CBW_10MHZ
390 "3")
391 bw="10"
392 ;;
393 # TM_CBW_5MHZ
394 "4")
395 bw="5"
396 ;;
397 # TM_CBW_160MHZ
398 "5")
399 bw="160"
400 ;;
401 # TM_CBW_8080MHZ
402 "6")
403 bw="80p80"
404 ;;
405 # TM_CBW_320MHZ
406 "12")
407 bw="320"
408 ;;
409 esac
410
411 echo ${bw}
412}
413
414function convert_bw {
415 local system_bw=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
416 local data_bw=$(echo $1 | sed s/:/' '/g | cut -d " " -f 2)
417 # Convert TM_CBW to NL80211_CHAN_WIDTH
418 local tx_pkt_bw=$(convert_tm_cbw_to_nl ${data_bw})
419
420 record_config "ATETXBW" ${system_bw} ${iwpriv_file}
421
422 # apply per-packet bw
423 if [[ $1 == *":"* ]]; then
424 do_cmd "mt76-test phy${phy_idx} set tx_pkt_bw=${tx_pkt_bw}"
425 fi
426}
427
developerb9b4cd12022-10-11 13:18:59 +0800428function convert_channel {
developerb9b4cd12022-10-11 13:18:59 +0800429 local ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
developer05f3b2b2024-08-19 19:17:34 +0800430 local control_ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
431 local band=$(echo $1 | sed s/:/' '/g | cut -d " " -f 2)
432 local pri_sel=$(echo $1 | sed s/:/' '/g | cut -d " " -f 3)
433 local ctrl_band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
developerb9b4cd12022-10-11 13:18:59 +0800434 local bw=$(get_config "ATETXBW" ${iwpriv_file} | cut -d ":" -f 1)
developer05f3b2b2024-08-19 19:17:34 +0800435 local bw_str="20"
developerb9b4cd12022-10-11 13:18:59 +0800436 local base_chan=1
437 local control_freq=0
438 local base_freq=0
developerc5ce7502022-12-19 11:33:22 +0800439 local temp=$((phy_idx+1))
developerb9b4cd12022-10-11 13:18:59 +0800440
developerc5ce7502022-12-19 11:33:22 +0800441 # Handle ATECTRLBANDIDX
442 if [ ! -z ${ctrl_band_idx} ]; then
443 if [ "${ctrl_band_idx}" == "1" ] && [ ${band} == "0" ]; then
444 local temp=$(cat "/etc/config/wireless"| grep "option band" | sed -n ${temp}p | cut -c 15)
445 if [ "${temp}" == "2" ]; then
446 local band=0
447 elif [ "${temp}" == "5" ]; then
448 local band=1
449 elif [ "${temp}" == "6" ]; then
450 local band=2
451 else
452 echo "iwpriv wrapper band translate error!"
453 fi
454 else
455 # mt7915 in AX8400 case: band should be determined by only the input band
developer13655da2023-01-10 19:53:25 +0800456 if [ "${SOC_start_idx}" == "1" ] && [ ${phy_idx} == "0" ]; then
developerc5ce7502022-12-19 11:33:22 +0800457 local band=$((band))
458 else
459 local band=$((ctrl_band_idx * band))
460 fi
461 fi
developerb9b4cd12022-10-11 13:18:59 +0800462 fi
463
developer05f3b2b2024-08-19 19:17:34 +0800464 if [[ $1 == *":"* ]] && [ -n "${pri_sel}" ]; then
465 do_cmd "mt76-test phy${phy_idx} set tx_pri_sel=${pri_sel}"
466 fi
467
developerb9b4cd12022-10-11 13:18:59 +0800468 if [[ $1 != *":"* ]] || [ "${band}" = "0" ]; then
469 case ${bw} in
470 "1")
471 if [ "${ch}" -lt "3" ] || [ "${ch}" -gt "12" ]; then
developer05f3b2b2024-08-19 19:17:34 +0800472 bw_str="20"
developerb9b4cd12022-10-11 13:18:59 +0800473 else
developer05f3b2b2024-08-19 19:17:34 +0800474 bw_str="40"
475 control_ch=$(expr ${ch} - "2")
developerb9b4cd12022-10-11 13:18:59 +0800476 fi
477 ;;
developerb9b4cd12022-10-11 13:18:59 +0800478 esac
developer05f3b2b2024-08-19 19:17:34 +0800479 base_freq=2412
developerb9b4cd12022-10-11 13:18:59 +0800480 else
481 case ${bw} in
developerbb6ddff2023-03-08 17:22:32 +0800482 "12")
developer05f3b2b2024-08-19 19:17:34 +0800483 bw_str="320"
484 control_ch=$(expr ${ch} - "30")
developerbb6ddff2023-03-08 17:22:32 +0800485 ;;
developerb9b4cd12022-10-11 13:18:59 +0800486 "5")
developer05f3b2b2024-08-19 19:17:34 +0800487 bw_str="160"
488 control_ch=$(expr ${ch} - "14")
developerb9b4cd12022-10-11 13:18:59 +0800489 ;;
490 "2")
developer05f3b2b2024-08-19 19:17:34 +0800491 bw_str="80"
492 control_ch=$(expr ${ch} - "6")
developerb9b4cd12022-10-11 13:18:59 +0800493 ;;
494 "1")
developer05f3b2b2024-08-19 19:17:34 +0800495 bw_str="40"
496 control_ch=$(expr ${ch} - "2")
developerb9b4cd12022-10-11 13:18:59 +0800497 ;;
498 "0")
developer05f3b2b2024-08-19 19:17:34 +0800499 bw_str="20"
500 control_ch=${ch}
developerb9b4cd12022-10-11 13:18:59 +0800501 ;;
502 esac
developer05f3b2b2024-08-19 19:17:34 +0800503 if [ "${band}" = "1" ]; then
504 base_freq=5180
505 base_chan=36
506 else
507 base_freq=5955
508 fi
developerb9b4cd12022-10-11 13:18:59 +0800509 fi
510
developer05f3b2b2024-08-19 19:17:34 +0800511 local center_freq=$(((ch - base_chan) * 5 + base_freq))
512 local control_freq=$(((control_ch - base_chan) * 5 + base_freq))
513 if [ "${center_freq}" == "${control_freq}" ]; then
514 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str}"
515 else
516 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str} ${center_freq}"
517 fi
developerb9b4cd12022-10-11 13:18:59 +0800518}
519
520function convert_rxstat {
521 local res=$(do_cmd "mt76-test ${interface} dump stats")
522 local mdrdy=$(echo "${res}" | grep "rx_packets" | cut -d "=" -f 2)
523 local fcs_error=$(echo "${res}" | grep "rx_fcs_error" | cut -d "=" -f 2)
524 local rcpi=$(echo "${res}" | grep "last_rcpi" | cut -d "=" -f 2 | sed 's/,/ /g')
525 local ib_rssi=$(echo "${res}" | grep "last_ib_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
526 local wb_rssi=$(echo "${res}" | grep "last_wb_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
527 local rx_ok=$(expr ${mdrdy} - ${fcs_error})
528
529 write_dmesg "rcpi: ${rcpi}"
530 write_dmesg "fagc rssi ib: ${ib_rssi}"
531 write_dmesg "fagc rssi wb: ${wb_rssi}"
532 write_dmesg "all_mac_rx_mdrdy_cnt: ${mdrdy}"
533 write_dmesg "all_mac_rx_fcs_err_cnt: ${fcs_error}"
534 write_dmesg "all_mac_rx_ok_cnt : ${rx_ok}"
535}
536
537function set_mac_addr {
538 record_config ${cmd} ${param} ${iwpriv_file}
539
540 local addr1=$(get_config "ATEDA" ${iwpriv_file})
541 local addr2=$(get_config "ATESA" ${iwpriv_file})
542 local addr3=$(get_config "ATEBSSID" ${iwpriv_file})
543
544 if [ -z "${addr1}" ]; then
545 addr1="00:11:22:33:44:55"
546 fi
547 if [ -z "${addr2}" ]; then
548 addr2="00:11:22:33:44:55"
549 fi
550 if [ -z "${addr3}" ]; then
551 addr3="00:11:22:33:44:55"
552 fi
553
554 do_cmd "mt76-test phy${phy_idx} set mac_addrs=${addr1},${addr2},${addr3}"
555}
556
557function convert_ibf {
558 local cmd=$1
559 local param=$2
560 local new_cmd=""
561 local new_param=$(echo ${param} | sed s/":"/","/g)
562
563 case ${cmd} in
564 "ATETxBfInit")
565 new_cmd="init"
developerc5ce7502022-12-19 11:33:22 +0800566 new_param="1"
567 do_cmd "mt76-test phy${phy_idx} set state=idle"
568 ;;
569 "ATETxBfGdInit")
570 new_cmd="golden_init"
571 new_param="1"
developerb9b4cd12022-10-11 13:18:59 +0800572 do_cmd "mt76-test phy${phy_idx} set state=idle"
573 ;;
574 "ATEIBFPhaseComp")
575 new_cmd="phase_comp"
developerc5ce7502022-12-19 11:33:22 +0800576 new_param="${new_param}"
developerb9b4cd12022-10-11 13:18:59 +0800577 ;;
578 "ATEEBfProfileConfig")
579 new_cmd="ebf_prof_update"
580 ;;
581 "ATEIBfProfileConfig")
582 new_cmd="ibf_prof_update"
583 ;;
584 "ATEIBfInstCal")
585 new_cmd="phase_cal"
586 ;;
587 "ATEIBfGdCal")
developera46f6132024-03-26 14:09:54 +0800588 local group=${new_param:0:2}
589 local group_l_m_h=${new_param:3:2}
590 local band_idx=${new_param:6:2}
591 local cal_type=${new_param:9:2}
592 local version=${new_param:12}
593 local lna_level="00"
594
595 # only ibf 2.0 will set version, so add null check for backward compatibility
596 if [ -z $version ]; then
597 version="00"
598 fi
599
developerb9b4cd12022-10-11 13:18:59 +0800600 new_cmd="phase_cal"
developera46f6132024-03-26 14:09:54 +0800601 new_param="${group},${group_l_m_h},${band_idx},${cal_type},${lna_level},${version}"
developerb9b4cd12022-10-11 13:18:59 +0800602 ;;
603 "TxBfTxApply")
604 new_cmd="apply_tx"
605 ;;
606 "ATETxPacketWithBf")
607 local bf_on=${new_param:0:2}
608 local aid="01"
609 local wlan_idx=${new_param:3:2}
610 local update="00"
developera46f6132024-03-26 14:09:54 +0800611 local tx_count=${new_param:6}
developerb9b4cd12022-10-11 13:18:59 +0800612
613 new_cmd="tx_prep"
614 new_param="${bf_on},${aid},${wlan_idx},${update}"
developera46f6132024-03-26 14:09:54 +0800615 if [ "${tx_count}" = "00" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800616 new_param="${new_param} aid=1 tx_count=10000000 tx_length=1024"
617 else
developera46f6132024-03-26 14:09:54 +0800618 new_param="${new_param} aid=1 tx_count=${tx_count} tx_length=1024"
developerb9b4cd12022-10-11 13:18:59 +0800619 fi
620 do_cmd "mt76-test phy${phy_idx} set state=idle"
621 ;;
622 "TxBfProfileData20MAllWrite")
623 new_cmd="prof_update_all"
624 ;;
625 "ATEIBFPhaseE2pUpdate")
626 new_cmd="e2p_update"
627 ;;
developerc5ce7502022-12-19 11:33:22 +0800628 "ATEIBFPhaseVerify")
629 local group=${new_param:0:2}
630 local group_l_m_h=${new_param:3:2}
631 local band_idx=${new_param:6:2}
632 local phase_cal_type=${new_param:9:2}
633 local LNA_gain_level=${new_param:12:2}
634 local read_from_e2p=${new_param:15:2}
635
636 do_cmd "mt76-test phy${phy_idx} set txbf_act=phase_comp txbf_param=1,${band_idx},${group},${read_from_e2p},0"
637 new_cmd="phase_cal"
638 new_param="${group},${group_l_m_h},${band_idx},${phase_cal_type},${LNA_gain_level}"
639 ;;
640 "TxBfProfileTagRead")
641 new_cmd="pfmu_tag_read"
642 ;;
643 "TxBfProfileTagWrite")
644 new_cmd="pfmu_tag_write"
645 ;;
646 "TxBfProfileTagInValid")
647 new_cmd="set_invalid_prof"
648 ;;
649 "StaRecBfRead")
650 new_cmd="sta_rec_read"
651 ;;
652 "TriggerSounding")
653 new_cmd="trigger_sounding"
654 ;;
655 "StopSounding")
656 new_cmd="stop_sounding"
657 new_param="0"
658 ;;
developer7af0f762023-05-22 15:16:16 +0800659 "TxBfTxCmd")
660 new_cmd="txcmd"
661 ;;
developerc5ce7502022-12-19 11:33:22 +0800662 "ATEConTxETxBfGdProc")
663 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
664 local tx_rate_idx=${new_param:3:2}
665 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
666 local channel=${new_param:9:3}
667 local channel2=${new_param:13:3}
668 local band=${new_param:17}
669
670 new_cmd="ebf_golden_init"
671 do_ate_work "ATESTART"
672 do_cmd "mt76-test phy${phy_idx} set state=idle"
673 record_config "ATETXBW" ${bw} ${iwpriv_file}
674 convert_channel "${channel}:${band}"
675 if [ "${bw}" = "5" ]; then
676 new_param="1,1"
677 else
678 new_param="1,0"
679 fi
680 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=${tx_rate_mode} tx_rate_idx=${tx_rate_idx} tx_rate_sgi=0"
681 ;;
682 "ATEConTxETxBfInitProc")
683 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
684 local tx_rate_idx=${new_param:3:2}
685 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
686 local tx_rate_nss=${new_param:9:2}
687 local tx_stream=${new_param:12:2}
688 local tx_power=${new_param:15:2}
developer7af0f762023-05-22 15:16:16 +0800689 local channel=$(echo ${new_param:18:3} | sed 's/^0//')
developerc5ce7502022-12-19 11:33:22 +0800690 local channel2=${new_param:22:3}
691 local band=${new_param:26:1}
developer7af0f762023-05-22 15:16:16 +0800692 local tx_length=$(echo ${new_param:28:5} | sed 's/^0//')
developerc5ce7502022-12-19 11:33:22 +0800693
694 new_cmd="ebf_init"
695 do_ate_work "ATESTART"
696 do_cmd "mt76-test phy${phy_idx} set state=idle"
697 record_config "ATETXBW" ${bw} ${iwpriv_file}
698 convert_channel "${channel}:${band}"
699 new_param="1"
700 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=${tx_rate_mode} tx_rate_idx=${tx_rate_idx} tx_rate_nss=${tx_rate_nss} tx_rate_sgi=0 tx_rate_ldpc=1 tx_power=${tx_power},0,0,0 tx_count=10000000 tx_length=${tx_length} tx_ipg=4"
701 ;;
developerb9b4cd12022-10-11 13:18:59 +0800702 *)
703 esac
704
705 do_cmd "mt76-test phy${phy_idx} set txbf_act=${new_cmd} txbf_param=${new_param}"
706
707 if [ "${cmd}" = "ATETxPacketWithBf" ]; then
708 do_cmd "mt76-test phy${phy_idx} set state=tx_frames"
developerc5ce7502022-12-19 11:33:22 +0800709 elif [ "${cmd}" = "ATEConTxETxBfInitProc" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800710 local wlan_idx="1"
developerc8796032023-08-09 10:28:15 +0800711 if [ ${is_connac3} == "1" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800712 local wlan_idx=$((phy_idx+1))
713 fi
developerc5ce7502022-12-19 11:33:22 +0800714 do_cmd "mt76-test phy${phy_idx} set aid=1"
715 do_cmd "mt76-test phy${phy_idx} set txbf_act=stop_sounding txbf_param=1"
716 do_cmd "mt76-test phy${phy_idx} set txbf_act=update_ch txbf_param=1"
717 do_cmd "mt76-test phy${phy_idx} set txbf_act=ebf_prof_update txbf_param=0,0,0"
developerbb6ddff2023-03-08 17:22:32 +0800718 do_cmd "mt76-test phy${phy_idx} set txbf_act=apply_tx txbf_param=${wlan_idx},1,0,0,0"
developerc8796032023-08-09 10:28:15 +0800719 if [ ${is_connac3} == "1" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800720 do_cmd "mt76-test phy${phy_idx} set txbf_act=txcmd txbf_param=1,1,1"
721 fi
developerc5ce7502022-12-19 11:33:22 +0800722 do_cmd "mt76-test phy${phy_idx} set txbf_act=pfmu_tag_read txbf_param=0,1"
developerbb6ddff2023-03-08 17:22:32 +0800723 do_cmd "mt76-test phy${phy_idx} set txbf_act=sta_rec_read txbf_param=${wlan_idx}"
724 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=0,1,0,${wlan_idx},0,0,0"
725 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=2,1,ff,${wlan_idx},0,0,0"
developerc5ce7502022-12-19 11:33:22 +0800726 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
727 elif [ "${cmd}" = "ATEConTxETxBfGdProc" ]; then
728 do_cmd "mt76-test phy${phy_idx} set aid=1"
729 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
730 elif [ "${cmd}" = "ATETxBfInit" ]; then
731 do_cmd "mt76-test phy${phy_idx} set aid=1"
732 elif [ "${cmd}" = "ATETxBfGdInit" ]; then
733 do_cmd "mt76-test phy${phy_idx} set aid=1"
developerf9b00212023-07-31 12:27:06 +0800734 elif [ "${cmd}" = "ATEIBFPhaseE2pUpdate" ]; then
735 do_cmd "atenl -i phy${phy_idx} -c \"eeprom ibf sync\""
developerb9b4cd12022-10-11 13:18:59 +0800736 fi
737}
738
developer9a587882023-07-17 11:11:44 +0800739function convert_ruinfo {
740 local new_param=$1
741
742 do_cmd "mt76-test phy${phy_idx} set state=idle"
743 while [ -n "$new_param" ]
744 do
745 [ ${new_param:1:1} = ':' ] && {
746 new_param=${new_param:2}
747 }
748 local oIFS="$IFS"; IFS=":"; set -- $new_param; IFS="$oIFS"
749
750 parsing_ruinfo $new_param
751 new_param=${new_param:${#1}+1}
752 done
753}
754
755function parsing_ruinfo {
756 local new_param=$1
757 local oIFS="$IFS"; IFS="-:"; set -- $new_param; IFS="$oIFS"
758
759 # $7 is Start spatial stream and it should be 0, $9 is alpha, not used
760 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=he_mu tx_rate_sgi=0 tx_ltf=0 ru_alloc=$1 aid=$2 ru_idx=$3\
761 tx_rate_idx=$4 tx_rate_ldpc=$5 tx_rate_nss=$6 tx_length=$8"
762}
763
developerb403ad02022-11-08 10:16:29 +0800764function convert_dfs {
765 local cmd=$1
766 local param=$2
767
768 case ${cmd} in
769 "DfsRxCtrl")
770 local offchan_ch="$(echo $param | cut -d ':' -f1)"
771 local offchan_bw="$(echo $param | cut -d ':' -f2)"
772
developerc9333e12023-04-06 18:07:42 +0800773 if [ "$offchan_bw" = "0" ]; then
774 offchan_bw="20"
775 elif [ "$offchan_bw" = "1" ]; then
776 offchan_bw="40"
777 elif [ "$offchan_bw" = "2" ]; then
778 offchan_bw="80"
779 elif [ "$offchan_bw" = "3" ]; then
780 offchan_bw="160"
781 fi
developerb403ad02022-11-08 10:16:29 +0800782
developerc9333e12023-04-06 18:07:42 +0800783 do_cmd "mt76-test phy${phy_idx} set state=idle"
784 do_cmd "mt76-test phy${phy_idx} set offchan_ch=${offchan_ch} offchan_bw=${offchan_bw}"
developerb403ad02022-11-08 10:16:29 +0800785 ;;
786 "DfsRxHist")
787 local ipi_th="$(echo $param | cut -d ':' -f 1)"
788 local ipi_period="$(echo $param | cut -d ':' -f 2)"
developerc9333e12023-04-06 18:07:42 +0800789 local ipi_antenna="$(echo $param | cut -d ':' -f 3)"
developerb403ad02022-11-08 10:16:29 +0800790
developerc9333e12023-04-06 18:07:42 +0800791 if [ -z $ipi_antenna ]; then
792 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period}"
793 else
794 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period} ipi_antenna_idx=${ipi_antenna}"
795 fi
developerb403ad02022-11-08 10:16:29 +0800796 ;;
797 *)
798 esac
799}
800
developerb9b4cd12022-10-11 13:18:59 +0800801function do_ate_work() {
802 local ate_cmd=$1
803
804 case ${ate_cmd} in
805 "ATESTART")
806 local if_str=$(ifconfig | grep mon${phy_idx})
807
808 if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
809 echo "ATE already starts."
810 else
811 do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
developer3f784572023-01-31 15:21:28 +0800812
813 if [ $phy_idx -ge $SOC_start_idx ]; then
814 local end_idx=$SOC_end_idx
815 local start_idx=$SOC_start_idx
816 else
817 local end_idx=$((SOC_start_idx-1))
818 local start_idx="0"
819 fi
820
821 for phy_index in $( seq $start_idx $end_idx )
822 do
823 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
824 local prev_phy_index=$((phy_index-1))
825 local if_num=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep -c Interface)
826 local j="1"
827 # avoid del_if_count reset to 0 when start ate on another band in dbdc case
828 local del_if_count=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
829 if [ -z "${del_if_count}" ]; then
830 local del_if_count="0"
831 fi
832
833 for if_count in $( seq 1 $if_num )
834 do
835 local del_if=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep Interface | sed -n ${j}p | cut -d " " -f 2)
836 if [ ! -z "${del_if}" ] && [[ "$del_if" != *"mon"* ]]; then
837 do_cmd "iw dev ${del_if} del"
838 del_if_count=$((del_if_count+1))
839 # handle the case of multiple interface in a phy
840 record_config "DEL_IF${phy_index}-${del_if_count}" ${del_if} ${interface_file}
841 else
842 # j add 1 to skip mon interface
843 j=$((j+1))
844 fi
845 done
846 record_config "DEL_IF${phy_index}_NUM" ${del_if_count} ${interface_file}
847 done
848
developerb9b4cd12022-10-11 13:18:59 +0800849 do_cmd "ifconfig mon${phy_idx} up"
850 do_cmd "iw reg set VV"
851 fi
852 ;;
853 "ATESTOP")
854 local if_str=$(ifconfig | grep mon${phy_idx})
855
856 if [ -z "${if_str}" -a "${if_str}" != " " ]; then
857 echo "ATE does not start."
858 else
859 do_cmd "mt76-test ${interface} set state=off"
860 do_cmd "iw dev mon${phy_idx} del"
developer3f784572023-01-31 15:21:28 +0800861
862 if [ $phy_idx -ge $SOC_start_idx ]; then
863 local end_idx=$SOC_end_idx
864 local start_idx=$SOC_start_idx
865 else
866 local end_idx=$((SOC_start_idx-1))
867 local start_idx="0"
868 fi
869
870 # first check its phy and dbdc band phy has monitor interface or not
871 # if has at lease one mon interface, then skip adding back normal interface
872 local has_mon="0"
873 for phy_index in $( seq $start_idx $end_idx )
874 do
875 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
876 local prev_phy_index=$((phy_index-1))
877 local has_mon_phy=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep "Interface mon")
878 # if this phy interface has mon interface
879 if [ ! -z "${has_mon_phy}" ]; then
880 local has_mon="1"
881 fi
882 done
883
884 for phy_index in $( seq $start_idx $end_idx )
885 do
886 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
887 local prev_phy_index=$((phy_index-1))
888 local j="1"
889 local add_if_num=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
890 if [ -z "${add_if_num}" ]; then
891 local add_if_num="0"
892 fi
893 # if this phy interface (including its dbdc phy) has no mon interface and can find deleted interface in file, then add it back
894 if [ "${has_mon}" == "0" ] && [ $add_if_num -ge "1" ]; then
895 local if_index=$add_if_num
896 # add interface backwards
897 while [ $if_index -gt "0" ]
898 do
899 local add_if=$(get_config "DEL_IF${phy_index}-${if_index}" ${interface_file})
900 do_cmd "iw phy phy${phy_index} interface add ${add_if} type managed"
901 # remove the deleted interface in interface_file since it is added back
902 sed -i "/DEL_IF${phy_index}-${if_index}=/d" ${interface_file}
903 if_index=$((if_index-1))
904 done
905 # remove the number of deleted interface in interface_file since it is all added back
906 sed -i "/DEL_IF${phy_index}_NUM=/d" ${interface_file}
907 fi
908 done
909
developerb9b4cd12022-10-11 13:18:59 +0800910 do_cmd "mt76-test ${interface} set aid=0"
911 fi
912
developer13655da2023-01-10 19:53:25 +0800913 if [ ${phy_idx} -lt ${SOC_start_idx} ]; then
developerb9b4cd12022-10-11 13:18:59 +0800914 sed -i '/_PCIE=/d' ${iwpriv_file}
developer13655da2023-01-10 19:53:25 +0800915 elif [ ${phy_idx} -ge ${SOC_start_idx} ]; then
916 sed -i '/_SOC=/d' ${iwpriv_file}
developerb9b4cd12022-10-11 13:18:59 +0800917 fi
918 ;;
919 "TXCOMMIT")
920 do_cmd "mt76-test ${interface} set aid=1"
921 ;;
922 "TXFRAME")
923 do_cmd "mt76-test ${interface} set state=tx_frames"
924 ;;
925 "TXSTOP"|"RXSTOP")
926 do_cmd "mt76-test ${interface} set state=idle"
927 ;;
928 "TXREVERT")
929 do_cmd "mt76-test ${interface} set aid=0"
930 ;;
931 "RXFRAME")
932 do_cmd "mt76-test ${interface} set state=rx_frames"
933 ;;
934 "TXCONT")
935 do_cmd "mt76-test ${interface} set state=tx_cont"
936 ;;
937 "GROUPREK")
938 do_cmd "mt76-test ${interface} set state=group_prek"
939 do_cmd "atenl -i ${interface} -c \"eeprom precal sync group\""
940 ;;
941 "GROUPREKDump")
942 do_cmd "mt76-test ${interface} set state=group_prek_dump"
943 ;;
944 "GROUPREKClean")
945 do_cmd "mt76-test ${interface} set state=group_prek_clean"
946 do_cmd "atenl -i ${interface} -c \"eeprom precal group clean\""
947 ;;
948 "DPD2G")
949 do_cmd "mt76-test ${interface} set state=dpd_2g"
950 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 2g\""
951 ;;
952 "DPD5G")
953 do_cmd "mt76-test ${interface} set state=dpd_5g"
954 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 5g\""
955 ;;
956 "DPD6G")
957 do_cmd "mt76-test ${interface} set state=dpd_6g"
958 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 6g\""
959 ;;
960 "DPDDump")
961 do_cmd "mt76-test ${interface} set state=dpd_dump"
962 ;;
963 "DPDClean")
964 do_cmd "mt76-test ${interface} set state=dpd_clean"
965 do_cmd "atenl -i ${interface} -c \"eeprom precal dpd clean\""
966 ;;
967 *)
968 print_debug "skip ${ate_cmd}"
969 ;;
970 esac
971}
972
developer13655da2023-01-10 19:53:25 +0800973function dump_usage {
974 echo "Usage:"
975 echo " mwctl <interface> set csi ctrl=<opt1>,<opt2>,<opt3>,<opt4> (macaddr=<macaddr>)"
976 echo " mwctl <interface> set csi interval=<interval (us)>"
977 echo " mwctl <interface> dump csi <packet num> <filename>"
978 echo " mwctl <interface> set amnt <index>(0x0~0xf) <mac addr>(xx:xx:xx:xx:xx:xx)"
979 echo " mwctl <interface> dump amnt <index> (0x0~0xf or 0xff)"
980 echo " mwctl <interface> set ap_rfeatures he_gi=<val>"
981 echo " mwctl <interface> set ap_rfeatures he_ltf=<val>"
982 echo " mwctl <interface> set ap_rfeatures trig_type=<enable>,<val> (val: 0-7)"
983 echo " mwctl <interface> set ap_rfeatures ack_policy=<val> (val: 0-4)"
984 echo " mwctl <interface> set ap_wireless fixed_mcs=<val>"
985 echo " mwctl <interface> set ap_wireless ofdma=<val> (0: disable, 1: DL, 2: UL)"
986 echo " mwctl <interface> set ap_wireless nusers_ofdma=<val>"
987 echo " mwctl <interface> set ap_wireless ppdu_type=<val> (0: SU, 1: MU, 4: LEGACY)"
988 echo " mwctl <interface> set ap_wireless add_ba_req_bufsize=<val>"
989 echo " mwctl <interface> set ap_wireless mimo=<val> (0: DL, 1: UL)"
990 echo " mwctl <interface> set ap_wireless ampdu=<enable>"
991 echo " mwctl <interface> set ap_wireless amsdu=<enable>"
992 echo " mwctl <interface> set ap_wireless cert=<enable>"
developer2c78ce72023-02-24 11:26:12 +0800993 echo " mwctl <interface> set mu onoff=<val> (bitmap- UL MU-MIMO(bit3), DL MU-MIMO(bit2), UL OFDMA(bit1), DL OFDMA(bit0))"
developer13655da2023-01-10 19:53:25 +0800994 echo " mwctl <interface> dump phy_capa"
995}
996
developer092b55c2023-01-18 18:20:58 +0800997function register_handler {
998
developer9237f442024-06-14 17:13:04 +0800999 local offset=$1
1000 local val=$2
1001 local cmd=$3
developer092b55c2023-01-18 18:20:58 +08001002 local w_cmd="write"
1003
developer9237f442024-06-14 17:13:04 +08001004 regidx=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/regidx
1005 regval=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/regval
developer092b55c2023-01-18 18:20:58 +08001006
1007 echo ${offset} > ${regidx}
1008 if [[ "${cmd}" == "${w_cmd}" ]]; then
1009 echo ${val} > ${regval}
1010 fi
1011
1012 res=$(cat ${regval} | cut -d 'x' -f 2)
1013 printf "%s mac:[%s]:%s\n" ${interface_ori} ${offset} ${res}
1014}
1015
developerb9b4cd12022-10-11 13:18:59 +08001016# main start here
developer3f784572023-01-31 15:21:28 +08001017parse_sku
developer13655da2023-01-10 19:53:25 +08001018if [ -z ${interface} ]; then
1019 dump_usage
1020 exit
1021elif [[ ${interface} == "ra"* ]]; then
developerb9b4cd12022-10-11 13:18:59 +08001022 convert_interface $interface
developerbb6ddff2023-03-08 17:22:32 +08001023elif [[ ${interface} == "phy" ]]; then
1024 # handle mwctl phy phy0 e2p ... case
1025 interface=$2
1026 cmd_type=$3
1027 full_cmd=$4
developerb9b4cd12022-10-11 13:18:59 +08001028fi
1029
developer9237f442024-06-14 17:13:04 +08001030# get main phy idx
1031if [ "${phy_idx}" -ge "${SOC_start_idx}" ]; then
1032 main_phy_idx=${SOC_start_idx}
1033fi
1034
developerb9b4cd12022-10-11 13:18:59 +08001035tmp_work_mode=$(get_config "WORKMODE" ${iwpriv_file})
1036
1037if [ ! -z ${tmp_work_mode} ]; then
1038 work_mode=${tmp_work_mode}
1039fi
1040
1041cmd=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 1)
1042param=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 2)
developera20cdc22024-05-31 18:57:31 +08001043mld=$(iw dev | grep 'link ID')
developerb9b4cd12022-10-11 13:18:59 +08001044
1045if [ "${cmd_type}" = "set" ]; then
1046 skip=0
1047 case ${cmd} in
developer13655da2023-01-10 19:53:25 +08001048 ## In wifi 7 chipset, testmode & vendor command both use mwctl
1049 ## Therefore this wrapper would translate it to either mt76-test or mt76-vendor based on the attribute of the command
1050 ## Translate to mt76-vendor command
developer327aa322023-07-10 13:49:56 +08001051 "csi"|"amnt"|"ap_rfeatures"|"ap_wireless"|"mu"|"set_muru_manual_config")
developera20cdc22024-05-31 18:57:31 +08001052 cert_cmd="$*"
developer42c7a432024-07-12 14:39:29 +08001053
1054 if [ ! -z "$mld" ]; then
1055 mld_interface=$(iw dev | grep Interface | awk '{print $2}')
1056 if [ $cmd == "ap_rfeatures" ] || [ "$cmd" == "ap_wireless" ]; then
1057
1058 band_number=$(echo "$cert_cmd" | grep -o 'band[0-9]*')
1059
1060 links_info_base="/sys/kernel/debug/ieee80211/phy0/netdev"
1061 links_info_intf="${mld_interface}/mt76_links_info"
1062 links_info_cmd="${links_info_base}:${links_info_intf}"
1063
1064 band_link_id_info=$(
1065 cat "$links_info_cmd" | grep "${band_number}_link_id"
1066 )
1067 band_link_id=$(
1068 echo "$band_link_id_info" | awk -F'=' '{print $2}' | tr -d ' '
1069 )
1070
1071 cmd_w_link_id=$(echo $* | sed "s/band[0-9]/& -l ${band_link_id}/g")
1072 cert_cmd=${cmd_w_link_id}
1073
1074 fi
1075 ## convert bandX to mld interface name
1076 cert_cmd="$(echo ${cert_cmd} | sed 's/band[0-9]/${mld_interface}/')"
1077 fi
1078
developerc8796032023-08-09 10:28:15 +08001079 if [ ${is_connac3} == "1" ]; then
developera20cdc22024-05-31 18:57:31 +08001080 hostapd_cmd="$(echo $cert_cmd | sed 's/set/raw/')"
developer1475cf22023-05-05 13:45:43 +08001081 do_cmd "hostapd_cli -i $hostapd_cmd"
developerbb6ddff2023-03-08 17:22:32 +08001082 else
developera20cdc22024-05-31 18:57:31 +08001083 do_cmd "mt76-vendor $cert_cmd"
developerbb6ddff2023-03-08 17:22:32 +08001084 fi
1085 skip=1
developer13655da2023-01-10 19:53:25 +08001086 ;;
developer42c7a432024-07-12 14:39:29 +08001087 "txbftxsndinfo"|"TxBfTxSndInfo")
1088 cert_cmd="$*"
1089 cmd_setting=$(echo $cert_cmd | awk -F'=' '{print $2}')
1090 snd_cmd_base="/sys/kernel/debug/ieee80211/phy0/mt76/band0/bf_txsnd_info"
1091 mt76_snd_cmd="echo $cmd_setting > $snd_cmd_base"
1092 do_cmd "$mt76_snd_cmd"
1093 skip=1
1094 ;;
1095 "muruDbgInfo")
1096 cert_cmd="$*"
1097 cmd_setting=$(echo $cert_cmd | awk -F'=' '{print $2}')
1098 muru_cmd_base="/sys/kernel/debug/ieee80211/phy0/mt76/muru_dbg"
1099 mt76_muru_cmd="echo $cmd_setting > $muru_cmd_base"
1100 do_cmd "$mt76_muru_cmd"
1101 skip=1
1102 ;;
developerb9b4cd12022-10-11 13:18:59 +08001103 "ATE")
1104 do_ate_work ${param}
1105
1106 skip=1
1107 ;;
1108 "ATETXCNT"|"ATETXLEN"|"ATETXMCS"|"ATEVHTNSS"|"ATETXLDPC"|"ATETXSTBC"| \
1109 "ATEPKTTXTIME"|"ATEIPG"|"ATEDUTYCYCLE"|"ATETXFREQOFFSET")
1110 cmd_new=$(simple_convert ${cmd})
1111 if [ "${param_new}" = "undefined" ]; then
1112 echo "unknown cmd: ${cmd}"
1113 exit
1114 fi
1115 param_new=${param}
developerc5ce7502022-12-19 11:33:22 +08001116 if [ "${cmd}" = "ATETXCNT" ] && [ "${param}" = "0" ]; then
developer15c355d2023-03-21 17:28:34 +08001117 param_new="0xFFFFFFFF"
developerc5ce7502022-12-19 11:33:22 +08001118 fi
developerb9b4cd12022-10-11 13:18:59 +08001119 ;;
1120 "ATETXANT"|"ATERXANT")
1121 cmd_new="tx_antenna"
1122 param_new=${param}
1123 ;;
1124 "ATETXGI")
developerc8796032023-08-09 10:28:15 +08001125 if [ ${is_connac3} == "0" ]; then
developerbb6ddff2023-03-08 17:22:32 +08001126 tx_mode=$(convert_tx_mode $(get_config "ATETXMODE" ${iwpriv_file}))
1127 convert_gi ${tx_mode} ${param}
1128 skip=1
1129 else
1130 cmd_new="tx_rate_sgi"
1131 param_new=${param}
1132 fi
developerb9b4cd12022-10-11 13:18:59 +08001133 ;;
1134 "ATETXMODE")
1135 cmd_new="tx_rate_mode"
1136 param_new=$(convert_tx_mode ${param})
1137 if [ "${param_new}" = "undefined" ]; then
1138 echo "unknown tx mode"
1139 echo "0:cck, 1:ofdm, 2:ht, 4:vht, 8:he_su, 9:he_er, 10:he_tb, 11:he_mu"
1140 exit
1141 else
1142 record_config ${cmd} ${param} ${iwpriv_file}
1143 fi
1144 ;;
developerbb6ddff2023-03-08 17:22:32 +08001145 "ATETXPOW0"|"ATETXPOW1"|"ATETXPOW2"|"ATETXPOW3"|"ATETXPOW")
developerb9b4cd12022-10-11 13:18:59 +08001146 cmd_new="tx_power"
developerbb6ddff2023-03-08 17:22:32 +08001147 if [ "${param}" == "127" ]; then
1148 # for iTest verification
1149 exit
1150 fi
developerb9b4cd12022-10-11 13:18:59 +08001151 param_new="${param},0,0,0"
1152 ;;
developerbb6ddff2023-03-08 17:22:32 +08001153 "ATEMUAID")
1154 cmd_new="aid"
1155 param_new=${param}
1156 ;;
developerb9b4cd12022-10-11 13:18:59 +08001157 "ATETXBW")
developer05f3b2b2024-08-19 19:17:34 +08001158 convert_bw ${param}
developerb9b4cd12022-10-11 13:18:59 +08001159 skip=1
1160 ;;
1161 "ATECHANNEL")
1162 convert_channel ${param}
1163 skip=1
1164 ;;
1165 "ATERXSTAT")
1166 convert_rxstat
1167 skip=1
1168 ;;
1169 "ATECTRLBANDIDX")
1170 change_band_idx ${param}
1171 skip=1
1172 ;;
1173 "ATEDA"|"ATESA"|"ATEBSSID")
1174 set_mac_addr ${cmd} ${param}
1175 skip=1
1176 ;;
developerb403ad02022-11-08 10:16:29 +08001177 "DfsRxCtrl"|"DfsRxHist")
1178 convert_dfs ${cmd} ${param}
1179 skip=1
1180 ;;
developerc5ce7502022-12-19 11:33:22 +08001181 "ATETxBfInit"|"ATETxBfGdInit"|"ATEIBFPhaseComp"|"ATEEBfProfileConfig"|"ATEIBfProfileConfig"| \
1182 "TxBfTxApply"|"ATETxPacketWithBf"|"TxBfProfileData20MAllWrite"|"ATEIBfInstCal"| \
developer7af0f762023-05-22 15:16:16 +08001183 "ATEIBfGdCal"|"ATEIBFPhaseE2pUpdate"|"TriggerSounding"|"StopSounding"|"TxBfTxCmd"| \
developerc5ce7502022-12-19 11:33:22 +08001184 "StaRecBfRead"|"TxBfProfileTagInValid"|"TxBfProfileTagWrite"|"TxBfProfileTagRead"| \
1185 "ATEIBFPhaseVerify"|"ATEConTxETxBfGdProc"|"ATEConTxETxBfInitProc")
developerb9b4cd12022-10-11 13:18:59 +08001186 convert_ibf ${cmd} ${param}
1187 skip=1
1188 ;;
1189 "bufferMode")
1190 if [ "${param}" = "2" ]; then
1191 do_cmd "atenl -i ${interface} -c \"eeprom update buffermode\""
1192 fi
1193 skip=1
1194 ;;
1195 "ResetCounter"|"ATERXSTATRESET")
1196 skip=1
1197 ;;
1198 "WORKMODE")
1199 record_config "WORKMODE" ${param} ${iwpriv_file}
1200 echo "Entering ${param} mode in iwpriv"
1201 skip=1
1202 ;;
developer9a587882023-07-17 11:11:44 +08001203 "ATERUINFO")
1204 convert_ruinfo ${param}
1205 skip=1
1206 ;;
developerb9b4cd12022-10-11 13:18:59 +08001207 *)
1208 print_debug "Unknown command to set: ${cmd}"
1209 skip=1
1210 esac
1211
1212 if [ "${skip}" != "1" ]; then
1213 do_cmd "mt76-test ${interface} set ${cmd_new}=${param_new}"
1214 fi
1215
1216elif [ "${cmd_type}" = "show" ]; then
developerc5ce7502022-12-19 11:33:22 +08001217 if [ "${cmd}" = "wtbl" ]; then
developer9237f442024-06-14 17:13:04 +08001218 wlan_idx=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/wlan_idx
1219 wtbl_info=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/wtbl_info
developerc5ce7502022-12-19 11:33:22 +08001220
1221 do_cmd "echo ${param} > ${wlan_idx}"
1222 do_cmd "cat ${wtbl_info}"
developerbb6ddff2023-03-08 17:22:32 +08001223 elif [ "${cmd}" = "ATERXSTAT" ]; then
1224 convert_rxstat
developerc5ce7502022-12-19 11:33:22 +08001225 else
1226 do_cmd "mt76-test ${interface} dump"
1227 do_cmd "mt76-test ${interface} dump stats"
1228 fi
developerb9b4cd12022-10-11 13:18:59 +08001229
1230elif [ "${cmd_type}" = "e2p" ]; then
developer13655da2023-01-10 19:53:25 +08001231 # support multiple read write
developerb9b4cd12022-10-11 13:18:59 +08001232 # eeprom offset write
1233 if [[ ${full_cmd} == *"="* ]]; then
developer13655da2023-01-10 19:53:25 +08001234 IFS=,
1235 for tuple in $full_cmd
1236 do
1237 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1238 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1239 offset=$(printf "0x%s" ${cmd})
1240 val=$(printf "0x%s" ${param})
1241 tmp=$((${val} & 0xff))
1242 tmp=$(printf "0x%x" ${tmp})
1243 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
developerb9b4cd12022-10-11 13:18:59 +08001244
developer13655da2023-01-10 19:53:25 +08001245 offset=$((${offset}))
1246 offset=$(expr ${offset} + "1")
1247 offset=$(printf "0x%x" ${offset})
1248 tmp=$(((${val} >> 8) & 0xff))
1249 tmp=$(printf "0x%x" ${tmp})
1250 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
1251 done
developerb9b4cd12022-10-11 13:18:59 +08001252 else
developer13655da2023-01-10 19:53:25 +08001253 IFS=,
1254 for tuple in $full_cmd
1255 do
1256 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1257 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1258 offset=$(printf "0x%s" ${cmd})
1259 val=$(printf "0x%s" ${param})
1260 v1=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param}\"")
1261 v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developerb9b4cd12022-10-11 13:18:59 +08001262
developer13655da2023-01-10 19:53:25 +08001263 tmp=$(printf "0x%s" ${param})
1264 tmp=$((${tmp}))
1265 param2=$(expr ${tmp} + "1")
1266 param2=$(printf "%x" ${param2})
1267 v2=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param2}\"")
1268 v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developerb9b4cd12022-10-11 13:18:59 +08001269
developer13655da2023-01-10 19:53:25 +08001270 param=$(printf "0x%s" ${param})
1271 param=$(printf "%04x" ${param})
1272 param=$(echo $param | tr 'a-z' 'A-Z')
1273 printf "%s e2p:\n" ${interface_ori}
1274 printf "[0x%s]:0x%02x%02x\n" ${param} ${v2} ${v1}
1275 done
developerb9b4cd12022-10-11 13:18:59 +08001276 fi
1277
1278elif [ "${cmd_type}" = "mac" ]; then
developerb9b4cd12022-10-11 13:18:59 +08001279 offset=$(printf "0x%s" ${cmd})
1280 val=$(printf "0x%s" ${param})
1281
developerb9b4cd12022-10-11 13:18:59 +08001282 # reg write
1283 if [[ ${full_cmd} == *"="* ]]; then
developer9237f442024-06-14 17:13:04 +08001284 register_handler ${offset} ${val} "write"
developer092b55c2023-01-18 18:20:58 +08001285 else
1286 start_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 1)
1287 end_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 2)
1288 loop=$((0x${end_addr}-0x${start_addr}))
developerb9b4cd12022-10-11 13:18:59 +08001289
developer092b55c2023-01-18 18:20:58 +08001290 if [[ ${loop} == "0" ]]; then
developer9237f442024-06-14 17:13:04 +08001291 register_handler ${offset} ${val}
developer092b55c2023-01-18 18:20:58 +08001292 else
1293 i=0
1294 while [ $i -le $loop ]; do
1295 addr=$((0x${start_addr}+$i))
1296 offset=$(printf "0x%x" ${addr})
developer9237f442024-06-14 17:13:04 +08001297 register_handler ${offset} ${val}
developer092b55c2023-01-18 18:20:58 +08001298 i=$(($i + 4))
1299 done
1300 fi
1301 fi
developerb9b4cd12022-10-11 13:18:59 +08001302
developer13655da2023-01-10 19:53:25 +08001303## dump command is only for vendor commands
1304elif [ "${cmd_type}" = "dump" ]; then
1305 do_cmd "mt76-vendor $*"
developerc9333e12023-04-06 18:07:42 +08001306elif [ "${cmd_type}" = "switch" ]; then
developer2299de92023-10-27 15:40:47 +08001307 eeprom_mode_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom_mode
developerc9333e12023-04-06 18:07:42 +08001308 eeprom_mode=$(cat ${eeprom_mode_file} | grep "mode" | sed -n 2p | cut -d " " -f 4)
1309 eeprom_testmode_offset="1af"
1310 testmode_enable="0"
1311
developerc8796032023-08-09 10:28:15 +08001312 if [ ${is_connac3} == "0" ]; then
developerc9333e12023-04-06 18:07:42 +08001313 return
1314 fi
1315
1316 if [ "${cmd}" = "testmode" ]; then
1317 testmode_enable="1"
developerdad89a32024-04-29 14:17:17 +08001318 do_cmd "wifi down"
1319 do_cmd "uci set wireless.radio0.disabled=1"
1320 do_cmd "uci set wireless.radio1.disabled=1"
1321 do_cmd "uci set wireless.radio2.disabled=1"
1322 do_cmd "uci commit"
developerc9333e12023-04-06 18:07:42 +08001323 fi
1324
1325 if [ "${eeprom_mode}" = "flash" ]; then
1326 ## flash mode should set eeprom testmode offset bit
1327 ## efuse/bin file/default bin mode rely on module param only
1328 do_cmd "atenl -i ${interface} -c \"eeprom set 0x${eeprom_testmode_offset}=0x${testmode_enable}\""
1329 ## If has no precal, it would not affect
1330 do_cmd "atenl -i ${interface} -c \"eeprom precal sync\""
1331 do_cmd "atenl -i ${interface} -c \"sync eeprom all\""
1332 fi
1333
1334 do_cmd "rmmod mt7996e"
1335 do_cmd "rmmod mt76-connac-lib"
1336 do_cmd "rmmod mt76"
1337 do_cmd "rmmod mac80211"
1338 do_cmd "rmmod cfg80211"
1339 do_cmd "rmmod compat"
1340 do_cmd "insmod compat"
1341 do_cmd "insmod cfg80211"
1342 do_cmd "insmod mac80211"
1343 do_cmd "insmod mt76"
1344 do_cmd "insmod mt76-connac-lib"
1345 do_cmd "insmod mt7996e testmode_enable=${testmode_enable}"
1346 do_cmd "sleep 5"
1347 do_cmd "killall hostapd"
1348 do_cmd "killall netifd"
developerb9b4cd12022-10-11 13:18:59 +08001349else
1350 echo "Unknown command"
1351fi