--- /dev/null
+From 2ef0359031b9ed891ca381b2687186fb52b277f8 Mon Sep 17 00:00:00 2001
+From: Arend Van Spriel <arend.vanspriel@broadcom.com>
+Date: Fri, 27 Jan 2017 12:27:45 +0000
+Subject: [PATCH] brcmfmac: provide a value for struct
+ wowlan_support::max_nd_match_sets
+
+The driver advertises support for WOWLAN_NETDETECT but did not specify
+maximum amount of netdetect match sets. This was no issue due to a bug
+in nl80211. As that has been fixed, brcmfmac also needs fixing.
+
+Reviewed-by: Hante Meuleman <hante.meuleman@broadcom.com>
+Reviewed-by: Pieter-Paul Giesberts <pieter-paul.giesberts@broadcom.com>
+Reviewed-by: Franky Lin <franky.lin@broadcom.com>
+Signed-off-by: Arend van Spriel <arend.vanspriel@broadcom.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
+@@ -6356,6 +6356,8 @@ static void brcmf_wiphy_wowl_params(stru
+ if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) {
+ if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ND)) {
+ brcmf_wowlan_support.flags |= WIPHY_WOWLAN_NET_DETECT;
++ brcmf_wowlan_support.max_nd_match_sets =
++ BRCMF_PNO_MAX_PFN_COUNT;
+ init_waitqueue_head(&cfg->wowl.nd_data_wait);
+ }
+ }
--- /dev/null
+From d29afe91af5995306d940b3dfee2419e0bb24a51 Mon Sep 17 00:00:00 2001
+From: Arend Van Spriel <arend.vanspriel@broadcom.com>
+Date: Fri, 27 Jan 2017 12:27:46 +0000
+Subject: [PATCH] brcmfmac: fix handling firmware results for wowl netdetect
+
+For wowl netdetect the event data changed for newer chips. This
+was recently fixed for scheduled scan, but same change is needed
+for wowl netdetect. Removing now pointles += operation from both
+result handlers.
+
+Reviewed-by: Hante Meuleman <hante.meuleman@broadcom.com>
+Reviewed-by: Pieter-Paul Giesberts <pieter-paul.giesberts@broadcom.com>
+Reviewed-by: Franky Lin <franky.lin@broadcom.com>
+Signed-off-by: Arend van Spriel <arend.vanspriel@broadcom.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 4 +---
+ 1 file changed, 1 insertion(+), 3 deletions(-)
+
+--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
+@@ -3328,7 +3328,6 @@ brcmf_notify_sched_scan_results(struct b
+ goto out_err;
+ }
+
+- data += sizeof(struct brcmf_pno_scanresults_le);
+ netinfo_start = brcmf_get_netinfo_array(pfn_result);
+
+ for (i = 0; i < result_count; i++) {
+@@ -3476,8 +3475,7 @@ brcmf_wowl_nd_results(struct brcmf_if *i
+ return -EINVAL;
+ }
+
+- data += sizeof(struct brcmf_pno_scanresults_le);
+- netinfo = (struct brcmf_pno_net_info_le *)data;
++ netinfo = brcmf_get_netinfo_array(pfn_result);
+ memcpy(cfg->wowl.nd->ssid.ssid, netinfo->SSID, netinfo->SSID_len);
+ cfg->wowl.nd->ssid.ssid_len = netinfo->SSID_len;
+ cfg->wowl.nd->n_channels = 1;
--- /dev/null
+From 0b57010fc18e12c19d14379cd739d4eb7c3898f3 Mon Sep 17 00:00:00 2001
+From: Arend Van Spriel <arend.vanspriel@broadcom.com>
+Date: Fri, 27 Jan 2017 12:27:47 +0000
+Subject: [PATCH] brcmfmac: allow wowlan support to be per device
+
+The wowlan support is (partially) determined dynamic by checking the
+device/firmware capabilities. So they can differ per device. So it
+is not possible to use a static global. Instead use the global as a
+template and use kmemdup(). When kmemdup() fails the template is used
+unmodified.
+
+Reviewed-by: Hante Meuleman <hante.meuleman@broadcom.com>
+Reviewed-by: Pieter-Paul Giesberts <pieter-paul.giesberts@broadcom.com>
+Reviewed-by: Franky Lin <franky.lin@broadcom.com>
+Signed-off-by: Arend van Spriel <arend.vanspriel@broadcom.com>
+Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
+---
+ .../broadcom/brcm80211/brcmfmac/cfg80211.c | 26 ++++++++++++++++------
+ 1 file changed, 19 insertions(+), 7 deletions(-)
+
+--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
+@@ -6337,7 +6337,7 @@ static void brcmf_wiphy_pno_params(struc
+ }
+
+ #ifdef CONFIG_PM
+-static struct wiphy_wowlan_support brcmf_wowlan_support = {
++static const struct wiphy_wowlan_support brcmf_wowlan_support = {
+ .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
+ .n_patterns = BRCMF_WOWL_MAXPATTERNS,
+ .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE,
+@@ -6350,21 +6350,29 @@ static void brcmf_wiphy_wowl_params(stru
+ {
+ #ifdef CONFIG_PM
+ struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
++ struct wiphy_wowlan_support *wowl;
++
++ wowl = kmemdup(&brcmf_wowlan_support, sizeof(brcmf_wowlan_support),
++ GFP_KERNEL);
++ if (!wowl) {
++ brcmf_err("only support basic wowlan features\n");
++ wiphy->wowlan = &brcmf_wowlan_support;
++ return;
++ }
+
+ if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_PNO)) {
+ if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_ND)) {
+- brcmf_wowlan_support.flags |= WIPHY_WOWLAN_NET_DETECT;
+- brcmf_wowlan_support.max_nd_match_sets =
+- BRCMF_PNO_MAX_PFN_COUNT;
++ wowl->flags |= WIPHY_WOWLAN_NET_DETECT;
++ wowl->max_nd_match_sets = BRCMF_PNO_MAX_PFN_COUNT;
+ init_waitqueue_head(&cfg->wowl.nd_data_wait);
+ }
+ }
+ if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL_GTK)) {
+- brcmf_wowlan_support.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY;
+- brcmf_wowlan_support.flags |= WIPHY_WOWLAN_GTK_REKEY_FAILURE;
++ wowl->flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY;
++ wowl->flags |= WIPHY_WOWLAN_GTK_REKEY_FAILURE;
+ }
+
+- wiphy->wowlan = &brcmf_wowlan_support;
++ wiphy->wowlan = wowl;
+ #endif
+ }
+
+@@ -6745,6 +6753,10 @@ static void brcmf_free_wiphy(struct wiph
+ kfree(wiphy->bands[NL80211_BAND_5GHZ]->channels);
+ kfree(wiphy->bands[NL80211_BAND_5GHZ]);
+ }
++#if IS_ENABLED(CONFIG_PM)
++ if (wiphy->wowlan != &brcmf_wowlan_support)
++ kfree(wiphy->wowlan);
++#endif
+ wiphy_free(wiphy);
+ }
+
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
-@@ -5884,6 +5884,9 @@ static int brcmf_construct_chaninfo(stru
+@@ -5882,6 +5882,9 @@ static int brcmf_construct_chaninfo(stru
continue;
}
/* assuming the chanspecs order is HT20,
* HT40 upper, HT40 lower, and VHT80.
*/
-@@ -6475,6 +6478,9 @@ static int brcmf_setup_wiphy(struct wiph
+@@ -6483,6 +6486,9 @@ static int brcmf_setup_wiphy(struct wiph
wiphy->bands[NL80211_BAND_5GHZ] = band;
}
}