[][MAC80211][WiFi6/7][app][Add single wiphy support for atenl & iwpriv wrapper]

[Description]
Add single wiphy support for atenl & iwpirv wrapper
To support single wiphy, main phy idx is used for debugfs in atenl &
iwpriv wrapper.

[Release-log]
N/A

Change-Id: Ic146442a8838cd812be9e92ce3e4f5e5f32c91fe
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/9176525
diff --git a/feed/app/atenl/files/ated.sh b/feed/app/atenl/files/ated.sh
index e989e44..9037054 100755
--- a/feed/app/atenl/files/ated.sh
+++ b/feed/app/atenl/files/ated.sh
@@ -9,8 +9,10 @@
 interface=""
 phy_idx=0
 ated_file="/tmp/interface"
+iwpriv_file="/tmp/iwpriv_wrapper"
 SOC_start_idx="0"
-is_eagle="0"
+SOC_end_idx="0"
+is_connac3="0"
 
 function do_cmd() {
     case ${work_mode} in
@@ -31,8 +33,8 @@
     local config=$1
     local tmp_file=$3
 
-    # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config
-    if [ ${config} != "STARTIDX" ] && [ ${config} != "IS_EAGLE" ]; then
+    # check it is SOC(mt7986)/Eagle/Kite or PCIE card (mt7915/7916), and write its config
+    if [ ${config} != "STARTIDX" ] && [ ${config} != "ENDIDX" ] && [ ${config} != "IS_CONNAC3" ]; then
         if [ $phy_idx -lt $SOC_start_idx ]; then
             config="${config}_PCIE"
         elif [ $phy_idx -ge $SOC_start_idx ]; then
@@ -60,8 +62,8 @@
         return
     fi
 
-    # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config
-    if [ ${config} != "STARTIDX" ] && [ ${config} != "IS_EAGLE" ]; then
+    # check it is SOC(mt7986)/Eagle/Kite or PCIE card (mt7915/7916), and write its config
+    if [ ${config} != "STARTIDX" ] && [ ${config} != "ENDIDX" ] && [ ${config} != "IS_CONNAC3" ]; then
         if [ $phy_idx -lt $SOC_start_idx ]; then
             config="${config}_PCIE"
         elif [ $phy_idx -ge $SOC_start_idx ]; then
@@ -76,37 +78,69 @@
     fi
 }
 
-function convert_interface {
+function parse_sku {
     SOC_start_idx=$(get_config "STARTIDX" ${ated_file})
-    is_eagle=$(get_config "IS_EAGLE" ${ated_file})
+    SOC_end_idx=$(get_config "ENDIDX" ${ated_file})
+    is_connac3=$(get_config "IS_CONNAC3" ${ated_file})
     local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom
-    if [ -z "${SOC_start_idx}" ] || [ -z "${is_eagle}" ]; then
+    if [ -z "${SOC_start_idx}" ] || [ -z "${SOC_end_idx}" ] || [ -z "${is_connac3}" ]; then
         if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then
             SOC_start_idx="2"
-            is_eagle="0"
+            SOC_end_idx="3"
+            is_connac3="0"
         elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then
             SOC_start_idx="1"
-            is_eagle="0"
+            SOC_end_idx="2"
+            is_connac3="0"
+        elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7981")" ]; then
+            SOC_start_idx="0"
+            SOC_end_idx="1"
+            is_connac3="0"
         elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then
             SOC_start_idx="0"
-            is_eagle="0"
+            SOC_end_idx="1"
+            is_connac3="0"
         elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7990")" ]; then
             SOC_start_idx="0"
+            SOC_end_idx="2"
+            is_connac3="1"
+        elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7992")" ]; then
+            SOC_start_idx="0"
-            is_eagle="1"
+            SOC_end_idx="1"
+            is_connac3="1"
         else
             echo "Interface Conversion Failed!"
             echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands"
-            echo "For AX6000/Eagle: echo STARTIDX=0 >> ${ated_file}"
-            echo "For AX7800: echo STARTIDX=2 >> ${ated_file}"
-            echo "For AX8400: echo STARTIDX=1 >> ${ated_file}"
+            echo "For AX3000/AX6000:"
+            echo "      echo STARTIDX=0 >> ${ated_file}"
+            echo "      echo ENDIDX=1 >> ${ated_file}"
+            echo "      echo IS_CONNAC3=0 >> ${ated_file}"
+            echo "For AX7800:"
+            echo "      echo STARTIDX=2 >> ${ated_file}"
+            echo "      echo ENDIDX=3 >> ${ated_file}"
+            echo "      echo IS_CONNAC3=0 >> ${ated_file}"
+            echo "For AX8400:"
+            echo "      echo STARTIDX=1 >> ${ated_file}"
+            echo "      echo ENDIDX=2 >> ${ated_file}"
+            echo "      echo IS_CONNAC3=0 >> ${ated_file}"
+            echo "For Eagle:"
+            echo "      echo STARTIDX=0 >> ${ated_file}"
+            echo "      echo ENDIDX=2 >> ${ated_file}"
+            echo "      echo IS_CONNAC3=1 >> ${ated_file}"
+            echo "For Kite:"
+            echo "      echo STARTIDX=0 >> ${ated_file}"
+            echo "      echo ENDIDX=1 >> ${ated_file}"
+            echo "      echo IS_CONNAC3=1 >> ${ated_file}"
             exit 0
         fi
         record_config "STARTIDX" ${SOC_start_idx} ${ated_file}
