xref: /linux/drivers/net/wireless/intel/iwlwifi/fw/acpi.c (revision 7bb377107c72a40ab7505341f8626c8eb79a0cb7)
1 /******************************************************************************
2  *
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.
5  *
6  * GPL LICENSE SUMMARY
7  *
8  * Copyright(c) 2017        Intel Deutschland GmbH
9  * Copyright (C) 2019 - 2020 Intel Corporation
10  *
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.
14  *
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.
19  *
20  * The full GNU General Public License is included in this distribution
21  * in the file called COPYING.
22  *
23  * Contact Information:
24  *  Intel Linux Wireless <linuxwifi@intel.com>
25  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26  *
27  * BSD LICENSE
28  *
29  * Copyright(c) 2017        Intel Deutschland GmbH
30  * Copyright (C) 2019 - 2020 Intel Corporation
31  * All rights reserved.
32  *
33  * Redistribution and use in source and binary forms, with or without
34  * modification, are permitted provided that the following conditions
35  * are met:
36  *
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
42  *    distribution.
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.
46  *
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.
58  *
59  *****************************************************************************/
60 
61 #include "iwl-drv.h"
62 #include "iwl-debug.h"
63 #include "acpi.h"
64 #include "fw/runtime.h"
65 
66 void *iwl_acpi_get_object(struct device *dev, acpi_string method)
67 {
68 	acpi_handle root_handle;
69 	acpi_handle handle;
70 	struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL};
71 	acpi_status status;
72 
73 	root_handle = ACPI_HANDLE(dev);
74 	if (!root_handle) {
75 		IWL_DEBUG_DEV_RADIO(dev,
76 				    "Could not retrieve root port ACPI handle\n");
77 		return ERR_PTR(-ENOENT);
78 	}
79 
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);
85 	}
86 
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",
91 				    method, status);
92 		return ERR_PTR(-ENOENT);
93 	}
94 
95 	return buf.pointer;
96 }
97 IWL_EXPORT_SYMBOL(iwl_acpi_get_object);
98 
99 union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
100 					 union acpi_object *data,
101 					 int data_size, int *tbl_rev)
102 {
103 	int i;
104 	union acpi_object *wifi_pkg;
105 
106 	/*
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.
110 	 */
111 	if (WARN_ON_ONCE(data_size < 2))
112 		return ERR_PTR(-EINVAL);
113 
114 	/*
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
118 	 * 2 revisions).
119 	 */
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);
126 	}
127 
128 	*tbl_rev = data->package.elements[0].integer.value;
129 
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;
133 
134 		wifi_pkg = &data->package.elements[i];
135 
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)
139 			continue;
140 
141 		domain = &wifi_pkg->package.elements[0];
142 		if (domain->type == ACPI_TYPE_INTEGER &&
143 		    domain->integer.value == ACPI_WIFI_DOMAIN)
144 			goto found;
145 	}
146 
147 	return ERR_PTR(-ENOENT);
148 
149 found:
150 	return wifi_pkg;
151 }
152 IWL_EXPORT_SYMBOL(iwl_acpi_get_wifi_pkg);
153 
154 int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt,
155 		     __le32 *black_list_array,
156 		     int *black_list_size)
157 {
158 	union acpi_object *wifi_pkg, *data;
159 	int ret, tbl_rev, i;
160 	bool enabled;
161 
162 	data = iwl_acpi_get_object(fwrt->dev, ACPI_WTAS_METHOD);
163 	if (IS_ERR(data))
164 		return PTR_ERR(data);
165 
166 	wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
167 					 ACPI_WTAS_WIFI_DATA_SIZE,
168 					 &tbl_rev);
169 	if (IS_ERR(wifi_pkg)) {
170 		ret = PTR_ERR(wifi_pkg);
171 		goto out_free;
172 	}
173 
174 	if (wifi_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
175 	    tbl_rev != 0) {
176 		ret = -EINVAL;
177 		goto out_free;
178 	}
179 
180 	enabled = !!wifi_pkg->package.elements[0].integer.value;
181 
182 	if (!enabled) {
183 		*black_list_size = -1;
184 		IWL_DEBUG_RADIO(fwrt, "TAS not enabled\n");
185 		ret = 0;
186 		goto out_free;
187 	}
188 
189 	if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
190 	    wifi_pkg->package.elements[1].integer.value >
191 	    APCI_WTAS_BLACK_LIST_MAX) {
192 		IWL_DEBUG_RADIO(fwrt, "TAS invalid array size %llu\n",
193 				wifi_pkg->package.elements[1].integer.value);
194 		ret = -EINVAL;
195 		goto out_free;
196 	}
197 	*black_list_size = wifi_pkg->package.elements[1].integer.value;
198 
199 	IWL_DEBUG_RADIO(fwrt, "TAS array size %d\n", *black_list_size);
200 	if (*black_list_size > APCI_WTAS_BLACK_LIST_MAX) {
201 		IWL_DEBUG_RADIO(fwrt, "TAS invalid array size value %u\n",
202 				*black_list_size);
203 		ret = -EINVAL;
204 		goto out_free;
205 	}
206 
207 	for (i = 0; i < *black_list_size; i++) {
208 		u32 country;
209 
210 		if (wifi_pkg->package.elements[2 + i].type !=
211 		    ACPI_TYPE_INTEGER) {
212 			IWL_DEBUG_RADIO(fwrt,
213 					"TAS invalid array elem %d\n", 2 + i);
214 			ret = -EINVAL;
215 			goto out_free;
216 		}
217 
218 		country = wifi_pkg->package.elements[2 + i].integer.value;
219 		black_list_array[i] = cpu_to_le32(country);
220 		IWL_DEBUG_RADIO(fwrt, "TAS black list country %d\n", country);
221 	}
222 
223 	ret = 0;
224 out_free:
225 	kfree(data);
226 	return ret;
227 }
228 IWL_EXPORT_SYMBOL(iwl_acpi_get_tas);
229 
230 int iwl_acpi_get_mcc(struct device *dev, char *mcc)
231 {
232 	union acpi_object *wifi_pkg, *data;
233 	u32 mcc_val;
234 	int ret, tbl_rev;
235 
236 	data = iwl_acpi_get_object(dev, ACPI_WRDD_METHOD);
237 	if (IS_ERR(data))
238 		return PTR_ERR(data);
239 
240 	wifi_pkg = iwl_acpi_get_wifi_pkg(dev, data, ACPI_WRDD_WIFI_DATA_SIZE,
241 					 &tbl_rev);
242 	if (IS_ERR(wifi_pkg)) {
243 		ret = PTR_ERR(wifi_pkg);
244 		goto out_free;
245 	}
246 
247 	if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
248 	    tbl_rev != 0) {
249 		ret = -EINVAL;
250 		goto out_free;
251 	}
252 
253 	mcc_val = wifi_pkg->package.elements[1].integer.value;
254 
255 	mcc[0] = (mcc_val >> 8) & 0xff;
256 	mcc[1] = mcc_val & 0xff;
257 	mcc[2] = '\0';
258 
259 	ret = 0;
260 out_free:
261 	kfree(data);
262 	return ret;
263 }
264 IWL_EXPORT_SYMBOL(iwl_acpi_get_mcc);
265 
266 u64 iwl_acpi_get_pwr_limit(struct device *dev)
267 {
268 	union acpi_object *data, *wifi_pkg;
269 	u64 dflt_pwr_limit;
270 	int tbl_rev;
271 
272 	data = iwl_acpi_get_object(dev, ACPI_SPLC_METHOD);
273 	if (IS_ERR(data)) {
274 		dflt_pwr_limit = 0;
275 		goto out;
276 	}
277 
278 	wifi_pkg = iwl_acpi_get_wifi_pkg(dev, data,
279 					 ACPI_SPLC_WIFI_DATA_SIZE, &tbl_rev);
280 	if (IS_ERR(wifi_pkg) || tbl_rev != 0 ||
281 	    wifi_pkg->package.elements[1].integer.value != ACPI_TYPE_INTEGER) {
282 		dflt_pwr_limit = 0;
283 		goto out_free;
284 	}
285 
286 	dflt_pwr_limit = wifi_pkg->package.elements[1].integer.value;
287 out_free:
288 	kfree(data);
289 out:
290 	return dflt_pwr_limit;
291 }
292 IWL_EXPORT_SYMBOL(iwl_acpi_get_pwr_limit);
293 
294 int iwl_acpi_get_eckv(struct device *dev, u32 *extl_clk)
295 {
296 	union acpi_object *wifi_pkg, *data;
297 	int ret, tbl_rev;
298 
299 	data = iwl_acpi_get_object(dev, ACPI_ECKV_METHOD);
300 	if (IS_ERR(data))
301 		return PTR_ERR(data);
302 
303 	wifi_pkg = iwl_acpi_get_wifi_pkg(dev, data, ACPI_ECKV_WIFI_DATA_SIZE,
304 					 &tbl_rev);
305 	if (IS_ERR(wifi_pkg)) {
306 		ret = PTR_ERR(wifi_pkg);
307 		goto out_free;
308 	}
309 
310 	if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
311 	    tbl_rev != 0) {
312 		ret = -EINVAL;
313 		goto out_free;
314 	}
315 
316 	*extl_clk = wifi_pkg->package.elements[1].integer.value;
317 
318 	ret = 0;
319 
320 out_free:
321 	kfree(data);
322 	return ret;
323 }
324 IWL_EXPORT_SYMBOL(iwl_acpi_get_eckv);
325 
326 int iwl_sar_set_profile(union acpi_object *table,
327 			struct iwl_sar_profile *profile,
328 			bool enabled)
329 {
330 	int i;
331 
332 	profile->enabled = enabled;
333 
334 	for (i = 0; i < ACPI_SAR_TABLE_SIZE; i++) {
335 		if (table[i].type != ACPI_TYPE_INTEGER ||
336 		    table[i].integer.value > U8_MAX)
337 			return -EINVAL;
338 
339 		profile->table[i] = table[i].integer.value;
340 	}
341 
342 	return 0;
343 }
344 IWL_EXPORT_SYMBOL(iwl_sar_set_profile);
345 
346 int iwl_sar_select_profile(struct iwl_fw_runtime *fwrt,
347 			   __le16 per_chain_restriction[][IWL_NUM_SUB_BANDS],
348 			   int prof_a, int prof_b)
349 {
350 	int i, j, idx;
351 	int profs[ACPI_SAR_NUM_CHAIN_LIMITS] = { prof_a, prof_b };
352 
353 	BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS < 2);
354 	BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS * ACPI_SAR_NUM_SUB_BANDS !=
355 		     ACPI_SAR_TABLE_SIZE);
356 
357 	for (i = 0; i < ACPI_SAR_NUM_CHAIN_LIMITS; i++) {
358 		struct iwl_sar_profile *prof;
359 
360 		/* don't allow SAR to be disabled (profile 0 means disable) */
361 		if (profs[i] == 0)
362 			return -EPERM;
363 
364 		/* we are off by one, so allow up to ACPI_SAR_PROFILE_NUM */
365 		if (profs[i] > ACPI_SAR_PROFILE_NUM)
366 			return -EINVAL;
367 
368 		/* profiles go from 1 to 4, so decrement to access the array */
369 		prof = &fwrt->sar_profiles[profs[i] - 1];
370 
371 		/* if the profile is disabled, do nothing */
372 		if (!prof->enabled) {
373 			IWL_DEBUG_RADIO(fwrt, "SAR profile %d is disabled.\n",
374 					profs[i]);
375 			/*
376 			 * if one of the profiles is disabled, we
377 			 * ignore all of them and return 1 to
378 			 * differentiate disabled from other failures.
379 			 */
380 			return 1;
381 		}
382 
383 		IWL_DEBUG_INFO(fwrt,
384 			       "SAR EWRD: chain %d profile index %d\n",
385 			       i, profs[i]);
386 		IWL_DEBUG_RADIO(fwrt, "  Chain[%d]:\n", i);
387 		for (j = 0; j < ACPI_SAR_NUM_SUB_BANDS; j++) {
388 			idx = (i * ACPI_SAR_NUM_SUB_BANDS) + j;
389 			per_chain_restriction[i][j] =
390 				cpu_to_le16(prof->table[idx]);
391 			IWL_DEBUG_RADIO(fwrt, "    Band[%d] = %d * .125dBm\n",
392 					j, prof->table[idx]);
393 		}
394 	}
395 
396 	return 0;
397 }
398 IWL_EXPORT_SYMBOL(iwl_sar_select_profile);
399 
400 int iwl_sar_get_wrds_table(struct iwl_fw_runtime *fwrt)
401 {
402 	union acpi_object *wifi_pkg, *table, *data;
403 	bool enabled;
404 	int ret, tbl_rev;
405 
406 	data = iwl_acpi_get_object(fwrt->dev, ACPI_WRDS_METHOD);
407 	if (IS_ERR(data))
408 		return PTR_ERR(data);
409 
410 	wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
411 					 ACPI_WRDS_WIFI_DATA_SIZE, &tbl_rev);
412 	if (IS_ERR(wifi_pkg) || tbl_rev != 0) {
413 		ret = PTR_ERR(wifi_pkg);
414 		goto out_free;
415 	}
416 
417 	if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) {
418 		ret = -EINVAL;
419 		goto out_free;
420 	}
421 
422 	enabled = !!(wifi_pkg->package.elements[1].integer.value);
423 
424 	/* position of the actual table */
425 	table = &wifi_pkg->package.elements[2];
426 
427 	/* The profile from WRDS is officially profile 1, but goes
428 	 * into sar_profiles[0] (because we don't have a profile 0).
429 	 */
430 	ret = iwl_sar_set_profile(table, &fwrt->sar_profiles[0], enabled);
431 out_free:
432 	kfree(data);
433 	return ret;
434 }
435 IWL_EXPORT_SYMBOL(iwl_sar_get_wrds_table);
436 
437 int iwl_sar_get_ewrd_table(struct iwl_fw_runtime *fwrt)
438 {
439 	union acpi_object *wifi_pkg, *data;
440 	bool enabled;
441 	int i, n_profiles, tbl_rev, pos;
442 	int ret = 0;
443 
444 	data = iwl_acpi_get_object(fwrt->dev, ACPI_EWRD_METHOD);
445 	if (IS_ERR(data))
446 		return PTR_ERR(data);
447 
448 	wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
449 					 ACPI_EWRD_WIFI_DATA_SIZE, &tbl_rev);
450 	if (IS_ERR(wifi_pkg) || tbl_rev != 0) {
451 		ret = PTR_ERR(wifi_pkg);
452 		goto out_free;
453 	}
454 
455 	if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER ||
456 	    wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER) {
457 		ret = -EINVAL;
458 		goto out_free;
459 	}
460 
461 	enabled = !!(wifi_pkg->package.elements[1].integer.value);
462 	n_profiles = wifi_pkg->package.elements[2].integer.value;
463 
464 	/*
465 	 * Check the validity of n_profiles.  The EWRD profiles start
466 	 * from index 1, so the maximum value allowed here is
467 	 * ACPI_SAR_PROFILES_NUM - 1.
468 	 */
469 	if (n_profiles <= 0 || n_profiles >= ACPI_SAR_PROFILE_NUM) {
470 		ret = -EINVAL;
471 		goto out_free;
472 	}
473 
474 	/* the tables start at element 3 */
475 	pos = 3;
476 
477 	for (i = 0; i < n_profiles; i++) {
478 		/* The EWRD profiles officially go from 2 to 4, but we
479 		 * save them in sar_profiles[1-3] (because we don't
480 		 * have profile 0).  So in the array we start from 1.
481 		 */
482 		ret = iwl_sar_set_profile(&wifi_pkg->package.elements[pos],
483 					  &fwrt->sar_profiles[i + 1],
484 					  enabled);
485 		if (ret < 0)
486 			break;
487 
488 		/* go to the next table */
489 		pos += ACPI_SAR_TABLE_SIZE;
490 	}
491 
492 out_free:
493 	kfree(data);
494 	return ret;
495 }
496 IWL_EXPORT_SYMBOL(iwl_sar_get_ewrd_table);
497 
498 int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt)
499 {
500 	union acpi_object *wifi_pkg, *data;
501 	int i, j, ret, tbl_rev;
502 	int idx = 1;
503 
504 	data = iwl_acpi_get_object(fwrt->dev, ACPI_WGDS_METHOD);
505 	if (IS_ERR(data))
506 		return PTR_ERR(data);
507 
508 	wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
509 					 ACPI_WGDS_WIFI_DATA_SIZE, &tbl_rev);
510 	if (IS_ERR(wifi_pkg) || tbl_rev > 1) {
511 		ret = PTR_ERR(wifi_pkg);
512 		goto out_free;
513 	}
514 
515 	fwrt->geo_rev = tbl_rev;
516 	for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
517 		for (j = 0; j < ACPI_GEO_TABLE_SIZE; j++) {
518 			union acpi_object *entry;
519 
520 			entry = &wifi_pkg->package.elements[idx++];
521 			if (entry->type != ACPI_TYPE_INTEGER ||
522 			    entry->integer.value > U8_MAX) {
523 				ret = -EINVAL;
524 				goto out_free;
525 			}
526 
527 			fwrt->geo_profiles[i].values[j] = entry->integer.value;
528 		}
529 	}
530 	ret = 0;
531 out_free:
532 	kfree(data);
533 	return ret;
534 }
535 IWL_EXPORT_SYMBOL(iwl_sar_get_wgds_table);
536 
537 bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt)
538 {
539 	/*
540 	 * The GEO_TX_POWER_LIMIT command is not supported on earlier
541 	 * firmware versions.  Unfortunately, we don't have a TLV API
542 	 * flag to rely on, so rely on the major version which is in
543 	 * the first byte of ucode_ver.  This was implemented
544 	 * initially on version 38 and then backported to 17.  It was
545 	 * also backported to 29, but only for 7265D devices.  The
546 	 * intention was to have it in 36 as well, but not all 8000
547 	 * family got this feature enabled.  The 8000 family is the
548 	 * only one using version 36, so skip this version entirely.
549 	 */
550 	return IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) >= 38 ||
551 	       IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) == 17 ||
552 	       (IWL_UCODE_SERIAL(fwrt->fw->ucode_ver) == 29 &&
553 		((fwrt->trans->hw_rev & CSR_HW_REV_TYPE_MSK) ==
554 		 CSR_HW_REV_TYPE_7265D));
555 }
556 IWL_EXPORT_SYMBOL(iwl_sar_geo_support);
557 
558 int iwl_validate_sar_geo_profile(struct iwl_fw_runtime *fwrt,
559 				 struct iwl_host_cmd *cmd)
560 {
561 	struct iwl_geo_tx_power_profiles_resp *resp;
562 	int ret;
563 
564 	resp = (void *)cmd->resp_pkt->data;
565 	ret = le32_to_cpu(resp->profile_idx);
566 	if (WARN_ON(ret > ACPI_NUM_GEO_PROFILES)) {
567 		ret = -EIO;
568 		IWL_WARN(fwrt, "Invalid geographic profile idx (%d)\n", ret);
569 	}
570 
571 	return ret;
572 }
573 IWL_EXPORT_SYMBOL(iwl_validate_sar_geo_profile);
574 
575 int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
576 		     struct iwl_per_chain_offset_group *table)
577 {
578 	int ret, i, j;
579 
580 	if (!iwl_sar_geo_support(fwrt))
581 		return -EOPNOTSUPP;
582 
583 	ret = iwl_sar_get_wgds_table(fwrt);
584 	if (ret < 0) {
585 		IWL_DEBUG_RADIO(fwrt,
586 				"Geo SAR BIOS table invalid or unavailable. (%d)\n",
587 				ret);
588 		/* we don't fail if the table is not available */
589 		return -ENOENT;
590 	}
591 
592 	BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES * ACPI_WGDS_NUM_BANDS *
593 		     ACPI_WGDS_TABLE_SIZE + 1 !=  ACPI_WGDS_WIFI_DATA_SIZE);
594 
595 	BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES > IWL_NUM_GEO_PROFILES);
596 
597 	for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
598 		struct iwl_per_chain_offset *chain =
599 			(struct iwl_per_chain_offset *)&table[i];
600 
601 		for (j = 0; j < ACPI_WGDS_NUM_BANDS; j++) {
602 			u8 *value;
603 
604 			value = &fwrt->geo_profiles[i].values[j *
605 				ACPI_GEO_PER_CHAIN_SIZE];
606 			chain[j].max_tx_power = cpu_to_le16(value[0]);
607 			chain[j].chain_a = value[1];
608 			chain[j].chain_b = value[2];
609 			IWL_DEBUG_RADIO(fwrt,
610 					"SAR geographic profile[%d] Band[%d]: chain A = %d chain B = %d max_tx_power = %d\n",
611 					i, j, value[1], value[2], value[0]);
612 		}
613 	}
614 
615 	return 0;
616 }
617 IWL_EXPORT_SYMBOL(iwl_sar_geo_init);
618