From a9a4abb637d90f8c173f466276d81736f08c12e8 Mon Sep 17 00:00:00 2001
From: David Bauer <blocktrron@users.noreply.github.com>
Date: Thu, 28 Mar 2019 14:49:17 +0100
Subject: [PATCH] ipq806x: add support for NETGEAR R7800 (#1669)

The device is broken until the next release. The LEDs are currently not
working (fixed in current OpenWRT master).

Also give a brief explanation about the BROKEN status being dependent on
the WiFi chip used and not the SoC family in general.
---
 .../luasrc/lib/gluon/upgrade/010-primary-mac  |  2 ++
 targets/ipq806x                               | 30 +++++++++++++++++--
 targets/targets.mk                            |  2 +-
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac b/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac
index 4bd26ea0f..038a77715 100755
--- a/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac
+++ b/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac
@@ -49,6 +49,8 @@ elseif platform.match('ar71xx', 'generic', {'archer-c5', 'archer-c58-v1',
 elseif platform.match('ipq40xx', nil, {'avm,fritzbox-4040',
                                        'openmesh,a42', 'openmesh,a62'}) then
   table.insert(try_files, 1, '/sys/class/net/eth0/address')
+elseif platform.match('ipq806x', nil, {'netgear,r7800'}) then
+  table.insert(try_files, 1, '/sys/class/net/eth1/address')
 elseif platform.match('ramips', 'mt7621', {'dir-860l-b1'}) then
   table.insert(try_files, 1, '/sys/class/ieee80211/phy1/macaddress')
 end
diff --git a/targets/ipq806x b/targets/ipq806x
index 287e8c782..cce037d54 100644
--- a/targets/ipq806x
+++ b/targets/ipq806x
@@ -1,7 +1,31 @@
-ATH10K_PACKAGES='-kmod-ath10k kmod-ath10k-ct -ath10k-firmware-qca99x0 ath10k-firmware-qca99x0-ct'
+# The QCA9980 was discontinued by Qualcomm. It didn't receive any firmware-update for over 4 years.
+# See https://github.com/kvalo/ath10k-firmware/tree/master/QCA99X0/hw2.0
+# 802.11s was never implemented for the chip's firmware. It will most likely be broken forever.
+# The QCA9984 on the other hand works fine for 11s meshes on both bands.
 
+QCA9980_PACKAGES='-kmod-ath10k kmod-ath10k-ct -ath10k-firmware-qca99x0 ath10k-firmware-qca99x0-ct'
+QCA9984_PACKAGES='kmod-ath10k -kmod-ath10k-ct ath10k-firmware-qca9984 -ath10k-firmware-qca9984-ct'
 
-# TP-Link
 
+#
+# QCA9980
+#
+
+if [ "$BROKEN" ]; then
+# TP-Link
 device tp-link-archer-c2600 tplink_c2600
-packages $ATH10K_PACKAGES
+packages $QCA9980_PACKAGES
+fi
+
+#
+# QCA9984
+#
+
+# -- ToDo --
+# The BROKEN flag for the target can be removed when switching to an OpenWrt base newer than 18.06,
+# as in 18.06 the LEDs are not yet functional. This is already fixed in the current OpenWrt master.
+
+# NETGEAR
+device netgear-nighthawk-x4s-r7800 netgear_r7800
+factory .img
+packages $QCA9984_PACKAGES
diff --git a/targets/targets.mk b/targets/targets.mk
index 9826f4720..f89c82f3d 100644
--- a/targets/targets.mk
+++ b/targets/targets.mk
@@ -22,6 +22,6 @@ endif
 ifneq ($(BROKEN),)
 $(eval $(call GluonTarget,ar71xx,mikrotik)) # BROKEN: no sysupgrade support
 $(eval $(call GluonTarget,brcm2708,bcm2710)) # BROKEN: Untested
-$(eval $(call GluonTarget,ipq806x)) # BROKEN: unstable wifi drivers
+$(eval $(call GluonTarget,ipq806x)) # BROKEN: See target file for details
 $(eval $(call GluonTarget,mvebu,cortexa9)) # BROKEN: No AP+IBSS or 11s support
 endif
-- 
GitLab