[][atenl: update package]

[Description]
Add per-phy eeprom file support in atenl and add more commands in iwpriv
wrapper.

[Release-log]
N/A

Change-Id: I533054e017c662b0ea395263f9ebf93a6d3d6076
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/5570119
diff --git a/feed/atenl/files/iwpriv.sh b/feed/atenl/files/iwpriv.sh
index be5a2ac..075be04 100755
--- a/feed/atenl/files/iwpriv.sh
+++ b/feed/atenl/files/iwpriv.sh
@@ -42,51 +42,6 @@
     echo "$(cat ${tmp_file} | grep $1 | sed s/=/' '/g | cut -d " " -f 2)"
 }
 
-function do_ate_work() {
-    local ate_cmd=$1
-
-    case ${ate_cmd} in
-        "ATESTART")
-            local if_str=$(ifconfig | grep mon${phy_idx})
-
-            if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
-                echo "ATE already starts."
-            else
-                do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
-                do_cmd "iw dev wlan${phy_idx} del"
-                do_cmd "ifconfig mon${phy_idx} up"
-            fi
-            ;;
-        "ATESTOP")
-            local if_str=$(ifconfig | grep mon${phy_idx})
-
-            if [ -z "${if_str}" -a "${if_str}" != " " ]; then
-                echo "ATE does not start."
-            else
-                do_cmd "mt76-test ${interface} set state=off"
-                do_cmd "iw dev mon${phy_idx} del"
-                do_cmd "iw phy ${interface} interface add wlan${phy_idx} type managed"
-                do_cmd "ifconfig wlan${phy_idx} up"
-            fi
-            ;;
-        "TXFRAME")
-            do_cmd "mt76-test ${interface} set state=tx_frames"
-            ;;
-        "TXSTOP")
-            do_cmd "mt76-test ${interface} set state=idle"
-            ;;
-        "RXFRAME")
-            do_cmd "mt76-test ${interface} set state=rx_frames"
-            ;;
-        "RXSTOP")
-            do_cmd "mt76-test ${interface} set state=idle"
-            ;;
-        "TXCONT")
-            do_cmd "mt76-test ${interface} set state=tx_cont"
-            ;;
-    esac
-}
-
 function simple_convert() {
     if [ "$1" = "ATETXCNT" ]; then
         echo "tx_count"
@@ -229,8 +184,11 @@
                 local bw_str="HT20"
                 ;;
         esac
-    else
+    elif [ "${band}" = "1" ]; then
         case ${bw} in
+            "5")
+                local bw_str="160MHz"
+                ;;
             "2")
                 local bw_str="80MHz"
                 ;;
@@ -249,11 +207,66 @@
                 local bw_str="HT20"
                 ;;
         esac
+    else
+        echo "6G Todo"
     fi
 
     do_cmd "iw dev mon${phy_idx} set channel ${ch} ${bw_str}"
 }
 
+function do_ate_work() {
+    local ate_cmd=$1
+
+    case ${ate_cmd} in
+        "ATESTART")
+            local if_str=$(ifconfig | grep mon${phy_idx})
+
+            if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
+                echo "ATE already starts."
+            else
+                do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
+                do_cmd "iw dev wlan${phy_idx} del"
+                do_cmd "ifconfig mon${phy_idx} up"
+            fi
+            ;;
+        "ATESTOP")
+            local if_str=$(ifconfig | grep mon${phy_idx})
+
+            if [ -z "${if_str}" -a "${if_str}" != " " ]; then
+                echo "ATE does not start."
+            else
+                do_cmd "mt76-test ${interface} set state=off"
+                do_cmd "iw dev mon${phy_idx} del"
+                do_cmd "iw phy ${interface} interface add wlan${phy_idx} type managed"
+                do_cmd "ifconfig wlan${phy_idx} up"
+            fi
+            ;;
+        "TXFRAME")
+            do_cmd "mt76-test ${interface} set state=tx_frames"
+            ;;
+        "TXSTOP"|"RXSTOP"|"TXREVERT")
+            do_cmd "mt76-test ${interface} set state=idle"
+            ;;
+        "RXFRAME")
+            do_cmd "mt76-test ${interface} set state=rx_frames"
+            ;;
+        "TXCONT")
+            do_cmd "mt76-test ${interface} set state=tx_cont"
+            ;;
+        "TXCOMMIT")
+            tx_mode=$(convert_tx_mode $(get_config "ATETXMODE"))
+                case ${tx_mode} in
+                    "ht"|"vht"|"he_su")
+                        do_cmd "mt76-test ${interface} set aid=1"
+                        ;;
+                    *)
+                        ;;
+                esac
+            do_cmd "mt76-test ${interface} set state=idle"
+            ;;
+    esac
+}
+
 if [ "${cmd_type}" = "set" ]; then
     skip=0
     use_ated=0
