CHROMIUM: iwl7000: don't send GEO_TX_POWER_LIMIT if no wgds table

The GEO_TX_POWER_LIMIT command was sent although
there is no wgds table, so the fw got wrong SAR values
from the driver.

Fix this by avoiding sending the command if no wgds
tables are available.

BUG=b:145757342
TEST=Connect wifi and make sure the TX power is as defined in the SAR
     tables.

Change-Id: Id5cf852ec8c5dbf20ba86bad7b165a0c828f8b2e
Signed-off-by: Golan Ben Ami <golan.ben.ami@intel.com>
iwl7000-tree: d97aa65f59ee64c05c3aebaacbc7cba7e5fac19a
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2102483
Tested-by: Brian Norris <briannorris@chromium.org>
Tested-by: George Engelbrecht <engeg@google.com>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Commit-Queue: George Engelbrecht <engeg@google.com>
(cherry picked from commit 878cc96fc2e0dd3ebfb830793dc429ff002216ba)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2118184
Commit-Queue: Brian Norris <briannorris@chromium.org>
diff --git a/drivers/net/wireless/iwl7000/iwlwifi/fw/acpi.c b/drivers/net/wireless/iwl7000/iwlwifi/fw/acpi.c
index 6988fe4..95ac251 100644
--- a/drivers/net/wireless/iwl7000/iwlwifi/fw/acpi.c
+++ b/drivers/net/wireless/iwl7000/iwlwifi/fw/acpi.c
@@ -6,7 +6,7 @@
  * GPL LICENSE SUMMARY
  *
  * Copyright(c) 2017        Intel Deutschland GmbH
- * Copyright (C) 2019 Intel Corporation
+ * Copyright (C) 2019 - 2020 Intel Corporation
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of version 2 of the GNU General Public License as
@@ -27,7 +27,7 @@
  * BSD LICENSE
  *
  * Copyright(c) 2017        Intel Deutschland GmbH
- * Copyright (C) 2019 Intel Corporation
+ * Copyright (C) 2019 - 2020 Intel Corporation
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -493,13 +493,13 @@
 }
 IWL_EXPORT_SYMBOL(iwl_validate_sar_geo_profile);
 
-void iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
-		      struct iwl_per_chain_offset_group *table)
+int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
+		     struct iwl_per_chain_offset_group *table)
 {
 	int ret, i, j;
 
 	if (!iwl_sar_geo_support(fwrt))
-		return;
+		return -EOPNOTSUPP;
 
 	ret = iwl_sar_get_wgds_table(fwrt);
 	if (ret < 0) {
@@ -507,7 +507,7 @@
 				"Geo SAR BIOS table invalid or unavailable. (%d)\n",
 				ret);
 		/* we don't fail if the table is not available */
-		return;
+		return -ENOENT;
 	}
 
 	IWL_DEBUG_RADIO(fwrt, "Sending GEO_TX_POWER_LIMIT\n");
@@ -534,5 +534,7 @@
 					i, j, value[1], value[2], value[0]);
 		}
 	}
+
+	return 0;
 }
 IWL_EXPORT_SYMBOL(iwl_sar_geo_init);
diff --git a/drivers/net/wireless/iwl7000/iwlwifi/fw/acpi.h b/drivers/net/wireless/iwl7000/iwlwifi/fw/acpi.h
index f27258a..cab369c 100644
--- a/drivers/net/wireless/iwl7000/iwlwifi/fw/acpi.h
+++ b/drivers/net/wireless/iwl7000/iwlwifi/fw/acpi.h
@@ -6,7 +6,7 @@
  * GPL LICENSE SUMMARY
  *
  * Copyright(c) 2017        Intel Deutschland GmbH
- * Copyright(c) 2018 - 2019        Intel Corporation
+ * Copyright(c) 2018 - 2020        Intel Corporation
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of version 2 of the GNU General Public License as
@@ -27,7 +27,7 @@
  * BSD LICENSE
  *
  * Copyright(c) 2017        Intel Deutschland GmbH
- * Copyright(c) 2018 - 2019       Intel Corporation
+ * Copyright(c) 2018 - 2020       Intel Corporation
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -159,8 +159,8 @@
 int iwl_validate_sar_geo_profile(struct iwl_fw_runtime *fwrt,
 				 struct iwl_host_cmd *cmd);
 
-void iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
-		      struct iwl_per_chain_offset_group *table);
+int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
+		     struct iwl_per_chain_offset_group *table);
 #else /* CONFIG_ACPI */
 
 static inline void *iwl_acpi_get_object(struct device *dev, acpi_string method)
@@ -231,9 +231,10 @@
 	return -ENOENT;
 }
 
-static inline void iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
-				    struct iwl_per_chain_offset_group *table)
+static inline int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
+				   struct iwl_per_chain_offset_group *table)
 {
+	return -ENOENT;
 }
 
 #endif /* CONFIG_ACPI */
diff --git a/drivers/net/wireless/iwl7000/iwlwifi/mvm/fw.c b/drivers/net/wireless/iwl7000/iwlwifi/mvm/fw.c
index 01d0e8d8..bdfac73 100644
--- a/drivers/net/wireless/iwl7000/iwlwifi/mvm/fw.c
+++ b/drivers/net/wireless/iwl7000/iwlwifi/mvm/fw.c
@@ -857,10 +857,17 @@
 	u16 cmd_wide_id =  WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT);
 	union geo_tx_power_profiles_cmd cmd;
 	u16 len;
+	int ret;
 
 	cmd.geo_cmd.ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_SET_TABLES);
 
-	iwl_sar_geo_init(&mvm->fwrt, cmd.geo_cmd.table);
+	ret = iwl_sar_geo_init(&mvm->fwrt, cmd.geo_cmd.table);
+	/*
+	 * It is a valid scenario to not support SAR, or miss wgds table,
+	 * but in that case there is no need to send the command.
+	 */
+	if (ret)
+		return 0;
 
 	cmd.geo_cmd.table_revision = cpu_to_le32(mvm->fwrt.geo_rev);
 
diff --git a/drivers/net/wireless/iwl7000/iwlwifi/xvt/xvt.c b/drivers/net/wireless/iwl7000/iwlwifi/xvt/xvt.c
index f54af24..cd1e943 100644
--- a/drivers/net/wireless/iwl7000/iwlwifi/xvt/xvt.c
+++ b/drivers/net/wireless/iwl7000/iwlwifi/xvt/xvt.c
@@ -811,10 +811,17 @@
 	u16 cmd_wide_id =  WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT);
 	union geo_tx_power_profiles_cmd cmd;
 	u16 len;
+	int ret;
 
 	cmd.geo_cmd.ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_SET_TABLES);
 
-	iwl_sar_geo_init(&xvt->fwrt, cmd.geo_cmd.table);
+	ret = iwl_sar_geo_init(&xvt->fwrt, cmd.geo_cmd.table);
+	/*
+	 * It is a valid scenario to not support SAR, or miss wgds table,
+	 * but in that case there is no need to send the command.
+	 */
+	if (ret)
+		return 0;
 
 	cmd.geo_cmd.table_revision = cpu_to_le32(xvt->fwrt.geo_rev);