developer | 3abe1ad | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 1 | #!/bin/ash |
| 2 | # This script is used for wrapping atenl daemon to ated |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 3 | # 0 is normal mode, 1 is used for doing specific commands such as "sync eeprom all" |
developer | 3abe1ad | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 4 | |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 5 | work_mode="RUN" # RUN/PRINT/DEBUG |
developer | 3abe1ad | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 6 | mode="0" |
| 7 | add_quote="0" |
| 8 | cmd="atenl" |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 9 | interface="" |
| 10 | phy_idx=0 |
| 11 | ated_file="/tmp/interface" |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 12 | SOC_start_idx="0" |
| 13 | is_eagle="0" |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 14 | |
| 15 | function do_cmd() { |
| 16 | case ${work_mode} in |
| 17 | "RUN") |
| 18 | eval "$1" |
| 19 | ;; |
| 20 | "PRINT") |
| 21 | echo "$1" |
| 22 | ;; |
| 23 | "DEBUG") |
| 24 | eval "$1" |
| 25 | echo "$1" |
| 26 | ;; |
| 27 | esac |
| 28 | } |
| 29 | |
| 30 | function record_config() { |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 31 | local config=$1 |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 32 | local tmp_file=$3 |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 33 | |
| 34 | # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config |
| 35 | if [ ${config} != "STARTIDX" ] && [ ${config} != "IS_EAGLE" ]; then |
| 36 | if [ $phy_idx -lt $SOC_start_idx ]; then |
| 37 | config="${config}_PCIE" |
| 38 | elif [ $phy_idx -ge $SOC_start_idx ]; then |
| 39 | config="${config}_SOC" |
| 40 | fi |
| 41 | fi |
| 42 | |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 43 | if [ -f ${tmp_file} ]; then |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 44 | if grep -q ${config} ${tmp_file}; then |
| 45 | sed -i "/${config}/c\\${config}=$2" ${tmp_file} |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 46 | else |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 47 | echo "${config}=$2" >> ${tmp_file} |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 48 | fi |
| 49 | else |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 50 | echo "${config}=$2" >> ${tmp_file} |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 51 | fi |
| 52 | } |
| 53 | |
| 54 | function get_config() { |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 55 | local config=$1 |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 56 | local tmp_file=$2 |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 57 | |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 58 | if [ ! -f ${tmp_file} ]; then |
| 59 | echo "" |
| 60 | return |
| 61 | fi |
| 62 | |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 63 | # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config |
| 64 | if [ ${config} != "STARTIDX" ] && [ ${config} != "IS_EAGLE" ]; then |
| 65 | if [ $phy_idx -lt $SOC_start_idx ]; then |
| 66 | config="${config}_PCIE" |
| 67 | elif [ $phy_idx -ge $SOC_start_idx ]; then |
| 68 | config="${config}_SOC" |
| 69 | fi |
| 70 | fi |
| 71 | |
| 72 | if grep -q ${config} ${tmp_file}; then |
| 73 | echo "$(cat ${tmp_file} | grep ${config} | sed s/=/' '/g | cut -d " " -f 2)" |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 74 | else |
| 75 | echo "" |
| 76 | fi |
| 77 | } |
| 78 | |
| 79 | function convert_interface { |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 80 | SOC_start_idx=$(get_config "STARTIDX" ${ated_file}) |
| 81 | is_eagle=$(get_config "IS_EAGLE" ${ated_file}) |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 82 | local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 83 | if [ -z "${SOC_start_idx}" ] || [ -z "${is_eagle}" ]; then |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 84 | if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 85 | SOC_start_idx="2" |
| 86 | is_eagle="0" |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 87 | elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 88 | SOC_start_idx="1" |
| 89 | is_eagle="0" |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 90 | elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 91 | SOC_start_idx="0" |
| 92 | is_eagle="0" |
| 93 | elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7990")" ]; then |
| 94 | SOC_start_idx="0" |
| 95 | is_eagle="1" |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 96 | else |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 97 | echo "Interface Conversion Failed!" |
| 98 | echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands" |
| 99 | echo "For AX6000/Eagle: echo STARTIDX=0 >> ${ated_file}" |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 100 | echo "For AX7800: echo STARTIDX=2 >> ${ated_file}" |
| 101 | echo "For AX8400: echo STARTIDX=1 >> ${ated_file}" |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 102 | exit 0 |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 103 | fi |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 104 | record_config "STARTIDX" ${SOC_start_idx} ${ated_file} |
| 105 | record_config "IS_EAGLE" ${is_eagle} ${ated_file} |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 106 | fi |
| 107 | |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 108 | |
| 109 | if [ ${is_eagle} == "0" ]; then |
| 110 | if [[ $1 == "raix"* ]]; then |
| 111 | phy_idx=1 |
| 112 | elif [[ $1 == "rai"* ]]; then |
| 113 | phy_idx=0 |
| 114 | elif [[ $1 == "rax"* ]]; then |
| 115 | phy_idx=$((SOC_start_idx+1)) |
| 116 | else |
| 117 | phy_idx=$SOC_start_idx |
| 118 | fi |
| 119 | |
| 120 | # convert phy index according to band idx |
| 121 | local band_idx=$(get_config "ATECTRLBANDIDX" ${ated_file}) |
| 122 | if [ "${band_idx}" = "0" ]; then |
| 123 | if [[ $1 == "raix"* ]]; then |
| 124 | phy_idx=0 |
| 125 | elif [[ $1 == "rax"* ]]; then |
| 126 | phy_idx=$SOC_start_idx |
| 127 | fi |
| 128 | elif [ "${band_idx}" = "1" ]; then |
| 129 | if [[ $1 == "rai"* ]]; then |
| 130 | # AX8400: mt7915 remain phy0 |
| 131 | # AX7800: mt7916 becomes phy1 |
| 132 | phy_idx=$((SOC_start_idx-1)) |
| 133 | elif [[ $1 == "ra"* ]]; then |
| 134 | phy_idx=$((SOC_start_idx+1)) |
| 135 | fi |
| 136 | fi |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 137 | else |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 138 | # Eagle has different mapping method |
| 139 | # phy0: ra0 |
| 140 | # phy1: rai0 |
| 141 | # phy2: rax0 |
| 142 | if [[ $1 == "rai"* ]]; then |
| 143 | phy_idx=1 |
| 144 | elif [[ $1 == "rax"* ]]; then |
| 145 | phy_idx=2 |
| 146 | else |
| 147 | phy_idx=0 |
| 148 | fi |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 149 | fi |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 150 | |
developer | f90c9af | 2022-12-28 22:40:23 +0800 | [diff] [blame] | 151 | interface="phy${phy_idx}" |
| 152 | } |
developer | 3abe1ad | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 153 | |
| 154 | for i in "$@" |
| 155 | do |
| 156 | if [ "$i" = "-c" ]; then |
| 157 | cmd="${cmd} -c" |
| 158 | mode="1" |
| 159 | add_quote="1" |
| 160 | elif [ "${add_quote}" = "1" ]; then |
| 161 | cmd="${cmd} \"${i}\"" |
| 162 | add_quote="0" |
| 163 | else |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 164 | if [[ ${i} == "ra"* ]]; then |
| 165 | convert_interface $i |
| 166 | cmd="${cmd} ${interface}" |
| 167 | else |
| 168 | cmd="${cmd} ${i}" |
developer | 9b7cdad | 2022-03-10 14:24:55 +0800 | [diff] [blame] | 169 | fi |
developer | 3abe1ad | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 170 | fi |
| 171 | done |
| 172 | |
| 173 | if [ "$mode" = "0" ]; then |
developer | 461cb54 | 2022-04-29 18:17:44 +0800 | [diff] [blame] | 174 | killall atenl > /dev/null 2>&1 |
developer | 3abe1ad | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 175 | fi |
| 176 | |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame] | 177 | do_cmd "${cmd}" |