Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 122 additions & 42 deletions drivers/net/wireless/apple/centauri/t6050/centauri_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ struct centauri_t6050_wifi {
u8 tx_defaults_applied;
struct ieee80211_supported_band bands[3];
struct ieee80211_channel channels[CEN_CHANNELS];
struct ieee80211_sband_iftype_data iftype_6ghz;
/* The station's HE capabilities per band: 2.4, 5 and 6 GHz. */
struct ieee80211_sband_iftype_data iftype_data[3];
/* The firmware's own reports, read at bring-up (system commands 19 and 8). */
u8 hw_channels[REPLY_SIZE], system_caps[REPLY_SIZE];
struct debugfs_blob_wrapper hw_channels_blob, system_caps_blob;
Expand Down Expand Up @@ -1119,17 +1120,23 @@ static void country_set(struct centauri_t6050_wifi *wifi, const u8 country[3])
}

/*
* 6 GHz needs HE: the station's HE capabilities element as the firmware
* reports it (capabilities TLV 0xff), with the 6 GHz band capabilities taken
* from its VHT element (TLV 0xbf). Without them the band is not registered.
* The station's HT, VHT and HE capabilities as the firmware reports them
* (system command 8): the HT element at offset 87 of TLV 262, the VHT element
* (TLV 0xbf) and the HE capabilities element (TLV 0xff). HT applies to 2.4 and
* 5 GHz, VHT to 5 GHz and HE to all three bands, without 40 MHz on 2.4 GHz
* where the firmware does not list it and without 160 MHz there. The 6 GHz
* band capabilities come from the VHT element. A band keeps what it has when
* its element is missing; without HE, 6 GHz is not registered.
*/
static bool he_6ghz_from_firmware(struct centauri_t6050_wifi *wifi)
static bool band_caps_from_firmware(struct centauri_t6050_wifi *wifi)
{
struct ieee80211_sband_iftype_data *data = &wifi->iftype_6ghz;
struct ieee80211_sta_he_cap *he = &data->he_cap;
const u8 *caps = wifi->system_caps, *he_elem = NULL, *vht = NULL;
size_t size = wifi->system_caps_blob.size, pos = 0, mcs;
const u8 *caps = wifi->system_caps;
const u8 *ht_elem = NULL, *vht_elem = NULL, *he_elem = NULL;
size_t size = wifi->system_caps_blob.size, pos = 0, mcs, ppe;
struct ieee80211_sta_he_cap base_he = {};
unsigned int band;
u32 vht_cap = 0;
u8 ampdu_density = 0;

while (pos + 4 <= size) {
u16 tag = get_unaligned_le16(caps + pos);
Expand All @@ -1138,43 +1145,118 @@ static bool he_6ghz_from_firmware(struct centauri_t6050_wifi *wifi)

if (length > size - pos - 4)
break;
if (tag == 262 &&
length >= 87 + 2 + sizeof(struct ieee80211_ht_cap) &&
value[87] == WLAN_EID_HT_CAPABILITY &&
value[88] == sizeof(struct ieee80211_ht_cap))
ht_elem = value + 87;
if (tag == WLAN_EID_VHT_CAPABILITY &&
length >= 2 + sizeof(struct ieee80211_vht_cap) &&
value[0] == WLAN_EID_VHT_CAPABILITY &&
value[1] == sizeof(struct ieee80211_vht_cap))
vht_elem = value;
if (tag == WLAN_EID_EXTENSION && length >= 3 + 6 + 11 + 4 &&
value[0] == WLAN_EID_EXTENSION && value[1] == length - 2 &&
value[2] == WLAN_EID_EXT_HE_CAPABILITY)
value[2] == WLAN_EID_EXT_HE_CAPABILITY &&
ieee80211_he_capa_size_ok(value + 3, value[1] - 1))
he_elem = value;
if (tag == WLAN_EID_VHT_CAPABILITY && length >= 2 + 12 &&
value[0] == WLAN_EID_VHT_CAPABILITY)
vht = value;
pos += 4 + length;
}

if (ht_elem) {
const struct ieee80211_ht_cap *ht =
(const struct ieee80211_ht_cap *)(ht_elem + 2);
struct ieee80211_sta_ht_cap ht_cap = {
.ht_supported = true,
.cap = le16_to_cpu(ht->cap_info),
.ampdu_factor = ht->ampdu_params_info &
IEEE80211_HT_AMPDU_PARM_FACTOR,
.ampdu_density = FIELD_GET(IEEE80211_HT_AMPDU_PARM_DENSITY,
ht->ampdu_params_info),
.mcs = ht->mcs,
};

wifi->bands[0].ht_cap = ht_cap;
wifi->bands[1].ht_cap = ht_cap;
ampdu_density = ht_cap.ampdu_density;
}

if (vht_elem) {
struct ieee80211_sta_vht_cap *vht = &wifi->bands[1].vht_cap;

vht_cap = get_unaligned_le32(vht_elem + 2);
vht->vht_supported = true;
vht->cap = vht_cap;
memcpy(&vht->vht_mcs, vht_elem + 6, sizeof(vht->vht_mcs));
}

