Skip to content

Commit 97f8a3d

Browse files
Ayala Barazanilucacoelho
Ayala Barazani
authored andcommitted
iwlwifi: ACPI: support revision 3 WGDS tables
There's a new revision of the WGDS table with more data, and corresponding firmware API to pass it through. Add support for both. Since we now support 4 different versions, make a table to load them instead of hard-coding it all. Signed-off-by: Ayala Barazani <[email protected]> Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: Luca Coelho <[email protected]> Link: https://lore.kernel.org/r/iwlwifi.20211024165252.2f9b8e304f25.If88d2d1309270e659d4845c5b5c22d5e8d8e2caf@changeid Signed-off-by: Luca Coelho <[email protected]>
1 parent 571836a commit 97f8a3d

File tree

5 files changed

+193
-69
lines changed

5 files changed

+193
-69
lines changed

drivers/net/wireless/intel/iwlwifi/fw/acpi.c

Lines changed: 101 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,11 @@ int iwl_acpi_get_dsm_u32(struct device *dev, int rev, int func,
184184
}
185185
IWL_EXPORT_SYMBOL(iwl_acpi_get_dsm_u32);
186186

187-
union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
188-
union acpi_object *data,
189-
int data_size, int *tbl_rev)
187+
union acpi_object *iwl_acpi_get_wifi_pkg_range(struct device *dev,
188+
union acpi_object *data,
189+
int min_data_size,
190+
int max_data_size,
191+
int *tbl_rev)
190192
{
191193
int i;
192194
union acpi_object *wifi_pkg;
@@ -196,7 +198,7 @@ union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
196198
* describes the domain, and one more entry, otherwise there's
197199
* no point in reading it.
198200
*/
199-
if (WARN_ON_ONCE(data_size < 2))
201+
if (WARN_ON_ONCE(min_data_size < 2 || min_data_size > max_data_size))
200202
return ERR_PTR(-EINVAL);
201203

202204
/*
@@ -222,7 +224,8 @@ union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
222224

223225
/* skip entries that are not a package with the right size */
224226
if (wifi_pkg->type != ACPI_TYPE_PACKAGE ||
225-
wifi_pkg->package.count != data_size)
227+
wifi_pkg->package.count < min_data_size ||
228+
wifi_pkg->package.count > max_data_size)
226229
continue;
227230

228231
domain = &wifi_pkg->package.elements[0];
@@ -236,7 +239,7 @@ union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
236239
found:
237240
return wifi_pkg;
238241
}
239-
IWL_EXPORT_SYMBOL(iwl_acpi_get_wifi_pkg);
242+
IWL_EXPORT_SYMBOL(iwl_acpi_get_wifi_pkg_range);
240243

241244
int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt,
242245
__le32 *block_list_array,
@@ -707,49 +710,103 @@ int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt)
707710
{
708711
union acpi_object *wifi_pkg, *data;
709712
int i, j, k, ret, tbl_rev;
710-
int idx = 1; /* start from one to skip the domain */
711-
u8 num_bands;
713+
u8 num_bands, num_profiles;
714+
static const struct {
715+
u8 revisions;
716+
u8 bands;
717+
u8 profiles;
718+
u8 min_profiles;
719+
} rev_data[] = {
720+
{
721+
.revisions = BIT(3),
722+
.bands = ACPI_GEO_NUM_BANDS_REV2,
723+
.profiles = ACPI_NUM_GEO_PROFILES_REV3,
724+
.min_profiles = 3,
725+
},
726+
{
727+
.revisions = BIT(2),
728+
.bands = ACPI_GEO_NUM_BANDS_REV2,
729+
.profiles = ACPI_NUM_GEO_PROFILES,
730+
},
731+
{
732+
.revisions = BIT(0) | BIT(1),
733+
.bands = ACPI_GEO_NUM_BANDS_REV0,
734+
.profiles = ACPI_NUM_GEO_PROFILES,
735+
},
736+
};
737+
int idx;
738+
/* start from one to skip the domain */
739+
int entry_idx = 1;
740+
741+
BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES_REV3 != IWL_NUM_GEO_PROFILES_V3);
742+
BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES != IWL_NUM_GEO_PROFILES);
712743

713744
data = iwl_acpi_get_object(fwrt->dev, ACPI_WGDS_METHOD);
714745
if (IS_ERR(data))
715746
return PTR_ERR(data);
716747

