developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 1 | #!/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 | |
| 5 | work_mode="RUN" # RUN/PRINT/DEBUG |
| 6 | mode="0" |
| 7 | add_quote="0" |
| 8 | cmd="atenl" |
| 9 | interface="" |
| 10 | phy_idx=0 |
| 11 | ated_file="/tmp/interface" |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 12 | iwpriv_file="/tmp/iwpriv_wrapper" |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 13 | SOC_start_idx="0" |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 14 | SOC_end_idx="0" |
| 15 | is_connac3="0" |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 16 | |
| 17 | function 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 | |
| 32 | function record_config() { |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 33 | local config=$1 |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 34 | local tmp_file=$3 |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 35 | |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 36 | # 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 |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 38 | 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 | |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 45 | if [ -f ${tmp_file} ]; then |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 46 | if grep -q ${config} ${tmp_file}; then |
| 47 | sed -i "/${config}/c\\${config}=$2" ${tmp_file} |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 48 | else |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 49 | echo "${config}=$2" >> ${tmp_file} |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 50 | fi |
| 51 | else |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 52 | echo "${config}=$2" >> ${tmp_file} |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 53 | fi |
| 54 | } |
| 55 | |
| 56 | function get_config() { |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 57 | local config=$1 |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 58 | local tmp_file=$2 |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 59 | |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 60 | if [ ! -f ${tmp_file} ]; then |
| 61 | echo "" |
| 62 | return |
| 63 | fi |
| 64 | |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 65 | # 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 |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 67 | 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)" |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 76 | else |
| 77 | echo "" |
| 78 | fi |
| 79 | } |
| 80 | |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 81 | function parse_sku { |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 82 | SOC_start_idx=$(get_config "STARTIDX" ${ated_file}) |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 83 | SOC_end_idx=$(get_config "ENDIDX" ${ated_file}) |
| 84 | is_connac3=$(get_config "IS_CONNAC3" ${ated_file}) |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 85 | local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 86 | if [ -z "${SOC_start_idx}" ] || [ -z "${SOC_end_idx}" ] || [ -z "${is_connac3}" ]; then |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 87 | if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 88 | SOC_start_idx="2" |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 89 | SOC_end_idx="3" |
| 90 | is_connac3="0" |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 91 | elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 92 | SOC_start_idx="1" |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 93 | 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" |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 99 | elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 100 | SOC_start_idx="0" |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 101 | SOC_end_idx="1" |
| 102 | is_connac3="0" |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 103 | elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7990")" ]; then |
| 104 | SOC_start_idx="0" |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 105 | 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" |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 111 | else |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 112 | echo "Interface Conversion Failed!" |
| 113 | echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands" |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 114 | 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}" |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 134 | exit 0 |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 135 | fi |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 136 | record_config "STARTIDX" ${SOC_start_idx} ${ated_file} |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 137 | record_config "ENDIDX" ${SOC_end_idx} ${ated_file} |
| 138 | record_config "IS_CONNAC3" ${is_connac3} ${ated_file} |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 139 | fi |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 140 | } |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 141 | |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 142 | function convert_interface { |
| 143 | if [ ${is_connac3} == "0" ]; then |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 144 | 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 |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 155 | local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file}) |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 156 | 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 |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 171 | else |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 172 | # Connac 3 chips has different mapping method |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 173 | # 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 |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 183 | fi |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 184 | |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 185 | interface="phy${phy_idx}" |
| 186 | } |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 187 | |
| 188 | for i in "$@" |
| 189 | do |
| 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 |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 199 | parse_sku |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 200 | convert_interface $i |
| 201 | cmd="${cmd} ${interface}" |
| 202 | else |
| 203 | cmd="${cmd} ${i}" |
| 204 | fi |
| 205 | fi |
| 206 | done |
| 207 | |
| 208 | if [ "$mode" = "0" ]; then |
| 209 | killall atenl > /dev/null 2>&1 |
| 210 | fi |
| 211 | |
| 212 | do_cmd "${cmd}" |