@@ -304,6 +317,9 @@
             fi
             skip=1
             ;;
+        "ResetCounter"|"ATERXSTATRESET")
+            skip=1
+            ;;
         *)
             echo "Unknown command to set"
             skip=1
@@ -316,14 +332,49 @@
     do_cmd "mt76-test ${interface} dump"
     do_cmd "mt76-test ${interface} dump stats"
 elif [ "${cmd_type}" = "e2p" ]; then
-    v1=$(do_cmd "ated -i ${interface} -c \"eeprom read ${param}\"")
-    v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
+    offset=$(printf "0x%s" ${cmd})
+    val=$(printf "0x%s" ${param})
+
+    # eeprom offset write
+    if [[ ${full_cmd} == *"="* ]]; then
+        tmp=$((${val} & 0xff))
+        tmp=$(printf "0x%x" ${tmp})
+        do_cmd "ated -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
+
+        offset=$((${offset}))
+        offset=$(expr ${offset} + "1")
+        offset=$(printf "0x%x" ${offset})
+        tmp=$(((${val} >> 8) & 0xff))
+        tmp=$(printf "0x%x" ${tmp})
+        do_cmd "ated -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
+    else
+        v1=$(do_cmd "ated -i ${interface} -c \"eeprom read ${param}\"")
+        v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
 
-    param2=$(expr ${param} + "1")
-    v2=$(do_cmd "ated -i ${interface} -c \"eeprom read ${param2}\"")
-    v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
-    printf "[0x%04x]:0x%02x%02x\n" ${param} ${v2} ${v1}
+        tmp=$(printf "0x%s" ${param})
+        tmp=$((${tmp}))
+        param2=$(expr ${tmp} + "1")
+        param2=$(printf "%x" ${param2})
+        v2=$(do_cmd "ated -i ${interface} -c \"eeprom read ${param2}\"")
+        v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
+
+        param=$(printf "0x%s" ${param})
+        printf "[0x%04x]:0x%02x%02x\n" ${param} ${v2} ${v1}
+    fi
+elif [ "${cmd_type}" = "mac" ]; then
+    regidx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regidx
+    regval=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regval
+    offset=$(printf "0x%s" ${cmd})
+    val=$(printf "0x%s" ${param})
+
+    echo ${offset} > ${regidx}
+    # reg write
+    if [[ ${full_cmd} == *"="* ]]; then
+        echo ${val} > ${regval}
+    else
+        res=$(cat ${regval} | cut -d 'x' -f 2)
+        printf "%s mac:[%s]:%s\n" ${interface} ${offset} ${res}
+    fi
 else
     echo "Unknown command"
 fi
-
diff --git a/feed/atenl/src/atenl.h b/feed/atenl/src/atenl.h
index ea8e4a0..0d4d6c6 100644
--- a/feed/atenl/src/atenl.h
+++ b/feed/atenl/src/atenl.h
@@ -95,7 +95,6 @@
 	u8 *eeprom_data;
 	int eeprom_fd;
 	u16 eeprom_size;
-	bool eeprom_exist;
 
 	bool cmd_mode;
 };
diff --git a/feed/atenl/src/eeprom.c b/feed/atenl/src/eeprom.c
index 2a46971..73c0f8b 100644
--- a/feed/atenl/src/eeprom.c
+++ b/feed/atenl/src/eeprom.c
@@ -7,7 +7,7 @@
 #include "atenl.h"
 
 #define EEPROM_PART_SIZE 20480
-#define EEPROM_FILE	"/tmp/atenl-eeprom"
+char *eeprom_file;
 
 static FILE *mtd_open(const char *mtd)
 {
@@ -47,7 +47,7 @@
 		return -1;
 	}
 
-	fd = open(EEPROM_FILE, O_RDWR | O_CREAT | O_EXCL, 00644);
+	fd = open(eeprom_file, O_RDWR | O_CREAT | O_EXCL, 00644);
 	if (fd < 0)
 		goto out;
 
@@ -63,7 +63,7 @@
 			goto retry;
 
 		perror("write");
-		unlink(EEPROM_FILE);
+		unlink(eeprom_file);
 		close(fd);
 		fd = -1;
 		goto out;
@@ -94,7 +94,7 @@
 	if (fd_ori < 0)
 		return -1;
 
-	fd = open(EEPROM_FILE, O_RDWR | O_CREAT | O_EXCL, 00644);
+	fd = open(eeprom_file, O_RDWR | O_CREAT | O_EXCL, 00644);
 	if (fd < 0)
 		goto out;
 
@@ -110,7 +110,7 @@
 			goto retry;
 
 		perror("write");