717-
/* start by trying to read revision 2 */
718-
wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
719-
ACPI_WGDS_WIFI_DATA_SIZE_REV2,
720-
&tbl_rev);
721-
if (!IS_ERR(wifi_pkg)) {
722-
if (tbl_rev != 2) {
723-
ret = PTR_ERR(wifi_pkg);
724-
goto out_free;
725-
}
726-
727-
num_bands = ACPI_GEO_NUM_BANDS_REV2;
728-
729-
goto read_table;
730-
}
731-
732-
/* then try revision 0 (which is the same as 1) */
733-
wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
734-
ACPI_WGDS_WIFI_DATA_SIZE_REV0,
735-
&tbl_rev);
736-
if (!IS_ERR(wifi_pkg)) {
737-
if (tbl_rev != 0 && tbl_rev != 1) {
738-
ret = PTR_ERR(wifi_pkg);
739-
goto out_free;
748+
/* read the highest revision we understand first */
749+
for (idx = 0; idx < ARRAY_SIZE(rev_data); idx++) {
750+
/* min_profiles != 0 requires num_profiles header */
751+
u32 hdr_size = 1 + !!rev_data[idx].min_profiles;
752+
u32 profile_size = ACPI_GEO_PER_CHAIN_SIZE *
753+
rev_data[idx].bands;
754+
u32 max_size = hdr_size + profile_size * rev_data[idx].profiles;
755+
u32 min_size;
756+
757+
if (!rev_data[idx].min_profiles)
758+
min_size = max_size;
759+
else
760+
min_size = hdr_size +
761+
profile_size * rev_data[idx].min_profiles;
762+
763+
wifi_pkg = iwl_acpi_get_wifi_pkg_range(fwrt->dev, data,
764+
min_size, max_size,
765+
&tbl_rev);
766+
if (!IS_ERR(wifi_pkg)) {
767+
if (!(BIT(tbl_rev) & rev_data[idx].revisions))
768+
continue;
769+
770+
num_bands = rev_data[idx].bands;
771+
num_profiles = rev_data[idx].profiles;
772+
773+
if (rev_data[idx].min_profiles) {
774+
/* read header that says # of profiles */
775+
union acpi_object *entry;
776+
777+
entry = &wifi_pkg->package.elements[entry_idx];
778+
entry_idx++;
779+
if (entry->type != ACPI_TYPE_INTEGER ||
780+
entry->integer.value > num_profiles) {
781+
ret = -EINVAL;
782+
goto out_free;
783+
}
784+
num_profiles = entry->integer.value;
785+
786+
/*
787+
* this also validates >= min_profiles since we
788+
* otherwise wouldn't have gotten the data when
789+
* looking up in ACPI
790+
*/
791+
if (wifi_pkg->package.count !=
792+
min_size + profile_size * num_profiles) {
793+
ret = -EINVAL;
794+
goto out_free;
795+
}
796+
}
797+
goto read_table;
740798
}
741-
742-
num_bands = ACPI_GEO_NUM_BANDS_REV0;
743-
744-
goto read_table;
745799
}
746800

747-
ret = PTR_ERR(wifi_pkg);
801+
if (idx < ARRAY_SIZE(rev_data))
802+
ret = PTR_ERR(wifi_pkg);
803+
else
804+
ret = -ENOENT;
748805
goto out_free;
749806

750807
read_table:
751808
fwrt->geo_rev = tbl_rev;
752-
for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
809+
for (i = 0; i < num_profiles; i++) {
753810
for (j = 0; j < ACPI_GEO_NUM_BANDS_REV2; j++) {
754811
union acpi_object *entry;
755812

@@ -762,7 +819,8 @@ int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt)
762819
fwrt->geo_profiles[i].bands[j].max =
763820
fwrt->geo_profiles[i].bands[1].max;
764821
} else {
765-
entry = &wifi_pkg->package.elements[idx++];
822+
entry = &wifi_pkg->package.elements[entry_idx];
823+
entry_idx++;
766824
if (entry->type != ACPI_TYPE_INTEGER ||
767825
entry->integer.value > U8_MAX) {
768826
ret = -EINVAL;
@@ -779,7 +837,8 @@ int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt)
779837
fwrt->geo_profiles[i].bands[j].chains[k] =
780838
fwrt->geo_profiles[i].bands[1].chains[k];
781839
} else {
782-
entry = &wifi_pkg->package.elements[idx++];
840+
entry = &wifi_pkg->package.elements[entry_idx];
841+
entry_idx++;
783842
if (entry->type != ACPI_TYPE_INTEGER ||
784843
entry->integer.value > U8_MAX) {
785844
ret = -EINVAL;
@@ -822,14 +881,15 @@ bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt)
822881
IWL_EXPORT_SYMBOL(iwl_sar_geo_support);
823882

824883
int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
825-
struct iwl_per_chain_offset *table, u32 n_bands)
884+
struct iwl_per_chain_offset *table,
885+
u32 n_bands, u32 n_profiles)
826886
{
827887
int i, j;
828888

829889
if (!iwl_sar_geo_support(fwrt))
830890
return -EOPNOTSUPP;
831891

832-
for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
892+
for (i = 0; i < n_profiles; i++) {
833893
for (j = 0; j < n_bands; j++) {
834894
struct iwl_per_chain_offset *chain =
835895
&table[i * n_bands + j];

drivers/net/wireless/intel/iwlwifi/fw/acpi.h

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define ACPI_SAR_PROFILE_NUM 4
3030

3131
#define ACPI_NUM_GEO_PROFILES 3
32+
#define ACPI_NUM_GEO_PROFILES_REV3 8
3233
#define ACPI_GEO_PER_CHAIN_SIZE 3
3334

3435
#define ACPI_SAR_NUM_CHAINS_REV0 2
@@ -59,13 +60,6 @@
5960
#define ACPI_GEO_NUM_BANDS_REV2 3
6061
#define ACPI_GEO_NUM_CHAINS 2
6162

62-
#define ACPI_WGDS_WIFI_DATA_SIZE_REV0 (ACPI_NUM_GEO_PROFILES * \
63-
ACPI_GEO_NUM_BANDS_REV0 * \
64-
ACPI_GEO_PER_CHAIN_SIZE + 1)
65-
#define ACPI_WGDS_WIFI_DATA_SIZE_REV2 (ACPI_NUM_GEO_PROFILES * \
66-
ACPI_GEO_NUM_BANDS_REV2 * \
67-
ACPI_GEO_PER_CHAIN_SIZE + 1)
68-
6963
#define ACPI_WRDD_WIFI_DATA_SIZE 2
7064
#define ACPI_SPLC_WIFI_DATA_SIZE 2
7165
#define ACPI_ECKV_WIFI_DATA_SIZE 2
@@ -159,10 +153,11 @@ int iwl_acpi_get_dsm_u8(struct device *dev, int rev, int func,
159153
int iwl_acpi_get_dsm_u32(struct device *dev, int rev, int func,
160154
const guid_t *guid, u32 *value);
161155

162-
union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
163-
union acpi_object *data,
164-
int data_size, int *tbl_rev);
165-
156+
union acpi_object *iwl_acpi_get_wifi_pkg_range(struct device *dev,
157+
union acpi_object *data,
158+
int min_data_size,
159+
int max_data_size,
160+
int *tbl_rev);
166161
/**
167162
* iwl_acpi_get_mcc - read MCC from ACPI, if available
168163
*
@@ -199,7 +194,8 @@ int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt);
199194
bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt);
200195

201196
int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
202-
struct iwl_per_chain_offset *table, u32 n_bands);
197+
struct iwl_per_chain_offset *table,
198+
u32 n_bands, u32 n_profiles);
203199

204200
int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt, __le32 *block_list_array,
205201
int *block_list_size);
@@ -231,10 +227,11 @@ static inline int iwl_acpi_get_dsm_u32(struct device *dev, int rev, int func,
231227
return -ENOENT;
232228
}
233229

234-
static inline union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
235-
union acpi_object *data,
236-
int data_size,
237-
int *tbl_rev)
230+
static inline union acpi_object *
231+
iwl_acpi_get_wifi_pkg_range(struct device *dev,
232+
union acpi_object *data,
233+
int min_data_size, int max_data_size,
234+
int *tbl_rev)
238235
{
239236
return ERR_PTR(-ENOENT);
240237
}
@@ -294,4 +291,14 @@ static inline __le32 iwl_acpi_get_lari_config_bitmap(struct iwl_fw_runtime *fwrt
294291
}
295292

296293
#endif /* CONFIG_ACPI */
294+
295+
static inline union acpi_object *
296+
iwl_acpi_get_wifi_pkg(struct device *dev,
297+
union acpi_object *data,
298+
int data_size, int *tbl_rev)
299+
{
300+
return iwl_acpi_get_wifi_pkg_range(dev, data, data_size, data_size,
301+
tbl_rev);
302+
}
303+
297304
#endif /* __iwl_fw_acpi__ */

drivers/net/wireless/intel/iwlwifi/fw/api/power.h

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
22
/*
3-
* Copyright (C) 2012-2014, 2018-2020 Intel Corporation
3+
* Copyright (C) 2012-2014, 2018-2021 Intel Corporation
44
* Copyright (C) 2013-2014 Intel Mobile Communications GmbH
55
* Copyright (C) 2015-2017 Intel Deutschland GmbH
66
*/
@@ -378,9 +378,10 @@ struct iwl_dev_tx_power_cmd {
378378
};
379379
};
380380

381-
#define IWL_NUM_GEO_PROFILES 3
382-
#define IWL_NUM_BANDS_PER_CHAIN_V1 2
383-
#define IWL_NUM_BANDS_PER_CHAIN_V2 3
381+
#define IWL_NUM_GEO_PROFILES 3
382+
#define IWL_NUM_GEO_PROFILES_V3 8
383+
#define IWL_NUM_BANDS_PER_CHAIN_V1 2
384+
#define IWL_NUM_BANDS_PER_CHAIN_V2 3
384385

385386
/**
386387
* enum iwl_geo_per_chain_offset_operation - type of operation
@@ -438,10 +439,36 @@ struct iwl_geo_tx_power_profiles_cmd_v3 {
438439
__le32 table_revision;
439440
} __packed; /* GEO_TX_POWER_LIMIT_VER_3 */
440441

442+
/**
443+
* struct iwl_geo_tx_power_profile_cmd_v4 - struct for GEO_TX_POWER_LIMIT cmd.
444+
* @ops: operations, value from &enum iwl_geo_per_chain_offset_operation
445+
* @table: offset profile per band.
446+
* @table_revision: BIOS table revision.
447+
*/
448+
struct iwl_geo_tx_power_profiles_cmd_v4 {
449+
__le32 ops;
450+
struct iwl_per_chain_offset table[IWL_NUM_GEO_PROFILES_V3][IWL_NUM_BANDS_PER_CHAIN_V1];
451+
__le32 table_revision;
452+
} __packed; /* GEO_TX_POWER_LIMIT_VER_4 */
453+
454+
/**
455+
* struct iwl_geo_tx_power_profile_cmd_v5 - struct for GEO_TX_POWER_LIMIT cmd.
456+
* @ops: operations, value from &enum iwl_geo_per_chain_offset_operation
457+
* @table: offset profile per band.
458+
* @table_revision: BIOS table revision.
459+
*/
460+
struct iwl_geo_tx_power_profiles_cmd_v5 {
461+
__le32 ops;
462+
struct iwl_per_chain_offset table[IWL_NUM_GEO_PROFILES_V3][IWL_NUM_BANDS_PER_CHAIN_V2];
463+
__le32 table_revision;
464+
} __packed; /* GEO_TX_POWER_LIMIT_VER_5 */
465+
441466
union iwl_geo_tx_power_profiles_cmd {
442467
struct iwl_geo_tx_power_profiles_cmd_v1 v1;
443468
struct iwl_geo_tx_power_profiles_cmd_v2 v2;
444469
struct iwl_geo_tx_power_profiles_cmd_v3 v3;
470+
struct iwl_geo_tx_power_profiles_cmd_v4 v4;
471+
struct iwl_geo_tx_power_profiles_cmd_v5 v5;
445472
};
446473

447474
/**

drivers/net/wireless/intel/iwlwifi/fw/runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ struct iwl_fw_runtime {
154154
struct iwl_sar_profile sar_profiles[ACPI_SAR_PROFILE_NUM];
155155
u8 sar_chain_a_profile;
156156
u8 sar_chain_b_profile;
157-
struct iwl_geo_profile geo_profiles[ACPI_NUM_GEO_PROFILES];
157+
struct iwl_geo_profile geo_profiles[ACPI_NUM_GEO_PROFILES_REV3];
158158
u32 geo_rev;
159159
union iwl_ppag_table_cmd ppag_table;
160160
u32 ppag_ver;

0 commit comments

Comments
 (0)