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",
299 /* if one of the profiles is disabled, we fail all */
303 "SAR EWRD: chain %d profile index %d\n",
305 IWL_DEBUG_RADIO(fwrt
, " Chain[%d]:\n", i
);
306 for (j
= 0; j
< ACPI_SAR_NUM_SUB_BANDS
; j
++) {
307 idx
= (i
* ACPI_SAR_NUM_SUB_BANDS
) + j
;
308 per_chain_restriction
[i
][j
] =
309 cpu_to_le16(prof
->table
[idx
]);
310 IWL_DEBUG_RADIO(fwrt
, " Band[%d] = %d * .125dBm\n",
311 j
, prof
->table
[idx
]);
317 IWL_EXPORT_SYMBOL(iwl_sar_select_profile
);
319 int iwl_sar_get_wrds_table(struct iwl_fw_runtime
*fwrt
)
321 union acpi_object
*wifi_pkg
, *table
, *data
;
325 data
= iwl_acpi_get_object(fwrt
->dev
, ACPI_WRDS_METHOD
);
327 return PTR_ERR(data
);
329 wifi_pkg
= iwl_acpi_get_wifi_pkg(fwrt
->dev
, data
,
330 ACPI_WRDS_WIFI_DATA_SIZE
, &tbl_rev
);
331 if (IS_ERR(wifi_pkg
) || tbl_rev
!= 0) {
332 ret
= PTR_ERR(wifi_pkg
);
336 if (wifi_pkg
->package
.elements
[1].type
!= ACPI_TYPE_INTEGER
) {
341 enabled
= !!(wifi_pkg
->package
.elements
[1].integer
.value
);
343 /* position of the actual table */
344 table
= &wifi_pkg
->package
.elements
[2];
346 /* The profile from WRDS is officially profile 1, but goes
347 * into sar_profiles[0] (because we don't have a profile 0).
349 ret
= iwl_sar_set_profile(table
, &fwrt
->sar_profiles
[0], enabled
);
354 IWL_EXPORT_SYMBOL(iwl_sar_get_wrds_table
);
356 int iwl_sar_get_ewrd_table(struct iwl_fw_runtime
*fwrt
)
358 union acpi_object
*wifi_pkg
, *data
;
360 int i
, n_profiles
, tbl_rev
, pos
;
363 data
= iwl_acpi_get_object(fwrt
->dev
, ACPI_EWRD_METHOD
);
365 return PTR_ERR(data
);
367 wifi_pkg
= iwl_acpi_get_wifi_pkg(fwrt
->dev
, data
,
368 ACPI_EWRD_WIFI_DATA_SIZE
, &tbl_rev
);
369 if (IS_ERR(wifi_pkg
) || tbl_rev
!= 0) {
370 ret
= PTR_ERR(wifi_pkg
);
374 if (wifi_pkg
->package
.elements
[1].type
!= ACPI_TYPE_INTEGER
||
375 wifi_pkg
->package
.elements
[2].type
!= ACPI_TYPE_INTEGER
) {
380 enabled
= !!(wifi_pkg
->package
.elements
[1].integer
.value
);
381 n_profiles
= wifi_pkg
->package
.elements
[2].integer
.value
;
384 * Check the validity of n_profiles. The EWRD profiles start
385 * from index 1, so the maximum value allowed here is
386 * ACPI_SAR_PROFILES_NUM - 1.
388 if (n_profiles
<= 0 || n_profiles
>= ACPI_SAR_PROFILE_NUM
) {
393 /* the tables start at element 3 */
396 for (i
= 0; i
< n_profiles
; i
++) {
397 /* The EWRD profiles officially go from 2 to 4, but we
398 * save them in sar_profiles[1-3] (because we don't
399 * have profile 0). So in the array we start from 1.
401 ret
= iwl_sar_set_profile(&wifi_pkg
->package
.elements
[pos
],
402 &fwrt
->sar_profiles
[i
+ 1],
407 /* go to the next table */
408 pos
+= ACPI_SAR_TABLE_SIZE
;
415 IWL_EXPORT_SYMBOL(iwl_sar_get_ewrd_table
);
417 int iwl_sar_get_wgds_table(struct iwl_fw_runtime
*fwrt
)
419 union acpi_object
*wifi_pkg
, *data
;
420 int i
, j
, ret
, tbl_rev
;
423 data
= iwl_acpi_get_object(fwrt
->dev
, ACPI_WGDS_METHOD
);
425 return PTR_ERR(data
);
427 wifi_pkg
= iwl_acpi_get_wifi_pkg(fwrt
->dev
, data
,
428 ACPI_WGDS_WIFI_DATA_SIZE
, &tbl_rev
);
429 if (IS_ERR(wifi_pkg
) || tbl_rev
> 1) {
430 ret
= PTR_ERR(wifi_pkg
);
434 fwrt
->geo_rev
= tbl_rev
;
435 for (i
= 0; i
< ACPI_NUM_GEO_PROFILES
; i
++) {
436 for (j
= 0; j
< ACPI_GEO_TABLE_SIZE
; j
++) {
437 union acpi_object
*entry
;
439 entry
= &wifi_pkg
->package
.elements
[idx
++];
440 if (entry
->type
!= ACPI_TYPE_INTEGER
||
441 entry
->integer
.value
> U8_MAX
) {
446 fwrt
->geo_profiles
[i
].values
[j
] = entry
->integer
.value
;
454 IWL_EXPORT_SYMBOL(iwl_sar_get_wgds_table
);
456 bool iwl_sar_geo_support(struct iwl_fw_runtime
*fwrt
)
459 * The GEO_TX_POWER_LIMIT command is not supported on earlier
460 * firmware versions. Unfortunately, we don't have a TLV API
461 * flag to rely on, so rely on the major version which is in
462 * the first byte of ucode_ver. This was implemented
463 * initially on version 38 and then backported to 17. It was
464 * also backported to 29, but only for 7265D devices. The
465 * intention was to have it in 36 as well, but not all 8000
466 * family got this feature enabled. The 8000 family is the
467 * only one using version 36, so skip this version entirely.
469 return IWL_UCODE_SERIAL(fwrt
->fw
->ucode_ver
) >= 38 ||
470 IWL_UCODE_SERIAL(fwrt
->fw
->ucode_ver
) == 17 ||
471 (IWL_UCODE_SERIAL(fwrt
->fw
->ucode_ver
) == 29 &&
472 ((fwrt
->trans
->hw_rev
& CSR_HW_REV_TYPE_MSK
) ==
473 CSR_HW_REV_TYPE_7265D
));
475 IWL_EXPORT_SYMBOL(iwl_sar_geo_support
);
477 int iwl_validate_sar_geo_profile(struct iwl_fw_runtime
*fwrt
,
478 struct iwl_host_cmd
*cmd
)
480 struct iwl_geo_tx_power_profiles_resp
*resp
;
483 resp
= (void *)cmd
->resp_pkt
->data
;
484 ret
= le32_to_cpu(resp
->profile_idx
);
485 if (WARN_ON(ret
> ACPI_NUM_GEO_PROFILES
)) {
487 IWL_WARN(fwrt
, "Invalid geographic profile idx (%d)\n", ret
);
492 IWL_EXPORT_SYMBOL(iwl_validate_sar_geo_profile
);
494 int iwl_sar_geo_init(struct iwl_fw_runtime
*fwrt
,
495 struct iwl_per_chain_offset_group
*table
)
499 if (!iwl_sar_geo_support(fwrt
))
502 ret
= iwl_sar_get_wgds_table(fwrt
);
504 IWL_DEBUG_RADIO(fwrt
,
505 "Geo SAR BIOS table invalid or unavailable. (%d)\n",
507 /* we don't fail if the table is not available */
511 BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES
* ACPI_WGDS_NUM_BANDS
*
512 ACPI_WGDS_TABLE_SIZE
+ 1 != ACPI_WGDS_WIFI_DATA_SIZE
);
514 BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES
> IWL_NUM_GEO_PROFILES
);
516 for (i
= 0; i
< ACPI_NUM_GEO_PROFILES
; i
++) {
517 struct iwl_per_chain_offset
*chain
=
518 (struct iwl_per_chain_offset
*)&table
[i
];
520 for (j
= 0; j
< ACPI_WGDS_NUM_BANDS
; j
++) {
523 value
= &fwrt
->geo_profiles
[i
].values
[j
*
524 ACPI_GEO_PER_CHAIN_SIZE
];
525 chain
[j
].max_tx_power
= cpu_to_le16(value
[0]);
526 chain
[j
].chain_a
= value
[1];
527 chain
[j
].chain_b
= value
[2];
528 IWL_DEBUG_RADIO(fwrt
,
529 "SAR geographic profile[%d] Band[%d]: chain A = %d chain B = %d max_tx_power = %d\n",
530 i
, j
, value
[1], value
[2], value
[0]);
536 IWL_EXPORT_SYMBOL(iwl_sar_geo_init
);