From bda0e566a474677412cc3097e93b954b628c626b Mon Sep 17 00:00:00 2001
From: John Crispin <john@phrozen.org>
Date: Thu, 25 Mar 2021 08:03:48 +0100
Subject: [PATCH 01/31] ipq40xx: add ath10k-ct fw.cfg stubs

Signed-off-by: John Crispin <john@phrozen.org>
---
 ...the-dst-buffer-to-of_get_mac_address.patch | 29 -----------------
 ...ss-the-dst-buffer-to-of_get_mac_addr.patch | 26 ---------------
 .../etc/hotplug.d/firmware/40-ct-fw-cfg       | 32 +++++++++++++++++++
 .../lib/firmware/ath10k/fwcfg-ipq4019.txt     | 15 +++++++++
 .../lib/firmware/ath10k/fwcfg-qca9888.txt     | 16 ++++++++++
 .../lib/firmware/ath10k/fwcfg-qca9984.txt     | 16 ++++++++++
 .../etc/hotplug.d/firmware/40-ct-fw-cfg       | 32 +++++++++++++++++++
 .../lib/firmware/ath10k/fwcfg-qca9888.txt     | 16 ++++++++++
 .../lib/firmware/ath10k/fwcfg-qca9984.txt     | 16 ++++++++++
 9 files changed, 143 insertions(+), 55 deletions(-)
 delete mode 100644 package/kernel/mac80211/patches/subsys/782-net-next-1-of-net-pass-the-dst-buffer-to-of_get_mac_address.patch
 delete mode 100644 package/kernel/mt76/patches/100-Revert-of-net-pass-the-dst-buffer-to-of_get_mac_addr.patch
 create mode 100644 target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/40-ct-fw-cfg
 create mode 100644 target/linux/ipq40xx/base-files/lib/firmware/ath10k/fwcfg-ipq4019.txt
 create mode 100644 target/linux/ipq40xx/base-files/lib/firmware/ath10k/fwcfg-qca9888.txt
 create mode 100644 target/linux/ipq40xx/base-files/lib/firmware/ath10k/fwcfg-qca9984.txt
 create mode 100644 target/linux/ipq806x/base-files/etc/hotplug.d/firmware/40-ct-fw-cfg
 create mode 100644 target/linux/ipq806x/base-files/lib/firmware/ath10k/fwcfg-qca9888.txt
 create mode 100644 target/linux/ipq806x/base-files/lib/firmware/ath10k/fwcfg-qca9984.txt

