1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2017 Intel Deutschland GmbH
4 * Copyright (C) 2019-2020 Intel Corporation
6 #include <linux/uuid.h>
10 #include "fw/runtime.h"
12 static const guid_t intel_wifi_guid = GUID_INIT(0xF21202BF, 0x8F78, 0x4DC6,
13 0xA5, 0xB3, 0x1F, 0x73,
14 0x8E, 0x28, 0x5A, 0xDE);
16 static int iwl_acpi_get_handle(struct device *dev, acpi_string method,
17 acpi_handle *ret_handle)
19 acpi_handle root_handle;
22 root_handle = ACPI_HANDLE(dev);
24 IWL_DEBUG_DEV_RADIO(dev,
25 "ACPI: Could not retrieve root port handle\n");
29 status = acpi_get_handle(root_handle, method, ret_handle);
30 if (ACPI_FAILURE(status)) {
31 IWL_DEBUG_DEV_RADIO(dev,
32 "ACPI: %s method not found\n", method);
38 void *iwl_acpi_get_object(struct device *dev, acpi_string method)
40 struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL};
45 ret = iwl_acpi_get_handle(dev, method, &handle);
47 return ERR_PTR(-ENOENT);
49 /* Call the method with no arguments */
50 status = acpi_evaluate_object(handle, NULL, NULL, &buf);
51 if (ACPI_FAILURE(status)) {
52 IWL_DEBUG_DEV_RADIO(dev,
53 "ACPI: %s method invocation failed (status: 0x%x)\n",
55 return ERR_PTR(-ENOENT);
59 IWL_EXPORT_SYMBOL(iwl_acpi_get_object);
62 * Generic function for evaluating a method defined in the device specific
63 * method (DSM) interface. The returned acpi object must be freed by calling
66 static void *iwl_acpi_get_dsm_object(struct device *dev, int rev, int func,
67 union acpi_object *args)
69 union acpi_object *obj;
71 obj = acpi_evaluate_dsm(ACPI_HANDLE(dev), &intel_wifi_guid, rev, func,
74 IWL_DEBUG_DEV_RADIO(dev,
75 "ACPI: DSM method invocation failed (rev: %d, func:%d)\n",
77 return ERR_PTR(-ENOENT);
83 * Evaluate a DSM with no arguments and a single u8 return value (inside a
84 * buffer object), verify and return that value.
86 int iwl_acpi_get_dsm_u8(struct device *dev, int rev, int func)
88 union acpi_object *obj;
91 obj = iwl_acpi_get_dsm_object(dev, rev, func, NULL);
95 if (obj->type != ACPI_TYPE_BUFFER) {
96 IWL_DEBUG_DEV_RADIO(dev,
97 "ACPI: DSM method did not return a valid object, type=%d\n",
103 if (obj->buffer.length != sizeof(u8)) {
104 IWL_DEBUG_DEV_RADIO(dev,
105 "ACPI: DSM method returned invalid buffer, length=%d\n",
111 ret = obj->buffer.pointer[0];
112 IWL_DEBUG_DEV_RADIO(dev,
113 "ACPI: DSM method evaluated: func=%d, ret=%d\n",
119 IWL_EXPORT_SYMBOL(iwl_acpi_get_dsm_u8);
121 union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
122 union acpi_object *data,
123 int data_size, int *tbl_rev)
126 union acpi_object *wifi_pkg;
129 * We need at least one entry in the wifi package that
130 * describes the domain, and one more entry, otherwise there's
131 * no point in reading it.
133 if (WARN_ON_ONCE(data_size < 2))
134 return ERR_PTR(-EINVAL);
137 * We need at least two packages, one for the revision and one
138 * for the data itself. Also check that the revision is valid
139 * (i.e. it is an integer smaller than 2, as we currently support only
142 if (data->type != ACPI_TYPE_PACKAGE ||
143 data->package.count < 2 ||
144 data->package.elements[0].type != ACPI_TYPE_INTEGER ||
145 data->package.elements[0].integer.value > 1) {
146 IWL_DEBUG_DEV_RADIO(dev, "Unsupported packages structure\n");
147 return ERR_PTR(-EINVAL);
150 *tbl_rev = data->package.elements[0].integer.value;
152 /* loop through all the packages to find the one for WiFi */
153 for (i = 1; i < data->package.count; i++) {
154 union acpi_object *domain;
156 wifi_pkg = &data->package.elements[i];
158 /* skip entries that are not a package with the right size */
159 if (wifi_pkg->type != ACPI_TYPE_PACKAGE ||
160 wifi_pkg->package.count != data_size)
163 domain = &wifi_pkg->package.elements[0];
164 if (domain->type == ACPI_TYPE_INTEGER &&
165 domain->integer.value == ACPI_WIFI_DOMAIN)
169 return ERR_PTR(-ENOENT);
174 IWL_EXPORT_SYMBOL(iwl_acpi_get_wifi_pkg);
176 int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt,
177 __le32 *block_list_array,
178 int *block_list_size)
180 union acpi_object *wifi_pkg, *data;
184 data = iwl_acpi_get_object(fwrt->dev, ACPI_WTAS_METHOD);
186 return PTR_ERR(data);
188 wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
189 ACPI_WTAS_WIFI_DATA_SIZE,
191 if (IS_ERR(wifi_pkg)) {
192 ret = PTR_ERR(wifi_pkg);
196 if (wifi_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
202 enabled = !!wifi_pkg->package.elements[0].integer.value;
205 *block_list_size = -1;
206 IWL_DEBUG_RADIO(fwrt, "TAS not enabled\n");
211 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
212 wifi_pkg->package.elements[1].integer.value >
213 APCI_WTAS_BLACK_LIST_MAX) {
214 IWL_DEBUG_RADIO(fwrt, "TAS invalid array size %llu\n",
215 wifi_pkg->package.elements[1].integer.value);
219 *block_list_size = wifi_pkg->package.elements[1].integer.value;
221 IWL_DEBUG_RADIO(fwrt, "TAS array size %d\n", *block_list_size);
222 if (*block_list_size > APCI_WTAS_BLACK_LIST_MAX) {
223 IWL_DEBUG_RADIO(fwrt, "TAS invalid array size value %u\n",
229 for (i = 0; i < *block_list_size; i++) {
232 if (wifi_pkg->package.elements[2 + i].type !=
234 IWL_DEBUG_RADIO(fwrt,
235 "TAS invalid array elem %d\n", 2 + i);
240 country = wifi_pkg->package.elements[2 + i].integer.value;
241 block_list_array[i] = cpu_to_le32(country);
242 IWL_DEBUG_RADIO(fwrt, "TAS block list country %d\n", country);
250 IWL_EXPORT_SYMBOL(iwl_acpi_get_tas);
252 int iwl_acpi_get_mcc(struct device *dev, char *mcc)
254 union acpi_object *wifi_pkg, *data;
258 data = iwl_acpi_get_object(dev, ACPI_WRDD_METHOD);
260 return PTR_ERR(data);
262 wifi_pkg = iwl_acpi_get_wifi_pkg(dev, data, ACPI_WRDD_WIFI_DATA_SIZE,
264 if (IS_ERR(wifi_pkg)) {
265 ret = PTR_ERR(wifi_pkg);
269 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
275 mcc_val = wifi_pkg->package.elements[1].integer.value;
277 mcc[0] = (mcc_val >> 8) & 0xff;
278 mcc[1] = mcc_val & 0xff;
286 IWL_EXPORT_SYMBOL(iwl_acpi_get_mcc);
288 u64 iwl_acpi_get_pwr_limit(struct device *dev)
290 union acpi_object *data, *wifi_pkg;
294 data = iwl_acpi_get_object(dev, ACPI_SPLC_METHOD);
300 wifi_pkg = iwl_acpi_get_wifi_pkg(dev, data,
301 ACPI_SPLC_WIFI_DATA_SIZE, &tbl_rev);
302 if (IS_ERR(wifi_pkg) || tbl_rev != 0 ||
303 wifi_pkg->package.elements[1].integer.value != ACPI_TYPE_INTEGER) {
308 dflt_pwr_limit = wifi_pkg->package.elements[1].integer.value;
312 return dflt_pwr_limit;
314 IWL_EXPORT_SYMBOL(iwl_acpi_get_pwr_limit);
316 int iwl_acpi_get_eckv(struct device *dev, u32 *extl_clk)
318 union acpi_object *wifi_pkg, *data;
321 data = iwl_acpi_get_object(dev, ACPI_ECKV_METHOD);
323 return PTR_ERR(data);
325 wifi_pkg = iwl_acpi_get_wifi_pkg(dev, data, ACPI_ECKV_WIFI_DATA_SIZE,
327 if (IS_ERR(wifi_pkg)) {
328 ret = PTR_ERR(wifi_pkg);
332 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
338 *extl_clk = wifi_pkg->package.elements[1].integer.value;
346 IWL_EXPORT_SYMBOL(iwl_acpi_get_eckv);
348 static int iwl_sar_set_profile(union acpi_object *table,
349 struct iwl_sar_profile *profile,
354 profile->enabled = enabled;
356 for (i = 0; i < ACPI_SAR_TABLE_SIZE; i++) {
357 if (table[i].type != ACPI_TYPE_INTEGER ||
358 table[i].integer.value > U8_MAX)
361 profile->table[i] = table[i].integer.value;
367 static int iwl_sar_fill_table(struct iwl_fw_runtime *fwrt,
368 __le16 *per_chain, u32 n_subbands,
369 int prof_a, int prof_b)
371 int profs[ACPI_SAR_NUM_CHAIN_LIMITS] = { prof_a, prof_b };
374 for (i = 0; i < ACPI_SAR_NUM_CHAIN_LIMITS; i++) {
375 struct iwl_sar_profile *prof;
377 /* don't allow SAR to be disabled (profile 0 means disable) */
381 /* we are off by one, so allow up to ACPI_SAR_PROFILE_NUM */
382 if (profs[i] > ACPI_SAR_PROFILE_NUM)
385 /* profiles go from 1 to 4, so decrement to access the array */
386 prof = &fwrt->sar_profiles[profs[i] - 1];
388 /* if the profile is disabled, do nothing */
389 if (!prof->enabled) {
390 IWL_DEBUG_RADIO(fwrt, "SAR profile %d is disabled.\n",
393 * if one of the profiles is disabled, we
394 * ignore all of them and return 1 to
395 * differentiate disabled from other failures.
401 "SAR EWRD: chain %d profile index %d\n",
403 IWL_DEBUG_RADIO(fwrt, " Chain[%d]:\n", i);
404 for (j = 0; j < n_subbands; j++) {
405 idx = i * ACPI_SAR_NUM_SUB_BANDS + j;
406 per_chain[i * n_subbands + j] =
407 cpu_to_le16(prof->table[idx]);
408 IWL_DEBUG_RADIO(fwrt, " Band[%d] = %d * .125dBm\n",
409 j, prof->table[idx]);
416 int iwl_sar_select_profile(struct iwl_fw_runtime *fwrt,
417 __le16 *per_chain, u32 n_tables, u32 n_subbands,
418 int prof_a, int prof_b)
422 for (i = 0; i < n_tables; i++) {
423 ret = iwl_sar_fill_table(fwrt,
424 &per_chain[i * n_subbands * ACPI_SAR_NUM_CHAIN_LIMITS],
425 n_subbands, prof_a, prof_b);
432 IWL_EXPORT_SYMBOL(iwl_sar_select_profile);
434 int iwl_sar_get_wrds_table(struct iwl_fw_runtime *fwrt)
436 union acpi_object *wifi_pkg, *table, *data;
440 data = iwl_acpi_get_object(fwrt->dev, ACPI_WRDS_METHOD);
442 return PTR_ERR(data);
444 wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
445 ACPI_WRDS_WIFI_DATA_SIZE, &tbl_rev);
446 if (IS_ERR(wifi_pkg) || tbl_rev != 0) {
447 ret = PTR_ERR(wifi_pkg);
451 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) {
456 enabled = !!(wifi_pkg->package.elements[1].integer.value);
458 /* position of the actual table */
459 table = &wifi_pkg->package.elements[2];
461 /* The profile from WRDS is officially profile 1, but goes
462 * into sar_profiles[0] (because we don't have a profile 0).
464 ret = iwl_sar_set_profile(table, &fwrt->sar_profiles[0], enabled);
469 IWL_EXPORT_SYMBOL(iwl_sar_get_wrds_table);
471 int iwl_sar_get_ewrd_table(struct iwl_fw_runtime *fwrt)
473 union acpi_object *wifi_pkg, *data;
475 int i, n_profiles, tbl_rev, pos;
478 data = iwl_acpi_get_object(fwrt->dev, ACPI_EWRD_METHOD);
480 return PTR_ERR(data);
482 wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
483 ACPI_EWRD_WIFI_DATA_SIZE, &tbl_rev);
484 if (IS_ERR(wifi_pkg) || tbl_rev != 0) {
485 ret = PTR_ERR(wifi_pkg);
489 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
490 wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER) {
495 enabled = !!(wifi_pkg->package.elements[1].integer.value);
496 n_profiles = wifi_pkg->package.elements[2].integer.value;
499 * Check the validity of n_profiles. The EWRD profiles start
500 * from index 1, so the maximum value allowed here is
501 * ACPI_SAR_PROFILES_NUM - 1.
503 if (n_profiles <= 0 || n_profiles >= ACPI_SAR_PROFILE_NUM) {
508 /* the tables start at element 3 */
511 for (i = 0; i < n_profiles; i++) {
512 /* The EWRD profiles officially go from 2 to 4, but we
513 * save them in sar_profiles[1-3] (because we don't
514 * have profile 0). So in the array we start from 1.
516 ret = iwl_sar_set_profile(&wifi_pkg->package.elements[pos],
517 &fwrt->sar_profiles[i + 1],
522 /* go to the next table */
523 pos += ACPI_SAR_TABLE_SIZE;
530 IWL_EXPORT_SYMBOL(iwl_sar_get_ewrd_table);
532 int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt)
534 union acpi_object *wifi_pkg, *data;
535 int i, j, ret, tbl_rev;
538 data = iwl_acpi_get_object(fwrt->dev, ACPI_WGDS_METHOD);
540 return PTR_ERR(data);
542 wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
543 ACPI_WGDS_WIFI_DATA_SIZE, &tbl_rev);
544 if (IS_ERR(wifi_pkg) || tbl_rev > 1) {
545 ret = PTR_ERR(wifi_pkg);
549 fwrt->geo_rev = tbl_rev;
550 for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
551 for (j = 0; j < ACPI_GEO_TABLE_SIZE; j++) {
552 union acpi_object *entry;
554 entry = &wifi_pkg->package.elements[idx++];
555 if (entry->type != ACPI_TYPE_INTEGER ||
556 entry->integer.value > U8_MAX) {
561 fwrt->geo_profiles[i].values[j] = entry->integer.value;
569 IWL_EXPORT_SYMBOL(iwl_sar_get_wgds_table);
571 bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt)
574 * The GEO_TX_POWER_LIMIT command is not supported on earlier
575 * firmware versions. Unfortunately, we don't have a TLV API
576 * flag to rely on, so rely on the major version which is in
577 * the first byte of ucode_ver. This was implemented
578 * initially on version 38 and then backported to 17. It was
579 * also backported to 29, but only for 7265D devices. The
580 * intention was to have it in 36 as well, but not all 8000
581 * family got this feature enabled. The 8000 family is the
582 * only one using version 36, so skip this version entirely.
584 return IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) >= 38 ||
585 IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) == 17 ||
586 (IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) == 29 &&
587 ((fwrt->trans->hw_rev & CSR_HW_REV_TYPE_MSK) ==
588 CSR_HW_REV_TYPE_7265D));
590 IWL_EXPORT_SYMBOL(iwl_sar_geo_support);
592 int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
593 struct iwl_per_chain_offset *table, u32 n_bands)
597 if (!iwl_sar_geo_support(fwrt))
600 ret = iwl_sar_get_wgds_table(fwrt);
602 IWL_DEBUG_RADIO(fwrt,
603 "Geo SAR BIOS table invalid or unavailable. (%d)\n",
605 /* we don't fail if the table is not available */
609 for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
610 for (j = 0; j < n_bands; j++) {
611 struct iwl_per_chain_offset *chain =
612 &table[i * n_bands + j];
615 if (j * ACPI_GEO_PER_CHAIN_SIZE >=
616 ARRAY_SIZE(fwrt->geo_profiles[0].values))
618 * Currently we only store lb an hb values, and
619 * don't have any special ones for uhb. So leave
620 * those empty for the time being
624 value = &fwrt->geo_profiles[i].values[j *
625 ACPI_GEO_PER_CHAIN_SIZE];
626 chain->max_tx_power = cpu_to_le16(value[0]);
627 chain->chain_a = value[1];
628 chain->chain_b = value[2];
629 IWL_DEBUG_RADIO(fwrt,
630 "SAR geographic profile[%d] Band[%d]: chain A = %d chain B = %d max_tx_power = %d\n",
631 i, j, value[1], value[2], value[0]);
637 IWL_EXPORT_SYMBOL(iwl_sar_geo_init);