All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luca Coelho <luca@coelho.fi>
To: linux-wireless@vger.kernel.org
Cc: Luca Coelho <luciano.coelho@intel.com>
Subject: [PATCH 32/56] iwlwifi: mvm: read SAR BIOS table from ACPI
Date: Wed,  6 Jul 2016 13:40:27 +0300	[thread overview]
Message-ID: <1467801651-1816-32-git-send-email-luca@coelho.fi> (raw)
In-Reply-To: <1467801452.25088.20.camel@coelho.fi>

From: Luca Coelho <luciano.coelho@intel.com>

Read the SAR BIOS table from the ACPI and parse it into the
iwl_mvm_sar_table structure.  If the table is enabled, send it to the
firmware via REDUCE_TX_POWER_CMD.

Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
---
 drivers/net/wireless/intel/iwlwifi/mvm/fw.c | 173 ++++++++++++++++++++++++++++
 1 file changed, 173 insertions(+)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c
index 510b4c1..4db1d84 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c
@@ -65,6 +65,7 @@
  *****************************************************************************/
 #include <net/mac80211.h>
 #include <linux/netdevice.h>
+#include <linux/acpi.h>
 
 #include "iwl-trans.h"
 #include "iwl-op-mode.h"
@@ -902,6 +903,174 @@ static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
 				    sizeof(cmd), &cmd);
 }
 