diff --git a/package/kernel/mac80211/patches/subsys/782-net-next-1-of-net-pass-the-dst-buffer-to-of_get_mac_address.patch b/package/kernel/mac80211/patches/subsys/782-net-next-1-of-net-pass-the-dst-buffer-to-of_get_mac_address.patch
deleted file mode 100644
index 26af6a2fb9..0000000000
--- a/package/kernel/mac80211/patches/subsys/782-net-next-1-of-net-pass-the-dst-buffer-to-of_get_mac_address.patch
+++ /dev/null
@@ -1,29 +0,0 @@
---- a/backport-include/linux/of_net.h
-+++ /dev/null
-@@ -1,26 +0,0 @@
--#ifndef _BP_OF_NET_H
--#define _BP_OF_NET_H
--#include_next <linux/of_net.h>
--#include <linux/version.h>
--#include <linux/etherdevice.h>
--
--/* The behavior of of_get_mac_address() changed in kernel 5.2, it now
-- * returns an error code and not NULL in case of an error.
-- */
--#if LINUX_VERSION_IS_LESS(5,13,0)
--static inline int backport_of_get_mac_address(struct device_node *np, u8 *mac_out)
--{
--	const void *mac = of_get_mac_address(np);
--
--	if (!mac)
--		return -ENODEV;
--	if (IS_ERR(mac))
--		return PTR_ERR(mac);
--	ether_addr_copy(mac_out, mac);
--	
--	return 0;
--}
--#define of_get_mac_address LINUX_BACKPORT(of_get_mac_address)
--#endif /* < 5.2 */
--
--#endif /* _BP_OF_NET_H */
diff --git a/package/kernel/mt76/patches/100-Revert-of-net-pass-the-dst-buffer-to-of_get_mac_addr.patch b/package/kernel/mt76/patches/100-Revert-of-net-pass-the-dst-buffer-to-of_get_mac_addr.patch
deleted file mode 100644
index 24b1240548..0000000000
--- a/package/kernel/mt76/patches/100-Revert-of-net-pass-the-dst-buffer-to-of_get_mac_addr.patch
+++ /dev/null
@@ -1,26 +0,0 @@
-From: Felix Fietkau <nbd@nbd.name>
-Date: Tue, 23 Nov 2021 17:01:45 +0100
-Subject: [PATCH] Revert "of: net: pass the dst buffer to of_get_mac_address()"
-
-This reverts commit 4932c5d80153c336c77dbe8d7af9f8fdd879d01f.
----
-
---- a/eeprom.c
-+++ b/eeprom.c
-@@ -105,9 +105,15 @@ mt76_eeprom_override(struct mt76_phy *ph
- {
- 	struct mt76_dev *dev = phy->dev;
- 
-+#ifdef CONFIG_OF
- 	struct device_node *np = dev->dev->of_node;
-+	const u8 *mac = NULL;
- 
--	of_get_mac_address(np, phy->macaddr);
-+	if (np)
-+		mac = of_get_mac_address(np);
-+	if (!IS_ERR_OR_NULL(mac))
-+		ether_addr_copy(phy->macaddr, mac);
-+#endif
- 
- 	if (!is_valid_ether_addr(phy->macaddr)) {
- 		eth_random_addr(phy->macaddr);
diff --git a/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/40-ct-fw-cfg b/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/40-ct-fw-cfg
new file mode 100644
index 0000000000..7e22cbd4f5
--- /dev/null
+++ b/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/40-ct-fw-cfg
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+[ -e /lib/firmware/$FIRMWARE ] && exit 0
+
+
+fwcfg_symlink() {
+	local chip=$1
+	local path=$2
+
+	ln -s /lib/firmware/ath10k/fwcfg-${chip}.txt /lib/firmware/${FIRMWARE}
+}
+
+case "$FIRMWARE" in                                                         
+ath10k/fwcfg-ahb-a000000.wifi.txt|\
+ath10k/fwcfg-ahb-a800000.wifi.txt)
+	fwcfg_symlink ipq4019
+	
+	;;
+ath10k/fwcfg-pci-0000:01:00.0.txt)
+        case "$(board_name)" in
+        linksys,ea8300)
+                fwcfg_symlink qca9888
+                ;;
+	tp-link,ap2220|\
+	tp-link,ec420-g1)
+		fwcfg_symlink qca9984
+		;;
+	esac
+	;;
+esac
+
+exit 0
diff --git a/target/linux/ipq40xx/base-files/lib/firmware/ath10k/fwcfg-ipq4019.txt b/target/linux/ipq40xx/base-files/lib/firmware/ath10k/fwcfg-ipq4019.txt
new file mode 100644
index 0000000000..7943173e51
--- /dev/null
+++ b/target/linux/ipq40xx/base-files/lib/firmware/ath10k/fwcfg-ipq4019.txt
@@ -0,0 +1,15 @@
+vdevs = 8
+peers = 147
+active_peers = 147
+stations = 147
+rate_ctrl_objs = 7
+#regdom = 840
+#fwname = firmware-5-htt-mgt-b.bin
+#fwver = 5
+nohwcrypt = 0
+ct_sta_mode = 0
+tx_desc = 2000
+#max_nss = 3
+tids = 450
+skid_limit = 360
+max_amsdus = 3 
diff --git a/target/linux/ipq40xx/base-files/lib/firmware/ath10k/fwcfg-qca9888.txt b/target/linux/ipq40xx/base-files/lib/firmware/ath10k/fwcfg-qca9888.txt
new file mode 100644
index 0000000000..560c8103d7
--- /dev/null
+++ b/target/linux/ipq40xx/base-files/lib/firmware/ath10k/fwcfg-qca9888.txt
@@ -0,0 +1,16 @@
+# 9888 chip
+vdevs = 8
+peers = 202
+active_peers = 202
+stations = 202
+rate_ctrl_objs = 7
+#regdom = 840
+#fwname = firmware-5-htt-mgt-b.bin
+#fwver = 5
+nohwcrypt = 0
+ct_sta_mode = 0
+tx_desc = 2200
+#max_nss = 3
+tids = 450
+skid_limit = 360
+max_amsdus = 3 
diff --git a/target/linux/ipq40xx/base-files/lib/firmware/ath10k/fwcfg-qca9984.txt b/target/linux/ipq40xx/base-files/lib/firmware/ath10k/fwcfg-qca9984.txt
new file mode 100644
index 0000000000..924a689000
--- /dev/null
+++ b/target/linux/ipq40xx/base-files/lib/firmware/ath10k/fwcfg-qca9984.txt
@@ -0,0 +1,16 @@
+# 9984
+vdevs = 8
+peers = 180
+active_peers = 180
+stations = 180
+rate_ctrl_objs = 7
+#regdom = 840
+#fwname = firmware-5-htt-mgt-b.bin
+#fwver = 5
+nohwcrypt = 0
+ct_sta_mode = 0
+tx_desc = 2400
+#max_nss = 3
+tids = 450
+skid_limit = 360
+max_amsdus = 3 
diff --git a/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/40-ct-fw-cfg b/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/40-ct-fw-cfg
new file mode 100644
index 0000000000..c33bbea506
--- /dev/null
+++ b/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/40-ct-fw-cfg
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+[ -e /lib/firmware/$FIRMWARE ] && exit 0
+
+
+fwcfg_symlink() {
+	local chip=$1
+	local path=$2
+
+	ln -s /lib/firmware/ath10k/fwcfg-${chip}.txt /lib/firmware/${FIRMWARE}
+}
+
+case "$FIRMWARE" in                                                         
+ath10k/fwcfg-pci-0001:01:00.0.txt)
+	case "$(board_name)" in
+	edgecore,ssw2ac2600|\
+	edgecore,ecw5410)
+		fwcfg_symlink qca9984
+		;;
+	esac
+	;;
+ath10k/fwcfg-pci-0002:01:00.0.txt)
+	case "$(board_name)" in
+	edgecore,ssw2ac2600|\
+	edgecore,ecw5410)
+		fwcfg_symlink qca9984
+		;;	
+	esac
+	;;
+esac
+
+exit 0
diff --git a/target/linux/ipq806x/base-files/lib/firmware/ath10k/fwcfg-qca9888.txt b/target/linux/ipq806x/base-files/lib/firmware/ath10k/fwcfg-qca9888.txt
new file mode 100644
index 0000000000..560c8103d7
--- /dev/null
+++ b/target/linux/ipq806x/base-files/lib/firmware/ath10k/fwcfg-qca9888.txt
@@ -0,0 +1,16 @@
+# 9888 chip
+vdevs = 8
+peers = 202
+active_peers = 202
+stations = 202
+rate_ctrl_objs = 7
+#regdom = 840
+#fwname = firmware-5-htt-mgt-b.bin
+#fwver = 5
+nohwcrypt = 0
+ct_sta_mode = 0
+tx_desc = 2200
+#max_nss = 3
+tids = 450
+skid_limit = 360
+max_amsdus = 3 
diff --git a/target/linux/ipq806x/base-files/lib/firmware/ath10k/fwcfg-qca9984.txt b/target/linux/ipq806x/base-files/lib/firmware/ath10k/fwcfg-qca9984.txt
new file mode 100644
index 0000000000..924a689000
--- /dev/null
+++ b/target/linux/ipq806x/base-files/lib/firmware/ath10k/fwcfg-qca9984.txt
@@ -0,0 +1,16 @@
+# 9984
+vdevs = 8
+peers = 180
+active_peers = 180
+stations = 180
+rate_ctrl_objs = 7
+#regdom = 840
+#fwname = firmware-5-htt-mgt-b.bin
+#fwver = 5
+nohwcrypt = 0
+ct_sta_mode = 0
+tx_desc = 2400
+#max_nss = 3
+tids = 450
+skid_limit = 360
+max_amsdus = 3 
-- 
2.25.1

