[Refactor and sync wifi from Openwrt]

[Description]
Refactor and sync wifi from Openwrt
1.mt76/mac80211/hostapd

[Release-log]
N/A

diff --git a/recipes-kernel/linux-mt76/files/patches/1118-mt76-mt7915-implement-bin-file-mode.patch b/recipes-kernel/linux-mt76/files/patches/1118-mt76-mt7915-implement-bin-file-mode.patch
new file mode 100644
index 0000000..8597721
--- /dev/null
+++ b/recipes-kernel/linux-mt76/files/patches/1118-mt76-mt7915-implement-bin-file-mode.patch
@@ -0,0 +1,180 @@
+From 8a072ddf45b67a379a2fb63dd45e0f5024101403 Mon Sep 17 00:00:00 2001
+From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
+Date: Thu, 7 Jul 2022 11:09:59 +0800
+Subject: [PATCH 1118/1119] mt76: mt7915: implement bin file mode
+
+Change-Id: I2a726341541a11cbecdb210b33a8e79aefbd6cf3
+Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
+---
+ drivers/net/wireless/mediatek/mt76/eeprom.c   | 18 +++++++
+ drivers/net/wireless/mediatek/mt76/mt76.h     |  1 +
+ .../wireless/mediatek/mt76/mt7915/eeprom.c    | 53 +++++++++++++++----
+ .../wireless/mediatek/mt76/mt7915/mt7915.h    | 10 ++++
+ 4 files changed, 71 insertions(+), 11 deletions(-)
+
+diff --git a/eeprom.c b/eeprom.c
+index d7ee123b..f2d0a65b 100644
+--- a/eeprom.c
++++ b/eeprom.c
+@@ -102,6 +102,24 @@ out_put_node:
+ }
+ EXPORT_SYMBOL_GPL(mt76_get_of_eeprom);
+ 
++bool mt76_check_bin_file_mode(struct mt76_dev *dev)
++{
++	struct device_node *np = dev->dev->of_node;
++	const __be32 *bin_file_mode;
++	bool ret = false;
++
++	if (!np)
++		return false;
++
++	bin_file_mode = of_get_property(np, "bin_file_mode", NULL);
++	if (bin_file_mode && be32_to_cpu(*bin_file_mode))
++		ret = true;
++
++	of_node_put(np);
++	return ret;
++}
++EXPORT_SYMBOL_GPL(mt76_check_bin_file_mode);
++
+ void
+ mt76_eeprom_override(struct mt76_phy *phy)
+ {
+diff --git a/mt76.h b/mt76.h
+index 4c8a671f..49314895 100644
+--- a/mt76.h
++++ b/mt76.h
+@@ -1005,6 +1005,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str,
+ int mt76_eeprom_init(struct mt76_dev *dev, int len);
+ void mt76_eeprom_override(struct mt76_phy *phy);
+ int mt76_get_of_eeprom(struct mt76_dev *dev, void *data, int offset, int len);
++bool mt76_check_bin_file_mode(struct mt76_dev *dev);
+ 
+ struct mt76_queue *
+ mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc,
+diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c
+index ee3049e5..e5cfa5b0 100644
+--- a/mt7915/eeprom.c
++++ b/mt7915/eeprom.c
+@@ -46,26 +46,36 @@ static char *mt7915_eeprom_name(struct mt7915_dev *dev)
+ {
+ 	switch (mt76_chip(&dev->mt76)) {
+ 	case 0x7915:
+-		return dev->dbdc_support ?
+-		       MT7915_EEPROM_DEFAULT_DBDC : MT7915_EEPROM_DEFAULT;
++		if (dev->bin_file_mode)
++			return dev->dbdc_support ?
++				MT7915_BIN_FILE_DBDC : MT7915_BIN_FILE;
++		else
++			return dev->dbdc_support ?
++				MT7915_EEPROM_DEFAULT_DBDC : MT7915_EEPROM_DEFAULT;
+ 	case 0x7986:
+ 		switch (mt7915_check_adie(dev, true)) {
+ 		case MT7976_ONE_ADIE_DBDC:
+-			return MT7986_EEPROM_MT7976_DEFAULT_DBDC;
++			return dev->bin_file_mode ?
++			MT7986_BIN_FILE_MT7976_DBDC : MT7986_EEPROM_MT7976_DEFAULT_DBDC;
+ 		case MT7975_ONE_ADIE:
+-			return MT7986_EEPROM_MT7975_DEFAULT;
++			return dev->bin_file_mode ?
++			MT7986_BIN_FILE_MT7975 : MT7986_EEPROM_MT7975_DEFAULT;
+ 		case MT7976_ONE_ADIE:
+-			return MT7986_EEPROM_MT7976_DEFAULT;
++			return dev->bin_file_mode ?
++			MT7986_BIN_FILE_MT7976 : MT7986_EEPROM_MT7976_DEFAULT;
+ 		case MT7975_DUAL_ADIE:
+-			return MT7986_EEPROM_MT7975_DUAL_DEFAULT;
++			return dev->bin_file_mode ?
++			MT7986_BIN_FILE_MT7975_DUAL : MT7986_EEPROM_MT7975_DUAL_DEFAULT;
+ 		case MT7976_DUAL_ADIE:
+-			return MT7986_EEPROM_MT7976_DUAL_DEFAULT;
++			return dev->bin_file_mode ?
++			MT7986_BIN_FILE_MT7976_DUAL : MT7986_EEPROM_MT7976_DUAL_DEFAULT;
+ 		default:
+ 			break;
+ 		}
+ 		return NULL;
+ 	default:
+-		return MT7916_EEPROM_DEFAULT;
++		return dev->bin_file_mode ?
++			MT7916_BIN_FILE : MT7916_EEPROM_DEFAULT;
+ 	}
+ }
+ 
+@@ -81,7 +91,10 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev)
+ 		return ret;
+ 
+ 	if (!fw || !fw->data) {
+-		dev_err(dev->mt76.dev, "Invalid default bin\n");
++		if (dev->bin_file_mode)
++			dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n");
++		else
++			dev_err(dev->mt76.dev, "Invalid default bin\n");
+ 		ret = -EINVAL;
+ 		goto out;
+ 	}
+@@ -234,12 +247,30 @@ int mt7915_eeprom_init(struct mt7915_dev *dev)
+ {
+ 	int ret;
+ 
+-	ret = mt7915_eeprom_load(dev);
++	dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76);
++
++	if (dev->bin_file_mode) {
++		dev->mt76.eeprom.size = mt7915_eeprom_size(dev);
++		dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size,
++						      GFP_KERNEL);
++		if (!dev->mt76.eeprom.data)
++			return -ENOMEM;
++		ret = mt7915_eeprom_load_default(dev);
++	} else {
++		ret = mt7915_eeprom_load(dev);
++	}
++
+ 	if (ret < 0) {
+ 		if (ret != -EINVAL)
+ 			return ret;
+ 
+-		dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n");
++		if (dev->bin_file_mode) {
++			dev_warn(dev->mt76.dev, "bin file load fail, use default bin\n");
++			dev->bin_file_mode = false;
++		} else {
++			dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n");
++		}
++
+ 		ret = mt7915_eeprom_load_default(dev);
+ 		if (ret)
+ 			return ret;
+diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
+index 6462d502..491566e9 100644
+--- a/mt7915/mt7915.h
++++ b/mt7915/mt7915.h
+@@ -51,6 +51,15 @@
+ #define MT7986_EEPROM_MT7976_DEFAULT_DBDC	"mediatek/mt7986_eeprom_mt7976_dbdc.bin"
+ #define MT7986_EEPROM_MT7976_DUAL_DEFAULT	"mediatek/mt7986_eeprom_mt7976_dual.bin"
+ 
++#define MT7915_BIN_FILE			"mediatek/mt7915_binfile.bin"
++#define MT7915_BIN_FILE_DBDC	 	        "mediatek/mt7915_binfile_dbdc.bin"
++#define MT7916_BIN_FILE		        "mediatek/mt7916_binfile.bin"
++#define MT7986_BIN_FILE_MT7975			"mediatek/mt7986_binfile_mt7975.bin"
++#define MT7986_BIN_FILE_MT7975_DUAL		"mediatek/mt7986_binfile_mt7975_dual.bin"
++#define MT7986_BIN_FILE_MT7976			"mediatek/mt7986_binfile_mt7976.bin"
++#define MT7986_BIN_FILE_MT7976_DBDC		"mediatek/mt7986_binfile_mt7976_dbdc.bin"
++#define MT7986_BIN_FILE_MT7976_DUAL		"mediatek/mt7986_binfile_mt7976_dual.bin"
++
+ #define MT7915_EEPROM_SIZE		3584
+ #define MT7916_EEPROM_SIZE		4096
+ 
+@@ -377,6 +386,7 @@ struct mt7915_dev {
+ 
+ 	bool dbdc_support;
+ 	bool flash_mode;
++	bool bin_file_mode;
+ 	bool muru_debug;
+ 	bool ibf;
+ 
+-- 
+2.25.1
+