1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2017 Intel Deutschland GmbH
9 * Copyright (C) 2019 - 2020 Intel Corporation
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * The full GNU General Public License is included in this distribution
21 * in the file called COPYING.
23 * Contact Information:
24 * Intel Linux Wireless <linuxwifi@intel.com>
25 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
29 * Copyright(c) 2017 Intel Deutschland GmbH
30 * Copyright (C) 2019 - 2020 Intel Corporation
31 * All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
37 * * Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * * Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in
41 * the documentation and/or other materials provided with the
43 * * Neither the name Intel Corporation nor the names of its
44 * contributors may be used to endorse or promote products derived
45 * from this software without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
50 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
51 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
54 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
55 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
57 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 *****************************************************************************/
62 #include "iwl-debug.h"
64 #include "fw/runtime.h"
66 void *iwl_acpi_get_object(struct device *dev, acpi_string method)
68 acpi_handle root_handle;
70 struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL};
73 root_handle = ACPI_HANDLE(dev);
75 IWL_DEBUG_DEV_RADIO(dev,
76 "Could not retrieve root port ACPI handle\n");
77 return ERR_PTR(-ENOENT);
80 /* Get the method's handle */
81 status = acpi_get_handle(root_handle, method, &handle);
82 if (ACPI_FAILURE(status)) {
83 IWL_DEBUG_DEV_RADIO(dev, "%s method not found\n", method);
84 return ERR_PTR(-ENOENT);
87 /* Call the method with no arguments */
88 status = acpi_evaluate_object(handle, NULL, NULL, &buf);
89 if (ACPI_FAILURE(status)) {
90 IWL_DEBUG_DEV_RADIO(dev, "%s invocation failed (0x%x)\n",
92 return ERR_PTR(-ENOENT);
97 IWL_EXPORT_SYMBOL(iwl_acpi_get_object);
99 union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
100 union acpi_object *data,
101 int data_size, int *tbl_rev)
104 union acpi_object *wifi_pkg;
107 * We need at least one entry in the wifi package that
108 * describes the domain, and one more entry, otherwise there's
109 * no point in reading it.
111 if (WARN_ON_ONCE(data_size < 2))
112 return ERR_PTR(-EINVAL);
115 * We need at least two packages, one for the revision and one
116 * for the data itself. Also check that the revision is valid
117 * (i.e. it is an integer smaller than 2, as we currently support only
120 if (data->type != ACPI_TYPE_PACKAGE ||
121 data->package.count < 2 ||
122 data->package.elements[0].type != ACPI_TYPE_INTEGER ||
123 data->package.elements[0].integer.value > 1) {
124 IWL_DEBUG_DEV_RADIO(dev, "Unsupported packages structure\n");
125 return ERR_PTR(-EINVAL);
128 *tbl_rev = data->package.elements[0].integer.value;
130 /* loop through all the packages to find the one for WiFi */
131 for (i = 1; i < data->package.count; i++) {
132 union acpi_object *domain;
134 wifi_pkg = &data->package.elements[i];
136 /* skip entries that are not a package with the right size */
137 if (wifi_pkg->type != ACPI_TYPE_PACKAGE ||
138 wifi_pkg->package.count != data_size)
141 domain = &wifi_pkg->package.elements[0];
142 if (domain->type == ACPI_TYPE_INTEGER &&
143 domain->integer.value == ACPI_WIFI_DOMAIN)
147 return ERR_PTR(-ENOENT);
152 IWL_EXPORT_SYMBOL(iwl_acpi_get_wifi_pkg);
154 int iwl_acpi_get_mcc(struct device *dev, char *mcc)
156 union acpi_object *wifi_pkg, *data;
160 data = iwl_acpi_get_object(dev, ACPI_WRDD_METHOD);
162 return PTR_ERR(data);
164 wifi_pkg = iwl_acpi_get_wifi_pkg(dev, data, ACPI_WRDD_WIFI_DATA_SIZE,
166 if (IS_ERR(wifi_pkg)) {
167 ret = PTR_ERR(wifi_pkg);
171 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
177 mcc_val = wifi_pkg->package.elements[1].integer.value;
179 mcc[0] = (mcc_val >> 8) & 0xff;
180 mcc[1] = mcc_val & 0xff;
188 IWL_EXPORT_SYMBOL(iwl_acpi_get_mcc);
190 u64 iwl_acpi_get_pwr_limit(struct device *dev)
192 union acpi_object *data, *wifi_pkg;
196 data = iwl_acpi_get_object(dev, ACPI_SPLC_METHOD);
202 wifi_pkg = iwl_acpi_get_wifi_pkg(dev, data,
203 ACPI_SPLC_WIFI_DATA_SIZE, &tbl_rev);
204 if (IS_ERR(wifi_pkg) || tbl_rev != 0 ||
205 wifi_pkg->package.elements[1].integer.value != ACPI_TYPE_INTEGER) {
210 dflt_pwr_limit = wifi_pkg->package.elements[1].integer.value;
214 return dflt_pwr_limit;
216 IWL_EXPORT_SYMBOL(iwl_acpi_get_pwr_limit);
218 int iwl_acpi_get_eckv(struct device *dev, u32 *extl_clk)
220 union acpi_object *wifi_pkg, *data;
223 data = iwl_acpi_get_object(dev, ACPI_ECKV_METHOD);
225 return PTR_ERR(data);
227 wifi_pkg = iwl_acpi_get_wifi_pkg(dev, data, ACPI_ECKV_WIFI_DATA_SIZE,
229 if (IS_ERR(wifi_pkg)) {
230 ret = PTR_ERR(wifi_pkg);
234 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
240 *extl_clk = wifi_pkg->package.elements[1].integer.value;
248 IWL_EXPORT_SYMBOL(iwl_acpi_get_eckv);
250 int iwl_sar_set_profile(union acpi_object *table,
251 struct iwl_sar_profile *profile,
256 profile->enabled = enabled;
258 for (i = 0; i < ACPI_SAR_TABLE_SIZE; i++) {
259 if (table[i].type != ACPI_TYPE_INTEGER ||
260 table[i].integer.value > U8_MAX)
263 profile->table[i] = table[i].integer.value;
268 IWL_EXPORT_SYMBOL(iwl_sar_set_profile);
270 int iwl_sar_select_profile(struct iwl_fw_runtime *fwrt,
271 __le16 per_chain_restriction[][IWL_NUM_SUB_BANDS],
272 int prof_a, int prof_b)
275 int profs[ACPI_SAR_NUM_CHAIN_LIMITS] = { prof_a, prof_b };
277 BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS < 2);
278 BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS * ACPI_SAR_NUM_SUB_BANDS !=
279 ACPI_SAR_TABLE_SIZE);
281 for (i = 0; i < ACPI_SAR_NUM_CHAIN_LIMITS; i++) {
282 struct iwl_sar_profile *prof;
284 /* don't allow SAR to be disabled (profile 0 means disable) */
288 /* we are off by one, so allow up to ACPI_SAR_PROFILE_NUM */
289 if (profs[i] > ACPI_SAR_PROFILE_NUM)
292 /* profiles go from 1 to 4, so decrement to access the array */
293 prof = &fwrt->sar_profiles[profs[i] - 1];
295 /* if the profile is disabled, do nothing */
296 if (!prof->enabled) {
297 IWL_DEBUG_RADIO(fwrt, "SAR profile %d is disabled.\n",
300 * if one of the profiles is disabled, we
301 * ignore all of them and return 1 to
302 * differentiate disabled from other failures.
308 "SAR EWRD: chain %d profile index %d\n",
310 IWL_DEBUG_RADIO(fwrt, " Chain[%d]:\n", i);
311 for (j = 0; j < ACPI_SAR_NUM_SUB_BANDS; j++) {
312 idx = (i * ACPI_SAR_NUM_SUB_BANDS) + j;
313 per_chain_restriction[i][j] =
314 cpu_to_le16(prof->table[idx]);
315 IWL_DEBUG_RADIO(fwrt, " Band[%d] = %d * .125dBm\n",
316 j, prof->table[idx]);
322 IWL_EXPORT_SYMBOL(iwl_sar_select_profile);
324 int iwl_sar_get_wrds_table(struct iwl_fw_runtime *fwrt)
326 union acpi_object *wifi_pkg, *table, *data;
330 data = iwl_acpi_get_object(fwrt->dev, ACPI_WRDS_METHOD);
332 return PTR_ERR(data);
334 wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
335 ACPI_WRDS_WIFI_DATA_SIZE, &tbl_rev);
336 if (IS_ERR(wifi_pkg) || tbl_rev != 0) {
337 ret = PTR_ERR(wifi_pkg);
341 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) {
346 enabled = !!(wifi_pkg->package.elements[1].integer.value);
348 /* position of the actual table */
349 table = &wifi_pkg->package.elements[2];
351 /* The profile from WRDS is officially profile 1, but goes
352 * into sar_profiles[0] (because we don't have a profile 0).
354 ret = iwl_sar_set_profile(table, &fwrt->sar_profiles[0], enabled);
359 IWL_EXPORT_SYMBOL(iwl_sar_get_wrds_table);
361 int iwl_sar_get_ewrd_table(struct iwl_fw_runtime *fwrt)
363 union acpi_object *wifi_pkg, *data;
365 int i, n_profiles, tbl_rev, pos;
368 data = iwl_acpi_get_object(fwrt->dev, ACPI_EWRD_METHOD);
370 return PTR_ERR(data);
372 wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
373 ACPI_EWRD_WIFI_DATA_SIZE, &tbl_rev);
374 if (IS_ERR(wifi_pkg) || tbl_rev != 0) {
375 ret = PTR_ERR(wifi_pkg);
379 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
380 wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER) {
385 enabled = !!(wifi_pkg->package.elements[1].integer.value);
386 n_profiles = wifi_pkg->package.elements[2].integer.value;
389 * Check the validity of n_profiles. The EWRD profiles start
390 * from index 1, so the maximum value allowed here is
391 * ACPI_SAR_PROFILES_NUM - 1.
393 if (n_profiles <= 0 || n_profiles >= ACPI_SAR_PROFILE_NUM) {
398 /* the tables start at element 3 */
401 for (i = 0; i < n_profiles; i++) {
402 /* The EWRD profiles officially go from 2 to 4, but we
403 * save them in sar_profiles[1-3] (because we don't
404 * have profile 0). So in the array we start from 1.
406 ret = iwl_sar_set_profile(&wifi_pkg->package.elements[pos],
407 &fwrt->sar_profiles[i + 1],
412 /* go to the next table */
413 pos += ACPI_SAR_TABLE_SIZE;
420 IWL_EXPORT_SYMBOL(iwl_sar_get_ewrd_table);
422 int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt)
424 union acpi_object *wifi_pkg, *data;
425 int i, j, ret, tbl_rev;
428 data = iwl_acpi_get_object(fwrt->dev, ACPI_WGDS_METHOD);
430 return PTR_ERR(data);
432 wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
433 ACPI_WGDS_WIFI_DATA_SIZE, &tbl_rev);
434 if (IS_ERR(wifi_pkg) || tbl_rev > 1) {
435 ret = PTR_ERR(wifi_pkg);
439 fwrt->geo_rev = tbl_rev;
440 for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
441 for (j = 0; j < ACPI_GEO_TABLE_SIZE; j++) {
442 union acpi_object *entry;
444 entry = &wifi_pkg->package.elements[idx++];
445 if (entry->type != ACPI_TYPE_INTEGER ||
446 entry->integer.value > U8_MAX) {
451 fwrt->geo_profiles[i].values[j] = entry->integer.value;
459 IWL_EXPORT_SYMBOL(iwl_sar_get_wgds_table);
461 bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt)
464 * The GEO_TX_POWER_LIMIT command is not supported on earlier
465 * firmware versions. Unfortunately, we don't have a TLV API
466 * flag to rely on, so rely on the major version which is in
467 * the first byte of ucode_ver. This was implemented
468 * initially on version 38 and then backported to 17. It was
469 * also backported to 29, but only for 7265D devices. The
470 * intention was to have it in 36 as well, but not all 8000
471 * family got this feature enabled. The 8000 family is the
472 * only one using version 36, so skip this version entirely.
474 return IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) >= 38 ||
475 IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) == 17 ||
476 (IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) == 29 &&
477 ((fwrt->trans->hw_rev & CSR_HW_REV_TYPE_MSK) ==
478 CSR_HW_REV_TYPE_7265D));
480 IWL_EXPORT_SYMBOL(iwl_sar_geo_support);
482 int iwl_validate_sar_geo_profile(struct iwl_fw_runtime *fwrt,
483 struct iwl_host_cmd *cmd)
485 struct iwl_geo_tx_power_profiles_resp *resp;
488 resp = (void *)cmd->resp_pkt->data;
489 ret = le32_to_cpu(resp->profile_idx);
490 if (WARN_ON(ret > ACPI_NUM_GEO_PROFILES)) {
492 IWL_WARN(fwrt, "Invalid geographic profile idx (%d)\n", ret);
497 IWL_EXPORT_SYMBOL(iwl_validate_sar_geo_profile);
499 int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
500 struct iwl_per_chain_offset_group *table)
504 if (!iwl_sar_geo_support(fwrt))
507 ret = iwl_sar_get_wgds_table(fwrt);
509 IWL_DEBUG_RADIO(fwrt,
510 "Geo SAR BIOS table invalid or unavailable. (%d)\n",
512 /* we don't fail if the table is not available */
516 BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES * ACPI_WGDS_NUM_BANDS *
517 ACPI_WGDS_TABLE_SIZE + 1 != ACPI_WGDS_WIFI_DATA_SIZE);
519 BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES > IWL_NUM_GEO_PROFILES);
521 for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
522 struct iwl_per_chain_offset *chain =
523 (struct iwl_per_chain_offset *)&table[i];
525 for (j = 0; j < ACPI_WGDS_NUM_BANDS; j++) {
528 value = &fwrt->geo_profiles[i].values[j *
529 ACPI_GEO_PER_CHAIN_SIZE];
530 chain[j].max_tx_power = cpu_to_le16(value[0]);
531 chain[j].chain_a = value[1];
532 chain[j].chain_b = value[2];
533 IWL_DEBUG_RADIO(fwrt,
534 "SAR geographic profile[%d] Band[%d]: chain A = %d chain B = %d max_tx_power = %d\n",
535 i, j, value[1], value[2], value[0]);
541 IWL_EXPORT_SYMBOL(iwl_sar_geo_init);