1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2017 Intel Deutschland GmbH
4 * Copyright (C) 2019-2021 Intel Corporation
6 #include <linux/uuid.h>
10 #include "fw/runtime.h"
12 const guid_t iwl_guid = GUID_INIT(0xF21202BF, 0x8F78, 0x4DC6,
13 0xA5, 0xB3, 0x1F, 0x73,
14 0x8E, 0x28, 0x5A, 0xDE);
15 IWL_EXPORT_SYMBOL(iwl_guid);
17 const guid_t iwl_rfi_guid = GUID_INIT(0x7266172C, 0x220B, 0x4B29,
18 0x81, 0x4F, 0x75, 0xE4,
19 0xDD, 0x26, 0xB5, 0xFD);
20 IWL_EXPORT_SYMBOL(iwl_rfi_guid);
22 static int iwl_acpi_get_handle(struct device *dev, acpi_string method,
23 acpi_handle *ret_handle)
25 acpi_handle root_handle;
28 root_handle = ACPI_HANDLE(dev);
30 IWL_DEBUG_DEV_RADIO(dev,
31 "ACPI: Could not retrieve root port handle\n");
35 status = acpi_get_handle(root_handle, method, ret_handle);
36 if (ACPI_FAILURE(status)) {
37 IWL_DEBUG_DEV_RADIO(dev,
38 "ACPI: %s method not found\n", method);
44 void *iwl_acpi_get_object(struct device *dev, acpi_string method)
46 struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL};
51 ret = iwl_acpi_get_handle(dev, method, &handle);
53 return ERR_PTR(-ENOENT);
55 /* Call the method with no arguments */
56 status = acpi_evaluate_object(handle, NULL, NULL, &buf);
57 if (ACPI_FAILURE(status)) {
58 IWL_DEBUG_DEV_RADIO(dev,
59 "ACPI: %s method invocation failed (status: 0x%x)\n",
61 return ERR_PTR(-ENOENT);
65 IWL_EXPORT_SYMBOL(iwl_acpi_get_object);
68 * Generic function for evaluating a method defined in the device specific
69 * method (DSM) interface. The returned acpi object must be freed by calling
72 static void *iwl_acpi_get_dsm_object(struct device *dev, int rev, int func,
73 union acpi_object *args,
76 union acpi_object *obj;
78 obj = acpi_evaluate_dsm(ACPI_HANDLE(dev), guid, rev, func,
81 IWL_DEBUG_DEV_RADIO(dev,
82 "ACPI: DSM method invocation failed (rev: %d, func:%d)\n",
84 return ERR_PTR(-ENOENT);
90 * Generic function to evaluate a DSM with no arguments
91 * and an integer return value,
92 * (as an integer object or inside a buffer object),
93 * verify and assign the value in the "value" parameter.
94 * return 0 in success and the appropriate errno otherwise.
96 static int iwl_acpi_get_dsm_integer(struct device *dev, int rev, int func,
97 const guid_t *guid, u64 *value,
100 union acpi_object *obj;
103 obj = iwl_acpi_get_dsm_object(dev, rev, func, NULL, guid);
105 IWL_DEBUG_DEV_RADIO(dev,
106 "Failed to get DSM object. func= %d\n",
111 if (obj->type == ACPI_TYPE_INTEGER) {
112 *value = obj->integer.value;
113 } else if (obj->type == ACPI_TYPE_BUFFER) {
116 if (WARN_ON_ONCE(expected_size > sizeof(le_value)))
119 /* if the buffer size doesn't match the expected size */
120 if (obj->buffer.length != expected_size)
121 IWL_DEBUG_DEV_RADIO(dev,
122 "ACPI: DSM invalid buffer size, padding or truncating (%d)\n",
125 /* assuming LE from Intel BIOS spec */
126 memcpy(&le_value, obj->buffer.pointer,
127 min_t(size_t, expected_size, (size_t)obj->buffer.length));
128 *value = le64_to_cpu(le_value);
130 IWL_DEBUG_DEV_RADIO(dev,
131 "ACPI: DSM method did not return a valid object, type=%d\n",
137 IWL_DEBUG_DEV_RADIO(dev,
138 "ACPI: DSM method evaluated: func=%d, ret=%d\n",
146 * Evaluate a DSM with no arguments and a u8 return value,
148 int iwl_acpi_get_dsm_u8(struct device *dev, int rev, int func,
149 const guid_t *guid, u8 *value)
154 ret = iwl_acpi_get_dsm_integer(dev, rev, func,
155 guid, &val, sizeof(u8));
160 /* cast val (u64) to be u8 */
164 IWL_EXPORT_SYMBOL(iwl_acpi_get_dsm_u8);
167 * Evaluate a DSM with no arguments and a u32 return value,
169 int iwl_acpi_get_dsm_u32(struct device *dev, int rev, int func,
170 const guid_t *guid, u32 *value)
175 ret = iwl_acpi_get_dsm_integer(dev, rev, func,
176 guid, &val, sizeof(u32));
181 /* cast val (u64) to be u32 */
185 IWL_EXPORT_SYMBOL(iwl_acpi_get_dsm_u32);
187 union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
188 union acpi_object *data,
189 int data_size, int *tbl_rev)
192 union acpi_object *wifi_pkg;
195 * We need at least one entry in the wifi package that
196 * describes the domain, and one more entry, otherwise there's
197 * no point in reading it.
199 if (WARN_ON_ONCE(data_size < 2))
200 return ERR_PTR(-EINVAL);
203 * We need at least two packages, one for the revision and one
204 * for the data itself. Also check that the revision is valid
205 * (i.e. it is an integer (each caller has to check by itself
206 * if the returned revision is supported)).
208 if (data->type != ACPI_TYPE_PACKAGE ||
209 data->package.count < 2 ||
210 data->package.elements[0].type != ACPI_TYPE_INTEGER) {
211 IWL_DEBUG_DEV_RADIO(dev, "Invalid packages structure\n");
212 return ERR_PTR(-EINVAL);
215 *tbl_rev = data->package.elements[0].integer.value;
217 /* loop through all the packages to find the one for WiFi */
218 for (i = 1; i < data->package.count; i++) {
219 union acpi_object *domain;
221 wifi_pkg = &data->package.elements[i];
223 /* skip entries that are not a package with the right size */
224 if (wifi_pkg->type != ACPI_TYPE_PACKAGE ||
225 wifi_pkg->package.count != data_size)
228 domain = &wifi_pkg->package.elements[0];
229 if (domain->type == ACPI_TYPE_INTEGER &&
230 domain->integer.value == ACPI_WIFI_DOMAIN)
234 return ERR_PTR(-ENOENT);
239 IWL_EXPORT_SYMBOL(iwl_acpi_get_wifi_pkg);
241 int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt,
242 __le32 *block_list_array,
243 int *block_list_size)
245 union acpi_object *wifi_pkg, *data;
249 data = iwl_acpi_get_object(fwrt->dev, ACPI_WTAS_METHOD);
251 return PTR_ERR(data);
253 wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
254 ACPI_WTAS_WIFI_DATA_SIZE,
256 if (IS_ERR(wifi_pkg)) {
257 ret = PTR_ERR(wifi_pkg);
261 if (wifi_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
267 enabled = !!wifi_pkg->package.elements[0].integer.value;
270 *block_list_size = -1;
271 IWL_DEBUG_RADIO(fwrt, "TAS not enabled\n");
276 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
277 wifi_pkg->package.elements[1].integer.value >
278 APCI_WTAS_BLACK_LIST_MAX) {
279 IWL_DEBUG_RADIO(fwrt, "TAS invalid array size %llu\n",
280 wifi_pkg->package.elements[1].integer.value);
284 *block_list_size = wifi_pkg->package.elements[1].integer.value;
286 IWL_DEBUG_RADIO(fwrt, "TAS array size %d\n", *block_list_size);
287 if (*block_list_size > APCI_WTAS_BLACK_LIST_MAX) {
288 IWL_DEBUG_RADIO(fwrt, "TAS invalid array size value %u\n",
294 for (i = 0; i < *block_list_size; i++) {
297 if (wifi_pkg->package.elements[2 + i].type !=
299 IWL_DEBUG_RADIO(fwrt,
300 "TAS invalid array elem %d\n", 2 + i);
305 country = wifi_pkg->package.elements[2 + i].integer.value;
306 block_list_array[i] = cpu_to_le32(country);
307 IWL_DEBUG_RADIO(fwrt, "TAS block list country %d\n", country);
315 IWL_EXPORT_SYMBOL(iwl_acpi_get_tas);
317 int iwl_acpi_get_mcc(struct device *dev, char *mcc)
319 union acpi_object *wifi_pkg, *data;
323 data = iwl_acpi_get_object(dev, ACPI_WRDD_METHOD);
325 return PTR_ERR(data);
327 wifi_pkg = iwl_acpi_get_wifi_pkg(dev, data, ACPI_WRDD_WIFI_DATA_SIZE,
329 if (IS_ERR(wifi_pkg)) {
330 ret = PTR_ERR(wifi_pkg);
334 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
340 mcc_val = wifi_pkg->package.elements[1].integer.value;
342 mcc[0] = (mcc_val >> 8) & 0xff;
343 mcc[1] = mcc_val & 0xff;
351 IWL_EXPORT_SYMBOL(iwl_acpi_get_mcc);
353 u64 iwl_acpi_get_pwr_limit(struct device *dev)
355 union acpi_object *data, *wifi_pkg;
359 data = iwl_acpi_get_object(dev, ACPI_SPLC_METHOD);
365 wifi_pkg = iwl_acpi_get_wifi_pkg(dev, data,
366 ACPI_SPLC_WIFI_DATA_SIZE, &tbl_rev);
367 if (IS_ERR(wifi_pkg) || tbl_rev != 0 ||
368 wifi_pkg->package.elements[1].integer.value != ACPI_TYPE_INTEGER) {
373 dflt_pwr_limit = wifi_pkg->package.elements[1].integer.value;
377 return dflt_pwr_limit;
379 IWL_EXPORT_SYMBOL(iwl_acpi_get_pwr_limit);
381 int iwl_acpi_get_eckv(struct device *dev, u32 *extl_clk)
383 union acpi_object *wifi_pkg, *data;
386 data = iwl_acpi_get_object(dev, ACPI_ECKV_METHOD);
388 return PTR_ERR(data);
390 wifi_pkg = iwl_acpi_get_wifi_pkg(dev, data, ACPI_ECKV_WIFI_DATA_SIZE,
392 if (IS_ERR(wifi_pkg)) {
393 ret = PTR_ERR(wifi_pkg);
397 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
403 *extl_clk = wifi_pkg->package.elements[1].integer.value;
411 IWL_EXPORT_SYMBOL(iwl_acpi_get_eckv);
413 static int iwl_sar_set_profile(union acpi_object *table,
414 struct iwl_sar_profile *profile,
419 profile->enabled = enabled;
421 for (i = 0; i < ACPI_SAR_TABLE_SIZE; i++) {
422 if (table[i].type != ACPI_TYPE_INTEGER ||
423 table[i].integer.value > U8_MAX)
426 profile->table[i] = table[i].integer.value;
432 static int iwl_sar_fill_table(struct iwl_fw_runtime *fwrt,
433 __le16 *per_chain, u32 n_subbands,
434 int prof_a, int prof_b)
436 int profs[ACPI_SAR_NUM_CHAIN_LIMITS] = { prof_a, prof_b };
439 for (i = 0; i < ACPI_SAR_NUM_CHAIN_LIMITS; i++) {
440 struct iwl_sar_profile *prof;
442 /* don't allow SAR to be disabled (profile 0 means disable) */
446 /* we are off by one, so allow up to ACPI_SAR_PROFILE_NUM */
447 if (profs[i] > ACPI_SAR_PROFILE_NUM)
450 /* profiles go from 1 to 4, so decrement to access the array */
451 prof = &fwrt->sar_profiles[profs[i] - 1];
453 /* if the profile is disabled, do nothing */
454 if (!prof->enabled) {
455 IWL_DEBUG_RADIO(fwrt, "SAR profile %d is disabled.\n",
458 * if one of the profiles is disabled, we
459 * ignore all of them and return 1 to
460 * differentiate disabled from other failures.
466 "SAR EWRD: chain %d profile index %d\n",
468 IWL_DEBUG_RADIO(fwrt, " Chain[%d]:\n", i);
469 for (j = 0; j < n_subbands; j++) {
470 idx = i * ACPI_SAR_NUM_SUB_BANDS + j;
471 per_chain[i * n_subbands + j] =
472 cpu_to_le16(prof->table[idx]);
473 IWL_DEBUG_RADIO(fwrt, " Band[%d] = %d * .125dBm\n",
474 j, prof->table[idx]);
481 int iwl_sar_select_profile(struct iwl_fw_runtime *fwrt,
482 __le16 *per_chain, u32 n_tables, u32 n_subbands,
483 int prof_a, int prof_b)
487 for (i = 0; i < n_tables; i++) {
488 ret = iwl_sar_fill_table(fwrt,
489 &per_chain[i * n_subbands * ACPI_SAR_NUM_CHAIN_LIMITS],
490 n_subbands, prof_a, prof_b);
497 IWL_EXPORT_SYMBOL(iwl_sar_select_profile);
499 int iwl_sar_get_wrds_table(struct iwl_fw_runtime *fwrt)
501 union acpi_object *wifi_pkg, *table, *data;
505 data = iwl_acpi_get_object(fwrt->dev, ACPI_WRDS_METHOD);
507 return PTR_ERR(data);
509 wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
510 ACPI_WRDS_WIFI_DATA_SIZE, &tbl_rev);
511 if (IS_ERR(wifi_pkg)) {
512 ret = PTR_ERR(wifi_pkg);
521 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) {
526 enabled = !!(wifi_pkg->package.elements[1].integer.value);
528 /* position of the actual table */
529 table = &wifi_pkg->package.elements[2];
531 /* The profile from WRDS is officially profile 1, but goes
532 * into sar_profiles[0] (because we don't have a profile 0).
534 ret = iwl_sar_set_profile(table, &fwrt->sar_profiles[0], enabled);
539 IWL_EXPORT_SYMBOL(iwl_sar_get_wrds_table);
541 int iwl_sar_get_ewrd_table(struct iwl_fw_runtime *fwrt)
543 union acpi_object *wifi_pkg, *data;
545 int i, n_profiles, tbl_rev, pos;
548 data = iwl_acpi_get_object(fwrt->dev, ACPI_EWRD_METHOD);
550 return PTR_ERR(data);
552 wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
553 ACPI_EWRD_WIFI_DATA_SIZE, &tbl_rev);
554 if (IS_ERR(wifi_pkg)) {
555 ret = PTR_ERR(wifi_pkg);
564 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
565 wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER) {
570 enabled = !!(wifi_pkg->package.elements[1].integer.value);
571 n_profiles = wifi_pkg->package.elements[2].integer.value;
574 * Check the validity of n_profiles. The EWRD profiles start
575 * from index 1, so the maximum value allowed here is
576 * ACPI_SAR_PROFILES_NUM - 1.
578 if (n_profiles <= 0 || n_profiles >= ACPI_SAR_PROFILE_NUM) {
583 /* the tables start at element 3 */
586 for (i = 0; i < n_profiles; i++) {
587 /* The EWRD profiles officially go from 2 to 4, but we
588 * save them in sar_profiles[1-3] (because we don't
589 * have profile 0). So in the array we start from 1.
591 ret = iwl_sar_set_profile(&wifi_pkg->package.elements[pos],
592 &fwrt->sar_profiles[i + 1],
597 /* go to the next table */
598 pos += ACPI_SAR_TABLE_SIZE;
605 IWL_EXPORT_SYMBOL(iwl_sar_get_ewrd_table);
607 int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt)
609 union acpi_object *wifi_pkg, *data;
610 int i, j, ret, tbl_rev;
613 data = iwl_acpi_get_object(fwrt->dev, ACPI_WGDS_METHOD);
615 return PTR_ERR(data);
617 wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
618 ACPI_WGDS_WIFI_DATA_SIZE, &tbl_rev);
620 if (IS_ERR(wifi_pkg)) {
621 ret = PTR_ERR(wifi_pkg);
630 fwrt->geo_rev = tbl_rev;
631 for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
632 for (j = 0; j < ACPI_GEO_TABLE_SIZE; j++) {
633 union acpi_object *entry;
635 entry = &wifi_pkg->package.elements[idx++];
636 if (entry->type != ACPI_TYPE_INTEGER ||
637 entry->integer.value > U8_MAX) {
642 fwrt->geo_profiles[i].values[j] = entry->integer.value;
650 IWL_EXPORT_SYMBOL(iwl_sar_get_wgds_table);
652 bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt)
655 * The GEO_TX_POWER_LIMIT command is not supported on earlier
656 * firmware versions. Unfortunately, we don't have a TLV API
657 * flag to rely on, so rely on the major version which is in
658 * the first byte of ucode_ver. This was implemented
659 * initially on version 38 and then backported to 17. It was
660 * also backported to 29, but only for 7265D devices. The
661 * intention was to have it in 36 as well, but not all 8000
662 * family got this feature enabled. The 8000 family is the
663 * only one using version 36, so skip this version entirely.
665 return IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) >= 38 ||
666 IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) == 17 ||
667 (IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) == 29 &&
668 ((fwrt->trans->hw_rev & CSR_HW_REV_TYPE_MSK) ==
669 CSR_HW_REV_TYPE_7265D));
671 IWL_EXPORT_SYMBOL(iwl_sar_geo_support);
673 int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
674 struct iwl_per_chain_offset *table, u32 n_bands)
678 if (!iwl_sar_geo_support(fwrt))
681 ret = iwl_sar_get_wgds_table(fwrt);
683 IWL_DEBUG_RADIO(fwrt,
684 "Geo SAR BIOS table invalid or unavailable. (%d)\n",
686 /* we don't fail if the table is not available */
690 for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
691 for (j = 0; j < n_bands; j++) {
692 struct iwl_per_chain_offset *chain =
693 &table[i * n_bands + j];
696 if (j * ACPI_GEO_PER_CHAIN_SIZE >=
697 ARRAY_SIZE(fwrt->geo_profiles[0].values))
699 * Currently we only store lb an hb values, and
700 * don't have any special ones for uhb. So leave
701 * those empty for the time being
705 value = &fwrt->geo_profiles[i].values[j *
706 ACPI_GEO_PER_CHAIN_SIZE];
707 chain->max_tx_power = cpu_to_le16(value[0]);
708 chain->chain_a = value[1];
709 chain->chain_b = value[2];
710 IWL_DEBUG_RADIO(fwrt,
711 "SAR geographic profile[%d] Band[%d]: chain A = %d chain B = %d max_tx_power = %d\n",
712 i, j, value[1], value[2], value[0]);
718 IWL_EXPORT_SYMBOL(iwl_sar_geo_init);
720 __le32 iwl_acpi_get_lari_config_bitmap(struct iwl_fw_runtime *fwrt)
724 __le32 config_bitmap = 0;
727 ** Evaluate func 'DSM_FUNC_ENABLE_INDONESIA_5G2'
729 ret = iwl_acpi_get_dsm_u8(fwrt->dev, 0,
730 DSM_FUNC_ENABLE_INDONESIA_5G2,
733 if (!ret && value == DSM_VALUE_INDONESIA_ENABLE)
735 cpu_to_le32(LARI_CONFIG_ENABLE_5G2_IN_INDONESIA_MSK);
738 ** Evaluate func 'DSM_FUNC_DISABLE_SRD'
740 ret = iwl_acpi_get_dsm_u8(fwrt->dev, 0,
741 DSM_FUNC_DISABLE_SRD,
744 if (value == DSM_VALUE_SRD_PASSIVE)
746 cpu_to_le32(LARI_CONFIG_CHANGE_ETSI_TO_PASSIVE_MSK);
747 else if (value == DSM_VALUE_SRD_DISABLE)
749 cpu_to_le32(LARI_CONFIG_CHANGE_ETSI_TO_DISABLED_MSK);
752 return config_bitmap;
754 IWL_EXPORT_SYMBOL(iwl_acpi_get_lari_config_bitmap);