developer | 4616dbd | 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 | b9a9660 | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 12 | SOC_start_idx="0" |
| 13 | is_eagle="0" |
developer | 4616dbd | 2022-10-11 13:18:59 +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 | b9a9660 | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 31 | local config=$1 |
developer | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 32 | local tmp_file=$3 |
developer | b9a9660 | 2023-01-10 19:53:25 +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 | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 43 | if [ -f ${tmp_file} ]; then |
developer | b9a9660 | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 44 | if grep -q ${config} ${tmp_file}; then |
| 45 | sed -i "/${config}/c\\${config}=$2" ${tmp_file} |
developer | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 46 | else |
developer | b9a9660 | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 47 | echo "${config}=$2" >> ${tmp_file} |
developer | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 48 | fi |
| 49 | else |
developer | b9a9660 | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 50 | echo "${config}=$2" >> ${tmp_file} |
developer | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 51 | fi |
| 52 | } |
| 53 | |
| 54 | function get_config() { |
developer | b9a9660 | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 55 | local config=$1 |
developer | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 56 | local tmp_file=$2 |
developer | b9a9660 | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 57 | |
developer | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 58 | if [ ! -f ${tmp_file} ]; then |
| 59 | echo "" |
| 60 | return |
| 61 | fi |
| 62 | |
developer | b9a9660 | 2023-01-10 19:53:25 +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 | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 74 | else |
| 75 | echo "" |
| 76 | fi |
| 77 | } |
| 78 | |
| 79 | function convert_interface { |
developer | b9a9660 | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 80 | SOC_start_idx=$(get_config "STARTIDX" ${ated_file}) |
| 81 | is_eagle=$(get_config "IS_EAGLE" ${ated_file}) |
developer | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 82 | local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom |
developer | b9a9660 | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 83 | if [ -z "${SOC_start_idx}" ] || [ -z "${is_eagle}" ]; then |
developer | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 84 | if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then |
developer | b9a9660 | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 85 | SOC_start_idx="2" |
| 86 | is_eagle="0" |
developer | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 87 | elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then |
developer | b9a9660 | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 88 | SOC_start_idx="1" |
| 89 | is_eagle="0" |
developer | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 90 | elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then |
developer | b9a9660 | 2023-01-10 19:53:25 +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 | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 96 | else |
developer | b9a9660 | 2023-01-10 19:53:25 +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 | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 100 | echo "For AX7800: echo STARTIDX=2 >> ${ated_file}" |
| 101 | echo "For AX8400: echo STARTIDX=1 >> ${ated_file}" |
developer | b9a9660 | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 102 | exit 0 |
developer | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 103 | fi |
developer | b9a9660 | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 104 | record_config "STARTIDX" ${SOC_start_idx} ${ated_file} |
| 105 | record_config "IS_EAGLE" ${is_eagle} ${ated_file} |
developer | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 106 | fi |
| 107 | |
developer | b9a9660 | 2023-01-10 19:53:25 +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 | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 137 | else |
developer | b9a9660 | 2023-01-10 19:53:25 +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 | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 149 | fi |
developer | 4616dbd | 2022-10-11 13:18:59 +0800 | [diff] [blame] | 150 | |
developer | b9a9660 | 2023-01-10 19:53:25 +0800 | [diff] [blame] | 151 | interface="phy${phy_idx}" |
| 152 | } |
developer | 4616dbd | 2022-10-11 13:18:59 +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 |
| 164 | if [[ ${i} == "ra"* ]]; then |
| 165 | convert_interface $i |
| 166 | cmd="${cmd} ${interface}" |
| 167 | else |
| 168 | cmd="${cmd} ${i}" |
| 169 | fi |
| 170 | fi |
| 171 | done |
| 172 | |
| 173 | if [ "$mode" = "0" ]; then |
| 174 | killall atenl > /dev/null 2>&1 |
| 175 | fi |
| 176 | |
| 177 | do_cmd "${cmd}" |