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 | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 111 | 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" |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 115 | else |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 116 | echo "Interface Conversion Failed!" |
| 117 | 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] | 118 | 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}" |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 138 | 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}" |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 142 | exit 0 |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 143 | fi |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 144 | record_config "STARTIDX" ${SOC_start_idx} ${ated_file} |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 145 | record_config "ENDIDX" ${SOC_end_idx} ${ated_file} |
| 146 | record_config "IS_CONNAC3" ${is_connac3} ${ated_file} |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 147 | fi |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 148 | } |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 149 | |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 150 | function convert_interface { |
| 151 | if [ ${is_connac3} == "0" ]; then |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 152 | 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 |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 163 | local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file}) |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 164 | 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 |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 179 | else |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 180 | # Connac 3 chips has different mapping method |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 181 | # 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 |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 191 | fi |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 192 | |
developer | 13655da | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 193 | interface="phy${phy_idx}" |
| 194 | } |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 195 | |
| 196 | for i in "$@" |
| 197 | do |
| 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 |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 207 | parse_sku |
developer | b9b4cd1 | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 208 | convert_interface $i |
| 209 | cmd="${cmd} ${interface}" |
| 210 | else |
| 211 | cmd="${cmd} ${i}" |
| 212 | fi |
| 213 | fi |
| 214 | done |
| 215 | |
| 216 | if [ "$mode" = "0" ]; then |
| 217 | killall atenl > /dev/null 2>&1 |
| 218 | fi |
| 219 | |
| 220 | do_cmd "${cmd}" |