if (!he_elem)
return false;
memcpy(&he->he_cap_elem, he_elem + 3, sizeof(he->he_cap_elem));
mcs = he_elem[1] - 1 - sizeof(he->he_cap_elem);
memcpy(&he->he_mcs_nss_supp, he_elem + 3 + sizeof(he->he_cap_elem),
min(mcs, sizeof(he->he_mcs_nss_supp)));
if (mcs > sizeof(he->he_mcs_nss_supp))
memcpy(he->ppe_thres,
he_elem + 3 + sizeof(he->he_cap_elem) +
sizeof(he->he_mcs_nss_supp),
min(mcs - sizeof(he->he_mcs_nss_supp),
sizeof(he->ppe_thres)));
he->has_he = true;
if (vht)
vht_cap = get_unaligned_le32(vht + 2);
data->he_6ghz_capa.capa = cpu_to_le16(
u16_encode_bits(u32_get_bits(vht_cap,
IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK),
IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP) |
u16_encode_bits(vht_cap & IEEE80211_VHT_CAP_MAX_MPDU_MASK,
IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN) |
u16_encode_bits(WLAN_HT_CAP_SM_PS_DISABLED,
IEEE80211_HE_6GHZ_CAP_SM_PS) |
(vht_cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN ?
IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS : 0) |
(vht_cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN ?
IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS : 0));
data->types_mask = BIT(NL80211_IFTYPE_STATION);

/*
* The MCS maps follow the fixed fields: 80 MHz always, 160 and 80+80
* only when the width set lists them (ieee80211_he_capa_size_ok()
* checked the length). A map the element leaves out is unsupported.
*/
memcpy(&base_he.he_cap_elem, he_elem + 3, sizeof(base_he.he_cap_elem));
memset(&base_he.he_mcs_nss_supp, 0xff, sizeof(base_he.he_mcs_nss_supp));
mcs = ieee80211_he_mcs_nss_size(&base_he.he_cap_elem);
memcpy(&base_he.he_mcs_nss_supp,
he_elem + 3 + sizeof(base_he.he_cap_elem), mcs);
ppe = he_elem[1] - 1 - sizeof(base_he.he_cap_elem) - mcs;
if (base_he.he_cap_elem.phy_cap_info[6] &
IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT)
memcpy(base_he.ppe_thres,
he_elem + 3 + sizeof(base_he.he_cap_elem) + mcs,
min(ppe, sizeof(base_he.ppe_thres)));
base_he.has_he = true;

for (band = 0; band < ARRAY_SIZE(wifi->iftype_data); band++) {
struct ieee80211_sband_iftype_data *data =
&wifi->iftype_data[band];
struct ieee80211_he_mcs_nss_supp *he_mcs =
&data->he_cap.he_mcs_nss_supp;

memset(data, 0, sizeof(*data));
data->types_mask = BIT(NL80211_IFTYPE_STATION);
data->he_cap = base_he;
if (band == 0) {
u8 *phy = data->he_cap.he_cap_elem.phy_cap_info;

/* Nothing wider than 40 MHz exists on 2.4 GHz. */
phy[0] &= IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G;
phy[1] &= ~IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK;
phy[4] &= ~IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_MASK;
phy[5] &= ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK;
phy[8] &= ~(IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU);
he_mcs->rx_mcs_160 = cpu_to_le16(0xffff);
he_mcs->tx_mcs_160 = cpu_to_le16(0xffff);
he_mcs->rx_mcs_80p80 = cpu_to_le16(0xffff);
he_mcs->tx_mcs_80p80 = cpu_to_le16(0xffff);
} else {
data->he_cap.he_cap_elem.phy_cap_info[0] &=
~(IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G |
IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G);
}
if (band == 2)
data->he_6ghz_capa.capa = cpu_to_le16(
u16_encode_bits(ampdu_density,
IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START) |
u16_encode_bits(u32_get_bits(vht_cap,
IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK),
IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP) |
u16_encode_bits(vht_cap & IEEE80211_VHT_CAP_MAX_MPDU_MASK,
IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN) |
u16_encode_bits(WLAN_HT_CAP_SM_PS_DISABLED,
IEEE80211_HE_6GHZ_CAP_SM_PS) |
(vht_cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN ?
IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS : 0) |
(vht_cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN ?
IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS : 0));
_ieee80211_set_sband_iftype_data(&wifi->bands[band], data, 1);
}
return true;
}

Expand Down Expand Up @@ -1216,9 +1298,7 @@ static void bands_init(struct centauri_t6050_wifi *wifi)
}
wifi->wiphy->bands[NL80211_BAND_2GHZ] = &wifi->bands[0];
wifi->wiphy->bands[NL80211_BAND_5GHZ] = &wifi->bands[1];
if (he_6ghz_from_firmware(wifi)) {
_ieee80211_set_sband_iftype_data(&wifi->bands[2],
&wifi->iftype_6ghz, 1);
if (band_caps_from_firmware(wifi)) {
wifi->wiphy->bands[NL80211_BAND_6GHZ] = &wifi->bands[2];
} else {
dev_warn(&wifi->control->pdev->dev,
Expand Down