| 1 |
// SPDX-License-Identifier: BSD-3-Clause-Clear |
| 2 |
/* Copyright (C) 2020 MediaTek Inc. */ |
| 3 |
|
| 4 |
#include <linux/devcoredump.h> |
| 5 |
#include <linux/etherdevice.h> |
| 6 |
#include <linux/timekeeping.h> |
| 7 |
#include "mt7921.h" |
| 8 |
#include "../dma.h" |
| 9 |
#include "../mt76_connac2_mac.h" |
| 10 |
#include "mcu.h" |
| 11 |
|
| 12 |
#define MT_WTBL_TXRX_CAP_RATE_OFFSET 7 |
| 13 |
#define MT_WTBL_TXRX_RATE_G2_HE 24 |
| 14 |
#define MT_WTBL_TXRX_RATE_G2 12 |
| 15 |
|
| 16 |
#define MT_WTBL_AC0_CTT_OFFSET 20 |
| 17 |
|
| 18 |
bool mt7921_mac_wtbl_update(struct mt792x_dev *dev, int idx, u32 mask) |
| 19 |
{ |
| 20 |
mt76_rmw(dev, MT_WTBL_UPDATE, MT_WTBL_UPDATE_WLAN_IDX, |
| 21 |
FIELD_PREP(MT_WTBL_UPDATE_WLAN_IDX, idx) | mask); |
| 22 |
|
| 23 |
return mt76_poll(dev, MT_WTBL_UPDATE, MT_WTBL_UPDATE_BUSY, |
| 24 |
0, 5000); |
| 25 |
} |
| 26 |
|
| 27 |
static u32 mt7921_mac_wtbl_lmac_addr(int idx, u8 offset) |
| 28 |
{ |
| 29 |
return MT_WTBL_LMAC_OFFS(idx, 0) + offset * 4; |
| 30 |
} |
| 31 |
|
| 32 |
static void mt7921_mac_sta_poll(struct mt792x_dev *dev) |
| 33 |
{ |
| 34 |
static const u8 ac_to_tid[] = { |
| 35 |
[IEEE80211_AC_BE] = 0, |
| 36 |
[IEEE80211_AC_BK] = 1, |
| 37 |
[IEEE80211_AC_VI] = 4, |
| 38 |
[IEEE80211_AC_VO] = 6 |
| 39 |
}; |
| 40 |
struct ieee80211_sta *sta; |
| 41 |
struct mt792x_sta *msta; |
| 42 |
struct mt792x_link_sta *mlink; |
| 43 |
u32 tx_time[IEEE80211_NUM_ACS], rx_time[IEEE80211_NUM_ACS]; |
| 44 |
LIST_HEAD(sta_poll_list); |
| 45 |
struct rate_info *rate; |
| 46 |
s8 rssi[4]; |
| 47 |
int i; |
| 48 |
|
| 49 |
spin_lock_bh(&dev->mt76.sta_poll_lock); |
| 50 |
list_splice_init(&dev->mt76.sta_poll_list, &sta_poll_list); |
| 51 |
spin_unlock_bh(&dev->mt76.sta_poll_lock); |
| 52 |
|
| 53 |
while (true) { |
| 54 |
bool clear = false; |
| 55 |
u32 addr, val; |
| 56 |
u16 idx; |
| 57 |
u8 bw; |
| 58 |
|
| 59 |
spin_lock_bh(&dev->mt76.sta_poll_lock); |
| 60 |
if (list_empty(&sta_poll_list)) { |
| 61 |
spin_unlock_bh(&dev->mt76.sta_poll_lock); |
| 62 |
break; |
| 63 |
} |
| 64 |
mlink = list_first_entry(&sta_poll_list, |
| 65 |
struct mt792x_link_sta, |
| 66 |
wcid.poll_list); |
| 67 |
msta = container_of(mlink, struct mt792x_sta, deflink); |
| 68 |
list_del_init(&mlink->wcid.poll_list); |
| 69 |
spin_unlock_bh(&dev->mt76.sta_poll_lock); |
| 70 |
|
| 71 |
idx = mlink->wcid.idx; |
| 72 |
addr = mt7921_mac_wtbl_lmac_addr(idx, MT_WTBL_AC0_CTT_OFFSET); |
| 73 |
|
| 74 |
for (i = 0; i < IEEE80211_NUM_ACS; i++) { |
| 75 |
u32 tx_last = mlink->airtime_ac[i]; |
| 76 |
u32 rx_last = mlink->airtime_ac[i + 4]; |
| 77 |
|
| 78 |
mlink->airtime_ac[i] = mt76_rr(dev, addr); |
| 79 |
mlink->airtime_ac[i + 4] = mt76_rr(dev, addr + 4); |
| 80 |
|
| 81 |
tx_time[i] = mlink->airtime_ac[i] - tx_last; |
| 82 |
rx_time[i] = mlink->airtime_ac[i + 4] - rx_last; |
| 83 |
|
| 84 |
if ((tx_last | rx_last) & BIT(30)) |
| 85 |
clear = true; |
| 86 |
|
| 87 |
addr += 8; |
| 88 |
} |
| 89 |
|
| 90 |
if (clear) { |
| 91 |
mt7921_mac_wtbl_update(dev, idx, |
| 92 |
MT_WTBL_UPDATE_ADM_COUNT_CLEAR); |
| 93 |
memset(mlink->airtime_ac, 0, sizeof(mlink->airtime_ac)); |
| 94 |
} |
| 95 |
|
| 96 |
if (!mlink->wcid.sta) |
| 97 |
continue; |
| 98 |
|
| 99 |
sta = container_of((void *)msta, struct ieee80211_sta, |
| 100 |
drv_priv); |
| 101 |
for (i = 0; i < IEEE80211_NUM_ACS; i++) { |
| 102 |
u8 q = mt76_connac_lmac_mapping(i); |
| 103 |
u32 tx_cur = tx_time[q]; |
| 104 |
u32 rx_cur = rx_time[q]; |
| 105 |
u8 tid = ac_to_tid[i]; |
| 106 |
|
| 107 |
if (!tx_cur && !rx_cur) |
| 108 |
continue; |
| 109 |
|
| 110 |
ieee80211_sta_register_airtime(sta, tid, tx_cur, |
| 111 |
rx_cur); |
| 112 |
} |
| 113 |
|
| 114 |
/* We don't support reading GI info from txs packets. |
| 115 |
* For accurate tx status reporting and AQL improvement, |
| 116 |
* we need to make sure that flags match so polling GI |
| 117 |
* from per-sta counters directly. |
| 118 |
*/ |
| 119 |
rate = &mlink->wcid.rate; |
| 120 |
addr = mt7921_mac_wtbl_lmac_addr(idx, |
| 121 |
MT_WTBL_TXRX_CAP_RATE_OFFSET); |
| 122 |
val = mt76_rr(dev, addr); |
| 123 |
|
| 124 |
switch (rate->bw) { |
| 125 |
case RATE_INFO_BW_160: |
| 126 |
bw = IEEE80211_STA_RX_BW_160; |
| 127 |
break; |
| 128 |
case RATE_INFO_BW_80: |
| 129 |
bw = IEEE80211_STA_RX_BW_80; |
| 130 |
break; |
| 131 |
case RATE_INFO_BW_40: |
| 132 |
bw = IEEE80211_STA_RX_BW_40; |
| 133 |
break; |
| 134 |
default: |
| 135 |
bw = IEEE80211_STA_RX_BW_20; |
| 136 |
break; |
| 137 |
} |
| 138 |
|
| 139 |
if (rate->flags & RATE_INFO_FLAGS_HE_MCS) { |
| 140 |
u8 offs = MT_WTBL_TXRX_RATE_G2_HE + 2 * bw; |
| 141 |
|
| 142 |
rate->he_gi = (val & (0x3 << offs)) >> offs; |
| 143 |
} else if (rate->flags & |
| 144 |
(RATE_INFO_FLAGS_VHT_MCS | RATE_INFO_FLAGS_MCS)) { |
| 145 |
if (val & BIT(MT_WTBL_TXRX_RATE_G2 + bw)) |
| 146 |
rate->flags |= RATE_INFO_FLAGS_SHORT_GI; |
| 147 |
else |
| 148 |
rate->flags &= ~RATE_INFO_FLAGS_SHORT_GI; |
| 149 |
} |
| 150 |
|
| 151 |
/* get signal strength of resp frames (CTS/BA/ACK) */ |
| 152 |
addr = mt7921_mac_wtbl_lmac_addr(idx, 30); |
| 153 |
val = mt76_rr(dev, addr); |
| 154 |
|
| 155 |
rssi[0] = to_rssi(GENMASK(7, 0), val); |
| 156 |
rssi[1] = to_rssi(GENMASK(15, 8), val); |
| 157 |
rssi[2] = to_rssi(GENMASK(23, 16), val); |
| 158 |
rssi[3] = to_rssi(GENMASK(31, 14), val); |
| 159 |
|
| 160 |
mlink->ack_signal = |
| 161 |
mt76_rx_signal(msta->vif->phy->mt76->antenna_mask, rssi); |
| 162 |
|
| 163 |
ewma_avg_signal_add(&mlink->avg_ack_signal, -mlink->ack_signal); |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
static int |
| 168 |
mt7921_mac_fill_rx(struct mt792x_dev *dev, struct sk_buff *skb) |
| 169 |
{ |
| 170 |
u32 csum_mask = MT_RXD0_NORMAL_IP_SUM | MT_RXD0_NORMAL_UDP_TCP_SUM; |
| 171 |
struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; |
| 172 |
bool hdr_trans, unicast, insert_ccmp_hdr = false; |
| 173 |
u8 chfreq, qos_ctl = 0, remove_pad, amsdu_info; |
| 174 |
u16 hdr_gap; |
| 175 |
__le32 *rxv = NULL, *rxd = (__le32 *)skb->data; |
| 176 |
struct mt76_phy *mphy = &dev->mt76.phy; |
| 177 |
struct mt792x_phy *phy = &dev->phy; |
| 178 |
struct ieee80211_supported_band *sband; |
| 179 |
u32 csum_status = *(u32 *)skb->cb; |
| 180 |
u32 rxd0 = le32_to_cpu(rxd[0]); |
| 181 |
u32 rxd1 = le32_to_cpu(rxd[1]); |
| 182 |
u32 rxd2 = le32_to_cpu(rxd[2]); |
| 183 |
u32 rxd3 = le32_to_cpu(rxd[3]); |
| 184 |
u32 rxd4 = le32_to_cpu(rxd[4]); |
| 185 |
struct mt792x_sta *msta = NULL; |
| 186 |
struct mt792x_link_sta *mlink; |
| 187 |
u16 seq_ctrl = 0; |
| 188 |
__le16 fc = 0; |
| 189 |
u8 mode = 0; |
| 190 |
int i, idx; |
| 191 |
|
| 192 |
memset(status, 0, sizeof(*status)); |
| 193 |
|
| 194 |
if (rxd1 & MT_RXD1_NORMAL_BAND_IDX) |
| 195 |
return -EINVAL; |
| 196 |
|
| 197 |
if (!test_bit(MT76_STATE_RUNNING, &mphy->state)) |
| 198 |
return -EINVAL; |
| 199 |
|
| 200 |
if (rxd2 & MT_RXD2_NORMAL_AMSDU_ERR) |
| 201 |
return -EINVAL; |
| 202 |
|
| 203 |
hdr_trans = rxd2 & MT_RXD2_NORMAL_HDR_TRANS; |
| 204 |
if (hdr_trans && (rxd1 & MT_RXD1_NORMAL_CM)) |
| 205 |
return -EINVAL; |
| 206 |
|
| 207 |
/* ICV error or CCMP/BIP/WPI MIC error */ |
| 208 |
if (rxd1 & MT_RXD1_NORMAL_ICV_ERR) |
| 209 |
status->flag |= RX_FLAG_ONLY_MONITOR; |
| 210 |
|
| 211 |
chfreq = FIELD_GET(MT_RXD3_NORMAL_CH_FREQ, rxd3); |
| 212 |
unicast = FIELD_GET(MT_RXD3_NORMAL_ADDR_TYPE, rxd3) == MT_RXD3_NORMAL_U2M; |
| 213 |
idx = FIELD_GET(MT_RXD1_NORMAL_WLAN_IDX, rxd1); |
| 214 |
status->wcid = mt792x_rx_get_wcid(dev, idx, unicast); |
| 215 |
|
| 216 |
if (status->wcid) { |
| 217 |
mlink = container_of(status->wcid, struct mt792x_link_sta, wcid); |
| 218 |
msta = container_of(mlink, struct mt792x_sta, deflink); |
| 219 |
mt76_wcid_add_poll(&dev->mt76, &mlink->wcid); |
| 220 |
} |
| 221 |
|
| 222 |
mt792x_get_status_freq_info(status, chfreq); |
| 223 |
|
| 224 |
switch (status->band) { |
| 225 |
case NL80211_BAND_5GHZ: |
| 226 |
sband = &mphy->sband_5g.sband; |
| 227 |
break; |
| 228 |
case NL80211_BAND_6GHZ: |
| 229 |
sband = &mphy->sband_6g.sband; |
| 230 |
break; |
| 231 |
default: |
| 232 |
sband = &mphy->sband_2g.sband; |
| 233 |
break; |
| 234 |
} |
| 235 |
|
| 236 |
if (!sband->channels) |
| 237 |
return -EINVAL; |
| 238 |
|
| 239 |
if (mt76_is_mmio(&dev->mt76) && (rxd0 & csum_mask) == csum_mask && |
| 240 |
!(csum_status & (BIT(0) | BIT(2) | BIT(3)))) |
| 241 |
skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 242 |
|
| 243 |
if (rxd1 & MT_RXD1_NORMAL_FCS_ERR) |
| 244 |
status->flag |= RX_FLAG_FAILED_FCS_CRC; |
| 245 |
|
| 246 |
if (rxd1 & MT_RXD1_NORMAL_TKIP_MIC_ERR) |
| 247 |
status->flag |= RX_FLAG_MMIC_ERROR; |
| 248 |
|
| 249 |
if (FIELD_GET(MT_RXD1_NORMAL_SEC_MODE, rxd1) != 0 && |
| 250 |
!(rxd1 & (MT_RXD1_NORMAL_CLM | MT_RXD1_NORMAL_CM))) { |
| 251 |
status->flag |= RX_FLAG_DECRYPTED; |
| 252 |
status->flag |= RX_FLAG_IV_STRIPPED; |
| 253 |
status->flag |= RX_FLAG_MMIC_STRIPPED | RX_FLAG_MIC_STRIPPED; |
| 254 |
} |
| 255 |
|
| 256 |
remove_pad = FIELD_GET(MT_RXD2_NORMAL_HDR_OFFSET, rxd2); |
| 257 |
|
| 258 |
if (rxd2 & MT_RXD2_NORMAL_MAX_LEN_ERROR) |
| 259 |
return -EINVAL; |
| 260 |
|
| 261 |
rxd += 6; |
| 262 |
if (rxd1 & MT_RXD1_NORMAL_GROUP_4) { |
| 263 |
u32 v0 = le32_to_cpu(rxd[0]); |
| 264 |
u32 v2 = le32_to_cpu(rxd[2]); |
| 265 |
|
| 266 |
fc = cpu_to_le16(FIELD_GET(MT_RXD6_FRAME_CONTROL, v0)); |
| 267 |
seq_ctrl = FIELD_GET(MT_RXD8_SEQ_CTRL, v2); |
| 268 |
qos_ctl = FIELD_GET(MT_RXD8_QOS_CTL, v2); |
| 269 |
|
| 270 |
rxd += 4; |
| 271 |
if ((u8 *)rxd - skb->data >= skb->len) |
| 272 |
return -EINVAL; |
| 273 |
} |
| 274 |
|
| 275 |
if (rxd1 & MT_RXD1_NORMAL_GROUP_1) { |
| 276 |
u8 *data = (u8 *)rxd; |
| 277 |
|
| 278 |
if (status->flag & RX_FLAG_DECRYPTED) { |
| 279 |
switch (FIELD_GET(MT_RXD1_NORMAL_SEC_MODE, rxd1)) { |
| 280 |
case MT_CIPHER_AES_CCMP: |
| 281 |
case MT_CIPHER_CCMP_CCX: |
| 282 |
case MT_CIPHER_CCMP_256: |
| 283 |
insert_ccmp_hdr = |
| 284 |
FIELD_GET(MT_RXD2_NORMAL_FRAG, rxd2); |
| 285 |
fallthrough; |
| 286 |
case MT_CIPHER_TKIP: |
| 287 |
case MT_CIPHER_TKIP_NO_MIC: |
| 288 |
case MT_CIPHER_GCMP: |
| 289 |
case MT_CIPHER_GCMP_256: |
| 290 |
status->iv[0] = data[5]; |
| 291 |
status->iv[1] = data[4]; |
| 292 |
status->iv[2] = data[3]; |
| 293 |
status->iv[3] = data[2]; |
| 294 |
status->iv[4] = data[1]; |
| 295 |
status->iv[5] = data[0]; |
| 296 |
break; |
| 297 |
default: |
| 298 |
break; |
| 299 |
} |
| 300 |
} |
| 301 |
rxd += 4; |
| 302 |
if ((u8 *)rxd - skb->data >= skb->len) |
| 303 |
return -EINVAL; |
| 304 |
} |
| 305 |
|
| 306 |
if (rxd1 & MT_RXD1_NORMAL_GROUP_2) { |
| 307 |
status->timestamp = le32_to_cpu(rxd[0]); |
| 308 |
status->flag |= RX_FLAG_MACTIME_START; |
| 309 |
|
| 310 |
if (!(rxd2 & MT_RXD2_NORMAL_NON_AMPDU)) { |
| 311 |
status->flag |= RX_FLAG_AMPDU_DETAILS; |
| 312 |
|
| 313 |
/* all subframes of an A-MPDU have the same timestamp */ |
| 314 |
if (phy->rx_ampdu_ts != status->timestamp) { |
| 315 |
if (!++phy->ampdu_ref) |
| 316 |
phy->ampdu_ref++; |
| 317 |
} |
| 318 |
phy->rx_ampdu_ts = status->timestamp; |
| 319 |
|
| 320 |
status->ampdu_ref = phy->ampdu_ref; |
| 321 |
} |
| 322 |
|
| 323 |
rxd += 2; |
| 324 |
if ((u8 *)rxd - skb->data >= skb->len) |
| 325 |
return -EINVAL; |
| 326 |
} |
| 327 |
|
| 328 |
/* RXD Group 3 - P-RXV */ |
| 329 |
if (rxd1 & MT_RXD1_NORMAL_GROUP_3) { |
| 330 |
u32 v0, v1; |
| 331 |
int ret; |
| 332 |
|
| 333 |
rxv = rxd; |
| 334 |
rxd += 2; |
| 335 |
if ((u8 *)rxd - skb->data >= skb->len) |
| 336 |
return -EINVAL; |
| 337 |
|
| 338 |
v0 = le32_to_cpu(rxv[0]); |
| 339 |
v1 = le32_to_cpu(rxv[1]); |
| 340 |
|
| 341 |
if (v0 & MT_PRXV_HT_AD_CODE) |
| 342 |
status->enc_flags |= RX_ENC_FLAG_LDPC; |
| 343 |
|
| 344 |
ret = mt76_connac2_mac_fill_rx_rate(&dev->mt76, status, sband, |
| 345 |
rxv, &mode); |
| 346 |
if (ret < 0) |
| 347 |
return ret; |
| 348 |
|
| 349 |
if (rxd1 & MT_RXD1_NORMAL_GROUP_5) { |
| 350 |
rxd += 6; |
| 351 |
if ((u8 *)rxd - skb->data >= skb->len) |
| 352 |
return -EINVAL; |
| 353 |
|
| 354 |
rxv = rxd; |
| 355 |
/* Monitor mode would use RCPI described in GROUP 5 |
| 356 |
* instead. |
| 357 |
*/ |
| 358 |
v1 = le32_to_cpu(rxv[0]); |
| 359 |
|
| 360 |
rxd += 12; |
| 361 |
if ((u8 *)rxd - skb->data >= skb->len) |
| 362 |
return -EINVAL; |
| 363 |
} |
| 364 |
|
| 365 |
status->chains = mphy->antenna_mask; |
| 366 |
status->chain_signal[0] = to_rssi(MT_PRXV_RCPI0, v1); |
| 367 |
status->chain_signal[1] = to_rssi(MT_PRXV_RCPI1, v1); |
| 368 |
status->chain_signal[2] = to_rssi(MT_PRXV_RCPI2, v1); |
| 369 |
status->chain_signal[3] = to_rssi(MT_PRXV_RCPI3, v1); |
| 370 |
status->signal = -128; |
| 371 |
for (i = 0; i < hweight8(mphy->antenna_mask); i++) { |
| 372 |
if (!(status->chains & BIT(i)) || |
| 373 |
status->chain_signal[i] >= 0) |
| 374 |
continue; |
| 375 |
|
| 376 |
status->signal = max(status->signal, |
| 377 |
status->chain_signal[i]); |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
amsdu_info = FIELD_GET(MT_RXD4_NORMAL_PAYLOAD_FORMAT, rxd4); |
| 382 |
status->amsdu = !!amsdu_info; |
| 383 |
if (status->amsdu) { |
| 384 |
status->first_amsdu = amsdu_info == MT_RXD4_FIRST_AMSDU_FRAME; |
| 385 |
status->last_amsdu = amsdu_info == MT_RXD4_LAST_AMSDU_FRAME; |
| 386 |
} |
| 387 |
|
| 388 |
hdr_gap = (u8 *)rxd - skb->data + 2 * remove_pad; |
| 389 |
if (hdr_trans && ieee80211_has_morefrags(fc)) { |
| 390 |
struct ieee80211_vif *vif; |
| 391 |
int err; |
| 392 |
|
| 393 |
if (!msta || !msta->vif) |
| 394 |
return -EINVAL; |
| 395 |
|
| 396 |
vif = container_of((void *)msta->vif, struct ieee80211_vif, |
| 397 |
drv_priv); |
| 398 |
err = mt76_connac2_reverse_frag0_hdr_trans(vif, skb, hdr_gap); |
| 399 |
if (err) |
| 400 |
return err; |
| 401 |
|
| 402 |
hdr_trans = false; |
| 403 |
} else { |
| 404 |
skb_pull(skb, hdr_gap); |
| 405 |
if (!hdr_trans && status->amsdu) { |
| 406 |
memmove(skb->data + 2, skb->data, |
| 407 |
ieee80211_get_hdrlen_from_skb(skb)); |
| 408 |
skb_pull(skb, 2); |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
if (!hdr_trans) { |
| 413 |
struct ieee80211_hdr *hdr; |
| 414 |
|
| 415 |
if (insert_ccmp_hdr) { |
| 416 |
u8 key_id = FIELD_GET(MT_RXD1_NORMAL_KEY_ID, rxd1); |
| 417 |
|
| 418 |
mt76_insert_ccmp_hdr(skb, key_id); |
| 419 |
} |
| 420 |
|
| 421 |
hdr = mt76_skb_get_hdr(skb); |
| 422 |
fc = hdr->frame_control; |
| 423 |
if (ieee80211_is_data_qos(fc)) { |
| 424 |
seq_ctrl = le16_to_cpu(hdr->seq_ctrl); |
| 425 |
qos_ctl = *ieee80211_get_qos_ctl(hdr); |
| 426 |
} |
| 427 |
} else { |
| 428 |
status->flag |= RX_FLAG_8023; |
| 429 |
} |
| 430 |
|
| 431 |
mt792x_mac_assoc_rssi(dev, skb); |
| 432 |
|
| 433 |
if (rxv && mode >= MT_PHY_TYPE_HE_SU && !(status->flag & RX_FLAG_8023)) |
| 434 |
mt76_connac2_mac_decode_he_radiotap(&dev->mt76, skb, rxv, mode); |
| 435 |
|
| 436 |
if (!status->wcid || !ieee80211_is_data_qos(fc)) |
| 437 |
return 0; |
| 438 |
|
| 439 |
status->aggr = unicast && !ieee80211_is_qos_nullfunc(fc); |
| 440 |
status->seqno = IEEE80211_SEQ_TO_SN(seq_ctrl); |
| 441 |
status->qos_ctl = qos_ctl; |
| 442 |
|
| 443 |
return 0; |
| 444 |
} |
| 445 |
|
| 446 |
void mt7921_mac_add_txs(struct mt792x_dev *dev, void *data) |
| 447 |
{ |
| 448 |
struct mt792x_link_sta *mlink; |
| 449 |
struct mt76_wcid *wcid; |
| 450 |
__le32 *txs_data = data; |
| 451 |
u16 wcidx; |
| 452 |
u8 pid; |
| 453 |
|
| 454 |
if (le32_get_bits(txs_data[0], MT_TXS0_TXS_FORMAT) > 1) |
| 455 |
return; |
| 456 |
|
| 457 |
wcidx = le32_get_bits(txs_data[2], MT_TXS2_WCID); |
| 458 |
pid = le32_get_bits(txs_data[3], MT_TXS3_PID); |
| 459 |
|
| 460 |
if (pid < MT_PACKET_ID_FIRST) |
| 461 |
return; |
| 462 |
|
| 463 |
if (wcidx >= MT792x_WTBL_SIZE) |
| 464 |
return; |
| 465 |
|
| 466 |
rcu_read_lock(); |
| 467 |
|
| 468 |
wcid = mt76_wcid_ptr(dev, wcidx); |
| 469 |
if (!wcid) |
| 470 |
goto out; |
| 471 |
|
| 472 |
mlink = container_of(wcid, struct mt792x_link_sta, wcid); |
| 473 |
|
| 474 |
mt76_connac2_mac_add_txs_skb(&dev->mt76, wcid, pid, txs_data); |
| 475 |
if (!wcid->sta) |
| 476 |
goto out; |
| 477 |
|
| 478 |
mt76_wcid_add_poll(&dev->mt76, &mlink->wcid); |
| 479 |
|
| 480 |
out: |
| 481 |
rcu_read_unlock(); |
| 482 |
} |
| 483 |
|
| 484 |
static void mt7921_mac_tx_free(struct mt792x_dev *dev, void *data, int len) |
| 485 |
{ |
| 486 |
struct mt76_connac_tx_free *free = data; |
| 487 |
__le32 *tx_info = (__le32 *)(data + sizeof(*free)); |
| 488 |
struct mt76_dev *mdev = &dev->mt76; |
| 489 |
struct mt76_txwi_cache *txwi; |
| 490 |
struct ieee80211_sta *sta = NULL; |
| 491 |
struct mt76_wcid *wcid = NULL; |
| 492 |
struct sk_buff *skb, *tmp; |
| 493 |
void *end = data + len; |
| 494 |
LIST_HEAD(free_list); |
| 495 |
bool wake = false; |
| 496 |
u8 i, count; |
| 497 |
|
| 498 |
/* clean DMA queues and unmap buffers first */ |
| 499 |
mt76_queue_tx_cleanup(dev, dev->mphy.q_tx[MT_TXQ_PSD], false); |
| 500 |
mt76_queue_tx_cleanup(dev, dev->mphy.q_tx[MT_TXQ_BE], false); |
| 501 |
|
| 502 |
count = le16_get_bits(free->ctrl, MT_TX_FREE_MSDU_CNT); |
| 503 |
if (WARN_ON_ONCE((void *)&tx_info[count] > end)) |
| 504 |
return; |
| 505 |
|
| 506 |
for (i = 0; i < count; i++) { |
| 507 |
u32 msdu, info = le32_to_cpu(tx_info[i]); |
| 508 |
u8 stat; |
| 509 |
|
| 510 |
/* 1'b1: new wcid pair. |
| 511 |
* 1'b0: msdu_id with the same 'wcid pair' as above. |
| 512 |
*/ |
| 513 |
if (info & MT_TX_FREE_PAIR) { |
| 514 |
struct mt792x_link_sta *mlink; |
| 515 |
u16 idx; |
| 516 |
|
| 517 |
count++; |
| 518 |
idx = FIELD_GET(MT_TX_FREE_WLAN_ID, info); |
| 519 |
wcid = mt76_wcid_ptr(dev, idx); |
| 520 |
sta = wcid_to_sta(wcid); |
| 521 |
if (!sta) |
| 522 |
continue; |
| 523 |
|
| 524 |
mlink = container_of(wcid, struct mt792x_link_sta, wcid); |
| 525 |
mt76_wcid_add_poll(&dev->mt76, &mlink->wcid); |
| 526 |
continue; |
| 527 |
} |
| 528 |
|
| 529 |
msdu = FIELD_GET(MT_TX_FREE_MSDU_ID, info); |
| 530 |
stat = FIELD_GET(MT_TX_FREE_STATUS, info); |
| 531 |
|
| 532 |
if (wcid) { |
| 533 |
wcid->stats.tx_retries += |
| 534 |
FIELD_GET(MT_TX_FREE_COUNT, info) - 1; |
| 535 |
wcid->stats.tx_failed += !!stat; |
| 536 |
} |
| 537 |
|
| 538 |
txwi = mt76_token_release(mdev, msdu, &wake); |
| 539 |
if (!txwi) |
| 540 |
continue; |
| 541 |
|
| 542 |
mt76_connac2_txwi_free(mdev, txwi, sta, &free_list); |
| 543 |
} |
| 544 |
|
| 545 |
if (wake) |
| 546 |
mt76_set_tx_blocked(&dev->mt76, false); |
| 547 |
|
| 548 |
list_for_each_entry_safe(skb, tmp, &free_list, list) { |
| 549 |
skb_list_del_init(skb); |
| 550 |
napi_consume_skb(skb, 1); |
| 551 |
} |
| 552 |
|
| 553 |
rcu_read_lock(); |
| 554 |
mt7921_mac_sta_poll(dev); |
| 555 |
rcu_read_unlock(); |
| 556 |
|
| 557 |
mt76_worker_schedule(&dev->mt76.tx_worker); |
| 558 |
} |
| 559 |
|
| 560 |
bool mt7921_rx_check(struct mt76_dev *mdev, void *data, int len) |
| 561 |
{ |
| 562 |
struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); |
| 563 |
__le32 *rxd = (__le32 *)data; |
| 564 |
__le32 *end = (__le32 *)&rxd[len / 4]; |
| 565 |
enum rx_pkt_type type; |
| 566 |
|
| 567 |
type = le32_get_bits(rxd[0], MT_RXD0_PKT_TYPE); |
| 568 |
|
| 569 |
switch (type) { |
| 570 |
case PKT_TYPE_TXRX_NOTIFY: |
| 571 |
/* PKT_TYPE_TXRX_NOTIFY can be received only by mmio devices */ |
| 572 |
mt7921_mac_tx_free(dev, data, len); /* mmio */ |
| 573 |
return false; |
| 574 |
case PKT_TYPE_TXS: |
| 575 |
for (rxd += 2; rxd + 8 <= end; rxd += 8) |
| 576 |
mt7921_mac_add_txs(dev, rxd); |
| 577 |
return false; |
| 578 |
default: |
| 579 |
return true; |
| 580 |
} |
| 581 |
} |
| 582 |
EXPORT_SYMBOL_GPL(mt7921_rx_check); |
| 583 |
|
| 584 |
void mt7921_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, |
| 585 |
struct sk_buff *skb, u32 *info) |
| 586 |
{ |
| 587 |
struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); |
| 588 |
__le32 *rxd = (__le32 *)skb->data; |
| 589 |
__le32 *end = (__le32 *)&skb->data[skb->len]; |
| 590 |
enum rx_pkt_type type; |
| 591 |
u16 flag; |
| 592 |
|
| 593 |
type = le32_get_bits(rxd[0], MT_RXD0_PKT_TYPE); |
| 594 |
flag = le32_get_bits(rxd[0], MT_RXD0_PKT_FLAG); |
| 595 |
|
| 596 |
if (type == PKT_TYPE_RX_EVENT && flag == 0x1) |
| 597 |
type = PKT_TYPE_NORMAL_MCU; |
| 598 |
|
| 599 |
switch (type) { |
| 600 |
case PKT_TYPE_TXRX_NOTIFY: |
| 601 |
/* PKT_TYPE_TXRX_NOTIFY can be received only by mmio devices */ |
| 602 |
mt7921_mac_tx_free(dev, skb->data, skb->len); |
| 603 |
napi_consume_skb(skb, 1); |
| 604 |
break; |
| 605 |
case PKT_TYPE_RX_EVENT: |
| 606 |
mt7921_mcu_rx_event(dev, skb); |
| 607 |
break; |
| 608 |
case PKT_TYPE_TXS: |
| 609 |
for (rxd += 2; rxd + 8 <= end; rxd += 8) |
| 610 |
mt7921_mac_add_txs(dev, rxd); |
| 611 |
dev_kfree_skb(skb); |
| 612 |
break; |
| 613 |
case PKT_TYPE_NORMAL_MCU: |
| 614 |
case PKT_TYPE_NORMAL: |
| 615 |
if (!mt7921_mac_fill_rx(dev, skb)) { |
| 616 |
mt76_rx(&dev->mt76, q, skb); |
| 617 |
return; |
| 618 |
} |
| 619 |
fallthrough; |
| 620 |
default: |
| 621 |
dev_kfree_skb(skb); |
| 622 |
break; |
| 623 |
} |
| 624 |
} |
| 625 |
EXPORT_SYMBOL_GPL(mt7921_queue_rx_skb); |
| 626 |
|
| 627 |
static void |
| 628 |
mt7921_vif_connect_iter(void *priv, u8 *mac, |
| 629 |
struct ieee80211_vif *vif) |
| 630 |
{ |
| 631 |
struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; |
| 632 |
struct mt792x_dev *dev = mvif->phy->dev; |
| 633 |
struct ieee80211_hw *hw = mt76_hw(dev); |
| 634 |
|
| 635 |
if (vif->type == NL80211_IFTYPE_STATION) |
| 636 |
ieee80211_disconnect(vif, true); |
| 637 |
|
| 638 |
mt76_connac_mcu_uni_add_dev(&dev->mphy, &vif->bss_conf, |
| 639 |
&mvif->bss_conf.mt76, |
| 640 |
&mvif->sta.deflink.wcid, true); |
| 641 |
mt7921_mcu_set_tx(dev, vif); |
| 642 |
|
| 643 |
if (vif->type == NL80211_IFTYPE_AP) { |
| 644 |
mt76_connac_mcu_uni_add_bss(dev->phy.mt76, vif, &mvif->sta.deflink.wcid, |
| 645 |
true, NULL); |
| 646 |
mt7921_mcu_sta_update(dev, NULL, vif, true, |
| 647 |
MT76_STA_INFO_STATE_NONE); |
| 648 |
mt7921_mcu_uni_add_beacon_offload(dev, hw, vif, true); |
| 649 |
} |
| 650 |
} |
| 651 |
|
| 652 |
/* system error recovery */ |
| 653 |
void mt7921_mac_reset_work(struct work_struct *work) |
| 654 |
{ |
| 655 |
struct mt792x_dev *dev = container_of(work, struct mt792x_dev, |
| 656 |
reset_work); |
| 657 |
struct ieee80211_hw *hw = mt76_hw(dev); |
| 658 |
struct mt76_connac_pm *pm = &dev->pm; |
| 659 |
int i, ret; |
| 660 |
|
| 661 |
dev_dbg(dev->mt76.dev, "chip reset\n"); |
| 662 |
set_bit(MT76_RESET, &dev->mphy.state); |
| 663 |
dev->hw_full_reset = true; |
| 664 |
ieee80211_stop_queues(hw); |
| 665 |
|
| 666 |
cancel_delayed_work_sync(&dev->mphy.mac_work); |
| 667 |
cancel_delayed_work_sync(&pm->ps_work); |
| 668 |
cancel_work_sync(&pm->wake_work); |
| 669 |
|
| 670 |
for (i = 0; i < 10; i++) { |
| 671 |
mutex_lock(&dev->mt76.mutex); |
| 672 |
ret = mt792x_dev_reset(dev); |
| 673 |
mutex_unlock(&dev->mt76.mutex); |
| 674 |
|
| 675 |
if (!ret) |
| 676 |
break; |
| 677 |
} |
| 678 |
if (mt76_is_sdio(&dev->mt76) && atomic_read(&dev->mt76.bus_hung)) |
| 679 |
return; |
| 680 |
|
| 681 |
if (i == 10) |
| 682 |
dev_err(dev->mt76.dev, "chip reset failed\n"); |
| 683 |
|
| 684 |
if (test_and_clear_bit(MT76_HW_SCANNING, &dev->mphy.state)) { |
| 685 |
struct cfg80211_scan_info info = { |
| 686 |
.aborted = true, |
| 687 |
}; |
| 688 |
|
| 689 |
ieee80211_scan_completed(dev->mphy.hw, &info); |
| 690 |
} |
| 691 |
|
| 692 |
dev->hw_full_reset = false; |
| 693 |
clear_bit(MT76_RESET, &dev->mphy.state); |
| 694 |
pm->suspended = false; |
| 695 |
ieee80211_wake_queues(hw); |
| 696 |
ieee80211_iterate_active_interfaces(hw, |
| 697 |
IEEE80211_IFACE_ITER_RESUME_ALL, |
| 698 |
mt7921_vif_connect_iter, NULL); |
| 699 |
mt76_connac_power_save_sched(&dev->mt76.phy, pm); |
| 700 |
} |
| 701 |
|
| 702 |
void mt7921_coredump_work(struct work_struct *work) |
| 703 |
{ |
| 704 |
struct mt792x_dev *dev; |
| 705 |
char *dump, *data; |
| 706 |
|
| 707 |
dev = (struct mt792x_dev *)container_of(work, struct mt792x_dev, |
| 708 |
coredump.work.work); |
| 709 |
|
| 710 |
if (time_is_after_jiffies(dev->coredump.last_activity + |
| 711 |
4 * MT76_CONNAC_COREDUMP_TIMEOUT)) { |
| 712 |
queue_delayed_work(dev->mt76.wq, &dev->coredump.work, |
| 713 |
MT76_CONNAC_COREDUMP_TIMEOUT); |
| 714 |
return; |
| 715 |
} |
| 716 |
|
| 717 |
dump = vzalloc(MT76_CONNAC_COREDUMP_SZ); |
| 718 |
data = dump; |
| 719 |
|
| 720 |
while (true) { |
| 721 |
struct sk_buff *skb; |
| 722 |
|
| 723 |
spin_lock_bh(&dev->mt76.lock); |
| 724 |
skb = __skb_dequeue(&dev->coredump.msg_list); |
| 725 |
spin_unlock_bh(&dev->mt76.lock); |
| 726 |
|
| 727 |
if (!skb) |
| 728 |
break; |
| 729 |
|
| 730 |
skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd)); |
| 731 |
if (!dump || data + skb->len - dump > MT76_CONNAC_COREDUMP_SZ) { |
| 732 |
dev_kfree_skb(skb); |
| 733 |
continue; |
| 734 |
} |
| 735 |
|
| 736 |
memcpy(data, skb->data, skb->len); |
| 737 |
data += skb->len; |
| 738 |
|
| 739 |
dev_kfree_skb(skb); |
| 740 |
} |
| 741 |
|
| 742 |
if (dump) |
| 743 |
dev_coredumpv(dev->mt76.dev, dump, MT76_CONNAC_COREDUMP_SZ, |
| 744 |
GFP_KERNEL); |
| 745 |
|
| 746 |
mt792x_reset(&dev->mt76); |
| 747 |
} |
| 748 |
|
| 749 |
/* usb_sdio */ |
| 750 |
static void |
| 751 |
mt7921_usb_sdio_write_txwi(struct mt792x_dev *dev, struct mt76_wcid *wcid, |
| 752 |
enum mt76_txq_id qid, struct ieee80211_sta *sta, |
| 753 |
struct ieee80211_key_conf *key, int pid, |
| 754 |
struct sk_buff *skb) |
| 755 |
{ |
| 756 |
__le32 *txwi = (__le32 *)(skb->data - MT_SDIO_TXD_SIZE); |
| 757 |
|
| 758 |
memset(txwi, 0, MT_SDIO_TXD_SIZE); |
| 759 |
mt76_connac2_mac_write_txwi(&dev->mt76, txwi, skb, wcid, key, pid, qid, 0); |
| 760 |
skb_push(skb, MT_SDIO_TXD_SIZE); |
| 761 |
} |
| 762 |
|
| 763 |
int mt7921_usb_sdio_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| 764 |
enum mt76_txq_id qid, struct mt76_wcid *wcid, |
| 765 |
struct ieee80211_sta *sta, |
| 766 |
struct mt76_tx_info *tx_info) |
| 767 |
{ |
| 768 |
struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); |
| 769 |
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_info->skb); |
| 770 |
struct ieee80211_key_conf *key = info->control.hw_key; |
| 771 |
struct sk_buff *skb = tx_info->skb; |
| 772 |
int err, pad, pktid, type; |
| 773 |
|
| 774 |
if (unlikely(tx_info->skb->len <= ETH_HLEN)) |
| 775 |
return -EINVAL; |
| 776 |
|
| 777 |
err = skb_cow_head(skb, MT_SDIO_TXD_SIZE + MT_SDIO_HDR_SIZE); |
| 778 |
if (err) |
| 779 |
return err; |
| 780 |
|
| 781 |
if (!wcid) |
| 782 |
wcid = &dev->mt76.global_wcid; |
| 783 |
|
| 784 |
if (sta) { |
| 785 |
struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; |
| 786 |
|
| 787 |
if (time_after(jiffies, msta->deflink.last_txs + HZ / 4)) { |
| 788 |
info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; |
| 789 |
msta->deflink.last_txs = jiffies; |
| 790 |
} |
| 791 |
} |
| 792 |
|
| 793 |
pktid = mt76_tx_status_skb_add(&dev->mt76, wcid, skb); |
| 794 |
mt7921_usb_sdio_write_txwi(dev, wcid, qid, sta, key, pktid, skb); |
| 795 |
|
| 796 |
type = mt76_is_sdio(mdev) ? MT7921_SDIO_DATA : 0; |
| 797 |
mt792x_skb_add_usb_sdio_hdr(dev, skb, type); |
| 798 |
pad = round_up(skb->len, 4) - skb->len; |
| 799 |
if (mt76_is_usb(mdev)) |
| 800 |
pad += 4; |
| 801 |
|
| 802 |
err = mt76_skb_adjust_pad(skb, pad); |
| 803 |
if (err) |
| 804 |
/* Release pktid in case of error. */ |
| 805 |
idr_remove(&wcid->pktid, pktid); |
| 806 |
|
| 807 |
return err; |
| 808 |
} |
| 809 |
EXPORT_SYMBOL_GPL(mt7921_usb_sdio_tx_prepare_skb); |
| 810 |
|
| 811 |
void mt7921_usb_sdio_tx_complete_skb(struct mt76_dev *mdev, |
| 812 |
struct mt76_queue_entry *e) |
| 813 |
{ |
| 814 |
__le32 *txwi = (__le32 *)(e->skb->data + MT_SDIO_HDR_SIZE); |
| 815 |
unsigned int headroom = MT_SDIO_TXD_SIZE + MT_SDIO_HDR_SIZE; |
| 816 |
struct ieee80211_sta *sta; |
| 817 |
struct mt76_wcid *wcid; |
| 818 |
u16 idx; |
| 819 |
|
| 820 |
idx = le32_get_bits(txwi[1], MT_TXD1_WLAN_IDX); |
| 821 |
wcid = __mt76_wcid_ptr(mdev, idx); |
| 822 |
sta = wcid_to_sta(wcid); |
| 823 |
|
| 824 |
if (sta && likely(e->skb->protocol != cpu_to_be16(ETH_P_PAE))) |
| 825 |
mt76_connac2_tx_check_aggr(sta, txwi); |
| 826 |
|
| 827 |
skb_pull(e->skb, headroom); |
| 828 |
mt76_tx_complete_skb(mdev, e->wcid, e->skb); |
| 829 |
} |
| 830 |
EXPORT_SYMBOL_GPL(mt7921_usb_sdio_tx_complete_skb); |
| 831 |
|
| 832 |
bool mt7921_usb_sdio_tx_status_data(struct mt76_dev *mdev, u8 *update) |
| 833 |
{ |
| 834 |
struct mt792x_dev *dev = container_of(mdev, struct mt792x_dev, mt76); |
| 835 |
|
| 836 |
mt792x_mutex_acquire(dev); |
| 837 |
mt7921_mac_sta_poll(dev); |
| 838 |
mt792x_mutex_release(dev); |
| 839 |
|
| 840 |
return false; |
| 841 |
} |
| 842 |
EXPORT_SYMBOL_GPL(mt7921_usb_sdio_tx_status_data); |
| 843 |
|
| 844 |
#if IS_ENABLED(CONFIG_IPV6) |
| 845 |
void mt7921_set_ipv6_ns_work(struct work_struct *work) |
| 846 |
{ |
| 847 |
struct mt792x_dev *dev = container_of(work, struct mt792x_dev, |
| 848 |
ipv6_ns_work); |
| 849 |
struct sk_buff *skb; |
| 850 |
int ret = 0; |
| 851 |
|
| 852 |
do { |
| 853 |
skb = skb_dequeue(&dev->ipv6_ns_list); |
| 854 |
|
| 855 |
if (!skb) |
| 856 |
break; |
| 857 |
|
| 858 |
mt792x_mutex_acquire(dev); |
| 859 |
ret = mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 860 |
MCU_UNI_CMD(OFFLOAD), true); |
| 861 |
mt792x_mutex_release(dev); |
| 862 |
|
| 863 |
} while (!ret); |
| 864 |
|
| 865 |
if (ret) |
| 866 |
skb_queue_purge(&dev->ipv6_ns_list); |
| 867 |
} |
| 868 |
#endif |