+#define ACPI_WRDS_METHOD	"WRDS"
+#define ACPI_WRDS_WIFI		(0x07)
+#define ACPI_WRDS_TABLE_SIZE	10
+
+struct iwl_mvm_sar_table {
+	bool enabled;
+	u8 values[ACPI_WRDS_TABLE_SIZE];
+};
+
+#ifdef CONFIG_ACPI
+static int iwl_mvm_sar_get_wrds(struct iwl_mvm *mvm, union acpi_object *wrds,
+				struct iwl_mvm_sar_table *sar_table)
+{
+	union acpi_object *data_pkg;
+	u32 i;
+
+	/* We need at least two packages, one for the revision and one
+	 * for the data itself.  Also check that the revision is valid
+	 * (i.e. it is an integer set to 0).
+	*/
+	if (wrds->type != ACPI_TYPE_PACKAGE ||
+	    wrds->package.count < 2 ||
+	    wrds->package.elements[0].type != ACPI_TYPE_INTEGER ||
+	    wrds->package.elements[0].integer.value != 0) {
+		IWL_DEBUG_RADIO(mvm, "Unsupported wrds structure\n");
+		return -EINVAL;
+	}
+
+	/* loop through all the packages to find the one for WiFi */
+	for (i = 1; i < wrds->package.count; i++) {
+		union acpi_object *domain;
+
+		data_pkg = &wrds->package.elements[i];
+
+		/* Skip anything that is not a package with the right
+		 * amount of elements (i.e. domain_type,
+		 * enabled/disabled plus the sar table size.
+		 */
+		if (data_pkg->type != ACPI_TYPE_PACKAGE ||
+		    data_pkg->package.count != ACPI_WRDS_TABLE_SIZE + 2)
+			continue;
+
+		domain = &data_pkg->package.elements[0];
+		if (domain->type == ACPI_TYPE_INTEGER &&
+		    domain->integer.value == ACPI_WRDS_WIFI)
+			break;
+
+		data_pkg = NULL;
+	}
+
+	if (!data_pkg)
+		return -ENOENT;
+
+	if (data_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
+		return -EINVAL;
+
+	sar_table->enabled = !!(data_pkg->package.elements[1].integer.value);
+
+	for (i = 0; i < ACPI_WRDS_TABLE_SIZE; i++) {
+		union acpi_object *entry;
+
+		entry = &data_pkg->package.elements[i + 2];
+		if ((entry->type != ACPI_TYPE_INTEGER) ||
+		    (entry->integer.value > U8_MAX))
+			return -EINVAL;
+
+		sar_table->values[i] = entry->integer.value;
+	}
+
+	return 0;
+}
+
+static int iwl_mvm_sar_get_table(struct iwl_mvm *mvm,
+				 struct iwl_mvm_sar_table *sar_table)
+{
+	acpi_handle root_handle;
+	acpi_handle handle;
+	struct acpi_buffer wrds = {ACPI_ALLOCATE_BUFFER, NULL};
+	acpi_status status;
+	int ret;
+
+	root_handle = ACPI_HANDLE(mvm->dev);
+	if (!root_handle) {
+		IWL_DEBUG_RADIO(mvm,
+				"Could not retrieve root port ACPI handle\n");
+		return -ENOENT;
+	}
+
+	/* Get the method's handle */
+	status = acpi_get_handle(root_handle, (acpi_string)ACPI_WRDS_METHOD,
+				 &handle);
+	if (ACPI_FAILURE(status)) {
+		IWL_DEBUG_RADIO(mvm, "WRDS method not found\n");
+		return -ENOENT;
+	}
+
+	/* Call WRDS with no arguments */
+	status = acpi_evaluate_object(handle, NULL, NULL, &wrds);
+	if (ACPI_FAILURE(status)) {
+		IWL_DEBUG_RADIO(mvm, "WRDS invocation failed (0x%x)\n", status);
+		return -ENOENT;
+	}
+
+	ret = iwl_mvm_sar_get_wrds(mvm, wrds.pointer, sar_table);
+	kfree(wrds.pointer);
+
+	return ret;
+}
+#else /* CONFIG_ACPI */
+static int iwl_mvm_sar_get_table(struct iwl_mvm *mvm,
+				 struct iwl_mvm_sar_table *sar_table)
+{
+	return -ENOENT;
+}
+#endif /* CONFIG_ACPI */
+
+static int iwl_mvm_sar_init(struct iwl_mvm *mvm)
+{
+	struct iwl_mvm_sar_table sar_table;
+	struct iwl_dev_tx_power_cmd cmd = {
+		.v2.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS),
+	};
+	int ret, i, j, idx;
+
+	/* we can't do anything with the table if the FW doesn't support it */
+	if (!fw_has_api(&mvm->fw->ucode_capa,
+			IWL_UCODE_TLV_API_TX_POWER_CHAIN)) {
+		IWL_DEBUG_RADIO(mvm,
+				"FW doesn't support per-chain TX power settings.\n");
+		return 0;
+	}
+
+	ret = iwl_mvm_sar_get_table(mvm, &sar_table);
+	if (ret < 0) {
+		IWL_DEBUG_RADIO(mvm,
+				"SAR BIOS table invalid or unavailable. (%d)\n",
+				ret);
+		/* we don't fail if the table is not available */
+		return 0;
+	}
+
+	if (!sar_table.enabled)
+		return 0;
+
+	IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n");
+
+	BUILD_BUG_ON(IWL_NUM_CHAIN_LIMITS * IWL_NUM_SUB_BANDS !=
+		     ACPI_WRDS_TABLE_SIZE);
+
+	for (i = 0; i < IWL_NUM_CHAIN_LIMITS; i++) {
+		IWL_DEBUG_RADIO(mvm, "  Chain[%d]:\n", i);
+		for (j = 0; j < IWL_NUM_SUB_BANDS; j++) {
+			idx = (i * IWL_NUM_SUB_BANDS) + j;
+			cmd.per_chain_restriction[i][j] =
+				cpu_to_le16(sar_table.values[idx]);
+			IWL_DEBUG_RADIO(mvm, "    Band[%d] = %d * .125dBm\n",
+					j, sar_table.values[idx]);
+		}
+	}
+
+	ret = iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
+				   sizeof(cmd), &cmd);
+	if (ret)
+		IWL_ERR(mvm, "failed to set per-chain TX power: %d\n", ret);
+
+	return ret;
+}
+
 int iwl_mvm_up(struct iwl_mvm *mvm)
 {
 	int ret, i;
@@ -1077,6 +1246,10 @@ int iwl_mvm_up(struct iwl_mvm *mvm)
 	if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
 		iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
 
+	ret = iwl_mvm_sar_init(mvm);
+	if (ret)
+		goto error;
+
 	IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
 	return 0;
  error:
-- 
2.8.1


  parent reply	other threads:[~2016-07-06 10:44 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-06 10:37 pull-request: iwlwifi-next 2016-07-06 Luca Coelho
2016-07-06 10:39 ` [PATCH 01/56] iwlwifi: remove useless enum values Luca Coelho
2016-07-06 10:39 ` [PATCH 02/56] iwlwifi: change fw.mvm_fw to fw.type Luca Coelho
2016-07-06 10:39 ` [PATCH 03/56] iwlwifi: mvm: support dqa queue inactivation upon timeout Luca Coelho
2016-07-06 10:39 ` [PATCH 04/56] iwlwifi: pcie: unify restock calls on init Luca Coelho
2016-07-06 10:40 ` [PATCH 05/56] iwlwifi: mvm: fix possible division by zero Luca Coelho
2016-07-06 10:40 ` [PATCH 06/56] iwlwifi: mvm: change scan timeout to a delayed work Luca Coelho
2016-07-06 10:40 ` [PATCH 07/56] iwlwifi: mvm: remove an unused variable Luca Coelho
2016-07-06 10:40 ` [PATCH 08/56] iwlwifi: mvm: silence uninitialized variable warning Luca Coelho
2016-07-06 10:40 ` [PATCH 09/56] iwlwifi: mvm: support dqa queue sharing Luca Coelho
2016-07-06 10:40 ` [PATCH 10/56] iwlwifi: mvm: set sta_id in SCD_QUEUE_CONFIG cmd Luca Coelho
2016-07-06 10:40 ` [PATCH 11/56] iwlwifi: mvm: update aux queue in dqa mode Luca Coelho
2016-07-06 10:40 ` [PATCH 12/56] iwlwifi: mvm: support dqa-enable hcmd Luca Coelho
2016-07-06 10:40 ` [PATCH 13/56] iwlwifi: add new 8260 PCI IDs Luca Coelho
2016-07-06 10:40 ` [PATCH 14/56] iwlwifi: add new 8265 Luca Coelho
2016-07-06 10:40 ` [PATCH 15/56] iwlwifi: mvm: remove unnecessary device conversion when reading the MCC Luca Coelho
2016-07-06 10:40 ` [PATCH 16/56] iwlwifi: pcie: poll RFH for RX DMA stop Luca Coelho
2016-07-06 10:40 ` [PATCH 17/56] iwlwifi: mvm: Do not open aggregations for null data packets Luca Coelho
2016-07-06 10:40 ` [PATCH 18/56] iwlwifi: mvm: fix RX mpdu status enum Luca Coelho
2016-07-06 10:40 ` [PATCH 19/56] iwlwifi: mvm: rs: add rate scaling support for 160MHz channels Luca Coelho
2016-07-06 10:40 ` [PATCH 20/56] iwlwifi: mvm: avoid harmless -Wmaybe-uninialized warning Luca Coelho
2016-07-06 10:40 ` [PATCH 21/56] iwlwifi: mvm: fix txq aggregation bug Luca Coelho
2016-07-06 10:40 ` [PATCH 22/56] iwlwifi: dvm: Remove unused array 'iwlagn_loose_lookup' Luca Coelho
2016-07-06 10:40 ` [PATCH 23/56] iwlwifi: add dump of RFH Luca Coelho
2016-07-06 10:40 ` [PATCH 24/56] iwlwifi: Reserve iwl_fw_error_dump_type enum Luca Coelho
2016-07-06 10:40 ` [PATCH 25/56] iwlwifi: mvm: add support for GCMP encryption Luca Coelho
2016-07-06 10:40 ` [PATCH 26/56] iwlwifi: mvm: support new statistics notification Luca Coelho
2016-07-06 10:40 ` [PATCH 27/56] iwlwifi: Add a000 HW family support Luca Coelho
2016-07-06 10:40 ` [PATCH 28/56] iwlwifi: pcie: enable interrupts before releasing the NIC's CPU Luca Coelho
2016-07-06 10:40 ` [PATCH 29/56] iwlmvm: mvm: set correct state in smart-fifo configuration Luca Coelho
2016-07-06 10:40 ` [PATCH 30/56] iwlwifi: mvm: checksum IPv6 fragmented packet Luca Coelho
2016-07-06 10:40 ` [PATCH 31/56] iwlwifi: mvm: cleanup the coex code Luca Coelho
2016-07-06 10:40 ` Luca Coelho [this message]
2016-07-06 10:40 ` [PATCH 33/56] iwlwifi: pcie: Enable MSI mode when using MSI interrupts Luca Coelho
2016-07-06 10:40 ` [PATCH 34/56] iwlwifi: pcie: fix access to scratch buffer Luca Coelho
2016-07-06 10:40 ` [PATCH 35/56] iwlwifi: mvm: write the correct internal TXF index Luca Coelho
2016-07-06 10:40 ` [PATCH 36/56] iwlwifi: mvm: fix coex related comments Luca Coelho
2016-07-06 10:40 ` [PATCH 37/56] iwlwifi: mvm: fix the channel inhibition table for Channel 14 Luca Coelho
2016-07-06 10:40 ` [PATCH 38/56] iwlwifi: remove iwl_ht_params.smps_mode Luca Coelho
2016-07-06 10:40 ` [PATCH 39/56] iwlwifi: mvm: unmap the paging memory before freeing it Luca Coelho
2016-07-06 10:40 ` [PATCH 40/56] iwlwifi: pcie: don't use vid 0 Luca Coelho
2016-07-06 10:40 ` [PATCH 41/56] iwlwifi: mvm: support tdls in dqa mode Luca Coelho
2016-07-06 10:40 ` [PATCH 42/56] iwlwifi: mvm: support dqa-mode scd queue redirection Luca Coelho
2016-07-06 10:40 ` [PATCH 43/56] iwlwifi: mvm: add RX aggregation prints Luca Coelho
2016-07-06 10:40 ` [PATCH 44/56] iwlwifi: mvm: free RX reorder buffer on restart Luca Coelho
2016-07-06 10:40 ` [PATCH 45/56] iwlwifi: store cipher scheme independent of mac80211 Luca Coelho
2016-07-06 10:40 ` [PATCH 46/56] iwlwifi: tracing: decouple from mac80211 Luca Coelho
2016-07-06 10:40 ` [PATCH 47/56] iwlwifi: decouple PCIe transport " Luca Coelho
2016-07-06 10:40 ` [PATCH 48/56] iwlwifi: pcie: fix a race in firmware loading flow Luca Coelho
2016-07-06 10:40 ` [PATCH 49/56] iwlwifi: pcie: track rxb status Luca Coelho
2016-07-06 10:40 ` [PATCH 50/56] iwlwifi: pcie: generalize and increase the size of scratchbuf Luca Coelho
2016-07-06 10:40 ` [PATCH 51/56] iwlwifi: centralize 64 bit HW registers write Luca Coelho
2016-07-06 10:40 ` [PATCH 52/56] iwlwifi: pcie: initialize a000 device's TFD table Luca Coelho
2016-07-06 10:40 ` [PATCH 53/56] iwlwifi: pcie: load FW chunk for a000 devices Luca Coelho
2016-07-06 10:40 ` [PATCH 54/56] iwlwifi: mvm: support v4 of the TX power command Luca Coelho
2016-07-06 10:40 ` [PATCH 55/56] iwlwifi: pcie: centralize SCD status logging Luca Coelho
2016-07-06 10:40 ` [PATCH 56/56] iwlwifi: move iwl_drv to be shared across transports Luca Coelho
2016-07-08  9:21 ` pull-request: iwlwifi-next 2016-07-06 Kalle Valo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1467801651-1816-32-git-send-email-luca@coelho.fi \
    --to=luca@coelho.fi \
    --cc=linux-wireless@vger.kernel.org \
    --cc=luciano.coelho@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.