Skip to content

Commit

Permalink
iwlwifi: ACPI: support revision 3 WGDS tables
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Ayala Barazani authored and lucacoelho committed Oct 28, 2021
1 parent 571836a commit 97f8a3d
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 69 deletions.
142 changes: 101 additions & 41 deletions drivers/net/wireless/intel/iwlwifi/fw/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,11 @@ int iwl_acpi_get_dsm_u32(struct device *dev, int rev, int func,
}
IWL_EXPORT_SYMBOL(iwl_acpi_get_dsm_u32);

union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
union acpi_object *data,
int data_size, int *tbl_rev)
union acpi_object *iwl_acpi_get_wifi_pkg_range(struct device *dev,
union acpi_object *data,
int min_data_size,
int max_data_size,
int *tbl_rev)
{
int i;
union acpi_object *wifi_pkg;
Expand All @@ -196,7 +198,7 @@ union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
* describes the domain, and one more entry, otherwise there's
* no point in reading it.
*/
if (WARN_ON_ONCE(data_size < 2))
if (WARN_ON_ONCE(min_data_size < 2 || min_data_size > max_data_size))
return ERR_PTR(-EINVAL);

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

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

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

int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt,
__le32 *block_list_array,
Expand Down Expand Up @@ -707,49 +710,103 @@ int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt)
{
union acpi_object *wifi_pkg, *data;
int i, j, k, ret, tbl_rev;
int idx = 1; /* start from one to skip the domain */
u8 num_bands;
u8 num_bands, num_profiles;
static const struct {
u8 revisions;
u8 bands;
u8 profiles;
u8 min_profiles;
} rev_data[] = {
{
.revisions = BIT(3),
.bands = ACPI_GEO_NUM_BANDS_REV2,
.profiles = ACPI_NUM_GEO_PROFILES_REV3,
.min_profiles = 3,
},
{
.revisions = BIT(2),
.bands = ACPI_GEO_NUM_BANDS_REV2,
.profiles = ACPI_NUM_GEO_PROFILES,
},
{
.revisions = BIT(0) | BIT(1),
.bands = ACPI_GEO_NUM_BANDS_REV0,
.profiles = ACPI_NUM_GEO_PROFILES,
},
};
int idx;
/* start from one to skip the domain */
int entry_idx = 1;

BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES_REV3 != IWL_NUM_GEO_PROFILES_V3);
BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES != IWL_NUM_GEO_PROFILES);

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

/* start by trying to read revision 2 */
wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
ACPI_WGDS_WIFI_DATA_SIZE_REV2,
&tbl_rev);
if (!IS_ERR(wifi_pkg)) {
if (tbl_rev != 2) {
ret = PTR_ERR(wifi_pkg);
goto out_free;
}

num_bands = ACPI_GEO_NUM_BANDS_REV2;

goto read_table;
}