-		unlink(EEPROM_FILE);
+		unlink(eeprom_file);
 		close(fd);
 		fd = -1;
 		goto out;
@@ -133,7 +133,7 @@
 {
 	struct stat st;
 
-	return stat(EEPROM_FILE, &st) == 0;
+	return stat(eeprom_file, &st) == 0;
 }
 
 static int
@@ -153,12 +153,10 @@
 		return atenl_efuse_create_file(an);
 	}
 
-	fd = open(EEPROM_FILE, O_RDWR);
+	fd = open(eeprom_file, O_RDWR);
 	if (fd < 0)
 		perror("open");
 
-	an->eeprom_exist = true;
-
 	return fd;
 }
 
@@ -264,8 +262,11 @@
 {
 	bool flash_mode;
 	int eeprom_fd;
+	char buf[30];
 
 	set_band_val(an, 0, phy_idx, phy_idx);
+	snprintf(buf, sizeof(buf), "/tmp/atenl-eeprom-phy%u", phy_idx);
+	eeprom_file = strdup(buf);
 
 	atenl_nl_check_mtd(an);
 	flash_mode = an->mtd_part != NULL;
@@ -300,9 +301,12 @@
 	munmap(an->eeprom_data, EEPROM_PART_SIZE);
 	close(an->eeprom_fd);
 
-	if (!an->eeprom_exist && (an->child_pid || an->cmd_mode))
-		if (remove(EEPROM_FILE))
+	if (!an->cmd_mode && an->child_pid) {
+		if (remove(eeprom_file))
 			perror("remove");
+	}
+
+	free(eeprom_file);
 }
 
 int atenl_eeprom_write_mtd(struct atenl *an)
@@ -319,7 +323,7 @@
 		return EXIT_FAILURE;
 	} else if (pid == 0) {
 		char *part = strdup(an->mtd_part);
-		char *cmd[] = {"mtd", "write", EEPROM_FILE, part, NULL};
+		char *cmd[] = {"mtd", "write", eeprom_file, part, NULL};
 		int ret;
 
 		ret = execvp("mtd", cmd);
@@ -378,7 +382,7 @@
 {
 	int i;
 
-	for (i = 0; i < 3584; i += 16)
+	for (i = 0; i < an->eeprom_size; i += 16)
 		atenl_nl_write_eeprom(an, i, &an->eeprom_data[i], 16);
 }
 
@@ -403,9 +407,9 @@
 
 		s++;
 		if (!strncmp(s, "reset", 5)) {
-			unlink(EEPROM_FILE);
+			unlink(eeprom_file);
 		} else if (!strncmp(s, "file", 4)) {
-			atenl_info("%s\n", EEPROM_FILE);
+			atenl_info("%s\n", eeprom_file);
 			atenl_info("Flash mode: %d\n", flash_mode);
 		} else if (!strncmp(s, "set", 3)) {
 			u32 offset, val;
@@ -422,6 +426,7 @@
 			an->eeprom_data[offset] = val;
 			atenl_info("set offset 0x%x to 0x%x\n", offset, val);
 		} else if (!strncmp(s, "update", 6)) {
+			atenl_eeprom_sync_to_driver(an);
 			atenl_nl_update_buffer_mode(an);
 		} else if (!strncmp(s, "write", 5)) {
 			s = strchr(s, ' ');
@@ -429,12 +434,8 @@
 				return;
 			s++;
 
-			if (!strncmp(s, "flash", 5)) {
+			if (!strncmp(s, "flash", 5))
 				atenl_eeprom_write_mtd(an);
-			} else if (!strncmp(s, "efuse", 5)) {
-				atenl_eeprom_sync_to_driver(an);
-				atenl_nl_write_efuse_all(an, NULL);
-			}
 		} else if (!strncmp(s, "read", 4)) {
 			u32 offset;
 
diff --git a/feed/atenl/src/hqa.c b/feed/atenl/src/hqa.c
index 24a6e9b..441825f 100644
--- a/feed/atenl/src/hqa.c
+++ b/feed/atenl/src/hqa.c
@@ -339,19 +339,10 @@
 				*(u16 *)(hdr->data + 2 + i) = val;
 			}
 		} else { /* write eeprom */
-			u16 offset_a;
-
 			for (i = 0; i < DIV_ROUND_UP(len, 2); i++) {
 				val = ntohs(v[i + 2]);
 				memcpy(&an->eeprom_data[offset + i * 2], &val, 2);
 			}
-
-			offset_a = offset - (offset % 16);
-			len += (offset - offset_a);
-			for (i = offset_a; i < offset_a + len; i += 16)
-				atenl_nl_write_eeprom(an, i, &an->eeprom_data[i], 16);
-
-			atenl_eeprom_write_mtd(an);
 		}
 	}