blob: 903705476e95de5ded09adf1c477df464e46c3fa [file] [log] [blame]
developer3abe1ad2022-01-24 11:13:32 +08001#!/bin/ash
2# This script is used for wrapping atenl daemon to ated
developer679a6aa2022-09-07 09:52:41 +08003# 0 is normal mode, 1 is used for doing specific commands such as "sync eeprom all"
developer3abe1ad2022-01-24 11:13:32 +08004
developer679a6aa2022-09-07 09:52:41 +08005work_mode="RUN" # RUN/PRINT/DEBUG
developer3abe1ad2022-01-24 11:13:32 +08006mode="0"
7add_quote="0"
8cmd="atenl"
developer679a6aa2022-09-07 09:52:41 +08009interface=""
10phy_idx=0
11ated_file="/tmp/interface"
developere0111812024-06-03 16:24:42 +080012iwpriv_file="/tmp/iwpriv_wrapper"
developerf90c9af2022-12-28 22:40:23 +080013SOC_start_idx="0"
developere0111812024-06-03 16:24:42 +080014SOC_end_idx="0"
15is_connac3="0"
developer679a6aa2022-09-07 09:52:41 +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() {
developerf90c9af2022-12-28 22:40:23 +080033 local config=$1
developer679a6aa2022-09-07 09:52:41 +080034 local tmp_file=$3
developerf90c9af2022-12-28 22:40:23 +080035
developere0111812024-06-03 16:24:42 +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
developerf90c9af2022-12-28 22:40:23 +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
developer679a6aa2022-09-07 09:52:41 +080045 if [ -f ${tmp_file} ]; then
developerf90c9af2022-12-28 22:40:23 +080046 if grep -q ${config} ${tmp_file}; then
47 sed -i "/${config}/c\\${config}=$2" ${tmp_file}
developer679a6aa2022-09-07 09:52:41 +080048 else
developerf90c9af2022-12-28 22:40:23 +080049 echo "${config}=$2" >> ${tmp_file}
developer679a6aa2022-09-07 09:52:41 +080050 fi
51 else
developerf90c9af2022-12-28 22:40:23 +080052 echo "${config}=$2" >> ${tmp_file}
developer679a6aa2022-09-07 09:52:41 +080053 fi
54}
55
56function get_config() {
developerf90c9af2022-12-28 22:40:23 +080057 local config=$1
developer679a6aa2022-09-07 09:52:41 +080058 local tmp_file=$2
developerf90c9af2022-12-28 22:40:23 +080059
developer679a6aa2022-09-07 09:52:41 +080060 if [ ! -f ${tmp_file} ]; then
61 echo ""
62 return
63 fi
64
developere0111812024-06-03 16:24:42 +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
developerf90c9af2022-12-28 22:40:23 +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)"
developer679a6aa2022-09-07 09:52:41 +080076 else
77 echo ""
78 fi
79}
80
developere0111812024-06-03 16:24:42 +080081function parse_sku {
developerf90c9af2022-12-28 22:40:23 +080082 SOC_start_idx=$(get_config "STARTIDX" ${ated_file})
developere0111812024-06-03 16:24:42 +080083 SOC_end_idx=$(get_config "ENDIDX" ${ated_file})
84 is_connac3=$(get_config "IS_CONNAC3" ${ated_file})
developer679a6aa2022-09-07 09:52:41 +080085 local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom
developere0111812024-06-03 16:24:42 +080086 if [ -z "${SOC_start_idx}" ] || [ -z "${SOC_end_idx}" ] || [ -z "${is_connac3}" ]; then
developer679a6aa2022-09-07 09:52:41 +080087 if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then
developerf90c9af2022-12-28 22:40:23 +080088 SOC_start_idx="2"
developere0111812024-06-03 16:24:42 +080089 SOC_end_idx="3"
90 is_connac3="0"
developer679a6aa2022-09-07 09:52:41 +080091 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then
developerf90c9af2022-12-28 22:40:23 +080092 SOC_start_idx="1"
developere0111812024-06-03 16:24:42 +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"
developer679a6aa2022-09-07 09:52:41 +080099 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then
developerf90c9af2022-12-28 22:40:23 +0800100 SOC_start_idx="0"
developere0111812024-06-03 16:24:42 +0800101 SOC_end_idx="1"
102 is_connac3="0"
developerf90c9af2022-12-28 22:40:23 +0800103 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7990")" ]; then
104 SOC_start_idx="0"
developere0111812024-06-03 16:24:42 +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"
developer679a6aa2022-09-07 09:52:41 +0800111 else
developerf90c9af2022-12-28 22:40:23 +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"
developere0111812024-06-03 16:24:42 +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}"
developerf90c9af2022-12-28 22:40:23 +0800134 exit 0
developer679a6aa2022-09-07 09:52:41 +0800135 fi
developerf90c9af2022-12-28 22:40:23 +0800136 record_config "STARTIDX" ${SOC_start_idx} ${ated_file}
developere0111812024-06-03 16:24:42 +0800137 record_config "ENDIDX" ${SOC_end_idx} ${ated_file}
138 record_config "IS_CONNAC3" ${is_connac3} ${ated_file}
developer679a6aa2022-09-07 09:52:41 +0800139 fi
developere0111812024-06-03 16:24:42 +0800140}
developerf90c9af2022-12-28 22:40:23 +0800141
developere0111812024-06-03 16:24:42 +0800142function convert_interface {
143 if [ ${is_connac3} == "0" ]; then
developerf90c9af2022-12-28 22:40:23 +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
developere0111812024-06-03 16:24:42 +0800155 local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
developerf90c9af2022-12-28 22:40:23 +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
developer679a6aa2022-09-07 09:52:41 +0800171 else
developere0111812024-06-03 16:24:42 +0800172 # Connac 3 chips has different mapping method
developerf90c9af2022-12-28 22:40:23 +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
developer679a6aa2022-09-07 09:52:41 +0800183 fi
developer679a6aa2022-09-07 09:52:41 +0800184
developerf90c9af2022-12-28 22:40:23 +0800185 interface="phy${phy_idx}"
186}
developer3abe1ad2022-01-24 11:13:32 +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
developer679a6aa2022-09-07 09:52:41 +0800198 if [[ ${i} == "ra"* ]]; then
developere0111812024-06-03 16:24:42 +0800199 parse_sku
developer679a6aa2022-09-07 09:52:41 +0800200 convert_interface $i
201 cmd="${cmd} ${interface}"
202 else
203 cmd="${cmd} ${i}"
developer9b7cdad2022-03-10 14:24:55 +0800204 fi
developer3abe1ad2022-01-24 11:13:32 +0800205 fi
206done
207
208if [ "$mode" = "0" ]; then
developer461cb542022-04-29 18:17:44 +0800209 killall atenl > /dev/null 2>&1
developer3abe1ad2022-01-24 11:13:32 +0800210fi
211
developer679a6aa2022-09-07 09:52:41 +0800212do_cmd "${cmd}"