/* then try revision 0 (which is the same as 1) */
wifi_pkg = iwl_acpi_get_wifi_pkg(fwrt->dev, data,
ACPI_WGDS_WIFI_DATA_SIZE_REV0,
&tbl_rev);
if (!IS_ERR(wifi_pkg)) {
if (tbl_rev != 0 && tbl_rev != 1) {
ret = PTR_ERR(wifi_pkg);
goto out_free;
/* read the highest revision we understand first */
for (idx = 0; idx < ARRAY_SIZE(rev_data); idx++) {
/* min_profiles != 0 requires num_profiles header */
u32 hdr_size = 1 + !!rev_data[idx].min_profiles;
u32 profile_size = ACPI_GEO_PER_CHAIN_SIZE *
rev_data[idx].bands;
u32 max_size = hdr_size + profile_size * rev_data[idx].profiles;
u32 min_size;

if (!rev_data[idx].min_profiles)
min_size = max_size;
else
min_size = hdr_size +
profile_size * rev_data[idx].min_profiles;

wifi_pkg = iwl_acpi_get_wifi_pkg_range(fwrt->dev, data,
min_size, max_size,
&tbl_rev);
if (!IS_ERR(wifi_pkg)) {
if (!(BIT(tbl_rev) & rev_data[idx].revisions))
continue;

num_bands = rev_data[idx].bands;
num_profiles = rev_data[idx].profiles;

if (rev_data[idx].min_profiles) {
/* read header that says # of profiles */
union acpi_object *entry;

entry = &wifi_pkg->package.elements[entry_idx];
entry_idx++;
if (entry->type != ACPI_TYPE_INTEGER ||
entry->integer.value > num_profiles) {
ret = -EINVAL;
goto out_free;
}
num_profiles = entry->integer.value;

/*
* this also validates >= min_profiles since we
* otherwise wouldn't have gotten the data when
* looking up in ACPI
*/
if (wifi_pkg->package.count !=
min_size + profile_size * num_profiles) {
ret = -EINVAL;
goto out_free;
}
}
goto read_table;
}

num_bands = ACPI_GEO_NUM_BANDS_REV0;

goto read_table;
}

ret = PTR_ERR(wifi_pkg);
if (idx < ARRAY_SIZE(rev_data))
ret = PTR_ERR(wifi_pkg);
else
ret = -ENOENT;
goto out_free;

read_table:
fwrt->geo_rev = tbl_rev;
for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
for (i = 0; i < num_profiles; i++) {
for (j = 0; j < ACPI_GEO_NUM_BANDS_REV2; j++) {
union acpi_object *entry;

Expand All @@ -762,7 +819,8 @@ int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt)
fwrt->geo_profiles[i].bands[j].max =
fwrt->geo_profiles[i].bands[1].max;
} else {
entry = &wifi_pkg->package.elements[idx++];
entry = &wifi_pkg->package.elements[entry_idx];
entry_idx++;
if (entry->type != ACPI_TYPE_INTEGER ||
entry->integer.value > U8_MAX) {
ret = -EINVAL;
Expand All @@ -779,7 +837,8 @@ int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt)
fwrt->geo_profiles[i].bands[j].chains[k] =
fwrt->geo_profiles[i].bands[1].chains[k];
} else {
entry = &wifi_pkg->package.elements[idx++];
entry = &wifi_pkg->package.elements[entry_idx];
entry_idx++;
if (entry->type != ACPI_TYPE_INTEGER ||
entry->integer.value > U8_MAX) {
ret = -EINVAL;
Expand Down Expand Up @@ -822,14 +881,15 @@ bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt)
IWL_EXPORT_SYMBOL(iwl_sar_geo_support);

int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
struct iwl_per_chain_offset *table, u32 n_bands)
struct iwl_per_chain_offset *table,
u32 n_bands, u32 n_profiles)
{
int i, j;

if (!iwl_sar_geo_support(fwrt))
return -EOPNOTSUPP;

for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
for (i = 0; i < n_profiles; i++) {
for (j = 0; j < n_bands; j++) {
struct iwl_per_chain_offset *chain =
&table[i * n_bands + j];
Expand Down
39 changes: 23 additions & 16 deletions drivers/net/wireless/intel/iwlwifi/fw/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define ACPI_SAR_PROFILE_NUM 4

#define ACPI_NUM_GEO_PROFILES 3
#define ACPI_NUM_GEO_PROFILES_REV3 8
#define ACPI_GEO_PER_CHAIN_SIZE 3

#define ACPI_SAR_NUM_CHAINS_REV0 2
Expand Down Expand Up @@ -59,13 +60,6 @@
#define ACPI_GEO_NUM_BANDS_REV2 3
#define ACPI_GEO_NUM_CHAINS 2

#define ACPI_WGDS_WIFI_DATA_SIZE_REV0 (ACPI_NUM_GEO_PROFILES * \
ACPI_GEO_NUM_BANDS_REV0 * \
ACPI_GEO_PER_CHAIN_SIZE + 1)
#define ACPI_WGDS_WIFI_DATA_SIZE_REV2 (ACPI_NUM_GEO_PROFILES * \
ACPI_GEO_NUM_BANDS_REV2 * \
ACPI_GEO_PER_CHAIN_SIZE + 1)

#define ACPI_WRDD_WIFI_DATA_SIZE 2
#define ACPI_SPLC_WIFI_DATA_SIZE 2
#define ACPI_ECKV_WIFI_DATA_SIZE 2
Expand Down Expand Up @@ -159,10 +153,11 @@ int iwl_acpi_get_dsm_u8(struct device *dev, int rev, int func,
int iwl_acpi_get_dsm_u32(struct device *dev, int rev, int func,
const guid_t *guid, u32 *value);

union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
union acpi_object *data,
int data_size, int *tbl_rev);

union acpi_object *iwl_acpi_get_wifi_pkg_range(struct device *dev,
union acpi_object *data,
int min_data_size,
int max_data_size,
int *tbl_rev);
/**
* iwl_acpi_get_mcc - read MCC from ACPI, if available
*
Expand Down Expand Up @@ -199,7 +194,8 @@ int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt);
bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt);

int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
struct iwl_per_chain_offset *table, u32 n_bands);
struct iwl_per_chain_offset *table,
u32 n_bands, u32 n_profiles);

int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt, __le32 *block_list_array,
int *block_list_size);
Expand Down Expand Up @@ -231,10 +227,11 @@ static inline int iwl_acpi_get_dsm_u32(struct device *dev, int rev, int func,
return -ENOENT;
}

static inline union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
union acpi_object *data,
int data_size,
int *tbl_rev)
static inline union acpi_object *
iwl_acpi_get_wifi_pkg_range(struct device *dev,
union acpi_object *data,
int min_data_size, int max_data_size,
int *tbl_rev)
{
return ERR_PTR(-ENOENT);
}
Expand Down Expand Up @@ -294,4 +291,14 @@ static inline __le32 iwl_acpi_get_lari_config_bitmap(struct iwl_fw_runtime *fwrt
}

#endif /* CONFIG_ACPI */

static inline union acpi_object *
iwl_acpi_get_wifi_pkg(struct device *dev,
union acpi_object *data,
int data_size, int *tbl_rev)
{
return iwl_acpi_get_wifi_pkg_range(dev, data, data_size, data_size,
tbl_rev);
}

#endif /* __iwl_fw_acpi__ */
35 changes: 31 additions & 4 deletions drivers/net/wireless/intel/iwlwifi/fw/api/power.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
/*
* Copyright (C) 2012-2014, 2018-2020 Intel Corporation
* Copyright (C) 2012-2014, 2018-2021 Intel Corporation
* Copyright (C) 2013-2014 Intel Mobile Communications GmbH
* Copyright (C) 2015-2017 Intel Deutschland GmbH
*/
Expand Down Expand Up @@ -378,9 +378,10 @@ struct iwl_dev_tx_power_cmd {
};
};

#define IWL_NUM_GEO_PROFILES 3
#define IWL_NUM_BANDS_PER_CHAIN_V1 2
#define IWL_NUM_BANDS_PER_CHAIN_V2 3
#define IWL_NUM_GEO_PROFILES 3
#define IWL_NUM_GEO_PROFILES_V3 8
#define IWL_NUM_BANDS_PER_CHAIN_V1 2
#define IWL_NUM_BANDS_PER_CHAIN_V2 3

/**
* enum iwl_geo_per_chain_offset_operation - type of operation
Expand Down Expand Up @@ -438,10 +439,36 @@ struct iwl_geo_tx_power_profiles_cmd_v3 {
__le32 table_revision;
} __packed; /* GEO_TX_POWER_LIMIT_VER_3 */

/**
* struct iwl_geo_tx_power_profile_cmd_v4 - struct for GEO_TX_POWER_LIMIT cmd.
* @ops: operations, value from &enum iwl_geo_per_chain_offset_operation
* @table: offset profile per band.
* @table_revision: BIOS table revision.
*/
struct iwl_geo_tx_power_profiles_cmd_v4 {
__le32 ops;
struct iwl_per_chain_offset table[IWL_NUM_GEO_PROFILES_V3][IWL_NUM_BANDS_PER_CHAIN_V1];
__le32 table_revision;
} __packed; /* GEO_TX_POWER_LIMIT_VER_4 */

/**
* struct iwl_geo_tx_power_profile_cmd_v5 - struct for GEO_TX_POWER_LIMIT cmd.
* @ops: operations, value from &enum iwl_geo_per_chain_offset_operation
* @table: offset profile per band.
* @table_revision: BIOS table revision.
*/
struct iwl_geo_tx_power_profiles_cmd_v5 {
__le32 ops;
struct iwl_per_chain_offset table[IWL_NUM_GEO_PROFILES_V3][IWL_NUM_BANDS_PER_CHAIN_V2];
__le32 table_revision;
} __packed; /* GEO_TX_POWER_LIMIT_VER_5 */

union iwl_geo_tx_power_profiles_cmd {
struct iwl_geo_tx_power_profiles_cmd_v1 v1;
struct iwl_geo_tx_power_profiles_cmd_v2 v2;
struct iwl_geo_tx_power_profiles_cmd_v3 v3;
struct iwl_geo_tx_power_profiles_cmd_v4 v4;
struct iwl_geo_tx_power_profiles_cmd_v5 v5;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/intel/iwlwifi/fw/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ struct iwl_fw_runtime {
struct iwl_sar_profile sar_profiles[ACPI_SAR_PROFILE_NUM];
u8 sar_chain_a_profile;
u8 sar_chain_b_profile;
struct iwl_geo_profile geo_profiles[ACPI_NUM_GEO_PROFILES];
struct iwl_geo_profile geo_profiles[ACPI_NUM_GEO_PROFILES_REV3];
u32 geo_rev;
union iwl_ppag_table_cmd ppag_table;
u32 ppag_ver;
Expand Down
Loading

0 comments on commit 97f8a3d

Please sign in to comment.