blob: 9046136a567e7252a9ed78ae5dac50b0c10da284 [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"
developerd0c89452024-10-11 16:53:27 +0800111 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7993")" ]; then
112 SOC_start_idx="0"
113 SOC_end_idx="1"
114 is_connac3="1"
developerb9b4cd12022-10-11 13:18:59 +0800115 else
developer13655da2023-01-10 19:53:25 +0800116 echo "Interface Conversion Failed!"
117 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 +0800118 echo "For AX3000/AX6000:"
119 echo " echo STARTIDX=0 >> ${ated_file}"
120 echo " echo ENDIDX=1 >> ${ated_file}"
121 echo " echo IS_CONNAC3=0 >> ${ated_file}"
122 echo "For AX7800:"
123 echo " echo STARTIDX=2 >> ${ated_file}"
124 echo " echo ENDIDX=3 >> ${ated_file}"
125 echo " echo IS_CONNAC3=0 >> ${ated_file}"
126 echo "For AX8400:"
127 echo " echo STARTIDX=1 >> ${ated_file}"
128 echo " echo ENDIDX=2 >> ${ated_file}"
129 echo " echo IS_CONNAC3=0 >> ${ated_file}"
130 echo "For Eagle:"
131 echo " echo STARTIDX=0 >> ${ated_file}"
132 echo " echo ENDIDX=2 >> ${ated_file}"
133 echo " echo IS_CONNAC3=1 >> ${ated_file}"
134 echo "For Kite:"
135 echo " echo STARTIDX=0 >> ${ated_file}"
136 echo " echo ENDIDX=1 >> ${ated_file}"
137 echo " echo IS_CONNAC3=1 >> ${ated_file}"
developerd0c89452024-10-11 16:53:27 +0800138 echo "For Griffin:"
139 echo " echo STARTIDX=0 >> ${interface_file}"
140 echo " echo ENDIDX=1 >> ${interface_file}"
141 echo " echo IS_CONNAC3=1 >> ${interface_file}"
developer13655da2023-01-10 19:53:25 +0800142 exit 0
developerb9b4cd12022-10-11 13:18:59 +0800143 fi
developer13655da2023-01-10 19:53:25 +0800144 record_config "STARTIDX" ${SOC_start_idx} ${ated_file}
developer9237f442024-06-14 17:13:04 +0800145 record_config "ENDIDX" ${SOC_end_idx} ${ated_file}
146 record_config "IS_CONNAC3" ${is_connac3} ${ated_file}
developerb9b4cd12022-10-11 13:18:59 +0800147 fi
developer9237f442024-06-14 17:13:04 +0800148}
developer13655da2023-01-10 19:53:25 +0800149
developer9237f442024-06-14 17:13:04 +0800150function convert_interface {
151 if [ ${is_connac3} == "0" ]; then
developer13655da2023-01-10 19:53:25 +0800152 if [[ $1 == "raix"* ]]; then
153 phy_idx=1
154 elif [[ $1 == "rai"* ]]; then
155 phy_idx=0
156 elif [[ $1 == "rax"* ]]; then
157 phy_idx=$((SOC_start_idx+1))
158 else
159 phy_idx=$SOC_start_idx
160 fi
161
162 # convert phy index according to band idx
developer9237f442024-06-14 17:13:04 +0800163 local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
developer13655da2023-01-10 19:53:25 +0800164 if [ "${band_idx}" = "0" ]; then
165 if [[ $1 == "raix"* ]]; then
166 phy_idx=0
167 elif [[ $1 == "rax"* ]]; then
168 phy_idx=$SOC_start_idx
169 fi
170 elif [ "${band_idx}" = "1" ]; then
171 if [[ $1 == "rai"* ]]; then
172 # AX8400: mt7915 remain phy0
173 # AX7800: mt7916 becomes phy1
174 phy_idx=$((SOC_start_idx-1))
175 elif [[ $1 == "ra"* ]]; then
176 phy_idx=$((SOC_start_idx+1))
177 fi
178 fi
developerb9b4cd12022-10-11 13:18:59 +0800179 else
developer9237f442024-06-14 17:13:04 +0800180 # Connac 3 chips has different mapping method
developer13655da2023-01-10 19:53:25 +0800181 # phy0: ra0
182 # phy1: rai0
183 # phy2: rax0
184 if [[ $1 == "rai"* ]]; then
185 phy_idx=1
186 elif [[ $1 == "rax"* ]]; then
187 phy_idx=2
188 else
189 phy_idx=0
190 fi
developerb9b4cd12022-10-11 13:18:59 +0800191 fi
developerb9b4cd12022-10-11 13:18:59 +0800192
developer13655da2023-01-10 19:53:25 +0800193 interface="phy${phy_idx}"
194}
developerb9b4cd12022-10-11 13:18:59 +0800195
196for i in "$@"
197do
198 if [ "$i" = "-c" ]; then
199 cmd="${cmd} -c"
200 mode="1"
201 add_quote="1"
202 elif [ "${add_quote}" = "1" ]; then
203 cmd="${cmd} \"${i}\""
204 add_quote="0"
205 else
206 if [[ ${i} == "ra"* ]]; then
developer9237f442024-06-14 17:13:04 +0800207 parse_sku
developerb9b4cd12022-10-11 13:18:59 +0800208 convert_interface $i
209 cmd="${cmd} ${interface}"
210 else
211 cmd="${cmd} ${i}"
212 fi
213 fi
214done
215
216if [ "$mode" = "0" ]; then
217 killall atenl > /dev/null 2>&1
218fi
219
220do_cmd "${cmd}"