blob: 9b73fe80a12b8a1234c0f81d447935d6df643732 [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"
developerd0c89452024-10-11 16:53:27 +0800121 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7993")" ]; then
122 SOC_start_idx="0"
123 SOC_end_idx="1"
124 is_connac3="1"
developerb9b4cd12022-10-11 13:18:59 +0800125 else
126 echo "Interface Conversion Failed!"
127 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 +0800128 echo "For AX3000/AX6000:"
developer3f784572023-01-31 15:21:28 +0800129 echo " echo STARTIDX=0 >> ${interface_file}"
130 echo " echo ENDIDX=1 >> ${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 AX7800:"
133 echo " echo STARTIDX=2 >> ${interface_file}"
134 echo " echo ENDIDX=3 >> ${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 AX8400:"
137 echo " echo STARTIDX=1 >> ${interface_file}"
138 echo " echo ENDIDX=2 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800139 echo " echo IS_CONNAC3=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800140 echo "For Eagle:"
developerc8796032023-08-09 10:28:15 +0800141 echo " echo STARTIDX=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800142 echo " echo ENDIDX=2 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800143 echo " echo IS_CONNAC3=1 >> ${interface_file}"
144 echo "For Kite:"
145 echo " echo STARTIDX=0 >> ${interface_file}"
146 echo " echo ENDIDX=1 >> ${interface_file}"
147 echo " echo IS_CONNAC3=1 >> ${interface_file}"
developerd0c89452024-10-11 16:53:27 +0800148 echo "For Griffin:"
149 echo " echo STARTIDX=0 >> ${interface_file}"
150 echo " echo ENDIDX=1 >> ${interface_file}"
151 echo " echo IS_CONNAC3=1 >> ${interface_file}"
developerb9b4cd12022-10-11 13:18:59 +0800152 exit 0
153 fi
developer13655da2023-01-10 19:53:25 +0800154 record_config "STARTIDX" ${SOC_start_idx} ${interface_file}
developer3f784572023-01-31 15:21:28 +0800155 record_config "ENDIDX" ${SOC_end_idx} ${interface_file}
developerc8796032023-08-09 10:28:15 +0800156 record_config "IS_CONNAC3" ${is_connac3} ${interface_file}
developerb9b4cd12022-10-11 13:18:59 +0800157 fi
developer3f784572023-01-31 15:21:28 +0800158}
developerb9b4cd12022-10-11 13:18:59 +0800159
developer3f784572023-01-31 15:21:28 +0800160function convert_interface {
developerc8796032023-08-09 10:28:15 +0800161 if [ ${is_connac3} == "0" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800162 if [[ $1 == "raix"* ]]; then
developer13655da2023-01-10 19:53:25 +0800163 phy_idx=1
164 elif [[ $1 == "rai"* ]]; then
developerb9b4cd12022-10-11 13:18:59 +0800165 phy_idx=0
166 elif [[ $1 == "rax"* ]]; then
developer13655da2023-01-10 19:53:25 +0800167 phy_idx=$((SOC_start_idx+1))
168 else
169 phy_idx=$SOC_start_idx
developerb9b4cd12022-10-11 13:18:59 +0800170 fi
developer13655da2023-01-10 19:53:25 +0800171
172 # convert phy index according to band idx
173 local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
174 if [ "${band_idx}" = "0" ]; then
175 if [[ $1 == "raix"* ]]; then
176 phy_idx=0
177 elif [[ $1 == "rax"* ]]; then
178 phy_idx=$SOC_start_idx
179 fi
180 elif [ "${band_idx}" = "1" ]; then
181 if [[ $1 == "rai"* ]]; then
182 # AX8400: mt7915 remain phy0
183 # AX7800: mt7916 becomes phy1
184 phy_idx=$((SOC_start_idx-1))
185 elif [[ $1 == "ra"* ]]; then
186 phy_idx=$((SOC_start_idx+1))
187 fi
188 fi
189 else
developer9237f442024-06-14 17:13:04 +0800190 # Connac 3 chips has different mapping method
developer13655da2023-01-10 19:53:25 +0800191 # phy0: ra0
192 # phy1: rai0
193 # phy2: rax0
developerb9b4cd12022-10-11 13:18:59 +0800194 if [[ $1 == "rai"* ]]; then
developer13655da2023-01-10 19:53:25 +0800195 phy_idx=1
196 elif [[ $1 == "rax"* ]]; then
197 phy_idx=2
198 else
199 phy_idx=0
developerb9b4cd12022-10-11 13:18:59 +0800200 fi
201 fi
202
203 interface="phy${phy_idx}"
204}
205
206function change_band_idx {
207 local new_idx=$1
208 local new_phy_idx=$phy_idx
developerb9b4cd12022-10-11 13:18:59 +0800209 local old_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
210
developerb9b4cd12022-10-11 13:18:59 +0800211 if [[ ${interface_ori} == "ra"* ]]; then
212 if [ -z "${old_idx}" ] || [ "${old_idx}" != "${new_idx}" ]; then
213 if [ "${new_idx}" = "0" ]; then
214 # raix0 & rai0 becomes rai0
215 if [[ $interface_ori == "rai"* ]]; then
216 new_phy_idx=0
217 # rax0 & ra0 becomes ra0
218 elif [[ $interface_ori == "ra"* ]]; then
developer13655da2023-01-10 19:53:25 +0800219 new_phy_idx=$SOC_start_idx
developerb9b4cd12022-10-11 13:18:59 +0800220 fi
221 elif [ "${new_idx}" = "1" ]; then
222 # raix0 & rai0 becomes raix0
223 if [[ $interface_ori == "rai"* ]]; then
developerc5ce7502022-12-19 11:33:22 +0800224 # For AX8400 => don't change phy idx
developer13655da2023-01-10 19:53:25 +0800225 if [ ${SOC_start_idx} != "1" ]; then
developerc5ce7502022-12-19 11:33:22 +0800226 new_phy_idx=1
227 fi
developerb9b4cd12022-10-11 13:18:59 +0800228 # rax0 & ra0 becomes rax0
229 elif [[ $interface_ori == "ra"* ]]; then
developer13655da2023-01-10 19:53:25 +0800230 new_phy_idx=$((SOC_start_idx+1))
developerb9b4cd12022-10-11 13:18:59 +0800231 fi
232 fi
233 fi
234
235 if [ ${new_phy_idx} != ${phy_idx} ]; then
236 do_ate_work "ATESTOP"
237 phy_idx=$new_phy_idx
238 interface="phy${phy_idx}"
239 do_ate_work "ATESTART"
240 fi
241 fi
242 record_config "ATECTRLBANDIDX" ${new_idx} ${iwpriv_file}
243}
244
245function simple_convert() {
246 if [ "$1" = "ATETXCNT" ]; then
247 echo "tx_count"
248 elif [ "$1" = "ATETXLEN" ]; then
249 echo "tx_length"
250 elif [ "$1" = "ATETXMCS" ]; then
251 echo "tx_rate_idx"
developerd0c89452024-10-11 16:53:27 +0800252 elif [ "$1" = "ATEVHTNSS" ] || [ "$1" = "ATETXNSS" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800253 echo "tx_rate_nss"
254 elif [ "$1" = "ATETXLDPC" ]; then
255 echo "tx_rate_ldpc"
256 elif [ "$1" = "ATETXSTBC" ]; then
257 echo "tx_rate_stbc"
258 elif [ "$1" = "ATEPKTTXTIME" ]; then
259 echo "tx_time"
260 elif [ "$1" = "ATEIPG" ]; then
261 echo "tx_ipg"
262 elif [ "$1" = "ATEDUTYCYCLE" ]; then
263 echo "tx_duty_cycle"
264 elif [ "$1" = "ATETXFREQOFFSET" ]; then
265 echo "freq_offset"
266 else
267 echo "undefined"
268 fi
269}
270
271function convert_tx_mode() {
developerc5ce7502022-12-19 11:33:22 +0800272 # Remove leading zeros
developer3f784572023-01-31 15:21:28 +0800273 local tx_mode=$(echo $1 | sed -r 's/0+([0-9]+)/\1/g')
developerc5ce7502022-12-19 11:33:22 +0800274
275 if [ "$tx_mode" = "0" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800276 echo "cck"
developerc5ce7502022-12-19 11:33:22 +0800277 elif [ "$tx_mode" = "1" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800278 echo "ofdm"
developerc5ce7502022-12-19 11:33:22 +0800279 elif [ "$tx_mode" = "2" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800280 echo "ht"
developerc5ce7502022-12-19 11:33:22 +0800281 elif [ "$tx_mode" = "4" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800282 echo "vht"
developerc5ce7502022-12-19 11:33:22 +0800283 elif [ "$tx_mode" = "8" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800284 echo "he_su"
developerc5ce7502022-12-19 11:33:22 +0800285 elif [ "$tx_mode" = "9" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800286 echo "he_er"
developerc5ce7502022-12-19 11:33:22 +0800287 elif [ "$tx_mode" = "10" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800288 echo "he_tb"
developerc5ce7502022-12-19 11:33:22 +0800289 elif [ "$tx_mode" = "11" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800290 echo "he_mu"
developerbb6ddff2023-03-08 17:22:32 +0800291 elif [ "$tx_mode" = "13" ]; then
292 echo "eht_su"
293 elif [ "$tx_mode" = "14" ]; then
294 echo "eht_tb"
295 elif [ "$tx_mode" = "15" ]; then
296 echo "eht_mu"
developerb9b4cd12022-10-11 13:18:59 +0800297 else
298 echo "undefined"
299 fi
300}
301
302function convert_gi {
303 local tx_mode=$1
304 local val=$2
305 local sgi="0"
306 local he_ltf="0"
307
308 case ${tx_mode} in
309 "ht"|"vht")
310 sgi=${val}
311 ;;
312 "he_su"|"he_er")
313 case ${val} in
314 "0")
315 ;;
316 "1")
317 he_ltf="1"
318 ;;
319 "2")
320 sgi="1"
321 he_ltf="1"
322 ;;
323 "3")
324 sgi="2"
325 he_ltf="2"
326 ;;
327 "4")
328 he_ltf="2"
329 ;;
330 *)
331 echo "unknown gi"
332 esac
333 ;;
334 "he_mu")
335 case ${val} in
336 "0")
337 he_ltf="2"
338 ;;
339 "1")
340 he_ltf="1"
341 ;;
342 "2")
343 sgi="1"
344 he_ltf="1"
345 ;;
346 "3")
347 sgi="2"
348 he_ltf="2"
349 ;;
350 *)
351 echo "unknown gi"
352 esac
353 ;;
354 "he_tb")
355 case ${val} in
356 "0")
357 sgi="1"
358 ;;
359 "1")
360 sgi="1"
361 he_ltf="1"
362 ;;
363 "2")
364 sgi="2"
365 he_ltf="2"
366 ;;
367 *)
368 echo "unknown gi"
369 esac
370 ;;
371 *)
372 print_debug "legacy mode no need gi"
373 esac
374
375 do_cmd "mt76-test ${interface} set tx_rate_sgi=${sgi} tx_ltf=${he_ltf}"
376}
377
developer05f3b2b2024-08-19 19:17:34 +0800378function convert_tm_cbw_to_nl {
379 local cbw=$1
380 local bw="NOHT"
381
382 case ${cbw} in
383 # TM_CBW_20MHZ
384 "0")
385 bw="20"
386 ;;
387 # TM_CBW_40MHZ
388 "1")
389 bw="40"
390 ;;
391 # TM_CBW_80MHZ
392 "2")
393 bw="80"
394 ;;
395 # TM_CBW_10MHZ
396 "3")
397 bw="10"
398 ;;
399 # TM_CBW_5MHZ
400 "4")
401 bw="5"
402 ;;
403 # TM_CBW_160MHZ
404 "5")
405 bw="160"
406 ;;
407 # TM_CBW_8080MHZ
408 "6")
409 bw="80p80"
410 ;;
411 # TM_CBW_320MHZ
412 "12")
413 bw="320"
414 ;;
415 esac
416
417 echo ${bw}
418}
419
420function convert_bw {
421 local system_bw=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
422 local data_bw=$(echo $1 | sed s/:/' '/g | cut -d " " -f 2)
423 # Convert TM_CBW to NL80211_CHAN_WIDTH
424 local tx_pkt_bw=$(convert_tm_cbw_to_nl ${data_bw})
425
426 record_config "ATETXBW" ${system_bw} ${iwpriv_file}
427
428 # apply per-packet bw
429 if [[ $1 == *":"* ]]; then
430 do_cmd "mt76-test phy${phy_idx} set tx_pkt_bw=${tx_pkt_bw}"
431 fi
432}
433
developerb9b4cd12022-10-11 13:18:59 +0800434function convert_channel {
developerb9b4cd12022-10-11 13:18:59 +0800435 local ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
developer05f3b2b2024-08-19 19:17:34 +0800436 local control_ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
437 local band=$(echo $1 | sed s/:/' '/g | cut -d " " -f 2)
438 local pri_sel=$(echo $1 | sed s/:/' '/g | cut -d " " -f 3)
439 local ctrl_band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
developerb9b4cd12022-10-11 13:18:59 +0800440 local bw=$(get_config "ATETXBW" ${iwpriv_file} | cut -d ":" -f 1)
developer05f3b2b2024-08-19 19:17:34 +0800441 local bw_str="20"
developerb9b4cd12022-10-11 13:18:59 +0800442 local base_chan=1
443 local control_freq=0
444 local base_freq=0
developerc5ce7502022-12-19 11:33:22 +0800445 local temp=$((phy_idx+1))
developerb9b4cd12022-10-11 13:18:59 +0800446
developerc5ce7502022-12-19 11:33:22 +0800447 # Handle ATECTRLBANDIDX
448 if [ ! -z ${ctrl_band_idx} ]; then
449 if [ "${ctrl_band_idx}" == "1" ] && [ ${band} == "0" ]; then
450 local temp=$(cat "/etc/config/wireless"| grep "option band" | sed -n ${temp}p | cut -c 15)
451 if [ "${temp}" == "2" ]; then
452 local band=0
453 elif [ "${temp}" == "5" ]; then
454 local band=1
455 elif [ "${temp}" == "6" ]; then
456 local band=2
457 else
458 echo "iwpriv wrapper band translate error!"
459 fi
460 else
461 # mt7915 in AX8400 case: band should be determined by only the input band
developer13655da2023-01-10 19:53:25 +0800462 if [ "${SOC_start_idx}" == "1" ] && [ ${phy_idx} == "0" ]; then
developerc5ce7502022-12-19 11:33:22 +0800463 local band=$((band))
464 else
465 local band=$((ctrl_band_idx * band))
466 fi
467 fi
developerb9b4cd12022-10-11 13:18:59 +0800468 fi
469
developer05f3b2b2024-08-19 19:17:34 +0800470 if [[ $1 == *":"* ]] && [ -n "${pri_sel}" ]; then
471 do_cmd "mt76-test phy${phy_idx} set tx_pri_sel=${pri_sel}"
472 fi
473
developerb9b4cd12022-10-11 13:18:59 +0800474 if [[ $1 != *":"* ]] || [ "${band}" = "0" ]; then
475 case ${bw} in
476 "1")
477 if [ "${ch}" -lt "3" ] || [ "${ch}" -gt "12" ]; then
developer05f3b2b2024-08-19 19:17:34 +0800478 bw_str="20"
developerb9b4cd12022-10-11 13:18:59 +0800479 else
developer05f3b2b2024-08-19 19:17:34 +0800480 bw_str="40"
481 control_ch=$(expr ${ch} - "2")
developerb9b4cd12022-10-11 13:18:59 +0800482 fi
483 ;;
developerb9b4cd12022-10-11 13:18:59 +0800484 esac
developer05f3b2b2024-08-19 19:17:34 +0800485 base_freq=2412
developerb9b4cd12022-10-11 13:18:59 +0800486 else
487 case ${bw} in
developerbb6ddff2023-03-08 17:22:32 +0800488 "12")
developer05f3b2b2024-08-19 19:17:34 +0800489 bw_str="320"
490 control_ch=$(expr ${ch} - "30")
developerbb6ddff2023-03-08 17:22:32 +0800491 ;;
developerb9b4cd12022-10-11 13:18:59 +0800492 "5")
developer05f3b2b2024-08-19 19:17:34 +0800493 bw_str="160"
494 control_ch=$(expr ${ch} - "14")
developerb9b4cd12022-10-11 13:18:59 +0800495 ;;
496 "2")
developer05f3b2b2024-08-19 19:17:34 +0800497 bw_str="80"
498 control_ch=$(expr ${ch} - "6")
developerb9b4cd12022-10-11 13:18:59 +0800499 ;;
500 "1")
developer05f3b2b2024-08-19 19:17:34 +0800501 bw_str="40"
502 control_ch=$(expr ${ch} - "2")
developerb9b4cd12022-10-11 13:18:59 +0800503 ;;
504 "0")
developer05f3b2b2024-08-19 19:17:34 +0800505 bw_str="20"
506 control_ch=${ch}
developerb9b4cd12022-10-11 13:18:59 +0800507 ;;
508 esac
developer05f3b2b2024-08-19 19:17:34 +0800509 if [ "${band}" = "1" ]; then
510 base_freq=5180
511 base_chan=36
512 else
513 base_freq=5955
514 fi
developerb9b4cd12022-10-11 13:18:59 +0800515 fi
516
developer05f3b2b2024-08-19 19:17:34 +0800517 local center_freq=$(((ch - base_chan) * 5 + base_freq))
518 local control_freq=$(((control_ch - base_chan) * 5 + base_freq))
519 if [ "${center_freq}" == "${control_freq}" ]; then
520 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str}"
521 else
522 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str} ${center_freq}"
523 fi
developerb9b4cd12022-10-11 13:18:59 +0800524}
525
526function convert_rxstat {
527 local res=$(do_cmd "mt76-test ${interface} dump stats")
528 local mdrdy=$(echo "${res}" | grep "rx_packets" | cut -d "=" -f 2)
529 local fcs_error=$(echo "${res}" | grep "rx_fcs_error" | cut -d "=" -f 2)
530 local rcpi=$(echo "${res}" | grep "last_rcpi" | cut -d "=" -f 2 | sed 's/,/ /g')
531 local ib_rssi=$(echo "${res}" | grep "last_ib_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
532 local wb_rssi=$(echo "${res}" | grep "last_wb_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
533 local rx_ok=$(expr ${mdrdy} - ${fcs_error})
534
535 write_dmesg "rcpi: ${rcpi}"
536 write_dmesg "fagc rssi ib: ${ib_rssi}"
537 write_dmesg "fagc rssi wb: ${wb_rssi}"
538 write_dmesg "all_mac_rx_mdrdy_cnt: ${mdrdy}"
539 write_dmesg "all_mac_rx_fcs_err_cnt: ${fcs_error}"
540 write_dmesg "all_mac_rx_ok_cnt : ${rx_ok}"
541}
542
543function set_mac_addr {
544 record_config ${cmd} ${param} ${iwpriv_file}
545
546 local addr1=$(get_config "ATEDA" ${iwpriv_file})
547 local addr2=$(get_config "ATESA" ${iwpriv_file})
548 local addr3=$(get_config "ATEBSSID" ${iwpriv_file})
549
550 if [ -z "${addr1}" ]; then
551 addr1="00:11:22:33:44:55"
552 fi
553 if [ -z "${addr2}" ]; then
554 addr2="00:11:22:33:44:55"
555 fi
556 if [ -z "${addr3}" ]; then
557 addr3="00:11:22:33:44:55"
558 fi
559
560 do_cmd "mt76-test phy${phy_idx} set mac_addrs=${addr1},${addr2},${addr3}"
561}
562
563function convert_ibf {
564 local cmd=$1
565 local param=$2
566 local new_cmd=""
567 local new_param=$(echo ${param} | sed s/":"/","/g)
568
569 case ${cmd} in
570 "ATETxBfInit")
571 new_cmd="init"
developerc5ce7502022-12-19 11:33:22 +0800572 new_param="1"
573 do_cmd "mt76-test phy${phy_idx} set state=idle"
574 ;;
575 "ATETxBfGdInit")
576 new_cmd="golden_init"
577 new_param="1"
developerb9b4cd12022-10-11 13:18:59 +0800578 do_cmd "mt76-test phy${phy_idx} set state=idle"
579 ;;
580 "ATEIBFPhaseComp")
581 new_cmd="phase_comp"
developerc5ce7502022-12-19 11:33:22 +0800582 new_param="${new_param}"
developerb9b4cd12022-10-11 13:18:59 +0800583 ;;
584 "ATEEBfProfileConfig")
585 new_cmd="ebf_prof_update"
586 ;;
587 "ATEIBfProfileConfig")
588 new_cmd="ibf_prof_update"
589 ;;
590 "ATEIBfInstCal")
591 new_cmd="phase_cal"
592 ;;
593 "ATEIBfGdCal")
developera46f6132024-03-26 14:09:54 +0800594 local group=${new_param:0:2}
595 local group_l_m_h=${new_param:3:2}
596 local band_idx=${new_param:6:2}
597 local cal_type=${new_param:9:2}
598 local version=${new_param:12}
599 local lna_level="00"
600
601 # only ibf 2.0 will set version, so add null check for backward compatibility
602 if [ -z $version ]; then
603 version="00"
604 fi
605
developerb9b4cd12022-10-11 13:18:59 +0800606 new_cmd="phase_cal"
developera46f6132024-03-26 14:09:54 +0800607 new_param="${group},${group_l_m_h},${band_idx},${cal_type},${lna_level},${version}"
developerb9b4cd12022-10-11 13:18:59 +0800608 ;;
609 "TxBfTxApply")
610 new_cmd="apply_tx"
611 ;;
612 "ATETxPacketWithBf")
613 local bf_on=${new_param:0:2}
614 local aid="01"
615 local wlan_idx=${new_param:3:2}
616 local update="00"
developera46f6132024-03-26 14:09:54 +0800617 local tx_count=${new_param:6}
developerb9b4cd12022-10-11 13:18:59 +0800618
619 new_cmd="tx_prep"
620 new_param="${bf_on},${aid},${wlan_idx},${update}"
developera46f6132024-03-26 14:09:54 +0800621 if [ "${tx_count}" = "00" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800622 new_param="${new_param} aid=1 tx_count=10000000 tx_length=1024"
623 else
developera46f6132024-03-26 14:09:54 +0800624 new_param="${new_param} aid=1 tx_count=${tx_count} tx_length=1024"
developerb9b4cd12022-10-11 13:18:59 +0800625 fi
626 do_cmd "mt76-test phy${phy_idx} set state=idle"
627 ;;
628 "TxBfProfileData20MAllWrite")
629 new_cmd="prof_update_all"
630 ;;
631 "ATEIBFPhaseE2pUpdate")
632 new_cmd="e2p_update"
633 ;;
developerc5ce7502022-12-19 11:33:22 +0800634 "ATEIBFPhaseVerify")
635 local group=${new_param:0:2}
636 local group_l_m_h=${new_param:3:2}
637 local band_idx=${new_param:6:2}
638 local phase_cal_type=${new_param:9:2}
639 local LNA_gain_level=${new_param:12:2}
640 local read_from_e2p=${new_param:15:2}
641
642 do_cmd "mt76-test phy${phy_idx} set txbf_act=phase_comp txbf_param=1,${band_idx},${group},${read_from_e2p},0"
643 new_cmd="phase_cal"
644 new_param="${group},${group_l_m_h},${band_idx},${phase_cal_type},${LNA_gain_level}"
645 ;;
646 "TxBfProfileTagRead")
647 new_cmd="pfmu_tag_read"
648 ;;
649 "TxBfProfileTagWrite")
650 new_cmd="pfmu_tag_write"
651 ;;
652 "TxBfProfileTagInValid")
653 new_cmd="set_invalid_prof"
654 ;;
655 "StaRecBfRead")
656 new_cmd="sta_rec_read"
657 ;;
658 "TriggerSounding")
659 new_cmd="trigger_sounding"
660 ;;
661 "StopSounding")
662 new_cmd="stop_sounding"
663 new_param="0"
664 ;;
developer7af0f762023-05-22 15:16:16 +0800665 "TxBfTxCmd")
666 new_cmd="txcmd"
667 ;;
developerc5ce7502022-12-19 11:33:22 +0800668 "ATEConTxETxBfGdProc")
669 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
670 local tx_rate_idx=${new_param:3:2}
671 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
672 local channel=${new_param:9:3}
673 local channel2=${new_param:13:3}
674 local band=${new_param:17}
675
676 new_cmd="ebf_golden_init"
677 do_ate_work "ATESTART"
678 do_cmd "mt76-test phy${phy_idx} set state=idle"
679 record_config "ATETXBW" ${bw} ${iwpriv_file}
680 convert_channel "${channel}:${band}"
681 if [ "${bw}" = "5" ]; then
682 new_param="1,1"
683 else
684 new_param="1,0"
685 fi
686 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=${tx_rate_mode} tx_rate_idx=${tx_rate_idx} tx_rate_sgi=0"
687 ;;
688 "ATEConTxETxBfInitProc")
689 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
690 local tx_rate_idx=${new_param:3:2}
691 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
692 local tx_rate_nss=${new_param:9:2}
693 local tx_stream=${new_param:12:2}
694 local tx_power=${new_param:15:2}
developer7af0f762023-05-22 15:16:16 +0800695 local channel=$(echo ${new_param:18:3} | sed 's/^0//')
developerc5ce7502022-12-19 11:33:22 +0800696 local channel2=${new_param:22:3}
697 local band=${new_param:26:1}
developer7af0f762023-05-22 15:16:16 +0800698 local tx_length=$(echo ${new_param:28:5} | sed 's/^0//')
developerc5ce7502022-12-19 11:33:22 +0800699
700 new_cmd="ebf_init"
701 do_ate_work "ATESTART"
702 do_cmd "mt76-test phy${phy_idx} set state=idle"
703 record_config "ATETXBW" ${bw} ${iwpriv_file}
704 convert_channel "${channel}:${band}"
705 new_param="1"
706 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"
707 ;;
developerb9b4cd12022-10-11 13:18:59 +0800708 *)
709 esac
710
711 do_cmd "mt76-test phy${phy_idx} set txbf_act=${new_cmd} txbf_param=${new_param}"
712
713 if [ "${cmd}" = "ATETxPacketWithBf" ]; then
714 do_cmd "mt76-test phy${phy_idx} set state=tx_frames"
developerc5ce7502022-12-19 11:33:22 +0800715 elif [ "${cmd}" = "ATEConTxETxBfInitProc" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800716 local wlan_idx="1"
developerc8796032023-08-09 10:28:15 +0800717 if [ ${is_connac3} == "1" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800718 local wlan_idx=$((phy_idx+1))
719 fi
developerc5ce7502022-12-19 11:33:22 +0800720 do_cmd "mt76-test phy${phy_idx} set aid=1"
721 do_cmd "mt76-test phy${phy_idx} set txbf_act=stop_sounding txbf_param=1"
722 do_cmd "mt76-test phy${phy_idx} set txbf_act=update_ch txbf_param=1"
723 do_cmd "mt76-test phy${phy_idx} set txbf_act=ebf_prof_update txbf_param=0,0,0"
developerbb6ddff2023-03-08 17:22:32 +0800724 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 +0800725 if [ ${is_connac3} == "1" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800726 do_cmd "mt76-test phy${phy_idx} set txbf_act=txcmd txbf_param=1,1,1"
727 fi
developerc5ce7502022-12-19 11:33:22 +0800728 do_cmd "mt76-test phy${phy_idx} set txbf_act=pfmu_tag_read txbf_param=0,1"
developerbb6ddff2023-03-08 17:22:32 +0800729 do_cmd "mt76-test phy${phy_idx} set txbf_act=sta_rec_read txbf_param=${wlan_idx}"
730 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=0,1,0,${wlan_idx},0,0,0"
731 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 +0800732 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
733 elif [ "${cmd}" = "ATEConTxETxBfGdProc" ]; then
734 do_cmd "mt76-test phy${phy_idx} set aid=1"
735 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
736 elif [ "${cmd}" = "ATETxBfInit" ]; then
737 do_cmd "mt76-test phy${phy_idx} set aid=1"
738 elif [ "${cmd}" = "ATETxBfGdInit" ]; then
739 do_cmd "mt76-test phy${phy_idx} set aid=1"
developerf9b00212023-07-31 12:27:06 +0800740 elif [ "${cmd}" = "ATEIBFPhaseE2pUpdate" ]; then
741 do_cmd "atenl -i phy${phy_idx} -c \"eeprom ibf sync\""
developerb9b4cd12022-10-11 13:18:59 +0800742 fi
743}
744
developer9a587882023-07-17 11:11:44 +0800745function convert_ruinfo {
746 local new_param=$1
747
748 do_cmd "mt76-test phy${phy_idx} set state=idle"
749 while [ -n "$new_param" ]
750 do
751 [ ${new_param:1:1} = ':' ] && {
752 new_param=${new_param:2}
753 }
754 local oIFS="$IFS"; IFS=":"; set -- $new_param; IFS="$oIFS"
755
756 parsing_ruinfo $new_param
757 new_param=${new_param:${#1}+1}
758 done
759}
760
761function parsing_ruinfo {
762 local new_param=$1
763 local oIFS="$IFS"; IFS="-:"; set -- $new_param; IFS="$oIFS"
764
765 # $7 is Start spatial stream and it should be 0, $9 is alpha, not used
766 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\
767 tx_rate_idx=$4 tx_rate_ldpc=$5 tx_rate_nss=$6 tx_length=$8"
768}
769
developerb403ad02022-11-08 10:16:29 +0800770function convert_dfs {
771 local cmd=$1
772 local param=$2
773
774 case ${cmd} in
775 "DfsRxCtrl")
776 local offchan_ch="$(echo $param | cut -d ':' -f1)"
777 local offchan_bw="$(echo $param | cut -d ':' -f2)"
778
developerc9333e12023-04-06 18:07:42 +0800779 if [ "$offchan_bw" = "0" ]; then
780 offchan_bw="20"
781 elif [ "$offchan_bw" = "1" ]; then
782 offchan_bw="40"
783 elif [ "$offchan_bw" = "2" ]; then
784 offchan_bw="80"
785 elif [ "$offchan_bw" = "3" ]; then
786 offchan_bw="160"
787 fi
developerb403ad02022-11-08 10:16:29 +0800788
developerc9333e12023-04-06 18:07:42 +0800789 do_cmd "mt76-test phy${phy_idx} set state=idle"
790 do_cmd "mt76-test phy${phy_idx} set offchan_ch=${offchan_ch} offchan_bw=${offchan_bw}"
developerb403ad02022-11-08 10:16:29 +0800791 ;;
792 "DfsRxHist")
793 local ipi_th="$(echo $param | cut -d ':' -f 1)"
794 local ipi_period="$(echo $param | cut -d ':' -f 2)"
developerc9333e12023-04-06 18:07:42 +0800795 local ipi_antenna="$(echo $param | cut -d ':' -f 3)"
developerb403ad02022-11-08 10:16:29 +0800796
developerc9333e12023-04-06 18:07:42 +0800797 if [ -z $ipi_antenna ]; then
798 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period}"
799 else
800 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period} ipi_antenna_idx=${ipi_antenna}"
801 fi
developerb403ad02022-11-08 10:16:29 +0800802 ;;
803 *)
804 esac
805}
806
developerb9b4cd12022-10-11 13:18:59 +0800807function do_ate_work() {
808 local ate_cmd=$1
809
810 case ${ate_cmd} in
811 "ATESTART")
812 local if_str=$(ifconfig | grep mon${phy_idx})
813
814 if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
815 echo "ATE already starts."
816 else
817 do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
developer3f784572023-01-31 15:21:28 +0800818
819 if [ $phy_idx -ge $SOC_start_idx ]; then
820 local end_idx=$SOC_end_idx
821 local start_idx=$SOC_start_idx
822 else
823 local end_idx=$((SOC_start_idx-1))
824 local start_idx="0"
825 fi
826
827 for phy_index in $( seq $start_idx $end_idx )
828 do
829 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
830 local prev_phy_index=$((phy_index-1))
831 local if_num=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep -c Interface)
832 local j="1"
833 # avoid del_if_count reset to 0 when start ate on another band in dbdc case
834 local del_if_count=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
835 if [ -z "${del_if_count}" ]; then
836 local del_if_count="0"
837 fi
838
839 for if_count in $( seq 1 $if_num )
840 do
841 local del_if=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep Interface | sed -n ${j}p | cut -d " " -f 2)
842 if [ ! -z "${del_if}" ] && [[ "$del_if" != *"mon"* ]]; then
843 do_cmd "iw dev ${del_if} del"
844 del_if_count=$((del_if_count+1))
845 # handle the case of multiple interface in a phy
846 record_config "DEL_IF${phy_index}-${del_if_count}" ${del_if} ${interface_file}
847 else
848 # j add 1 to skip mon interface
849 j=$((j+1))
850 fi
851 done
852 record_config "DEL_IF${phy_index}_NUM" ${del_if_count} ${interface_file}
853 done
854
developerb9b4cd12022-10-11 13:18:59 +0800855 do_cmd "ifconfig mon${phy_idx} up"
856 do_cmd "iw reg set VV"
857 fi
858 ;;
859 "ATESTOP")
860 local if_str=$(ifconfig | grep mon${phy_idx})
861
862 if [ -z "${if_str}" -a "${if_str}" != " " ]; then
863 echo "ATE does not start."
864 else
865 do_cmd "mt76-test ${interface} set state=off"
866 do_cmd "iw dev mon${phy_idx} del"
developer3f784572023-01-31 15:21:28 +0800867
868 if [ $phy_idx -ge $SOC_start_idx ]; then
869 local end_idx=$SOC_end_idx
870 local start_idx=$SOC_start_idx
871 else
872 local end_idx=$((SOC_start_idx-1))
873 local start_idx="0"
874 fi
875
876 # first check its phy and dbdc band phy has monitor interface or not
877 # if has at lease one mon interface, then skip adding back normal interface
878 local has_mon="0"
879 for phy_index in $( seq $start_idx $end_idx )
880 do
881 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
882 local prev_phy_index=$((phy_index-1))
883 local has_mon_phy=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep "Interface mon")
884 # if this phy interface has mon interface
885 if [ ! -z "${has_mon_phy}" ]; then
886 local has_mon="1"
887 fi
888 done
889
890 for phy_index in $( seq $start_idx $end_idx )
891 do
892 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
893 local prev_phy_index=$((phy_index-1))
894 local j="1"
895 local add_if_num=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
896 if [ -z "${add_if_num}" ]; then
897 local add_if_num="0"
898 fi
899 # if this phy interface (including its dbdc phy) has no mon interface and can find deleted interface in file, then add it back
900 if [ "${has_mon}" == "0" ] && [ $add_if_num -ge "1" ]; then
901 local if_index=$add_if_num
902 # add interface backwards
903 while [ $if_index -gt "0" ]
904 do
905 local add_if=$(get_config "DEL_IF${phy_index}-${if_index}" ${interface_file})
906 do_cmd "iw phy phy${phy_index} interface add ${add_if} type managed"
907 # remove the deleted interface in interface_file since it is added back
908 sed -i "/DEL_IF${phy_index}-${if_index}=/d" ${interface_file}
909 if_index=$((if_index-1))
910 done
911 # remove the number of deleted interface in interface_file since it is all added back
912 sed -i "/DEL_IF${phy_index}_NUM=/d" ${interface_file}
913 fi
914 done
915
developerb9b4cd12022-10-11 13:18:59 +0800916 do_cmd "mt76-test ${interface} set aid=0"
917 fi
918
developer13655da2023-01-10 19:53:25 +0800919 if [ ${phy_idx} -lt ${SOC_start_idx} ]; then
developerb9b4cd12022-10-11 13:18:59 +0800920 sed -i '/_PCIE=/d' ${iwpriv_file}
developer13655da2023-01-10 19:53:25 +0800921 elif [ ${phy_idx} -ge ${SOC_start_idx} ]; then
922 sed -i '/_SOC=/d' ${iwpriv_file}
developerb9b4cd12022-10-11 13:18:59 +0800923 fi
924 ;;
925 "TXCOMMIT")
926 do_cmd "mt76-test ${interface} set aid=1"
927 ;;
928 "TXFRAME")
929 do_cmd "mt76-test ${interface} set state=tx_frames"
930 ;;
931 "TXSTOP"|"RXSTOP")
932 do_cmd "mt76-test ${interface} set state=idle"
933 ;;
934 "TXREVERT")
935 do_cmd "mt76-test ${interface} set aid=0"
936 ;;
937 "RXFRAME")
938 do_cmd "mt76-test ${interface} set state=rx_frames"
939 ;;
940 "TXCONT")
941 do_cmd "mt76-test ${interface} set state=tx_cont"
942 ;;
943 "GROUPREK")
944 do_cmd "mt76-test ${interface} set state=group_prek"
945 do_cmd "atenl -i ${interface} -c \"eeprom precal sync group\""
946 ;;
947 "GROUPREKDump")
948 do_cmd "mt76-test ${interface} set state=group_prek_dump"
949 ;;
950 "GROUPREKClean")
951 do_cmd "mt76-test ${interface} set state=group_prek_clean"
952 do_cmd "atenl -i ${interface} -c \"eeprom precal group clean\""
953 ;;
954 "DPD2G")
955 do_cmd "mt76-test ${interface} set state=dpd_2g"
956 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 2g\""
957 ;;
958 "DPD5G")
959 do_cmd "mt76-test ${interface} set state=dpd_5g"
960 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 5g\""
961 ;;
962 "DPD6G")
963 do_cmd "mt76-test ${interface} set state=dpd_6g"
964 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 6g\""
965 ;;
966 "DPDDump")
967 do_cmd "mt76-test ${interface} set state=dpd_dump"
968 ;;
969 "DPDClean")
970 do_cmd "mt76-test ${interface} set state=dpd_clean"
971 do_cmd "atenl -i ${interface} -c \"eeprom precal dpd clean\""
972 ;;
973 *)
974 print_debug "skip ${ate_cmd}"
975 ;;
976 esac
977}
978
developer13655da2023-01-10 19:53:25 +0800979function dump_usage {
980 echo "Usage:"
981 echo " mwctl <interface> set csi ctrl=<opt1>,<opt2>,<opt3>,<opt4> (macaddr=<macaddr>)"
982 echo " mwctl <interface> set csi interval=<interval (us)>"
983 echo " mwctl <interface> dump csi <packet num> <filename>"
984 echo " mwctl <interface> set amnt <index>(0x0~0xf) <mac addr>(xx:xx:xx:xx:xx:xx)"
985 echo " mwctl <interface> dump amnt <index> (0x0~0xf or 0xff)"
986 echo " mwctl <interface> set ap_rfeatures he_gi=<val>"
987 echo " mwctl <interface> set ap_rfeatures he_ltf=<val>"
988 echo " mwctl <interface> set ap_rfeatures trig_type=<enable>,<val> (val: 0-7)"
989 echo " mwctl <interface> set ap_rfeatures ack_policy=<val> (val: 0-4)"
990 echo " mwctl <interface> set ap_wireless fixed_mcs=<val>"
991 echo " mwctl <interface> set ap_wireless ofdma=<val> (0: disable, 1: DL, 2: UL)"
992 echo " mwctl <interface> set ap_wireless nusers_ofdma=<val>"
993 echo " mwctl <interface> set ap_wireless ppdu_type=<val> (0: SU, 1: MU, 4: LEGACY)"
994 echo " mwctl <interface> set ap_wireless add_ba_req_bufsize=<val>"
995 echo " mwctl <interface> set ap_wireless mimo=<val> (0: DL, 1: UL)"
996 echo " mwctl <interface> set ap_wireless ampdu=<enable>"
997 echo " mwctl <interface> set ap_wireless amsdu=<enable>"
998 echo " mwctl <interface> set ap_wireless cert=<enable>"
developer2c78ce72023-02-24 11:26:12 +0800999 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 +08001000 echo " mwctl <interface> dump phy_capa"
1001}
1002
developer092b55c2023-01-18 18:20:58 +08001003function register_handler {
1004
developer9237f442024-06-14 17:13:04 +08001005 local offset=$1
1006 local val=$2
1007 local cmd=$3
developer092b55c2023-01-18 18:20:58 +08001008 local w_cmd="write"
1009
developer9237f442024-06-14 17:13:04 +08001010 regidx=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/regidx
1011 regval=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/regval
developer092b55c2023-01-18 18:20:58 +08001012
1013 echo ${offset} > ${regidx}
1014 if [[ "${cmd}" == "${w_cmd}" ]]; then
1015 echo ${val} > ${regval}
1016 fi
1017
1018 res=$(cat ${regval} | cut -d 'x' -f 2)
1019 printf "%s mac:[%s]:%s\n" ${interface_ori} ${offset} ${res}
1020}
1021
developerb9b4cd12022-10-11 13:18:59 +08001022# main start here
developer3f784572023-01-31 15:21:28 +08001023parse_sku
developer13655da2023-01-10 19:53:25 +08001024if [ -z ${interface} ]; then
1025 dump_usage
1026 exit
1027elif [[ ${interface} == "ra"* ]]; then
developerb9b4cd12022-10-11 13:18:59 +08001028 convert_interface $interface
developerbb6ddff2023-03-08 17:22:32 +08001029elif [[ ${interface} == "phy" ]]; then
1030 # handle mwctl phy phy0 e2p ... case
1031 interface=$2
1032 cmd_type=$3
1033 full_cmd=$4
developerb9b4cd12022-10-11 13:18:59 +08001034fi
1035
developer9237f442024-06-14 17:13:04 +08001036# get main phy idx
1037if [ "${phy_idx}" -ge "${SOC_start_idx}" ]; then
1038 main_phy_idx=${SOC_start_idx}
1039fi
1040
developerb9b4cd12022-10-11 13:18:59 +08001041tmp_work_mode=$(get_config "WORKMODE" ${iwpriv_file})
1042
1043if [ ! -z ${tmp_work_mode} ]; then
1044 work_mode=${tmp_work_mode}
1045fi
1046
1047cmd=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 1)
1048param=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 2)
developera20cdc22024-05-31 18:57:31 +08001049mld=$(iw dev | grep 'link ID')
developerb9b4cd12022-10-11 13:18:59 +08001050
1051if [ "${cmd_type}" = "set" ]; then
1052 skip=0
1053 case ${cmd} in
developer13655da2023-01-10 19:53:25 +08001054 ## In wifi 7 chipset, testmode & vendor command both use mwctl
1055 ## Therefore this wrapper would translate it to either mt76-test or mt76-vendor based on the attribute of the command
1056 ## Translate to mt76-vendor command
developer327aa322023-07-10 13:49:56 +08001057 "csi"|"amnt"|"ap_rfeatures"|"ap_wireless"|"mu"|"set_muru_manual_config")
developera20cdc22024-05-31 18:57:31 +08001058 cert_cmd="$*"
developer42c7a432024-07-12 14:39:29 +08001059
1060 if [ ! -z "$mld" ]; then
1061 mld_interface=$(iw dev | grep Interface | awk '{print $2}')
1062 if [ $cmd == "ap_rfeatures" ] || [ "$cmd" == "ap_wireless" ]; then
1063
1064 band_number=$(echo "$cert_cmd" | grep -o 'band[0-9]*')
1065
1066 links_info_base="/sys/kernel/debug/ieee80211/phy0/netdev"
1067 links_info_intf="${mld_interface}/mt76_links_info"
1068 links_info_cmd="${links_info_base}:${links_info_intf}"
1069
1070 band_link_id_info=$(
1071 cat "$links_info_cmd" | grep "${band_number}_link_id"
1072 )
1073 band_link_id=$(
1074 echo "$band_link_id_info" | awk -F'=' '{print $2}' | tr -d ' '
1075 )
1076
1077 cmd_w_link_id=$(echo $* | sed "s/band[0-9]/& -l ${band_link_id}/g")
1078 cert_cmd=${cmd_w_link_id}
1079
1080 fi
1081 ## convert bandX to mld interface name
1082 cert_cmd="$(echo ${cert_cmd} | sed 's/band[0-9]/${mld_interface}/')"
1083 fi
1084
developerc8796032023-08-09 10:28:15 +08001085 if [ ${is_connac3} == "1" ]; then
developera20cdc22024-05-31 18:57:31 +08001086 hostapd_cmd="$(echo $cert_cmd | sed 's/set/raw/')"
developer1475cf22023-05-05 13:45:43 +08001087 do_cmd "hostapd_cli -i $hostapd_cmd"
developerbb6ddff2023-03-08 17:22:32 +08001088 else
developera20cdc22024-05-31 18:57:31 +08001089 do_cmd "mt76-vendor $cert_cmd"
developerbb6ddff2023-03-08 17:22:32 +08001090 fi
1091 skip=1
developer13655da2023-01-10 19:53:25 +08001092 ;;
developer42c7a432024-07-12 14:39:29 +08001093 "txbftxsndinfo"|"TxBfTxSndInfo")
1094 cert_cmd="$*"
1095 cmd_setting=$(echo $cert_cmd | awk -F'=' '{print $2}')
1096 snd_cmd_base="/sys/kernel/debug/ieee80211/phy0/mt76/band0/bf_txsnd_info"
1097 mt76_snd_cmd="echo $cmd_setting > $snd_cmd_base"
1098 do_cmd "$mt76_snd_cmd"
1099 skip=1
1100 ;;
1101 "muruDbgInfo")
1102 cert_cmd="$*"
1103 cmd_setting=$(echo $cert_cmd | awk -F'=' '{print $2}')
1104 muru_cmd_base="/sys/kernel/debug/ieee80211/phy0/mt76/muru_dbg"
1105 mt76_muru_cmd="echo $cmd_setting > $muru_cmd_base"
1106 do_cmd "$mt76_muru_cmd"
1107 skip=1
1108 ;;
developerb9b4cd12022-10-11 13:18:59 +08001109 "ATE")
1110 do_ate_work ${param}
1111
1112 skip=1
1113 ;;
developerd0c89452024-10-11 16:53:27 +08001114 "ATETXCNT"|"ATETXLEN"|"ATETXMCS"|"ATEVHTNSS"|"ATETXNSS"|"ATETXLDPC"|"ATETXSTBC"| \
developerb9b4cd12022-10-11 13:18:59 +08001115 "ATEPKTTXTIME"|"ATEIPG"|"ATEDUTYCYCLE"|"ATETXFREQOFFSET")
1116 cmd_new=$(simple_convert ${cmd})
1117 if [ "${param_new}" = "undefined" ]; then
1118 echo "unknown cmd: ${cmd}"
1119 exit
1120 fi
1121 param_new=${param}
developerc5ce7502022-12-19 11:33:22 +08001122 if [ "${cmd}" = "ATETXCNT" ] && [ "${param}" = "0" ]; then
developer15c355d2023-03-21 17:28:34 +08001123 param_new="0xFFFFFFFF"
developerc5ce7502022-12-19 11:33:22 +08001124 fi
developerb9b4cd12022-10-11 13:18:59 +08001125 ;;
1126 "ATETXANT"|"ATERXANT")
1127 cmd_new="tx_antenna"
1128 param_new=${param}
1129 ;;
1130 "ATETXGI")
developerc8796032023-08-09 10:28:15 +08001131 if [ ${is_connac3} == "0" ]; then
developerbb6ddff2023-03-08 17:22:32 +08001132 tx_mode=$(convert_tx_mode $(get_config "ATETXMODE" ${iwpriv_file}))
1133 convert_gi ${tx_mode} ${param}
1134 skip=1
1135 else
1136 cmd_new="tx_rate_sgi"
1137 param_new=${param}
1138 fi
developerb9b4cd12022-10-11 13:18:59 +08001139 ;;
1140 "ATETXMODE")
1141 cmd_new="tx_rate_mode"
1142 param_new=$(convert_tx_mode ${param})
1143 if [ "${param_new}" = "undefined" ]; then
1144 echo "unknown tx mode"
1145 echo "0:cck, 1:ofdm, 2:ht, 4:vht, 8:he_su, 9:he_er, 10:he_tb, 11:he_mu"
1146 exit
1147 else
1148 record_config ${cmd} ${param} ${iwpriv_file}
1149 fi
1150 ;;
developerbb6ddff2023-03-08 17:22:32 +08001151 "ATETXPOW0"|"ATETXPOW1"|"ATETXPOW2"|"ATETXPOW3"|"ATETXPOW")
developerb9b4cd12022-10-11 13:18:59 +08001152 cmd_new="tx_power"
developerbb6ddff2023-03-08 17:22:32 +08001153 if [ "${param}" == "127" ]; then
1154 # for iTest verification
1155 exit
1156 fi
developerb9b4cd12022-10-11 13:18:59 +08001157 param_new="${param},0,0,0"
1158 ;;
developerbb6ddff2023-03-08 17:22:32 +08001159 "ATEMUAID")
1160 cmd_new="aid"
1161 param_new=${param}
1162 ;;
developerb9b4cd12022-10-11 13:18:59 +08001163 "ATETXBW")
developer05f3b2b2024-08-19 19:17:34 +08001164 convert_bw ${param}
developerb9b4cd12022-10-11 13:18:59 +08001165 skip=1
1166 ;;
1167 "ATECHANNEL")
1168 convert_channel ${param}
1169 skip=1
1170 ;;
1171 "ATERXSTAT")
1172 convert_rxstat
1173 skip=1
1174 ;;
1175 "ATECTRLBANDIDX")
1176 change_band_idx ${param}
1177 skip=1
1178 ;;
1179 "ATEDA"|"ATESA"|"ATEBSSID")
1180 set_mac_addr ${cmd} ${param}
1181 skip=1
1182 ;;
developerb403ad02022-11-08 10:16:29 +08001183 "DfsRxCtrl"|"DfsRxHist")
1184 convert_dfs ${cmd} ${param}
1185 skip=1
1186 ;;
developerc5ce7502022-12-19 11:33:22 +08001187 "ATETxBfInit"|"ATETxBfGdInit"|"ATEIBFPhaseComp"|"ATEEBfProfileConfig"|"ATEIBfProfileConfig"| \
1188 "TxBfTxApply"|"ATETxPacketWithBf"|"TxBfProfileData20MAllWrite"|"ATEIBfInstCal"| \
developer7af0f762023-05-22 15:16:16 +08001189 "ATEIBfGdCal"|"ATEIBFPhaseE2pUpdate"|"TriggerSounding"|"StopSounding"|"TxBfTxCmd"| \
developerc5ce7502022-12-19 11:33:22 +08001190 "StaRecBfRead"|"TxBfProfileTagInValid"|"TxBfProfileTagWrite"|"TxBfProfileTagRead"| \
1191 "ATEIBFPhaseVerify"|"ATEConTxETxBfGdProc"|"ATEConTxETxBfInitProc")
developerb9b4cd12022-10-11 13:18:59 +08001192 convert_ibf ${cmd} ${param}
1193 skip=1
1194 ;;
1195 "bufferMode")
1196 if [ "${param}" = "2" ]; then
1197 do_cmd "atenl -i ${interface} -c \"eeprom update buffermode\""
1198 fi
1199 skip=1
1200 ;;
1201 "ResetCounter"|"ATERXSTATRESET")
1202 skip=1
1203 ;;
1204 "WORKMODE")
1205 record_config "WORKMODE" ${param} ${iwpriv_file}
1206 echo "Entering ${param} mode in iwpriv"
1207 skip=1
1208 ;;
developer9a587882023-07-17 11:11:44 +08001209 "ATERUINFO")
1210 convert_ruinfo ${param}
1211 skip=1
1212 ;;
developerb9b4cd12022-10-11 13:18:59 +08001213 *)
1214 print_debug "Unknown command to set: ${cmd}"
1215 skip=1
1216 esac
1217
1218 if [ "${skip}" != "1" ]; then
1219 do_cmd "mt76-test ${interface} set ${cmd_new}=${param_new}"
1220 fi
1221
1222elif [ "${cmd_type}" = "show" ]; then
developerc5ce7502022-12-19 11:33:22 +08001223 if [ "${cmd}" = "wtbl" ]; then
developer9237f442024-06-14 17:13:04 +08001224 wlan_idx=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/wlan_idx
1225 wtbl_info=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/wtbl_info
developerc5ce7502022-12-19 11:33:22 +08001226
1227 do_cmd "echo ${param} > ${wlan_idx}"
1228 do_cmd "cat ${wtbl_info}"
developerbb6ddff2023-03-08 17:22:32 +08001229 elif [ "${cmd}" = "ATERXSTAT" ]; then
1230 convert_rxstat
developerc5ce7502022-12-19 11:33:22 +08001231 else
1232 do_cmd "mt76-test ${interface} dump"
1233 do_cmd "mt76-test ${interface} dump stats"
1234 fi
developerb9b4cd12022-10-11 13:18:59 +08001235
1236elif [ "${cmd_type}" = "e2p" ]; then
developer13655da2023-01-10 19:53:25 +08001237 # support multiple read write
developerb9b4cd12022-10-11 13:18:59 +08001238 # eeprom offset write
1239 if [[ ${full_cmd} == *"="* ]]; then
developer13655da2023-01-10 19:53:25 +08001240 IFS=,
1241 for tuple in $full_cmd
1242 do
1243 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1244 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1245 offset=$(printf "0x%s" ${cmd})
1246 val=$(printf "0x%s" ${param})
1247 tmp=$((${val} & 0xff))
1248 tmp=$(printf "0x%x" ${tmp})
1249 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
developerb9b4cd12022-10-11 13:18:59 +08001250
developer13655da2023-01-10 19:53:25 +08001251 offset=$((${offset}))
1252 offset=$(expr ${offset} + "1")
1253 offset=$(printf "0x%x" ${offset})
1254 tmp=$(((${val} >> 8) & 0xff))
1255 tmp=$(printf "0x%x" ${tmp})
1256 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
1257 done
developerb9b4cd12022-10-11 13:18:59 +08001258 else
developer13655da2023-01-10 19:53:25 +08001259 IFS=,
1260 for tuple in $full_cmd
1261 do
1262 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1263 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1264 offset=$(printf "0x%s" ${cmd})
1265 val=$(printf "0x%s" ${param})
1266 v1=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param}\"")
1267 v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developerb9b4cd12022-10-11 13:18:59 +08001268
developer13655da2023-01-10 19:53:25 +08001269 tmp=$(printf "0x%s" ${param})
1270 tmp=$((${tmp}))
1271 param2=$(expr ${tmp} + "1")
1272 param2=$(printf "%x" ${param2})
1273 v2=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param2}\"")
1274 v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developerb9b4cd12022-10-11 13:18:59 +08001275
developer13655da2023-01-10 19:53:25 +08001276 param=$(printf "0x%s" ${param})
1277 param=$(printf "%04x" ${param})
1278 param=$(echo $param | tr 'a-z' 'A-Z')
1279 printf "%s e2p:\n" ${interface_ori}
1280 printf "[0x%s]:0x%02x%02x\n" ${param} ${v2} ${v1}
1281 done
developerb9b4cd12022-10-11 13:18:59 +08001282 fi
1283
1284elif [ "${cmd_type}" = "mac" ]; then
developerb9b4cd12022-10-11 13:18:59 +08001285 offset=$(printf "0x%s" ${cmd})
1286 val=$(printf "0x%s" ${param})
1287
developerb9b4cd12022-10-11 13:18:59 +08001288 # reg write
1289 if [[ ${full_cmd} == *"="* ]]; then
developer9237f442024-06-14 17:13:04 +08001290 register_handler ${offset} ${val} "write"
developer092b55c2023-01-18 18:20:58 +08001291 else
1292 start_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 1)
1293 end_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 2)
1294 loop=$((0x${end_addr}-0x${start_addr}))
developerb9b4cd12022-10-11 13:18:59 +08001295
developer092b55c2023-01-18 18:20:58 +08001296 if [[ ${loop} == "0" ]]; then
developer9237f442024-06-14 17:13:04 +08001297 register_handler ${offset} ${val}
developer092b55c2023-01-18 18:20:58 +08001298 else
1299 i=0
1300 while [ $i -le $loop ]; do
1301 addr=$((0x${start_addr}+$i))
1302 offset=$(printf "0x%x" ${addr})
developer9237f442024-06-14 17:13:04 +08001303 register_handler ${offset} ${val}
developer092b55c2023-01-18 18:20:58 +08001304 i=$(($i + 4))
1305 done
1306 fi
1307 fi
developerb9b4cd12022-10-11 13:18:59 +08001308
developer13655da2023-01-10 19:53:25 +08001309## dump command is only for vendor commands
1310elif [ "${cmd_type}" = "dump" ]; then
1311 do_cmd "mt76-vendor $*"
developerc9333e12023-04-06 18:07:42 +08001312elif [ "${cmd_type}" = "switch" ]; then
developer2299de92023-10-27 15:40:47 +08001313 eeprom_mode_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom_mode
developerc9333e12023-04-06 18:07:42 +08001314 eeprom_mode=$(cat ${eeprom_mode_file} | grep "mode" | sed -n 2p | cut -d " " -f 4)
1315 eeprom_testmode_offset="1af"
1316 testmode_enable="0"
1317
developerc8796032023-08-09 10:28:15 +08001318 if [ ${is_connac3} == "0" ]; then
developerc9333e12023-04-06 18:07:42 +08001319 return
1320 fi
1321
1322 if [ "${cmd}" = "testmode" ]; then
1323 testmode_enable="1"
developerdad89a32024-04-29 14:17:17 +08001324 do_cmd "wifi down"
1325 do_cmd "uci set wireless.radio0.disabled=1"
1326 do_cmd "uci set wireless.radio1.disabled=1"
1327 do_cmd "uci set wireless.radio2.disabled=1"
1328 do_cmd "uci commit"
developerc9333e12023-04-06 18:07:42 +08001329 fi
1330
1331 if [ "${eeprom_mode}" = "flash" ]; then
1332 ## flash mode should set eeprom testmode offset bit
1333 ## efuse/bin file/default bin mode rely on module param only
1334 do_cmd "atenl -i ${interface} -c \"eeprom set 0x${eeprom_testmode_offset}=0x${testmode_enable}\""
1335 ## If has no precal, it would not affect
1336 do_cmd "atenl -i ${interface} -c \"eeprom precal sync\""
1337 do_cmd "atenl -i ${interface} -c \"sync eeprom all\""
1338 fi
1339
1340 do_cmd "rmmod mt7996e"
1341 do_cmd "rmmod mt76-connac-lib"
1342 do_cmd "rmmod mt76"
1343 do_cmd "rmmod mac80211"
1344 do_cmd "rmmod cfg80211"
1345 do_cmd "rmmod compat"
1346 do_cmd "insmod compat"
1347 do_cmd "insmod cfg80211"
1348 do_cmd "insmod mac80211"
1349 do_cmd "insmod mt76"
1350 do_cmd "insmod mt76-connac-lib"
1351 do_cmd "insmod mt7996e testmode_enable=${testmode_enable}"
1352 do_cmd "sleep 5"
1353 do_cmd "killall hostapd"
1354 do_cmd "killall netifd"
developerb9b4cd12022-10-11 13:18:59 +08001355else
1356 echo "Unknown command"
1357fi