From 2e25abb2008e0eed96ad6fe8f58881f31e1bf486 Mon Sep 17 00:00:00 2001
From: Venkateswara Naralasetty <vnaralas@codeaurora.org>
Date: Mon, 19 Apr 2021 11:11:06 +0530
Subject: [PATCH] ath11k: fix radar detection issue in 160mhz

Failed to detect RADAR pulses in the secondary 80mhz when the
the AP's primary 80mzh is in non-dfs region in 160mhz.

This is due to host is not setting WMI channel flags WMI_CHAN_INFO_DFS
and WMI_CHAN_INFO_DFS_FREQ2 in case of primary 80 is in non-dfs region.
HALPHY detects the RADAR pulses only when thse channel flags are set.

Fix this issue by setting WMI channel flags WMI_CHAN_INFO_DFS and
WMI_CHAN_INFO_DFS_FREQ2 based on the radar_enabled flag from channel
context.

Signed-off-by: Venkateswara Naralasetty <vnaralas@codeaurora.org>
---
 drivers/net/wireless/ath/ath11k/mac.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

--- a/drivers/net/wireless/ath/ath11k/mac.c
+++ b/drivers/net/wireless/ath/ath11k/mac.c
@@ -6864,7 +6864,7 @@ static void ath11k_mac_op_remove_chanctx
 static int
 ath11k_mac_vdev_start_restart(struct ath11k_vif *arvif,
 			      const struct cfg80211_chan_def *chandef,
-			      bool restart)
+			      bool restart, bool radar_enabled)
 {
 	struct ath11k *ar = arvif->ar;
 	struct ath11k_base *ab = ar->ab;
@@ -6903,8 +6903,7 @@ ath11k_mac_vdev_start_restart(struct ath
 		arg.channel.chan_radar =
 			!!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
 
-		arg.channel.freq2_radar =
-			!!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
+		arg.channel.freq2_radar = radar_enabled;
 
 		arg.channel.passive = arg.channel.chan_radar;
 
@@ -7026,15 +7025,19 @@ err:
 }
 
 static int ath11k_mac_vdev_start(struct ath11k_vif *arvif,
-				 const struct cfg80211_chan_def *chandef)
+				 const struct cfg80211_chan_def *chandef,
+				 bool radar_enabled)
 {
-	return ath11k_mac_vdev_start_restart(arvif, chandef, false);
+	return ath11k_mac_vdev_start_restart(arvif, chandef, false,
+					     radar_enabled);
 }
 
 static int ath11k_mac_vdev_restart(struct ath11k_vif *arvif,
-				   const struct cfg80211_chan_def *chandef)
+				   const struct cfg80211_chan_def *chandef,
+				   bool radar_enabled)
 {
-	return ath11k_mac_vdev_start_restart(arvif, chandef, true);
+	return ath11k_mac_vdev_start_restart(arvif, chandef, true,
+					     radar_enabled);
 }
 
 struct ath11k_mac_change_chanctx_arg {
@@ -7106,7 +7109,7 @@ ath11k_mac_update_vif_chan(struct ath11k
 		if (WARN_ON(!arvif->is_started))
 			continue;
 
-		if (WARN_ON(!arvif->is_up))
+		if (!arvif->is_up)
 			continue;
 
 		ret = ath11k_nss_vdev_down(arvif);
@@ -7135,16 +7138,17 @@ ath11k_mac_update_vif_chan(struct ath11k
 		if (WARN_ON(!arvif->is_started))
 			continue;
 
-		if (WARN_ON(!arvif->is_up))
-			continue;
-
-		ret = ath11k_mac_vdev_restart(arvif, &vifs[i].new_ctx->def);
+		ret = ath11k_mac_vdev_restart(arvif, &vifs[i].new_ctx->def,
+					      vifs[i].new_ctx->radar_enabled);
 		if (ret) {
 			ath11k_warn(ab, "failed to restart vdev %d: %d\n",
 				    arvif->vdev_id, ret);
 			continue;
 		}
 
+		if (!arvif->is_up)
+			continue;
+
 		ret = ath11k_mac_setup_bcn_tmpl(arvif);
 		if (ret)
 			ath11k_warn(ab, "failed to update bcn tmpl during csa: %d\n",
@@ -7224,7 +7228,8 @@ static void ath11k_mac_op_change_chanctx
 	if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
 		goto unlock;
 
-	if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH)
+	if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH ||
+	    changed & IEEE80211_CHANCTX_CHANGE_RADAR)
 		ath11k_mac_update_active_vif_chan(ar, ctx);
 
 	/* TODO: Recalc radar detection */
@@ -7244,7 +7249,8 @@ static int ath11k_start_vdev_delay(struc
 	if (WARN_ON(arvif->is_started))
 		return -EBUSY;
 
-	ret = ath11k_mac_vdev_start(arvif, &arvif->chanctx.def);
+	ret = ath11k_mac_vdev_start(arvif, &arvif->chanctx.def,
+				    arvif->chanctx.radar_enabled);
 	if (ret) {
 		ath11k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n",
 			    arvif->vdev_id, vif->addr,
@@ -7327,7 +7333,7 @@ ath11k_mac_op_assign_vif_chanctx(struct
 		goto exit;
 	}
 
-	ret = ath11k_mac_vdev_start(arvif, &ctx->def);
+	ret = ath11k_mac_vdev_start(arvif, &ctx->def, ctx->radar_enabled);
 	if (ret) {
 		ath11k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n",
 			    arvif->vdev_id, vif->addr,
