blob: 903705476e95de5ded09adf1c477df464e46c3fa [file] [log] [blame]
developerb9b4cd12022-10-11 13:18:59 +08001#!/bin/ash
2# This script is used for wrapping atenl daemon to ated
3# 0 is normal mode, 1 is used for doing specific commands such as "sync eeprom all"
4
5work_mode="RUN" # RUN/PRINT/DEBUG
6mode="0"
7add_quote="0"
8cmd="atenl"
9interface=""
10phy_idx=0
11ated_file="/tmp/interface"
developer9237f442024-06-14 17:13:04 +080012iwpriv_file="/tmp/iwpriv_wrapper"
developer13655da2023-01-10 19:53:25 +080013SOC_start_idx="0"
developer9237f442024-06-14 17:13:04 +080014SOC_end_idx="0"
15is_connac3="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")
26 eval "$1"
27 echo "$1"
28 ;;
29 esac
30}
31
32function record_config() {
developer13655da2023-01-10 19:53:25 +080033 local config=$1
developerb9b4cd12022-10-11 13:18:59 +080034 local tmp_file=$3
developer13655da2023-01-10 19:53:25 +080035
developer9237f442024-06-14 17:13:04 +080036 # check it is SOC(mt7986)/Eagle/Kite or PCIE card (mt7915/7916), and write its config
37 if [ ${config} != "STARTIDX" ] && [ ${config} != "ENDIDX" ] && [ ${config} != "IS_CONNAC3" ]; then
developer13655da2023-01-10 19:53:25 +080038 if [ $phy_idx -lt $SOC_start_idx ]; then
39 config="${config}_PCIE"
40 elif [ $phy_idx -ge $SOC_start_idx ]; then
41 config="${config}_SOC"
42 fi
43 fi
44
developerb9b4cd12022-10-11 13:18:59 +080045 if [ -f ${tmp_file} ]; then
developer13655da2023-01-10 19:53:25 +080046 if grep -q ${config} ${tmp_file}; then
47 sed -i "/${config}/c\\${config}=$2" ${tmp_file}
developerb9b4cd12022-10-11 13:18:59 +080048 else
developer13655da2023-01-10 19:53:25 +080049 echo "${config}=$2" >> ${tmp_file}
developerb9b4cd12022-10-11 13:18:59 +080050 fi
51 else
developer13655da2023-01-10 19:53:25 +080052 echo "${config}=$2" >> ${tmp_file}
developerb9b4cd12022-10-11 13:18:59 +080053 fi
54}
55
56function get_config() {
developer13655da2023-01-10 19:53:25 +080057 local config=$1
developerb9b4cd12022-10-11 13:18:59 +080058 local tmp_file=$2
developer13655da2023-01-10 19:53:25 +080059
developerb9b4cd12022-10-11 13:18:59 +080060 if [ ! -f ${tmp_file} ]; then
61 echo ""
62 return
63 fi
64
developer9237f442024-06-14 17:13:04 +080065 # check it is SOC(mt7986)/Eagle/Kite or PCIE card (mt7915/7916), and write its config
66 if [ ${config} != "STARTIDX" ] && [ ${config} != "ENDIDX" ] && [ ${config} != "IS_CONNAC3" ]; then
developer13655da2023-01-10 19:53:25 +080067 if [ $phy_idx -lt $SOC_start_idx ]; then
68 config="${config}_PCIE"
69 elif [ $phy_idx -ge $SOC_start_idx ]; then
70 config="${config}_SOC"
71 fi
72 fi
73
74 if grep -q ${config} ${tmp_file}; then
75 echo "$(cat ${tmp_file} | grep ${config} | sed s/=/' '/g | cut -d " " -f 2)"
developerb9b4cd12022-10-11 13:18:59 +080076 else
77 echo ""
78 fi
79}
80
developer9237f442024-06-14 17:13:04 +080081function parse_sku {
developer13655da2023-01-10 19:53:25 +080082 SOC_start_idx=$(get_config "STARTIDX" ${ated_file})
developer9237f442024-06-14 17:13:04 +080083 SOC_end_idx=$(get_config "ENDIDX" ${ated_file})
84 is_connac3=$(get_config "IS_CONNAC3" ${ated_file})
developerb9b4cd12022-10-11 13:18:59 +080085 local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom
developer9237f442024-06-14 17:13:04 +080086 if [ -z "${SOC_start_idx}" ] || [ -z "${SOC_end_idx}" ] || [ -z "${is_connac3}" ]; then
developerb9b4cd12022-10-11 13:18:59 +080087 if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then
developer13655da2023-01-10 19:53:25 +080088 SOC_start_idx="2"
developer9237f442024-06-14 17:13:04 +080089 SOC_end_idx="3"
90 is_connac3="0"
developerb9b4cd12022-10-11 13:18:59 +080091 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then
developer13655da2023-01-10 19:53:25 +080092 SOC_start_idx="1"
developer9237f442024-06-14 17:13:04 +080093 SOC_end_idx="2"
94 is_connac3="0"
95 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7981")" ]; then
96 SOC_start_idx="0"
97 SOC_end_idx="1"
98 is_connac3="0"
developerb9b4cd12022-10-11 13:18:59 +080099 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then
developer13655da2023-01-10 19:53:25 +0800100 SOC_start_idx="0"
developer9237f442024-06-14 17:13:04 +0800101 SOC_end_idx="1"
102 is_connac3="0"
developer13655da2023-01-10 19:53:25 +0800103 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7990")" ]; then
104 SOC_start_idx="0"
developer9237f442024-06-14 17:13:04 +0800105 SOC_end_idx="2"
106 is_connac3="1"
107 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7992")" ]; then
108 SOC_start_idx="0"
109 SOC_end_idx="1"
110 is_connac3="1"
developerb9b4cd12022-10-11 13:18:59 +0800111 else
developer13655da2023-01-10 19:53:25 +0800112 echo "Interface Conversion Failed!"
113 echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands"
developer9237f442024-06-14 17:13:04 +0800114 echo "For AX3000/AX6000:"
115 echo " echo STARTIDX=0 >> ${ated_file}"
116 echo " echo ENDIDX=1 >> ${ated_file}"
117 echo " echo IS_CONNAC3=0 >> ${ated_file}"
118 echo "For AX7800:"
119 echo " echo STARTIDX=2 >> ${ated_file}"
120 echo " echo ENDIDX=3 >> ${ated_file}"
121 echo " echo IS_CONNAC3=0 >> ${ated_file}"
122 echo "For AX8400:"
123 echo " echo STARTIDX=1 >> ${ated_file}"
124 echo " echo ENDIDX=2 >> ${ated_file}"
125 echo " echo IS_CONNAC3=0 >> ${ated_file}"
126 echo "For Eagle:"
127 echo " echo STARTIDX=0 >> ${ated_file}"
128 echo " echo ENDIDX=2 >> ${ated_file}"
129 echo " echo IS_CONNAC3=1 >> ${ated_file}"
130 echo "For Kite:"
131 echo " echo STARTIDX=0 >> ${ated_file}"
132 echo " echo ENDIDX=1 >> ${ated_file}"
133 echo " echo IS_CONNAC3=1 >> ${ated_file}"
developer13655da2023-01-10 19:53:25 +0800134 exit 0
developerb9b4cd12022-10-11 13:18:59 +0800135 fi
developer13655da2023-01-10 19:53:25 +0800136 record_config "STARTIDX" ${SOC_start_idx} ${ated_file}
developer9237f442024-06-14 17:13:04 +0800137 record_config "ENDIDX" ${SOC_end_idx} ${ated_file}
138 record_config "IS_CONNAC3" ${is_connac3} ${ated_file}
developerb9b4cd12022-10-11 13:18:59 +0800139 fi
developer9237f442024-06-14 17:13:04 +0800140}
developer13655da2023-01-10 19:53:25 +0800141
developer9237f442024-06-14 17:13:04 +0800142function convert_interface {
143 if [ ${is_connac3} == "0" ]; then
developer13655da2023-01-10 19:53:25 +0800144 if [[ $1 == "raix"* ]]; then
145 phy_idx=1
146 elif [[ $1 == "rai"* ]]; then
147 phy_idx=0
148 elif [[ $1 == "rax"* ]]; then
149 phy_idx=$((SOC_start_idx+1))
150 else
151 phy_idx=$SOC_start_idx
152 fi
153
154 # convert phy index according to band idx
developer9237f442024-06-14 17:13:04 +0800155 local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
developer13655da2023-01-10 19:53:25 +0800156 if [ "${band_idx}" = "0" ]; then
157 if [[ $1 == "raix"* ]]; then
158 phy_idx=0
159 elif [[ $1 == "rax"* ]]; then
160 phy_idx=$SOC_start_idx
161 fi
162 elif [ "${band_idx}" = "1" ]; then
163 if [[ $1 == "rai"* ]]; then
164 # AX8400: mt7915 remain phy0
165 # AX7800: mt7916 becomes phy1
166 phy_idx=$((SOC_start_idx-1))
167 elif [[ $1 == "ra"* ]]; then
168 phy_idx=$((SOC_start_idx+1))
169 fi
170 fi
developerb9b4cd12022-10-11 13:18:59 +0800171 else
developer9237f442024-06-14 17:13:04 +0800172 # Connac 3 chips has different mapping method
developer13655da2023-01-10 19:53:25 +0800173 # phy0: ra0
174 # phy1: rai0
175 # phy2: rax0
176 if [[ $1 == "rai"* ]]; then
177 phy_idx=1
178 elif [[ $1 == "rax"* ]]; then
179 phy_idx=2
180 else
181 phy_idx=0
182 fi
developerb9b4cd12022-10-11 13:18:59 +0800183 fi
developerb9b4cd12022-10-11 13:18:59 +0800184
developer13655da2023-01-10 19:53:25 +0800185 interface="phy${phy_idx}"
186}
developerb9b4cd12022-10-11 13:18:59 +0800187
188for i in "$@"
189do
190 if [ "$i" = "-c" ]; then
191 cmd="${cmd} -c"
192 mode="1"
193 add_quote="1"
194 elif [ "${add_quote}" = "1" ]; then
195 cmd="${cmd} \"${i}\""
196 add_quote="0"
197 else
198 if [[ ${i} == "ra"* ]]; then
developer9237f442024-06-14 17:13:04 +0800199 parse_sku
developerb9b4cd12022-10-11 13:18:59 +0800200 convert_interface $i
201 cmd="${cmd} ${interface}"
202 else
203 cmd="${cmd} ${i}"
204 fi
205 fi
206done
207
208if [ "$mode" = "0" ]; then
209 killall atenl > /dev/null 2>&1
210fi
211
212do_cmd "${cmd}"