[][MAC80211][WiFi6/7][app][Add ext eeprom write back cmd support]

[Description]
Add ext eeprom write back cmd support
atenl -i phyX -c "eeprom write to ext"

[Release-log]
N/A

Change-Id: Id19575775b6373443dc50d41ed6ff6cf14dbe751
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/9585425
diff --git a/feed/app/atenl/src/atenl.h b/feed/app/atenl/src/atenl.h
index a6695c9..edd3b78 100644
--- a/feed/app/atenl/src/atenl.h
+++ b/feed/app/atenl/src/atenl.h
@@ -435,6 +435,7 @@
 int atenl_nl_check_mtd(struct atenl *an);
 int atenl_nl_write_eeprom(struct atenl *an, u32 offset, u8 *val, int len);
 int atenl_nl_write_efuse_all(struct atenl *an);
+int atenl_nl_write_ext_eeprom_all(struct atenl *an);
 int atenl_nl_update_buffer_mode(struct atenl *an);
 int atenl_nl_set_state(struct atenl *an, u8 band,
 		       enum mt76_testmode_state state);
diff --git a/feed/app/atenl/src/eeprom.c b/feed/app/atenl/src/eeprom.c
index b3a652a..a3c73cf 100644
--- a/feed/app/atenl/src/eeprom.c
+++ b/feed/app/atenl/src/eeprom.c
@@ -484,7 +484,7 @@
 	return ret;
 }
 
-/* Update all eeprom values to driver before writing efuse */
+/* Update all eeprom values to driver before writing efuse or ext eeprom */
 static void
 atenl_eeprom_sync_to_driver(struct atenl *an)
 {
@@ -548,6 +548,9 @@
 			} else if (!strncmp(s, "to efuse", 8)) {
 				atenl_eeprom_sync_to_driver(an);
 				atenl_nl_write_efuse_all(an);
+			} else if (!strncmp(s, "to ext", 6)) {
+				atenl_eeprom_sync_to_driver(an);
+				atenl_nl_write_ext_eeprom_all(an);
 			}
 		} else if (!strncmp(s, "read", 4)) {
 			u32 offset;
diff --git a/feed/app/atenl/src/nl.c b/feed/app/atenl/src/nl.c
index baf2944..9982231 100644
--- a/feed/app/atenl/src/nl.c
+++ b/feed/app/atenl/src/nl.c
@@ -1305,6 +1305,36 @@
 	return 0;
 }
 
+int atenl_nl_write_ext_eeprom_all(struct atenl *an)
+{
+	struct atenl_nl_priv nl_priv = {};
+	struct nl_msg *msg;
+	void *ptr;
+
+	if (unl_genl_init(&nl_priv.unl, "nl80211") < 0) {
+		atenl_err("Failed to connect to nl80211\n");
+		return 2;
+	}
+
+	msg = unl_genl_msg(&nl_priv.unl, NL80211_CMD_TESTMODE, false);
+	nla_put_u32(msg, NL80211_ATTR_WIPHY, get_band_val(an, 0, phy_idx));
+
+	ptr = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
+	if (!ptr)
+		return -ENOMEM;
+
+	nla_put_u8(msg, MT76_TM_ATTR_EEPROM_ACTION,
+		   MT76_TM_EEPROM_ACTION_WRITE_TO_EXT_EEPROM);
+
+	nla_nest_end(msg, ptr);
+
+	unl_genl_request(&nl_priv.unl, msg, NULL, NULL);
+
+	unl_free(&nl_priv.unl);
+
+	return 0;
+}
+
 int atenl_nl_update_buffer_mode(struct atenl *an)
 {
 	struct atenl_nl_priv nl_priv = {};
diff --git a/feed/app/atenl/src/nl.h b/feed/app/atenl/src/nl.h
index b580a01..bd0aee7 100644
--- a/feed/app/atenl/src/nl.h
+++ b/feed/app/atenl/src/nl.h
@@ -267,11 +267,13 @@
  * 	eeprom data block
  * @MT76_TM_EEPROM_ACTION_UPDATE_BUFFER_MODE: send updated eeprom data to fw
  * @MT76_TM_EEPROM_ACTION_WRITE_TO_EFUSE: write eeprom data back to efuse
+ * @MT76_TM_EEPROM_ACTION_WRITE_TO_EXT_EEPROM: write eeprom data back to external eeprom
  */
 enum mt76_testmode_eeprom_action {
 	MT76_TM_EEPROM_ACTION_UPDATE_DATA,
 	MT76_TM_EEPROM_ACTION_UPDATE_BUFFER_MODE,
 	MT76_TM_EEPROM_ACTION_WRITE_TO_EFUSE,
+	MT76_TM_EEPROM_ACTION_WRITE_TO_EXT_EEPROM,
 
 	/* keep last */
 	NUM_MT76_TM_EEPROM_ACTION,