-        record_config "IS_EAGLE" ${is_eagle} ${ated_file}
+        record_config "ENDIDX" ${SOC_end_idx} ${ated_file}
+        record_config "IS_CONNAC3" ${is_connac3} ${ated_file}
     fi
-
+}
 
-    if [ ${is_eagle} == "0" ]; then
+function convert_interface {
+    if [ ${is_connac3} == "0" ]; then
         if [[ $1 == "raix"* ]]; then
             phy_idx=1
         elif [[ $1 == "rai"* ]]; then
@@ -118,7 +152,7 @@
         fi
 
         # convert phy index according to band idx
-        local band_idx=$(get_config "ATECTRLBANDIDX" ${ated_file})
+        local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
         if [ "${band_idx}" = "0" ]; then
             if [[ $1 == "raix"* ]]; then
                 phy_idx=0
@@ -135,7 +169,7 @@
             fi
         fi
     else
-        # Eagle has different mapping method
+        # Connac 3 chips has different mapping method
         # phy0: ra0
         # phy1: rai0
         # phy2: rax0
@@ -162,6 +196,7 @@
         add_quote="0"
     else
         if [[ ${i} == "ra"* ]]; then
+            parse_sku
             convert_interface $i
             cmd="${cmd} ${interface}"
         else
diff --git a/feed/app/atenl/files/iwpriv.sh b/feed/app/atenl/files/iwpriv.sh
index c2b2b88..0dde191 100755
--- a/feed/app/atenl/files/iwpriv.sh
+++ b/feed/app/atenl/files/iwpriv.sh
@@ -12,6 +12,7 @@
 iwpriv_file="/tmp/iwpriv_wrapper"
 interface_file="/tmp/interface"
 phy_idx=$(echo ${interface} | tr -dc '0-9')
+main_phy_idx=0
 
 function do_cmd() {
     case ${work_mode} in
@@ -42,7 +43,7 @@
     local config=$1
     local tmp_file=$3
 
-    # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config
+    # check it is SOC(mt7986)/Eagle/Kite or PCIE card (mt7915/7916), and write its config
     if [ ${tmp_file} != ${interface_file} ]; then
         if [ $phy_idx -lt $SOC_start_idx ]; then
             config="${config}_PCIE"
@@ -71,7 +72,7 @@
         return
     fi
 
-    # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config
+    # check it is SOC(mt7986)/Eagle/Kite or PCIE card (mt7915/7916), and write its config
     if [ ${tmp_file} != ${interface_file} ]; then
         if [ $phy_idx -lt $SOC_start_idx ]; then
             config="${config}_PCIE"
@@ -178,7 +179,7 @@
             fi
         fi
     else
-        # Eagle has different mapping method
+        # Connac 3 chips has different mapping method
         # phy0: ra0
         # phy1: rai0
         # phy2: rax0
@@ -1167,14 +1168,13 @@
 
 function register_handler {
 
-	local phy_idx=$1
-	local offset=$2
-	local val=$3
-	local cmd=$4
+	local offset=$1
+	local val=$2
+	local cmd=$3
 	local w_cmd="write"
 
-	regidx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regidx
-	regval=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regval
+	regidx=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/regidx
+	regval=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/regval
 
 	echo ${offset} > ${regidx}
 	if [[ "${cmd}" == "${w_cmd}" ]]; then
@@ -1199,6 +1199,11 @@
     full_cmd=$4
 fi
 
+# get main phy idx
+if [ "${phy_idx}" -ge "${SOC_start_idx}" ]; then
+    main_phy_idx=${SOC_start_idx}
+fi
+
 tmp_work_mode=$(get_config "WORKMODE" ${iwpriv_file})
 
 if [ ! -z ${tmp_work_mode} ]; then
@@ -1344,8 +1349,8 @@
 
 elif [ "${cmd_type}" = "show" ]; then
     if [ "${cmd}" = "wtbl" ]; then
-        wlan_idx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wlan_idx
-        wtbl_info=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wtbl_info
+        wlan_idx=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/wlan_idx
+        wtbl_info=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/wtbl_info
 
         do_cmd "echo ${param} > ${wlan_idx}"
         do_cmd "cat ${wtbl_info}"
@@ -1410,20 +1415,20 @@
 
     # reg write
     if [[ ${full_cmd} == *"="* ]]; then
-        register_handler ${phy_idx} ${offset} ${val} "write"
+        register_handler ${offset} ${val} "write"
     else
 	start_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 1)
 	end_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 2)
 	loop=$((0x${end_addr}-0x${start_addr}))
 
 	if [[ ${loop} == "0" ]]; then
-		register_handler ${phy_idx} ${offset} ${val}
+		register_handler ${offset} ${val}
         else
 		i=0
 		while [ $i -le $loop ]; do
 			addr=$((0x${start_addr}+$i))
 			offset=$(printf "0x%x" ${addr})
-			register_handler ${phy_idx} ${offset} ${val}
+			register_handler ${offset} ${val}
 			i=$(($i + 4))
 		done
        fi