| 1 |
// SPDX-License-Identifier: BSD-3-Clause-Clear |
| 2 |
/* Copyright (C) 2023 MediaTek Inc. */ |
| 3 |
|
| 4 |
#include <linux/fs.h> |
| 5 |
#include <linux/firmware.h> |
| 6 |
#include "mt7925.h" |
| 7 |
#include "regd.h" |
| 8 |
#include "mcu.h" |
| 9 |
#include "mac.h" |
| 10 |
|
| 11 |
#define MT_STA_BFER BIT(0) |
| 12 |
#define MT_STA_BFEE BIT(1) |
| 13 |
|
| 14 |
int mt7925_mcu_parse_response(struct mt76_dev *mdev, int cmd, |
| 15 |
struct sk_buff *skb, int seq) |
| 16 |
{ |
| 17 |
int mcu_cmd = FIELD_GET(__MCU_CMD_FIELD_ID, cmd); |
| 18 |
struct mt7925_mcu_rxd *rxd; |
| 19 |
int ret = 0; |
| 20 |
|
| 21 |
if (!skb) { |
| 22 |
dev_err(mdev->dev, "Message %08x (seq %d) timeout\n", cmd, seq); |
| 23 |
mt792x_reset(mdev); |
| 24 |
|
| 25 |
return -ETIMEDOUT; |
| 26 |
} |
| 27 |
|
| 28 |
rxd = (struct mt7925_mcu_rxd *)skb->data; |
| 29 |
if (seq != rxd->seq) |
| 30 |
return -EAGAIN; |
| 31 |
|
| 32 |
if (cmd == MCU_CMD(PATCH_SEM_CONTROL) || |
| 33 |
cmd == MCU_CMD(PATCH_FINISH_REQ)) { |
| 34 |
skb_pull(skb, sizeof(*rxd) - 4); |
| 35 |
ret = *skb->data; |
| 36 |
} else if (cmd == MCU_UNI_CMD(DEV_INFO_UPDATE) || |
| 37 |
cmd == MCU_UNI_CMD(BSS_INFO_UPDATE) || |
| 38 |
cmd == MCU_UNI_CMD(STA_REC_UPDATE) || |
| 39 |
cmd == MCU_UNI_CMD(OFFLOAD) || |
| 40 |
cmd == MCU_UNI_CMD(SUSPEND)) { |
| 41 |
struct mt7925_mcu_uni_event *event; |
| 42 |
|
| 43 |
skb_pull(skb, sizeof(*rxd)); |
| 44 |
event = (struct mt7925_mcu_uni_event *)skb->data; |
| 45 |
ret = le32_to_cpu(event->status); |
| 46 |
/* skip invalid event */ |
| 47 |
if (mcu_cmd != event->cid) |
| 48 |
ret = -EAGAIN; |
| 49 |
} else { |
| 50 |
skb_pull(skb, sizeof(*rxd)); |
| 51 |
} |
| 52 |
|
| 53 |
return ret; |
| 54 |
} |
| 55 |
EXPORT_SYMBOL_GPL(mt7925_mcu_parse_response); |
| 56 |
|
| 57 |
int mt7925_mcu_regval(struct mt792x_dev *dev, u32 regidx, u32 *val, bool set) |
| 58 |
{ |
| 59 |
#define MT_RF_REG_HDR GENMASK(31, 24) |
| 60 |
#define MT_RF_REG_ANT GENMASK(23, 16) |
| 61 |
#define RF_REG_PREFIX 0x99 |
| 62 |
struct { |
| 63 |
u8 __rsv[4]; |
| 64 |
union { |
| 65 |
struct uni_cmd_access_reg_basic { |
| 66 |
__le16 tag; |
| 67 |
__le16 len; |
| 68 |
__le32 idx; |
| 69 |
__le32 data; |
| 70 |
} __packed reg; |
| 71 |
struct uni_cmd_access_rf_reg_basic { |
| 72 |
__le16 tag; |
| 73 |
__le16 len; |
| 74 |
__le16 ant; |
| 75 |
u8 __rsv[2]; |
| 76 |
__le32 idx; |
| 77 |
__le32 data; |
| 78 |
} __packed rf_reg; |
| 79 |
}; |
| 80 |
} __packed * res, req; |
| 81 |
struct sk_buff *skb; |
| 82 |
int ret; |
| 83 |
|
| 84 |
if (u32_get_bits(regidx, MT_RF_REG_HDR) == RF_REG_PREFIX) { |
| 85 |
req.rf_reg.tag = cpu_to_le16(UNI_CMD_ACCESS_RF_REG_BASIC); |
| 86 |
req.rf_reg.len = cpu_to_le16(sizeof(req.rf_reg)); |
| 87 |
req.rf_reg.ant = cpu_to_le16(u32_get_bits(regidx, MT_RF_REG_ANT)); |
| 88 |
req.rf_reg.idx = cpu_to_le32(regidx); |
| 89 |
req.rf_reg.data = set ? cpu_to_le32(*val) : 0; |
| 90 |
} else { |
| 91 |
req.reg.tag = cpu_to_le16(UNI_CMD_ACCESS_REG_BASIC); |
| 92 |
req.reg.len = cpu_to_le16(sizeof(req.reg)); |
| 93 |
req.reg.idx = cpu_to_le32(regidx); |
| 94 |
req.reg.data = set ? cpu_to_le32(*val) : 0; |
| 95 |
} |
| 96 |
|
| 97 |
if (set) |
| 98 |
return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(REG_ACCESS), |
| 99 |
&req, sizeof(req), true); |
| 100 |
|
| 101 |
ret = mt76_mcu_send_and_get_msg(&dev->mt76, |
| 102 |
MCU_WM_UNI_CMD_QUERY(REG_ACCESS), |
| 103 |
&req, sizeof(req), true, &skb); |
| 104 |
if (ret) |
| 105 |
return ret; |
| 106 |
|
| 107 |
res = (void *)skb->data; |
| 108 |
if (u32_get_bits(regidx, MT_RF_REG_HDR) == RF_REG_PREFIX) |
| 109 |
*val = le32_to_cpu(res->rf_reg.data); |
| 110 |
else |
| 111 |
*val = le32_to_cpu(res->reg.data); |
| 112 |
|
| 113 |
dev_kfree_skb(skb); |
| 114 |
|
| 115 |
return 0; |
| 116 |
} |
| 117 |
EXPORT_SYMBOL_GPL(mt7925_mcu_regval); |
| 118 |
|
| 119 |
int mt7925_mcu_update_arp_filter(struct mt76_dev *dev, |
| 120 |
struct ieee80211_bss_conf *link_conf) |
| 121 |
{ |
| 122 |
struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); |
| 123 |
struct ieee80211_vif *mvif = link_conf->vif; |
| 124 |
struct sk_buff *skb; |
| 125 |
int i, len = min_t(int, mvif->cfg.arp_addr_cnt, |
| 126 |
IEEE80211_BSS_ARP_ADDR_LIST_LEN); |
| 127 |
struct { |
| 128 |
struct { |
| 129 |
u8 bss_idx; |
| 130 |
u8 pad[3]; |
| 131 |
} __packed hdr; |
| 132 |
struct mt7925_arpns_tlv arp; |
| 133 |
} req = { |
| 134 |
.hdr = { |
| 135 |
.bss_idx = mconf->mt76.idx, |
| 136 |
}, |
| 137 |
.arp = { |
| 138 |
.tag = cpu_to_le16(UNI_OFFLOAD_OFFLOAD_ARP), |
| 139 |
.len = cpu_to_le16(sizeof(req) - 4 + len * 2 * sizeof(__be32)), |
| 140 |
.ips_num = len, |
| 141 |
.enable = true, |
| 142 |
}, |
| 143 |
}; |
| 144 |
|
| 145 |
skb = mt76_mcu_msg_alloc(dev, NULL, sizeof(req) + len * 2 * sizeof(__be32)); |
| 146 |
if (!skb) |
| 147 |
return -ENOMEM; |
| 148 |
|
| 149 |
skb_put_data(skb, &req, sizeof(req)); |
| 150 |
for (i = 0; i < len; i++) { |
| 151 |
skb_put_data(skb, &mvif->cfg.arp_addr_list[i], sizeof(__be32)); |
| 152 |
skb_put_zero(skb, sizeof(__be32)); |
| 153 |
} |
| 154 |
|
| 155 |
return mt76_mcu_skb_send_msg(dev, skb, MCU_UNI_CMD(OFFLOAD), true); |
| 156 |
} |
| 157 |
|
| 158 |
#ifdef CONFIG_PM |
| 159 |
static int |
| 160 |
mt7925_connac_mcu_set_wow_ctrl(struct mt76_phy *phy, struct ieee80211_vif *vif, |
| 161 |
bool suspend, struct cfg80211_wowlan *wowlan) |
| 162 |
{ |
| 163 |
struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; |
| 164 |
struct ieee80211_scan_ies ies = {}; |
| 165 |
struct mt76_dev *dev = phy->dev; |
| 166 |
struct { |
| 167 |
struct { |
| 168 |
u8 bss_idx; |
| 169 |
u8 pad[3]; |
| 170 |
} __packed hdr; |
| 171 |
struct mt76_connac_wow_ctrl_tlv wow_ctrl_tlv; |
| 172 |
struct mt76_connac_wow_gpio_param_tlv gpio_tlv; |
| 173 |
} req = { |
| 174 |
.hdr = { |
| 175 |
.bss_idx = mvif->idx, |
| 176 |
}, |
| 177 |
.wow_ctrl_tlv = { |
| 178 |
.tag = cpu_to_le16(UNI_SUSPEND_WOW_CTRL), |
| 179 |
.len = cpu_to_le16(sizeof(struct mt76_connac_wow_ctrl_tlv)), |
| 180 |
.cmd = suspend ? 1 : 2, |
| 181 |
}, |
| 182 |
.gpio_tlv = { |
| 183 |
.tag = cpu_to_le16(UNI_SUSPEND_WOW_GPIO_PARAM), |
| 184 |
.len = cpu_to_le16(sizeof(struct mt76_connac_wow_gpio_param_tlv)), |
| 185 |
.gpio_pin = 0xff, /* follow fw about GPIO pin */ |
| 186 |
}, |
| 187 |
}; |
| 188 |
|
| 189 |
if (wowlan->magic_pkt) |
| 190 |
req.wow_ctrl_tlv.trigger |= UNI_WOW_DETECT_TYPE_MAGIC; |
| 191 |
if (wowlan->disconnect) |
| 192 |
req.wow_ctrl_tlv.trigger |= (UNI_WOW_DETECT_TYPE_DISCONNECT | |
| 193 |
UNI_WOW_DETECT_TYPE_BCN_LOST); |
| 194 |
if (wowlan->nd_config) { |
| 195 |
mt7925_mcu_sched_scan_req(phy, vif, wowlan->nd_config, &ies); |
| 196 |
req.wow_ctrl_tlv.trigger |= UNI_WOW_DETECT_TYPE_SCH_SCAN_HIT; |
| 197 |
mt7925_mcu_sched_scan_enable(phy, vif, suspend); |
| 198 |
} |
| 199 |
if (wowlan->n_patterns) |
| 200 |
req.wow_ctrl_tlv.trigger |= UNI_WOW_DETECT_TYPE_BITMAP; |
| 201 |
|
| 202 |
if (mt76_is_mmio(dev)) |
| 203 |
req.wow_ctrl_tlv.wakeup_hif = WOW_PCIE; |
| 204 |
else if (mt76_is_usb(dev)) |
| 205 |
req.wow_ctrl_tlv.wakeup_hif = WOW_USB; |
| 206 |
else if (mt76_is_sdio(dev)) |
| 207 |
req.wow_ctrl_tlv.wakeup_hif = WOW_GPIO; |
| 208 |
|
| 209 |
return mt76_mcu_send_msg(dev, MCU_UNI_CMD(SUSPEND), &req, |
| 210 |
sizeof(req), true); |
| 211 |
} |
| 212 |
|
| 213 |
static int |
| 214 |
mt7925_mcu_set_wow_pattern(struct mt76_dev *dev, |
| 215 |
struct ieee80211_vif *vif, |
| 216 |
u8 index, bool enable, |
| 217 |
struct cfg80211_pkt_pattern *pattern) |
| 218 |
{ |
| 219 |
struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; |
| 220 |
struct mt7925_wow_pattern_tlv *tlv; |
| 221 |
struct sk_buff *skb; |
| 222 |
struct { |
| 223 |
u8 bss_idx; |
| 224 |
u8 pad[3]; |
| 225 |
} __packed hdr = { |
| 226 |
.bss_idx = mvif->idx, |
| 227 |
}; |
| 228 |
|
| 229 |
skb = mt76_mcu_msg_alloc(dev, NULL, sizeof(hdr) + sizeof(*tlv)); |
| 230 |
if (!skb) |
| 231 |
return -ENOMEM; |
| 232 |
|
| 233 |
skb_put_data(skb, &hdr, sizeof(hdr)); |
| 234 |
tlv = (struct mt7925_wow_pattern_tlv *)skb_put(skb, sizeof(*tlv)); |
| 235 |
tlv->tag = cpu_to_le16(UNI_SUSPEND_WOW_PATTERN); |
| 236 |
tlv->len = cpu_to_le16(sizeof(*tlv)); |
| 237 |
tlv->bss_idx = 0xF; |
| 238 |
tlv->data_len = pattern->pattern_len; |
| 239 |
tlv->enable = enable; |
| 240 |
tlv->index = index; |
| 241 |
tlv->offset = 0; |
| 242 |
|
| 243 |
memcpy(tlv->pattern, pattern->pattern, pattern->pattern_len); |
| 244 |
memcpy(tlv->mask, pattern->mask, DIV_ROUND_UP(pattern->pattern_len, 8)); |
| 245 |
|
| 246 |
return mt76_mcu_skb_send_msg(dev, skb, MCU_UNI_CMD(SUSPEND), true); |
| 247 |
} |
| 248 |
|
| 249 |
void mt7925_mcu_set_suspend_iter(void *priv, u8 *mac, |
| 250 |
struct ieee80211_vif *vif) |
| 251 |
{ |
| 252 |
struct mt76_phy *phy = priv; |
| 253 |
bool suspend = !test_bit(MT76_STATE_RUNNING, &phy->state); |
| 254 |
struct ieee80211_hw *hw = phy->hw; |
| 255 |
struct cfg80211_wowlan *wowlan = hw->wiphy->wowlan_config; |
| 256 |
int i; |
| 257 |
|
| 258 |
mt76_connac_mcu_set_gtk_rekey(phy->dev, vif, suspend); |
| 259 |
|
| 260 |
mt76_connac_mcu_set_suspend_mode(phy->dev, vif, suspend, 1, true); |
| 261 |
|
| 262 |
for (i = 0; i < wowlan->n_patterns; i++) |
| 263 |
mt7925_mcu_set_wow_pattern(phy->dev, vif, i, suspend, |
| 264 |
&wowlan->patterns[i]); |
| 265 |
mt7925_connac_mcu_set_wow_ctrl(phy, vif, suspend, wowlan); |
| 266 |
} |
| 267 |
|
| 268 |
#endif /* CONFIG_PM */ |
| 269 |
|
| 270 |
static void |
| 271 |
mt7925_mcu_connection_loss_iter(void *priv, u8 *mac, |
| 272 |
struct ieee80211_vif *vif) |
| 273 |
{ |
| 274 |
struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; |
| 275 |
struct mt7925_uni_beacon_loss_event *event = priv; |
| 276 |
|
| 277 |
if (mvif->idx != event->hdr.bss_idx) |
| 278 |
return; |
| 279 |
|
| 280 |
if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER) || |
| 281 |
vif->type != NL80211_IFTYPE_STATION) |
| 282 |
return; |
| 283 |
|
| 284 |
ieee80211_connection_loss(vif); |
| 285 |
} |
| 286 |
|
| 287 |
static void |
| 288 |
mt7925_mcu_connection_loss_event(struct mt792x_dev *dev, struct sk_buff *skb) |
| 289 |
{ |
| 290 |
struct mt7925_uni_beacon_loss_event *event; |
| 291 |
struct mt76_phy *mphy = &dev->mt76.phy; |
| 292 |
|
| 293 |
skb_pull(skb, sizeof(struct mt7925_mcu_rxd)); |
| 294 |
event = (struct mt7925_uni_beacon_loss_event *)skb->data; |
| 295 |
|
| 296 |
ieee80211_iterate_active_interfaces_atomic(mphy->hw, |
| 297 |
IEEE80211_IFACE_ITER_RESUME_ALL, |
| 298 |
mt7925_mcu_connection_loss_iter, event); |
| 299 |
} |
| 300 |
|
| 301 |
static void |
| 302 |
mt7925_mcu_roc_iter(void *priv, u8 *mac, struct ieee80211_vif *vif) |
| 303 |
{ |
| 304 |
struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; |
| 305 |
struct mt7925_roc_grant_tlv *grant = priv; |
| 306 |
|
| 307 |
if (ieee80211_vif_is_mld(vif) && vif->type == NL80211_IFTYPE_STATION) |
| 308 |
return; |
| 309 |
|
| 310 |
if (mvif->idx != grant->bss_idx) |
| 311 |
return; |
| 312 |
|
| 313 |
mvif->band_idx = grant->dbdcband; |
| 314 |
} |
| 315 |
|
| 316 |
static void mt7925_mcu_roc_handle_grant(struct mt792x_dev *dev, |
| 317 |
struct tlv *tlv) |
| 318 |
{ |
| 319 |
struct ieee80211_hw *hw = dev->mt76.hw; |
| 320 |
struct mt7925_roc_grant_tlv *grant; |
| 321 |
int duration; |
| 322 |
|
| 323 |
grant = (struct mt7925_roc_grant_tlv *)tlv; |
| 324 |
|
| 325 |
/* should never happen */ |
| 326 |
WARN_ON_ONCE((le16_to_cpu(grant->tag) != UNI_EVENT_ROC_GRANT)); |
| 327 |
|
| 328 |
if (grant->reqtype == MT7925_ROC_REQ_ROC) |
| 329 |
ieee80211_ready_on_channel(hw); |
| 330 |
else if (grant->reqtype == MT7925_ROC_REQ_JOIN) |
| 331 |
ieee80211_iterate_active_interfaces_atomic(hw, |
| 332 |
IEEE80211_IFACE_ITER_RESUME_ALL, |
| 333 |
mt7925_mcu_roc_iter, grant); |
| 334 |
dev->phy.roc_grant = true; |
| 335 |
wake_up(&dev->phy.roc_wait); |
| 336 |
duration = le32_to_cpu(grant->max_interval); |
| 337 |
mod_timer(&dev->phy.roc_timer, |
| 338 |
jiffies + msecs_to_jiffies(duration)); |
| 339 |
} |
| 340 |
|
| 341 |
static void |
| 342 |
mt7925_mcu_handle_hif_ctrl_basic(struct mt792x_dev *dev, struct tlv *tlv) |
| 343 |
{ |
| 344 |
struct mt7925_mcu_hif_ctrl_basic_tlv *basic; |
| 345 |
|
| 346 |
basic = (struct mt7925_mcu_hif_ctrl_basic_tlv *)tlv; |
| 347 |
|
| 348 |
if (basic->hifsuspend) { |
| 349 |
dev->hif_idle = true; |
| 350 |
if (!(basic->hif_tx_traffic_status == HIF_TRAFFIC_IDLE && |
| 351 |
basic->hif_rx_traffic_status == HIF_TRAFFIC_IDLE)) |
| 352 |
dev_info(dev->mt76.dev, "Hif traffic not idle.\n"); |
| 353 |
} else { |
| 354 |
dev->hif_resumed = true; |
| 355 |
} |
| 356 |
wake_up(&dev->wait); |
| 357 |
} |
| 358 |
|
| 359 |
static void |
| 360 |
mt7925_mcu_uni_hif_ctrl_event(struct mt792x_dev *dev, struct sk_buff *skb) |
| 361 |
{ |
| 362 |
struct tlv *tlv; |
| 363 |
u32 tlv_len; |
| 364 |
|
| 365 |
skb_pull(skb, sizeof(struct mt7925_mcu_rxd) + 4); |
| 366 |
tlv = (struct tlv *)skb->data; |
| 367 |
tlv_len = skb->len; |
| 368 |
|
| 369 |
while (tlv_len > 0 && le16_to_cpu(tlv->len) <= tlv_len) { |
| 370 |
switch (le16_to_cpu(tlv->tag)) { |
| 371 |
case UNI_EVENT_HIF_CTRL_BASIC: |
| 372 |
mt7925_mcu_handle_hif_ctrl_basic(dev, tlv); |
| 373 |
break; |
| 374 |
default: |
| 375 |
break; |
| 376 |
} |
| 377 |
tlv_len -= le16_to_cpu(tlv->len); |
| 378 |
tlv = (struct tlv *)((char *)(tlv) + le16_to_cpu(tlv->len)); |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
static void |
| 383 |
mt7925_mcu_uni_roc_event(struct mt792x_dev *dev, struct sk_buff *skb) |
| 384 |
{ |
| 385 |
struct tlv *tlv; |
| 386 |
int i = 0; |
| 387 |
|
| 388 |
skb_pull(skb, sizeof(struct mt7925_mcu_rxd) + 4); |
| 389 |
|
| 390 |
while (i < skb->len) { |
| 391 |
tlv = (struct tlv *)(skb->data + i); |
| 392 |
|
| 393 |
switch (le16_to_cpu(tlv->tag)) { |
| 394 |
case UNI_EVENT_ROC_GRANT: |
| 395 |
mt7925_mcu_roc_handle_grant(dev, tlv); |
| 396 |
break; |
| 397 |
case UNI_EVENT_ROC_GRANT_SUB_LINK: |
| 398 |
break; |
| 399 |
} |
| 400 |
|
| 401 |
i += le16_to_cpu(tlv->len); |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
static void |
| 406 |
mt7925_mcu_scan_event(struct mt792x_dev *dev, struct sk_buff *skb) |
| 407 |
{ |
| 408 |
struct mt76_phy *mphy = &dev->mt76.phy; |
| 409 |
struct mt792x_phy *phy = mphy->priv; |
| 410 |
|
| 411 |
spin_lock_bh(&dev->mt76.lock); |
| 412 |
__skb_queue_tail(&phy->scan_event_list, skb); |
| 413 |
spin_unlock_bh(&dev->mt76.lock); |
| 414 |
|
| 415 |
ieee80211_queue_delayed_work(mphy->hw, &phy->scan_work, |
| 416 |
MT792x_HW_SCAN_TIMEOUT); |
| 417 |
} |
| 418 |
|
| 419 |
static void |
| 420 |
mt7925_mcu_tx_done_event(struct mt792x_dev *dev, struct sk_buff *skb) |
| 421 |
{ |
| 422 |
#define UNI_EVENT_TX_DONE_MSG 0 |
| 423 |
#define UNI_EVENT_TX_DONE_RAW 1 |
| 424 |
struct mt7925_mcu_txs_event { |
| 425 |
u8 ver; |
| 426 |
u8 rsv[3]; |
| 427 |
u8 data[]; |
| 428 |
} __packed * txs; |
| 429 |
struct tlv *tlv; |
| 430 |
u32 tlv_len; |
| 431 |
|
| 432 |
skb_pull(skb, sizeof(struct mt7925_mcu_rxd) + 4); |
| 433 |
tlv = (struct tlv *)skb->data; |
| 434 |
tlv_len = skb->len; |
| 435 |
|
| 436 |
while (tlv_len > 0 && le16_to_cpu(tlv->len) <= tlv_len) { |
| 437 |
switch (le16_to_cpu(tlv->tag)) { |
| 438 |
case UNI_EVENT_TX_DONE_RAW: |
| 439 |
txs = (struct mt7925_mcu_txs_event *)tlv->data; |
| 440 |
mt7925_mac_add_txs(dev, txs->data); |
| 441 |
break; |
| 442 |
default: |
| 443 |
break; |
| 444 |
} |
| 445 |
tlv_len -= le16_to_cpu(tlv->len); |
| 446 |
tlv = (struct tlv *)((char *)(tlv) + le16_to_cpu(tlv->len)); |
| 447 |
} |
| 448 |
} |
| 449 |
|
| 450 |
static void |
| 451 |
mt7925_mcu_rssi_monitor_iter(void *priv, u8 *mac, |
| 452 |
struct ieee80211_vif *vif) |
| 453 |
{ |
| 454 |
struct mt7925_uni_rssi_monitor_event *event = priv; |
| 455 |
enum nl80211_cqm_rssi_threshold_event nl_event; |
| 456 |
s32 rssi = le32_to_cpu(event->rssi); |
| 457 |
|
| 458 |
if (vif->type != NL80211_IFTYPE_STATION) |
| 459 |
return; |
| 460 |
|
| 461 |
if (!(vif->driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) |
| 462 |
return; |
| 463 |
|
| 464 |
if (rssi > vif->bss_conf.cqm_rssi_thold) |
| 465 |
nl_event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH; |
| 466 |
else |
| 467 |
nl_event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW; |
| 468 |
|
| 469 |
ieee80211_cqm_rssi_notify(vif, nl_event, rssi, GFP_KERNEL); |
| 470 |
} |
| 471 |
|
| 472 |
static void |
| 473 |
mt7925_mcu_rssi_monitor_event(struct mt792x_dev *dev, struct sk_buff *skb) |
| 474 |
{ |
| 475 |
struct tlv *tlv; |
| 476 |
u32 tlv_len; |
| 477 |
struct mt7925_uni_rssi_monitor_event *event; |
| 478 |
|
| 479 |
skb_pull(skb, sizeof(struct mt7925_mcu_rxd) + 4); |
| 480 |
tlv = (struct tlv *)skb->data; |
| 481 |
tlv_len = skb->len; |
| 482 |
|
| 483 |
while (tlv_len > 0 && le16_to_cpu(tlv->len) <= tlv_len) { |
| 484 |
switch (le16_to_cpu(tlv->tag)) { |
| 485 |
case UNI_EVENT_RSSI_MONITOR_INFO: |
| 486 |
event = (struct mt7925_uni_rssi_monitor_event *)skb->data; |
| 487 |
ieee80211_iterate_active_interfaces_atomic(dev->mt76.hw, |
| 488 |
IEEE80211_IFACE_ITER_RESUME_ALL, |
| 489 |
mt7925_mcu_rssi_monitor_iter, |
| 490 |
event); |
| 491 |
break; |
| 492 |
default: |
| 493 |
break; |
| 494 |
} |
| 495 |
tlv_len -= le16_to_cpu(tlv->len); |
| 496 |
tlv = (struct tlv *)((char *)(tlv) + le16_to_cpu(tlv->len)); |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
static void |
| 501 |
mt7925_mcu_uni_debug_msg_event(struct mt792x_dev *dev, struct sk_buff *skb) |
| 502 |
{ |
| 503 |
struct mt7925_uni_debug_msg { |
| 504 |
__le16 tag; |
| 505 |
__le16 len; |
| 506 |
u8 fmt; |
| 507 |
u8 rsv[3]; |
| 508 |
u8 id; |
| 509 |
u8 type:3; |
| 510 |
u8 nr_args:5; |
| 511 |
union { |
| 512 |
struct idxlog { |
| 513 |
__le16 rsv; |
| 514 |
__le32 ts; |
| 515 |
__le32 idx; |
| 516 |
u8 data[]; |
| 517 |
} __packed idx; |
| 518 |
struct txtlog { |
| 519 |
u8 len; |
| 520 |
u8 rsv; |
| 521 |
__le32 ts; |
| 522 |
u8 data[]; |
| 523 |
} __packed txt; |
| 524 |
}; |
| 525 |
} __packed * hdr; |
| 526 |
|
| 527 |
skb_pull(skb, sizeof(struct mt7925_mcu_rxd) + 4); |
| 528 |
hdr = (struct mt7925_uni_debug_msg *)skb->data; |
| 529 |
|
| 530 |
if (hdr->id == 0x28) { |
| 531 |
skb_pull(skb, offsetof(struct mt7925_uni_debug_msg, id)); |
| 532 |
wiphy_info(mt76_hw(dev)->wiphy, "%.*s", skb->len, skb->data); |
| 533 |
return; |
| 534 |
} else if (hdr->id != 0xa8) { |
| 535 |
return; |
| 536 |
} |
| 537 |
|
| 538 |
if (hdr->type == 0) { /* idx log */ |
| 539 |
int i, ret, len = PAGE_SIZE - 1, nr_val; |
| 540 |
struct page *page = dev_alloc_pages(get_order(len)); |
| 541 |
__le32 *val; |
| 542 |
char *buf, *cur; |
| 543 |
|
| 544 |
if (!page) |
| 545 |
return; |
| 546 |
|
| 547 |
buf = page_address(page); |
| 548 |
cur = buf; |
| 549 |
|
| 550 |
nr_val = (le16_to_cpu(hdr->len) - sizeof(*hdr)) / 4; |
| 551 |
val = (__le32 *)hdr->idx.data; |
| 552 |
for (i = 0; i < nr_val && len > 0; i++) { |
| 553 |
ret = snprintf(cur, len, "0x%x,", le32_to_cpu(val[i])); |
| 554 |
if (ret <= 0) |
| 555 |
break; |
| 556 |
|
| 557 |
cur += ret; |
| 558 |
len -= ret; |
| 559 |
} |
| 560 |
if (cur > buf) |
| 561 |
wiphy_info(mt76_hw(dev)->wiphy, "idx: 0x%X,%d,%s", |
| 562 |
le32_to_cpu(hdr->idx.idx), nr_val, buf); |
| 563 |
put_page(page); |
| 564 |
} else if (hdr->type == 2) { /* str log */ |
| 565 |
wiphy_info(mt76_hw(dev)->wiphy, "%.*s", hdr->txt.len, hdr->txt.data); |
| 566 |
} |
| 567 |
} |
| 568 |
|
| 569 |
static void |
| 570 |
mt7925_mcu_uni_rx_unsolicited_event(struct mt792x_dev *dev, |
| 571 |
struct sk_buff *skb) |
| 572 |
{ |
| 573 |
struct mt7925_mcu_rxd *rxd; |
| 574 |
|
| 575 |
rxd = (struct mt7925_mcu_rxd *)skb->data; |
| 576 |
|
| 577 |
switch (rxd->eid) { |
| 578 |
case MCU_UNI_EVENT_HIF_CTRL: |
| 579 |
mt7925_mcu_uni_hif_ctrl_event(dev, skb); |
| 580 |
break; |
| 581 |
case MCU_UNI_EVENT_FW_LOG_2_HOST: |
| 582 |
mt7925_mcu_uni_debug_msg_event(dev, skb); |
| 583 |
break; |
| 584 |
case MCU_UNI_EVENT_ROC: |
| 585 |
mt7925_mcu_uni_roc_event(dev, skb); |
| 586 |
break; |
| 587 |
case MCU_UNI_EVENT_SCAN_DONE: |
| 588 |
mt7925_mcu_scan_event(dev, skb); |
| 589 |
return; |
| 590 |
case MCU_UNI_EVENT_TX_DONE: |
| 591 |
mt7925_mcu_tx_done_event(dev, skb); |
| 592 |
break; |
| 593 |
case MCU_UNI_EVENT_BSS_BEACON_LOSS: |
| 594 |
mt7925_mcu_connection_loss_event(dev, skb); |
| 595 |
break; |
| 596 |
case MCU_UNI_EVENT_RSSI_MONITOR: |
| 597 |
mt7925_mcu_rssi_monitor_event(dev, skb); |
| 598 |
break; |
| 599 |
case MCU_UNI_EVENT_COREDUMP: |
| 600 |
dev->fw_assert = true; |
| 601 |
mt76_connac_mcu_coredump_event(&dev->mt76, skb, &dev->coredump); |
| 602 |
return; |
| 603 |
default: |
| 604 |
break; |
| 605 |
} |
| 606 |
dev_kfree_skb(skb); |
| 607 |
} |
| 608 |
|
| 609 |
void mt7925_mcu_rx_event(struct mt792x_dev *dev, struct sk_buff *skb) |
| 610 |
{ |
| 611 |
struct mt7925_mcu_rxd *rxd = (struct mt7925_mcu_rxd *)skb->data; |
| 612 |
|
| 613 |
if (skb_linearize(skb)) |
| 614 |
return; |
| 615 |
|
| 616 |
if (rxd->option & MCU_UNI_CMD_UNSOLICITED_EVENT) { |
| 617 |
mt7925_mcu_uni_rx_unsolicited_event(dev, skb); |
| 618 |
return; |
| 619 |
} |
| 620 |
|
| 621 |
mt76_mcu_rx_event(&dev->mt76, skb); |
| 622 |
} |
| 623 |
|
| 624 |
static int |
| 625 |
mt7925_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif_link *mvif, |
| 626 |
struct ieee80211_ampdu_params *params, |
| 627 |
bool enable, bool tx) |
| 628 |
{ |
| 629 |
struct mt76_wcid *wcid = (struct mt76_wcid *)params->sta->drv_priv; |
| 630 |
struct sta_rec_ba_uni *ba; |
| 631 |
struct sk_buff *skb; |
| 632 |
struct tlv *tlv; |
| 633 |
int len; |
| 634 |
|
| 635 |
len = sizeof(struct sta_req_hdr) + sizeof(*ba); |
| 636 |
skb = __mt76_connac_mcu_alloc_sta_req(dev, mvif, wcid, |
| 637 |
len); |
| 638 |
if (IS_ERR(skb)) |
| 639 |
return PTR_ERR(skb); |
| 640 |
|
| 641 |
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_BA, sizeof(*ba)); |
| 642 |
|
| 643 |
ba = (struct sta_rec_ba_uni *)tlv; |
| 644 |
ba->ba_type = tx ? MT_BA_TYPE_ORIGINATOR : MT_BA_TYPE_RECIPIENT; |
| 645 |
ba->winsize = cpu_to_le16(params->buf_size); |
| 646 |
ba->ssn = cpu_to_le16(params->ssn); |
| 647 |
ba->ba_en = enable << params->tid; |
| 648 |
ba->amsdu = params->amsdu; |
| 649 |
ba->tid = params->tid; |
| 650 |
|
| 651 |
return mt76_mcu_skb_send_msg(dev, skb, |
| 652 |
MCU_UNI_CMD(STA_REC_UPDATE), true); |
| 653 |
} |
| 654 |
|
| 655 |
/** starec & wtbl **/ |
| 656 |
int mt7925_mcu_uni_tx_ba(struct mt792x_dev *dev, |
| 657 |
struct ieee80211_ampdu_params *params, |
| 658 |
bool enable) |
| 659 |
{ |
| 660 |
struct mt792x_sta *msta = (struct mt792x_sta *)params->sta->drv_priv; |
| 661 |
struct mt792x_vif *mvif = msta->vif; |
| 662 |
|
| 663 |
if (enable && !params->amsdu) |
| 664 |
msta->deflink.wcid.amsdu = false; |
| 665 |
|
| 666 |
return mt7925_mcu_sta_ba(&dev->mt76, &mvif->bss_conf.mt76, params, |
| 667 |
enable, true); |
| 668 |
} |
| 669 |
|
| 670 |
int mt7925_mcu_uni_rx_ba(struct mt792x_dev *dev, |
| 671 |
struct ieee80211_ampdu_params *params, |
| 672 |
bool enable) |
| 673 |
{ |
| 674 |
struct mt792x_sta *msta = (struct mt792x_sta *)params->sta->drv_priv; |
| 675 |
struct mt792x_vif *mvif = msta->vif; |
| 676 |
|
| 677 |
return mt7925_mcu_sta_ba(&dev->mt76, &mvif->bss_conf.mt76, params, |
| 678 |
enable, false); |
| 679 |
} |
| 680 |
|
| 681 |
static int mt7925_mcu_read_eeprom(struct mt792x_dev *dev, u32 offset, u8 *val) |
| 682 |
{ |
| 683 |
struct { |
| 684 |
u8 rsv[4]; |
| 685 |
|
| 686 |
__le16 tag; |
| 687 |
__le16 len; |
| 688 |
|
| 689 |
__le32 addr; |
| 690 |
__le32 valid; |
| 691 |
u8 data[MT7925_EEPROM_BLOCK_SIZE]; |
| 692 |
} __packed req = { |
| 693 |
.tag = cpu_to_le16(1), |
| 694 |
.len = cpu_to_le16(sizeof(req) - 4), |
| 695 |
.addr = cpu_to_le32(round_down(offset, |
| 696 |
MT7925_EEPROM_BLOCK_SIZE)), |
| 697 |
}; |
| 698 |
struct evt { |
| 699 |
u8 rsv[4]; |
| 700 |
|
| 701 |
__le16 tag; |
| 702 |
__le16 len; |
| 703 |
|
| 704 |
__le32 ver; |
| 705 |
__le32 addr; |
| 706 |
__le32 valid; |
| 707 |
__le32 size; |
| 708 |
__le32 magic_num; |
| 709 |
__le32 type; |
| 710 |
__le32 rsv1[4]; |
| 711 |
u8 data[32]; |
| 712 |
} __packed *res; |
| 713 |
struct sk_buff *skb; |
| 714 |
int ret; |
| 715 |
|
| 716 |
ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_WM_UNI_CMD_QUERY(EFUSE_CTRL), |
| 717 |
&req, sizeof(req), true, &skb); |
| 718 |
if (ret) |
| 719 |
return ret; |
| 720 |
|
| 721 |
res = (struct evt *)skb->data; |
| 722 |
*val = res->data[offset % MT7925_EEPROM_BLOCK_SIZE]; |
| 723 |
|
| 724 |
dev_kfree_skb(skb); |
| 725 |
|
| 726 |
return 0; |
| 727 |
} |
| 728 |
|
| 729 |
static int mt7925_load_clc(struct mt792x_dev *dev, const char *fw_name) |
| 730 |
{ |
| 731 |
const struct mt76_connac2_fw_trailer *hdr; |
| 732 |
const struct mt76_connac2_fw_region *region; |
| 733 |
const struct mt7925_clc *clc; |
| 734 |
struct mt76_dev *mdev = &dev->mt76; |
| 735 |
struct mt792x_phy *phy = &dev->phy; |
| 736 |
const struct firmware *fw; |
| 737 |
u8 *clc_base = NULL, hw_encap = 0; |
| 738 |
int ret, i, len, offset = 0; |
| 739 |
|
| 740 |
dev->phy.clc_chan_conf = 0xff; |
| 741 |
dev->regd_user = false; |
| 742 |
if (!mt7925_regd_clc_supported(dev)) |
| 743 |
return 0; |
| 744 |
|
| 745 |
if (mt76_is_mmio(&dev->mt76)) { |
| 746 |
ret = mt7925_mcu_read_eeprom(dev, MT_EE_HW_TYPE, &hw_encap); |
| 747 |
if (ret) |
| 748 |
return ret; |
| 749 |
hw_encap = u8_get_bits(hw_encap, MT_EE_HW_TYPE_ENCAP); |
| 750 |
} |
| 751 |
|
| 752 |
ret = request_firmware(&fw, fw_name, mdev->dev); |
| 753 |
if (ret) |
| 754 |
return ret; |
| 755 |
|
| 756 |
if (!fw || !fw->data || fw->size < sizeof(*hdr)) { |
| 757 |
dev_err(mdev->dev, "Invalid firmware\n"); |
| 758 |
ret = -EINVAL; |
| 759 |
goto out; |
| 760 |
} |
| 761 |
|
| 762 |
hdr = (const void *)(fw->data + fw->size - sizeof(*hdr)); |
| 763 |
for (i = 0; i < hdr->n_region; i++) { |
| 764 |
region = (const void *)((const u8 *)hdr - |
| 765 |
(hdr->n_region - i) * sizeof(*region)); |
| 766 |
len = le32_to_cpu(region->len); |
| 767 |
|
| 768 |
/* check if we have valid buffer size */ |
| 769 |
if (offset + len > fw->size) { |
| 770 |
dev_err(mdev->dev, "Invalid firmware region\n"); |
| 771 |
ret = -EINVAL; |
| 772 |
goto out; |
| 773 |
} |
| 774 |
|
| 775 |
if ((region->feature_set & FW_FEATURE_NON_DL) && |
| 776 |
region->type == FW_TYPE_CLC) { |
| 777 |
clc_base = (u8 *)(fw->data + offset); |
| 778 |
break; |
| 779 |
} |
| 780 |
offset += len; |
| 781 |
} |
| 782 |
|
| 783 |
if (!clc_base) |
| 784 |
goto out; |
| 785 |
|
| 786 |
for (offset = 0; offset < len; offset += le32_to_cpu(clc->len)) { |
| 787 |
clc = (const struct mt7925_clc *)(clc_base + offset); |
| 788 |
|
| 789 |
if (clc->idx >= ARRAY_SIZE(phy->clc)) |
| 790 |
break; |
| 791 |
|
| 792 |
/* do not init buf again if chip reset triggered */ |
| 793 |
if (phy->clc[clc->idx]) |
| 794 |
continue; |
| 795 |
|
| 796 |
/* header content sanity */ |
| 797 |
if ((clc->idx == MT792x_CLC_BE_CTRL && |
| 798 |
u8_get_bits(clc->t2.type, MT_EE_HW_TYPE_ENCAP) != hw_encap) || |
| 799 |
u8_get_bits(clc->t0.type, MT_EE_HW_TYPE_ENCAP) != hw_encap) |
| 800 |
continue; |
| 801 |
|
| 802 |
phy->clc[clc->idx] = devm_kmemdup(mdev->dev, clc, |
| 803 |
le32_to_cpu(clc->len), |
| 804 |
GFP_KERNEL); |
| 805 |
|
| 806 |
if (!phy->clc[clc->idx]) { |
| 807 |
ret = -ENOMEM; |
| 808 |
goto out; |
| 809 |
} |
| 810 |
} |
| 811 |
|
| 812 |
ret = mt7925_regd_init(phy); |
| 813 |
out: |
| 814 |
release_firmware(fw); |
| 815 |
|
| 816 |
return ret; |
| 817 |
} |
| 818 |
|
| 819 |
int mt7925_mcu_fw_log_2_host(struct mt792x_dev *dev, u8 ctrl) |
| 820 |
{ |
| 821 |
struct { |
| 822 |
u8 _rsv[4]; |
| 823 |
|
| 824 |
__le16 tag; |
| 825 |
__le16 len; |
| 826 |
u8 ctrl; |
| 827 |
u8 interval; |
| 828 |
u8 _rsv2[2]; |
| 829 |
} __packed req = { |
| 830 |
.tag = cpu_to_le16(UNI_WSYS_CONFIG_FW_LOG_CTRL), |
| 831 |
.len = cpu_to_le16(sizeof(req) - 4), |
| 832 |
.ctrl = ctrl, |
| 833 |
}; |
| 834 |
int ret; |
| 835 |
|
| 836 |
ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_UNI_CMD(WSYS_CONFIG), |
| 837 |
&req, sizeof(req), true, NULL); |
| 838 |
return ret; |
| 839 |
} |
| 840 |
|
| 841 |
int mt7925_mcu_get_temperature(struct mt792x_phy *phy) |
| 842 |
{ |
| 843 |
struct { |
| 844 |
u8 _rsv[4]; |
| 845 |
|
| 846 |
__le16 tag; |
| 847 |
__le16 len; |
| 848 |
u8 _rsv2[4]; |
| 849 |
} __packed req = { |
| 850 |
.tag = cpu_to_le16(0x0), |
| 851 |
.len = cpu_to_le16(sizeof(req) - 4), |
| 852 |
}; |
| 853 |
struct mt7925_thermal_evt { |
| 854 |
u8 rsv[4]; |
| 855 |
__le32 temperature; |
| 856 |
} __packed * evt; |
| 857 |
struct mt792x_dev *dev = phy->dev; |
| 858 |
int temperature, ret; |
| 859 |
struct sk_buff *skb; |
| 860 |
|
| 861 |
ret = mt76_mcu_send_and_get_msg(&dev->mt76, |
| 862 |
MCU_WM_UNI_CMD_QUERY(THERMAL), |
| 863 |
&req, sizeof(req), true, &skb); |
| 864 |
if (ret) |
| 865 |
return ret; |
| 866 |
|
| 867 |
skb_pull(skb, 4 + sizeof(struct tlv)); |
| 868 |
evt = (struct mt7925_thermal_evt *)skb->data; |
| 869 |
|
| 870 |
temperature = le32_to_cpu(evt->temperature); |
| 871 |
|
| 872 |
dev_kfree_skb(skb); |
| 873 |
|
| 874 |
return temperature; |
| 875 |
} |
| 876 |
|
| 877 |
static void |
| 878 |
mt7925_mcu_parse_phy_cap(struct mt792x_dev *dev, char *data) |
| 879 |
{ |
| 880 |
struct mt76_phy *mphy = &dev->mt76.phy; |
| 881 |
struct mt76_dev *mdev = mphy->dev; |
| 882 |
struct mt7925_mcu_phy_cap { |
| 883 |
u8 ht; |
| 884 |
u8 vht; |
| 885 |
u8 _5g; |
| 886 |
u8 max_bw; |
| 887 |
u8 nss; |
| 888 |
u8 dbdc; |
| 889 |
u8 tx_ldpc; |
| 890 |
u8 rx_ldpc; |
| 891 |
u8 tx_stbc; |
| 892 |
u8 rx_stbc; |
| 893 |
u8 hw_path; |
| 894 |
u8 he; |
| 895 |
u8 eht; |
| 896 |
} __packed * cap; |
| 897 |
enum { |
| 898 |
WF0_24G, |
| 899 |
WF0_5G |
| 900 |
}; |
| 901 |
|
| 902 |
cap = (struct mt7925_mcu_phy_cap *)data; |
| 903 |
|
| 904 |
mdev->phy.antenna_mask = BIT(cap->nss) - 1; |
| 905 |
mdev->phy.chainmask = mdev->phy.antenna_mask; |
| 906 |
mdev->phy.cap.has_2ghz = cap->hw_path & BIT(WF0_24G); |
| 907 |
mdev->phy.cap.has_5ghz = cap->hw_path & BIT(WF0_5G); |
| 908 |
} |
| 909 |
|
| 910 |
static void |
| 911 |
mt7925_mcu_parse_eml_cap(struct mt792x_dev *dev, char *data) |
| 912 |
{ |
| 913 |
struct mt7925_mcu_eml_cap { |
| 914 |
u8 rsv[4]; |
| 915 |
__le16 eml_cap; |
| 916 |
u8 rsv2[6]; |
| 917 |
} __packed * cap; |
| 918 |
|
| 919 |
cap = (struct mt7925_mcu_eml_cap *)data; |
| 920 |
|
| 921 |
dev->phy.eml_cap = le16_to_cpu(cap->eml_cap); |
| 922 |
} |
| 923 |
|
| 924 |
static int |
| 925 |
mt7925_mcu_get_nic_capability(struct mt792x_dev *dev) |
| 926 |
{ |
| 927 |
struct mt76_phy *mphy = &dev->mt76.phy; |
| 928 |
struct { |
| 929 |
u8 _rsv[4]; |
| 930 |
|
| 931 |
__le16 tag; |
| 932 |
__le16 len; |
| 933 |
} __packed req = { |
| 934 |
.tag = cpu_to_le16(UNI_CHIP_CONFIG_NIC_CAPA), |
| 935 |
.len = cpu_to_le16(sizeof(req) - 4), |
| 936 |
}; |
| 937 |
struct mt76_connac_cap_hdr { |
| 938 |
__le16 n_element; |
| 939 |
u8 rsv[2]; |
| 940 |
} __packed * hdr; |
| 941 |
struct sk_buff *skb; |
| 942 |
int ret, i; |
| 943 |
|
| 944 |
ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_UNI_CMD(CHIP_CONFIG), |
| 945 |
&req, sizeof(req), true, &skb); |
| 946 |
if (ret) |
| 947 |
return ret; |
| 948 |
|
| 949 |
hdr = (struct mt76_connac_cap_hdr *)skb->data; |
| 950 |
if (skb->len < sizeof(*hdr)) { |
| 951 |
ret = -EINVAL; |
| 952 |
goto out; |
| 953 |
} |
| 954 |
|
| 955 |
skb_pull(skb, sizeof(*hdr)); |
| 956 |
|
| 957 |
for (i = 0; i < le16_to_cpu(hdr->n_element); i++) { |
| 958 |
struct tlv *tlv = (struct tlv *)skb->data; |
| 959 |
int len; |
| 960 |
|
| 961 |
if (skb->len < sizeof(*tlv)) |
| 962 |
break; |
| 963 |
|
| 964 |
len = le16_to_cpu(tlv->len); |
| 965 |
if (skb->len < len) |
| 966 |
break; |
| 967 |
|
| 968 |
switch (le16_to_cpu(tlv->tag)) { |
| 969 |
case MT_NIC_CAP_6G: |
| 970 |
mphy->cap.has_6ghz = !!tlv->data[0]; |
| 971 |
break; |
| 972 |
case MT_NIC_CAP_MAC_ADDR: |
| 973 |
memcpy(mphy->macaddr, (void *)tlv->data, ETH_ALEN); |
| 974 |
break; |
| 975 |
case MT_NIC_CAP_PHY: |
| 976 |
mt7925_mcu_parse_phy_cap(dev, tlv->data); |
| 977 |
break; |
| 978 |
case MT_NIC_CAP_CHIP_CAP: |
| 979 |
dev->phy.chip_cap = le64_to_cpu(*(__le64 *)tlv->data); |
| 980 |
break; |
| 981 |
case MT_NIC_CAP_EML_CAP: |
| 982 |
mt7925_mcu_parse_eml_cap(dev, tlv->data); |
| 983 |
break; |
| 984 |
default: |
| 985 |
break; |
| 986 |
} |
| 987 |
skb_pull(skb, len); |
| 988 |
} |
| 989 |
out: |
| 990 |
dev_kfree_skb(skb); |
| 991 |
return ret; |
| 992 |
} |
| 993 |
|
| 994 |
int mt7925_mcu_chip_config(struct mt792x_dev *dev, const char *cmd) |
| 995 |
{ |
| 996 |
u16 len = strlen(cmd) + 1; |
| 997 |
struct { |
| 998 |
u8 _rsv[4]; |
| 999 |
__le16 tag; |
| 1000 |
__le16 len; |
| 1001 |
struct mt76_connac_config config; |
| 1002 |
} __packed req = { |
| 1003 |
.tag = cpu_to_le16(UNI_CHIP_CONFIG_CHIP_CFG), |
| 1004 |
.len = cpu_to_le16(sizeof(req) - 4), |
| 1005 |
.config = { |
| 1006 |
.resp_type = 0, |
| 1007 |
.type = 0, |
| 1008 |
.data_size = cpu_to_le16(len), |
| 1009 |
}, |
| 1010 |
}; |
| 1011 |
|
| 1012 |
memcpy(req.config.data, cmd, len); |
| 1013 |
|
| 1014 |
return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(CHIP_CONFIG), |
| 1015 |
&req, sizeof(req), false); |
| 1016 |
} |
| 1017 |
|
| 1018 |
int mt7925_mcu_set_deep_sleep(struct mt792x_dev *dev, bool enable) |
| 1019 |
{ |
| 1020 |
char cmd[16]; |
| 1021 |
|
| 1022 |
snprintf(cmd, sizeof(cmd), "KeepFullPwr %d", !enable); |
| 1023 |
|
| 1024 |
return mt7925_mcu_chip_config(dev, cmd); |
| 1025 |
} |
| 1026 |
EXPORT_SYMBOL_GPL(mt7925_mcu_set_deep_sleep); |
| 1027 |
|
| 1028 |
int mt7925_mcu_set_thermal_protect(struct mt792x_dev *dev) |
| 1029 |
{ |
| 1030 |
char cmd[64]; |
| 1031 |
int ret = 0; |
| 1032 |
|
| 1033 |
snprintf(cmd, sizeof(cmd), "ThermalProtGband %d %d %d %d %d %d %d %d %d %d", |
| 1034 |
0, 100, 90, 80, 30, 1, 1, 115, 105, 5); |
| 1035 |
ret = mt7925_mcu_chip_config(dev, cmd); |
| 1036 |
|
| 1037 |
snprintf(cmd, sizeof(cmd), "ThermalProtAband %d %d %d %d %d %d %d %d %d %d", |
| 1038 |
1, 100, 90, 80, 30, 1, 1, 115, 105, 5); |
| 1039 |
ret |= mt7925_mcu_chip_config(dev, cmd); |
| 1040 |
|
| 1041 |
return ret; |
| 1042 |
} |
| 1043 |
EXPORT_SYMBOL_GPL(mt7925_mcu_set_thermal_protect); |
| 1044 |
|
| 1045 |
int mt7925_run_firmware(struct mt792x_dev *dev) |
| 1046 |
{ |
| 1047 |
int err; |
| 1048 |
|
| 1049 |
err = mt792x_load_firmware(dev); |
| 1050 |
if (err) |
| 1051 |
return err; |
| 1052 |
|
| 1053 |
err = mt7925_mcu_get_nic_capability(dev); |
| 1054 |
if (err) |
| 1055 |
return err; |
| 1056 |
|
| 1057 |
err = mt7925_load_clc(dev, mt792x_ram_name(dev)); |
| 1058 |
if (err) |
| 1059 |
return err; |
| 1060 |
set_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state); |
| 1061 |
|
| 1062 |
return mt7925_mcu_fw_log_2_host(dev, 1); |
| 1063 |
} |
| 1064 |
EXPORT_SYMBOL_GPL(mt7925_run_firmware); |
| 1065 |
|
| 1066 |
static void |
| 1067 |
mt7925_mcu_sta_hdr_trans_tlv(struct sk_buff *skb, |
| 1068 |
struct ieee80211_vif *vif, |
| 1069 |
struct ieee80211_link_sta *link_sta) |
| 1070 |
{ |
| 1071 |
struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; |
| 1072 |
struct sta_rec_hdr_trans *hdr_trans; |
| 1073 |
struct mt76_wcid *wcid; |
| 1074 |
struct tlv *tlv; |
| 1075 |
|
| 1076 |
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_HDR_TRANS, sizeof(*hdr_trans)); |
| 1077 |
hdr_trans = (struct sta_rec_hdr_trans *)tlv; |
| 1078 |
hdr_trans->dis_rx_hdr_tran = true; |
| 1079 |
|
| 1080 |
if (vif->type == NL80211_IFTYPE_STATION) |
| 1081 |
hdr_trans->to_ds = true; |
| 1082 |
else |
| 1083 |
hdr_trans->from_ds = true; |
| 1084 |
|
| 1085 |
if (link_sta) { |
| 1086 |
struct mt792x_sta *msta = (struct mt792x_sta *)link_sta->sta->drv_priv; |
| 1087 |
struct mt792x_link_sta *mlink; |
| 1088 |
|
| 1089 |
mlink = mt792x_sta_to_link(msta, link_sta->link_id); |
| 1090 |
wcid = &mlink->wcid; |
| 1091 |
} else { |
| 1092 |
wcid = &mvif->sta.deflink.wcid; |
| 1093 |
} |
| 1094 |
|
| 1095 |
if (!wcid) |
| 1096 |
return; |
| 1097 |
|
| 1098 |
hdr_trans->dis_rx_hdr_tran = !test_bit(MT_WCID_FLAG_HDR_TRANS, &wcid->flags); |
| 1099 |
if (test_bit(MT_WCID_FLAG_4ADDR, &wcid->flags)) { |
| 1100 |
hdr_trans->to_ds = true; |
| 1101 |
hdr_trans->from_ds = true; |
| 1102 |
} |
| 1103 |
} |
| 1104 |
|
| 1105 |
int mt7925_mcu_wtbl_update_hdr_trans(struct mt792x_dev *dev, |
| 1106 |
struct ieee80211_vif *vif, |
| 1107 |
struct ieee80211_sta *sta, |
| 1108 |
int link_id) |
| 1109 |
{ |
| 1110 |
struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; |
| 1111 |
struct ieee80211_link_sta *link_sta = sta ? &sta->deflink : NULL; |
| 1112 |
struct mt792x_link_sta *mlink; |
| 1113 |
struct mt792x_bss_conf *mconf; |
| 1114 |
struct mt792x_sta *msta; |
| 1115 |
struct sk_buff *skb; |
| 1116 |
|
| 1117 |
msta = sta ? (struct mt792x_sta *)sta->drv_priv : &mvif->sta; |
| 1118 |
|
| 1119 |
mlink = mt792x_sta_to_link(msta, link_id); |
| 1120 |
link_sta = mt792x_sta_to_link_sta(vif, sta, link_id); |
| 1121 |
mconf = mt792x_vif_to_link(mvif, link_id); |
| 1122 |
|
| 1123 |
skb = __mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mconf->mt76, |
| 1124 |
&mlink->wcid, |
| 1125 |
MT7925_STA_UPDATE_MAX_SIZE); |
| 1126 |
if (IS_ERR(skb)) |
| 1127 |
return PTR_ERR(skb); |
| 1128 |
|
| 1129 |
/* starec hdr trans */ |
| 1130 |
mt7925_mcu_sta_hdr_trans_tlv(skb, vif, link_sta); |
| 1131 |
return mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 1132 |
MCU_WMWA_UNI_CMD(STA_REC_UPDATE), true); |
| 1133 |
} |
| 1134 |
|
| 1135 |
int mt7925_mcu_set_tx(struct mt792x_dev *dev, |
| 1136 |
struct ieee80211_bss_conf *bss_conf) |
| 1137 |
{ |
| 1138 |
#define MCU_EDCA_AC_PARAM 0 |
| 1139 |
#define WMM_AIFS_SET BIT(0) |
| 1140 |
#define WMM_CW_MIN_SET BIT(1) |
| 1141 |
#define WMM_CW_MAX_SET BIT(2) |
| 1142 |
#define WMM_TXOP_SET BIT(3) |
| 1143 |
#define WMM_PARAM_SET (WMM_AIFS_SET | WMM_CW_MIN_SET | \ |
| 1144 |
WMM_CW_MAX_SET | WMM_TXOP_SET) |
| 1145 |
struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(bss_conf); |
| 1146 |
struct { |
| 1147 |
u8 bss_idx; |
| 1148 |
u8 __rsv[3]; |
| 1149 |
} __packed hdr = { |
| 1150 |
.bss_idx = mconf->mt76.idx, |
| 1151 |
}; |
| 1152 |
struct sk_buff *skb; |
| 1153 |
int len = sizeof(hdr) + IEEE80211_NUM_ACS * sizeof(struct edca); |
| 1154 |
int ac; |
| 1155 |
|
| 1156 |
skb = mt76_mcu_msg_alloc(&dev->mt76, NULL, len); |
| 1157 |
if (!skb) |
| 1158 |
return -ENOMEM; |
| 1159 |
|
| 1160 |
skb_put_data(skb, &hdr, sizeof(hdr)); |
| 1161 |
|
| 1162 |
for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 1163 |
struct ieee80211_tx_queue_params *q = &mconf->queue_params[ac]; |
| 1164 |
struct edca *e; |
| 1165 |
struct tlv *tlv; |
| 1166 |
|
| 1167 |
tlv = mt76_connac_mcu_add_tlv(skb, MCU_EDCA_AC_PARAM, sizeof(*e)); |
| 1168 |
|
| 1169 |
e = (struct edca *)tlv; |
| 1170 |
e->set = WMM_PARAM_SET; |
| 1171 |
e->queue = ac; |
| 1172 |
e->aifs = q->aifs; |
| 1173 |
e->txop = cpu_to_le16(q->txop); |
| 1174 |
|
| 1175 |
if (q->cw_min) |
| 1176 |
e->cw_min = fls(q->cw_min); |
| 1177 |
else |
| 1178 |
e->cw_min = 5; |
| 1179 |
|
| 1180 |
if (q->cw_max) |
| 1181 |
e->cw_max = fls(q->cw_max); |
| 1182 |
else |
| 1183 |
e->cw_max = 10; |
| 1184 |
} |
| 1185 |
|
| 1186 |
return mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 1187 |
MCU_UNI_CMD(EDCA_UPDATE), true); |
| 1188 |
} |
| 1189 |
|
| 1190 |
static int |
| 1191 |
mt7925_mcu_sta_key_tlv(struct mt76_wcid *wcid, |
| 1192 |
struct mt76_connac_sta_key_conf *sta_key_conf, |
| 1193 |
struct sk_buff *skb, |
| 1194 |
struct ieee80211_key_conf *key, |
| 1195 |
enum set_key_cmd cmd, |
| 1196 |
struct mt792x_sta *msta) |
| 1197 |
{ |
| 1198 |
struct mt792x_vif *mvif = msta->vif; |
| 1199 |
struct mt792x_bss_conf *mconf = mt792x_vif_to_link(mvif, wcid->link_id); |
| 1200 |
struct sta_rec_sec_uni *sec; |
| 1201 |
struct ieee80211_sta *sta; |
| 1202 |
struct ieee80211_vif *vif; |
| 1203 |
struct tlv *tlv; |
| 1204 |
|
| 1205 |
sta = msta == &mvif->sta ? |
| 1206 |
NULL : |
| 1207 |
container_of((void *)msta, struct ieee80211_sta, drv_priv); |
| 1208 |
vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv); |
| 1209 |
|
| 1210 |
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_KEY_V3, sizeof(*sec)); |
| 1211 |
sec = (struct sta_rec_sec_uni *)tlv; |
| 1212 |
sec->bss_idx = mconf->mt76.idx; |
| 1213 |
sec->is_authenticator = 0; |
| 1214 |
sec->mgmt_prot = 1; /* only used in MLO mode */ |
| 1215 |
sec->wlan_idx = (u8)wcid->idx; |
| 1216 |
|
| 1217 |
if (sta) { |
| 1218 |
struct ieee80211_link_sta *link_sta; |
| 1219 |
|
| 1220 |
sec->tx_key = 1; |
| 1221 |
sec->key_type = 1; |
| 1222 |
link_sta = mt792x_sta_to_link_sta(vif, sta, wcid->link_id); |
| 1223 |
|
| 1224 |
if (link_sta) |
| 1225 |
memcpy(sec->peer_addr, link_sta->addr, ETH_ALEN); |
| 1226 |
} else { |
| 1227 |
struct ieee80211_bss_conf *link_conf; |
| 1228 |
|
| 1229 |
link_conf = mt792x_vif_to_bss_conf(vif, wcid->link_id); |
| 1230 |
|
| 1231 |
if (link_conf) |
| 1232 |
memcpy(sec->peer_addr, link_conf->bssid, ETH_ALEN); |
| 1233 |
} |
| 1234 |
|
| 1235 |
if (cmd == SET_KEY) { |
| 1236 |
u8 cipher; |
| 1237 |
|
| 1238 |
sec->add = 1; |
| 1239 |
cipher = mt7925_mcu_get_cipher(key->cipher); |
| 1240 |
if (cipher == CONNAC3_CIPHER_NONE) |
| 1241 |
return -EOPNOTSUPP; |
| 1242 |
|
| 1243 |
if (cipher == CONNAC3_CIPHER_BIP_CMAC_128) { |
| 1244 |
sec->cipher_id = CONNAC3_CIPHER_BIP_CMAC_128; |
| 1245 |
sec->key_id = sta_key_conf->keyidx; |
| 1246 |
sec->key_len = 32; |
| 1247 |
memcpy(sec->key, sta_key_conf->key, 16); |
| 1248 |
memcpy(sec->key + 16, key->key, 16); |
| 1249 |
} else { |
| 1250 |
sec->cipher_id = cipher; |
| 1251 |
sec->key_id = key->keyidx; |
| 1252 |
sec->key_len = key->keylen; |
| 1253 |
memcpy(sec->key, key->key, key->keylen); |
| 1254 |
|
| 1255 |
if (cipher == CONNAC3_CIPHER_TKIP) { |
| 1256 |
/* Rx/Tx MIC keys are swapped */ |
| 1257 |
memcpy(sec->key + 16, key->key + 24, 8); |
| 1258 |
memcpy(sec->key + 24, key->key + 16, 8); |
| 1259 |
} |
| 1260 |
|
| 1261 |
/* store key_conf for BIP batch update */ |
| 1262 |
if (cipher == CONNAC3_CIPHER_AES_CCMP) { |
| 1263 |
memcpy(sta_key_conf->key, key->key, key->keylen); |
| 1264 |
sta_key_conf->keyidx = key->keyidx; |
| 1265 |
} |
| 1266 |
} |
| 1267 |
} else { |
| 1268 |
sec->add = 0; |
| 1269 |
} |
| 1270 |
|
| 1271 |
return 0; |
| 1272 |
} |
| 1273 |
|
| 1274 |
int mt7925_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif, |
| 1275 |
struct mt76_connac_sta_key_conf *sta_key_conf, |
| 1276 |
struct ieee80211_key_conf *key, int mcu_cmd, |
| 1277 |
struct mt76_wcid *wcid, enum set_key_cmd cmd, |
| 1278 |
struct mt792x_sta *msta) |
| 1279 |
{ |
| 1280 |
struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; |
| 1281 |
struct mt792x_bss_conf *mconf = mt792x_vif_to_link(mvif, wcid->link_id); |
| 1282 |
struct sk_buff *skb; |
| 1283 |
int ret; |
| 1284 |
|
| 1285 |
skb = __mt76_connac_mcu_alloc_sta_req(dev, &mconf->mt76, wcid, |
| 1286 |
MT7925_STA_UPDATE_MAX_SIZE); |
| 1287 |
if (IS_ERR(skb)) |
| 1288 |
return PTR_ERR(skb); |
| 1289 |
|
| 1290 |
ret = mt7925_mcu_sta_key_tlv(wcid, sta_key_conf, skb, key, cmd, msta); |
| 1291 |
if (ret) { |
| 1292 |
dev_kfree_skb(skb); |
| 1293 |
return ret; |
| 1294 |
} |
| 1295 |
|
| 1296 |
return mt76_mcu_skb_send_msg(dev, skb, mcu_cmd, true); |
| 1297 |
} |
| 1298 |
|
| 1299 |
int mt7925_mcu_set_mlo_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf, |
| 1300 |
u16 sel_links, int duration, u8 token_id) |
| 1301 |
{ |
| 1302 |
struct mt792x_vif *mvif = mconf->vif; |
| 1303 |
struct ieee80211_vif *vif = container_of((void *)mvif, |
| 1304 |
struct ieee80211_vif, drv_priv); |
| 1305 |
struct ieee80211_bss_conf *link_conf; |
| 1306 |
struct ieee80211_channel *chan; |
| 1307 |
const u8 ch_band[] = { |
| 1308 |
[NL80211_BAND_2GHZ] = 1, |
| 1309 |
[NL80211_BAND_5GHZ] = 2, |
| 1310 |
[NL80211_BAND_6GHZ] = 3, |
| 1311 |
}; |
| 1312 |
enum mt7925_roc_req type; |
| 1313 |
int center_ch, i = 0; |
| 1314 |
bool is_AG_band = false; |
| 1315 |
struct { |
| 1316 |
u8 id; |
| 1317 |
u8 bss_idx; |
| 1318 |
u16 tag; |
| 1319 |
struct mt792x_bss_conf *mconf; |
| 1320 |
struct ieee80211_channel *chan; |
| 1321 |
} links[2]; |
| 1322 |
|
| 1323 |
struct { |
| 1324 |
struct { |
| 1325 |
u8 rsv[4]; |
| 1326 |
} __packed hdr; |
| 1327 |
struct roc_acquire_tlv roc[2]; |
| 1328 |
} __packed req = { |
| 1329 |
.roc[0].tag = cpu_to_le16(UNI_ROC_NUM), |
| 1330 |
.roc[0].len = cpu_to_le16(sizeof(struct roc_acquire_tlv)), |
| 1331 |
.roc[1].tag = cpu_to_le16(UNI_ROC_NUM), |
| 1332 |
.roc[1].len = cpu_to_le16(sizeof(struct roc_acquire_tlv)) |
| 1333 |
}; |
| 1334 |
|
| 1335 |
struct wiphy *wiphy = phy->mt76->hw->wiphy; |
| 1336 |
|
| 1337 |
if (!mconf || hweight16(vif->valid_links) < 2 || |
| 1338 |
hweight16(sel_links) != 2) |
| 1339 |
return -EPERM; |
| 1340 |
|
| 1341 |
for (i = 0; i < ARRAY_SIZE(links); i++) { |
| 1342 |
links[i].id = i ? __ffs(~BIT(mconf->link_id) & sel_links) : |
| 1343 |
mconf->link_id; |
| 1344 |
link_conf = mt792x_vif_to_bss_conf(vif, links[i].id); |
| 1345 |
if (WARN_ON_ONCE(!link_conf)) |
| 1346 |
return -EPERM; |
| 1347 |
|
| 1348 |
links[i].chan = link_conf->chanreq.oper.chan; |
| 1349 |
if (WARN_ON_ONCE(!links[i].chan)) |
| 1350 |
return -EPERM; |
| 1351 |
|
| 1352 |
links[i].mconf = mt792x_vif_to_link(mvif, links[i].id); |
| 1353 |
links[i].tag = links[i].id == mconf->link_id ? |
| 1354 |
UNI_ROC_ACQUIRE : UNI_ROC_SUB_LINK; |
| 1355 |
|
| 1356 |
is_AG_band |= links[i].chan->band == NL80211_BAND_2GHZ; |
| 1357 |
} |
| 1358 |
|
| 1359 |
if (!(wiphy->iftype_ext_capab[0].mld_capa_and_ops & |
| 1360 |
IEEE80211_MLD_CAP_OP_MAX_SIMUL_LINKS)) |
| 1361 |
type = is_AG_band ? MT7925_ROC_REQ_MLSR_AG : |
| 1362 |
MT7925_ROC_REQ_MLSR_AA; |
| 1363 |
else |
| 1364 |
type = MT7925_ROC_REQ_JOIN; |
| 1365 |
|
| 1366 |
for (i = 0; i < ARRAY_SIZE(links) && i < hweight16(vif->active_links); i++) { |
| 1367 |
if (WARN_ON_ONCE(!links[i].mconf || !links[i].chan)) |
| 1368 |
continue; |
| 1369 |
|
| 1370 |
chan = links[i].chan; |
| 1371 |
center_ch = ieee80211_frequency_to_channel(chan->center_freq); |
| 1372 |
req.roc[i].len = cpu_to_le16(sizeof(struct roc_acquire_tlv)); |
| 1373 |
req.roc[i].tag = cpu_to_le16(links[i].tag); |
| 1374 |
req.roc[i].tokenid = token_id; |
| 1375 |
req.roc[i].reqtype = type; |
| 1376 |
req.roc[i].maxinterval = cpu_to_le32(duration); |
| 1377 |
req.roc[i].bss_idx = links[i].mconf->mt76.idx; |
| 1378 |
req.roc[i].control_channel = chan->hw_value; |
| 1379 |
req.roc[i].bw = CMD_CBW_20MHZ; |
| 1380 |
req.roc[i].bw_from_ap = CMD_CBW_20MHZ; |
| 1381 |
req.roc[i].center_chan = center_ch; |
| 1382 |
req.roc[i].center_chan_from_ap = center_ch; |
| 1383 |
req.roc[i].center_chan2 = 0; |
| 1384 |
req.roc[i].center_chan2_from_ap = 0; |
| 1385 |
|
| 1386 |
/* STR : 0xfe indicates BAND_ALL with enabling DBDC |
| 1387 |
* EMLSR : 0xff indicates (BAND_AUTO) without DBDC |
| 1388 |
*/ |
| 1389 |
req.roc[i].dbdcband = type == MT7925_ROC_REQ_JOIN ? 0xfe : 0xff; |
| 1390 |
|
| 1391 |
if (chan->hw_value < center_ch) |
| 1392 |
req.roc[i].sco = 1; /* SCA */ |
| 1393 |
else if (chan->hw_value > center_ch) |
| 1394 |
req.roc[i].sco = 3; /* SCB */ |
| 1395 |
|
| 1396 |
req.roc[i].band = ch_band[chan->band]; |
| 1397 |
} |
| 1398 |
|
| 1399 |
return mt76_mcu_send_msg(&mvif->phy->dev->mt76, MCU_UNI_CMD(ROC), |
| 1400 |
&req, sizeof(req), true); |
| 1401 |
} |
| 1402 |
|
| 1403 |
int mt7925_mcu_set_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf, |
| 1404 |
struct ieee80211_channel *chan, int duration, |
| 1405 |
enum mt7925_roc_req type, u8 token_id) |
| 1406 |
{ |
| 1407 |
int center_ch = ieee80211_frequency_to_channel(chan->center_freq); |
| 1408 |
struct mt792x_dev *dev = phy->dev; |
| 1409 |
struct { |
| 1410 |
struct { |
| 1411 |
u8 rsv[4]; |
| 1412 |
} __packed hdr; |
| 1413 |
struct roc_acquire_tlv roc; |
| 1414 |
} __packed req = { |
| 1415 |
.roc = { |
| 1416 |
.tag = cpu_to_le16(UNI_ROC_ACQUIRE), |
| 1417 |
.len = cpu_to_le16(sizeof(struct roc_acquire_tlv)), |
| 1418 |
.tokenid = token_id, |
| 1419 |
.reqtype = type, |
| 1420 |
.maxinterval = cpu_to_le32(duration), |
| 1421 |
.bss_idx = mconf->mt76.idx, |
| 1422 |
.control_channel = chan->hw_value, |
| 1423 |
.bw = CMD_CBW_20MHZ, |
| 1424 |
.bw_from_ap = CMD_CBW_20MHZ, |
| 1425 |
.center_chan = center_ch, |
| 1426 |
.center_chan_from_ap = center_ch, |
| 1427 |
.dbdcband = 0xff, /* auto */ |
| 1428 |
}, |
| 1429 |
}; |
| 1430 |
|
| 1431 |
if (chan->hw_value < center_ch) |
| 1432 |
req.roc.sco = 1; /* SCA */ |
| 1433 |
else if (chan->hw_value > center_ch) |
| 1434 |
req.roc.sco = 3; /* SCB */ |
| 1435 |
|
| 1436 |
switch (chan->band) { |
| 1437 |
case NL80211_BAND_6GHZ: |
| 1438 |
req.roc.band = 3; |
| 1439 |
break; |
| 1440 |
case NL80211_BAND_5GHZ: |
| 1441 |
req.roc.band = 2; |
| 1442 |
break; |
| 1443 |
default: |
| 1444 |
req.roc.band = 1; |
| 1445 |
break; |
| 1446 |
} |
| 1447 |
|
| 1448 |
return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(ROC), |
| 1449 |
&req, sizeof(req), true); |
| 1450 |
} |
| 1451 |
|
| 1452 |
int mt7925_mcu_abort_roc(struct mt792x_phy *phy, struct mt792x_bss_conf *mconf, |
| 1453 |
u8 token_id) |
| 1454 |
{ |
| 1455 |
struct mt792x_dev *dev = phy->dev; |
| 1456 |
struct { |
| 1457 |
struct { |
| 1458 |
u8 rsv[4]; |
| 1459 |
} __packed hdr; |
| 1460 |
struct roc_abort_tlv { |
| 1461 |
__le16 tag; |
| 1462 |
__le16 len; |
| 1463 |
u8 bss_idx; |
| 1464 |
u8 tokenid; |
| 1465 |
u8 dbdcband; |
| 1466 |
u8 rsv[5]; |
| 1467 |
} __packed abort; |
| 1468 |
} __packed req = { |
| 1469 |
.abort = { |
| 1470 |
.tag = cpu_to_le16(UNI_ROC_ABORT), |
| 1471 |
.len = cpu_to_le16(sizeof(struct roc_abort_tlv)), |
| 1472 |
.tokenid = token_id, |
| 1473 |
.bss_idx = mconf->mt76.idx, |
| 1474 |
.dbdcband = 0xff, /* auto*/ |
| 1475 |
}, |
| 1476 |
}; |
| 1477 |
|
| 1478 |
return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(ROC), |
| 1479 |
&req, sizeof(req), true); |
| 1480 |
} |
| 1481 |
|
| 1482 |
int mt7925_mcu_set_eeprom(struct mt792x_dev *dev) |
| 1483 |
{ |
| 1484 |
struct { |
| 1485 |
u8 _rsv[4]; |
| 1486 |
|
| 1487 |
__le16 tag; |
| 1488 |
__le16 len; |
| 1489 |
u8 buffer_mode; |
| 1490 |
u8 format; |
| 1491 |
__le16 buf_len; |
| 1492 |
} __packed req = { |
| 1493 |
.tag = cpu_to_le16(UNI_EFUSE_BUFFER_MODE), |
| 1494 |
.len = cpu_to_le16(sizeof(req) - 4), |
| 1495 |
.buffer_mode = EE_MODE_EFUSE, |
| 1496 |
.format = EE_FORMAT_WHOLE |
| 1497 |
}; |
| 1498 |
|
| 1499 |
return mt76_mcu_send_and_get_msg(&dev->mt76, MCU_UNI_CMD(EFUSE_CTRL), |
| 1500 |
&req, sizeof(req), true, NULL); |
| 1501 |
} |
| 1502 |
EXPORT_SYMBOL_GPL(mt7925_mcu_set_eeprom); |
| 1503 |
|
| 1504 |
int mt7925_mcu_uni_bss_ps(struct mt792x_dev *dev, |
| 1505 |
struct ieee80211_bss_conf *link_conf) |
| 1506 |
{ |
| 1507 |
struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); |
| 1508 |
struct { |
| 1509 |
struct { |
| 1510 |
u8 bss_idx; |
| 1511 |
u8 pad[3]; |
| 1512 |
} __packed hdr; |
| 1513 |
struct ps_tlv { |
| 1514 |
__le16 tag; |
| 1515 |
__le16 len; |
| 1516 |
u8 ps_state; /* 0: device awake |
| 1517 |
* 1: static power save |
| 1518 |
* 2: dynamic power saving |
| 1519 |
* 3: enter TWT power saving |
| 1520 |
* 4: leave TWT power saving |
| 1521 |
*/ |
| 1522 |
u8 pad[3]; |
| 1523 |
} __packed ps; |
| 1524 |
} __packed ps_req = { |
| 1525 |
.hdr = { |
| 1526 |
.bss_idx = mconf->mt76.idx, |
| 1527 |
}, |
| 1528 |
.ps = { |
| 1529 |
.tag = cpu_to_le16(UNI_BSS_INFO_PS), |
| 1530 |
.len = cpu_to_le16(sizeof(struct ps_tlv)), |
| 1531 |
.ps_state = link_conf->vif->cfg.ps ? 2 : 0, |
| 1532 |
}, |
| 1533 |
}; |
| 1534 |
|
| 1535 |
if (link_conf->vif->type != NL80211_IFTYPE_STATION) |
| 1536 |
return -EOPNOTSUPP; |
| 1537 |
|
| 1538 |
return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(BSS_INFO_UPDATE), |
| 1539 |
&ps_req, sizeof(ps_req), true); |
| 1540 |
} |
| 1541 |
|
| 1542 |
int |
| 1543 |
mt7925_mcu_uni_bss_bcnft(struct mt792x_dev *dev, |
| 1544 |
struct ieee80211_bss_conf *link_conf, bool enable) |
| 1545 |
{ |
| 1546 |
struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); |
| 1547 |
struct { |
| 1548 |
struct { |
| 1549 |
u8 bss_idx; |
| 1550 |
u8 pad[3]; |
| 1551 |
} __packed hdr; |
| 1552 |
struct bcnft_tlv { |
| 1553 |
__le16 tag; |
| 1554 |
__le16 len; |
| 1555 |
__le16 bcn_interval; |
| 1556 |
u8 dtim_period; |
| 1557 |
u8 bmc_delivered_ac; |
| 1558 |
u8 bmc_triggered_ac; |
| 1559 |
u8 pad[3]; |
| 1560 |
} __packed bcnft; |
| 1561 |
} __packed bcnft_req = { |
| 1562 |
.hdr = { |
| 1563 |
.bss_idx = mconf->mt76.idx, |
| 1564 |
}, |
| 1565 |
.bcnft = { |
| 1566 |
.tag = cpu_to_le16(UNI_BSS_INFO_BCNFT), |
| 1567 |
.len = cpu_to_le16(sizeof(struct bcnft_tlv)), |
| 1568 |
.bcn_interval = cpu_to_le16(link_conf->beacon_int), |
| 1569 |
.dtim_period = link_conf->dtim_period, |
| 1570 |
}, |
| 1571 |
}; |
| 1572 |
|
| 1573 |
if (link_conf->vif->type != NL80211_IFTYPE_STATION) |
| 1574 |
return 0; |
| 1575 |
|
| 1576 |
return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(BSS_INFO_UPDATE), |
| 1577 |
&bcnft_req, sizeof(bcnft_req), true); |
| 1578 |
} |
| 1579 |
|
| 1580 |
int |
| 1581 |
mt7925_mcu_set_bss_pm(struct mt792x_dev *dev, |
| 1582 |
struct ieee80211_bss_conf *link_conf, |
| 1583 |
bool enable) |
| 1584 |
{ |
| 1585 |
struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); |
| 1586 |
struct { |
| 1587 |
struct { |
| 1588 |
u8 bss_idx; |
| 1589 |
u8 pad[3]; |
| 1590 |
} __packed hdr; |
| 1591 |
struct bcnft_tlv { |
| 1592 |
__le16 tag; |
| 1593 |
__le16 len; |
| 1594 |
__le16 bcn_interval; |
| 1595 |
u8 dtim_period; |
| 1596 |
u8 bmc_delivered_ac; |
| 1597 |
u8 bmc_triggered_ac; |
| 1598 |
u8 pad[3]; |
| 1599 |
} __packed enable; |
| 1600 |
} req = { |
| 1601 |
.hdr = { |
| 1602 |
.bss_idx = mconf->mt76.idx, |
| 1603 |
}, |
| 1604 |
.enable = { |
| 1605 |
.tag = cpu_to_le16(UNI_BSS_INFO_BCNFT), |
| 1606 |
.len = cpu_to_le16(sizeof(struct bcnft_tlv)), |
| 1607 |
.dtim_period = link_conf->dtim_period, |
| 1608 |
.bcn_interval = cpu_to_le16(link_conf->beacon_int), |
| 1609 |
}, |
| 1610 |
}; |
| 1611 |
struct { |
| 1612 |
struct { |
| 1613 |
u8 bss_idx; |
| 1614 |
u8 pad[3]; |
| 1615 |
} __packed hdr; |
| 1616 |
struct pm_disable { |
| 1617 |
__le16 tag; |
| 1618 |
__le16 len; |
| 1619 |
} __packed disable; |
| 1620 |
} req1 = { |
| 1621 |
.hdr = { |
| 1622 |
.bss_idx = mconf->mt76.idx, |
| 1623 |
}, |
| 1624 |
.disable = { |
| 1625 |
.tag = cpu_to_le16(UNI_BSS_INFO_PM_DISABLE), |
| 1626 |
.len = cpu_to_le16(sizeof(struct pm_disable)) |
| 1627 |
}, |
| 1628 |
}; |
| 1629 |
int err; |
| 1630 |
|
| 1631 |
err = mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(BSS_INFO_UPDATE), |
| 1632 |
&req1, sizeof(req1), true); |
| 1633 |
if (err < 0 || !enable) |
| 1634 |
return err; |
| 1635 |
|
| 1636 |
return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(BSS_INFO_UPDATE), |
| 1637 |
&req, sizeof(req), true); |
| 1638 |
} |
| 1639 |
|
| 1640 |
static void |
| 1641 |
mt7925_mcu_sta_he_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta) |
| 1642 |
{ |
| 1643 |
if (!link_sta->he_cap.has_he) |
| 1644 |
return; |
| 1645 |
|
| 1646 |
mt76_connac_mcu_sta_he_tlv_v2(skb, link_sta->sta); |
| 1647 |
} |
| 1648 |
|
| 1649 |
static void |
| 1650 |
mt7925_mcu_sta_he_6g_tlv(struct sk_buff *skb, |
| 1651 |
struct ieee80211_link_sta *link_sta) |
| 1652 |
{ |
| 1653 |
struct sta_rec_he_6g_capa *he_6g; |
| 1654 |
struct tlv *tlv; |
| 1655 |
|
| 1656 |
if (!link_sta->he_6ghz_capa.capa) |
| 1657 |
return; |
| 1658 |
|
| 1659 |
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_HE_6G, sizeof(*he_6g)); |
| 1660 |
|
| 1661 |
he_6g = (struct sta_rec_he_6g_capa *)tlv; |
| 1662 |
he_6g->capa = link_sta->he_6ghz_capa.capa; |
| 1663 |
} |
| 1664 |
|
| 1665 |
static void |
| 1666 |
mt7925_mcu_sta_eht_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta) |
| 1667 |
{ |
| 1668 |
struct ieee80211_eht_mcs_nss_supp *mcs_map; |
| 1669 |
struct ieee80211_eht_cap_elem_fixed *elem; |
| 1670 |
struct sta_rec_eht *eht; |
| 1671 |
struct tlv *tlv; |
| 1672 |
|
| 1673 |
if (!link_sta->eht_cap.has_eht) |
| 1674 |
return; |
| 1675 |
|
| 1676 |
mcs_map = &link_sta->eht_cap.eht_mcs_nss_supp; |
| 1677 |
elem = &link_sta->eht_cap.eht_cap_elem; |
| 1678 |
|
| 1679 |
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_EHT, sizeof(*eht)); |
| 1680 |
|
| 1681 |
eht = (struct sta_rec_eht *)tlv; |
| 1682 |
eht->tid_bitmap = 0xff; |
| 1683 |
eht->mac_cap = cpu_to_le16(*(u16 *)elem->mac_cap_info); |
| 1684 |
eht->phy_cap = cpu_to_le64(*(u64 *)elem->phy_cap_info); |
| 1685 |
eht->phy_cap_ext = cpu_to_le64(elem->phy_cap_info[8]); |
| 1686 |
|
| 1687 |
if (link_sta->bandwidth == IEEE80211_STA_RX_BW_20) |
| 1688 |
memcpy(eht->mcs_map_bw20, &mcs_map->only_20mhz, sizeof(eht->mcs_map_bw20)); |
| 1689 |
memcpy(eht->mcs_map_bw80, &mcs_map->bw._80, sizeof(eht->mcs_map_bw80)); |
| 1690 |
memcpy(eht->mcs_map_bw160, &mcs_map->bw._160, sizeof(eht->mcs_map_bw160)); |
| 1691 |
} |
| 1692 |
|
| 1693 |
static void |
| 1694 |
mt7925_mcu_sta_ht_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta) |
| 1695 |
{ |
| 1696 |
struct sta_rec_ht *ht; |
| 1697 |
struct tlv *tlv; |
| 1698 |
|
| 1699 |
if (!link_sta->ht_cap.ht_supported) |
| 1700 |
return; |
| 1701 |
|
| 1702 |
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_HT, sizeof(*ht)); |
| 1703 |
|
| 1704 |
ht = (struct sta_rec_ht *)tlv; |
| 1705 |
ht->ht_cap = cpu_to_le16(link_sta->ht_cap.cap); |
| 1706 |
} |
| 1707 |
|
| 1708 |
static void |
| 1709 |
mt7925_mcu_sta_vht_tlv(struct sk_buff *skb, struct ieee80211_link_sta *link_sta) |
| 1710 |
{ |
| 1711 |
struct sta_rec_vht *vht; |
| 1712 |
struct tlv *tlv; |
| 1713 |
|
| 1714 |
/* For 6G band, this tlv is necessary to let hw work normally */ |
| 1715 |
if (!link_sta->he_6ghz_capa.capa && !link_sta->vht_cap.vht_supported) |
| 1716 |
return; |
| 1717 |
|
| 1718 |
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_VHT, sizeof(*vht)); |
| 1719 |
|
| 1720 |
vht = (struct sta_rec_vht *)tlv; |
| 1721 |
vht->vht_cap = cpu_to_le32(link_sta->vht_cap.cap); |
| 1722 |
vht->vht_rx_mcs_map = link_sta->vht_cap.vht_mcs.rx_mcs_map; |
| 1723 |
vht->vht_tx_mcs_map = link_sta->vht_cap.vht_mcs.tx_mcs_map; |
| 1724 |
} |
| 1725 |
|
| 1726 |
static void |
| 1727 |
mt7925_mcu_sta_amsdu_tlv(struct sk_buff *skb, |
| 1728 |
struct ieee80211_vif *vif, |
| 1729 |
struct ieee80211_link_sta *link_sta) |
| 1730 |
{ |
| 1731 |
struct mt792x_sta *msta = (struct mt792x_sta *)link_sta->sta->drv_priv; |
| 1732 |
struct mt792x_link_sta *mlink; |
| 1733 |
struct sta_rec_amsdu *amsdu; |
| 1734 |
struct tlv *tlv; |
| 1735 |
|
| 1736 |
if (vif->type != NL80211_IFTYPE_STATION && |
| 1737 |
vif->type != NL80211_IFTYPE_AP) |
| 1738 |
return; |
| 1739 |
|
| 1740 |
if (!link_sta->agg.max_amsdu_len) |
| 1741 |
return; |
| 1742 |
|
| 1743 |
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_HW_AMSDU, sizeof(*amsdu)); |
| 1744 |
amsdu = (struct sta_rec_amsdu *)tlv; |
| 1745 |
amsdu->max_amsdu_num = 8; |
| 1746 |
amsdu->amsdu_en = true; |
| 1747 |
|
| 1748 |
mlink = mt792x_sta_to_link(msta, link_sta->link_id); |
| 1749 |
mlink->wcid.amsdu = true; |
| 1750 |
|
| 1751 |
switch (link_sta->agg.max_amsdu_len) { |
| 1752 |
case IEEE80211_MAX_MPDU_LEN_VHT_11454: |
| 1753 |
amsdu->max_mpdu_size = |
| 1754 |
IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454; |
| 1755 |
return; |
| 1756 |
case IEEE80211_MAX_MPDU_LEN_HT_7935: |
| 1757 |
case IEEE80211_MAX_MPDU_LEN_VHT_7991: |
| 1758 |
amsdu->max_mpdu_size = IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991; |
| 1759 |
return; |
| 1760 |
default: |
| 1761 |
amsdu->max_mpdu_size = IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895; |
| 1762 |
return; |
| 1763 |
} |
| 1764 |
} |
| 1765 |
|
| 1766 |
static void |
| 1767 |
mt7925_mcu_sta_phy_tlv(struct sk_buff *skb, |
| 1768 |
struct ieee80211_vif *vif, |
| 1769 |
struct ieee80211_link_sta *link_sta) |
| 1770 |
{ |
| 1771 |
struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; |
| 1772 |
struct ieee80211_bss_conf *link_conf; |
| 1773 |
struct cfg80211_chan_def *chandef; |
| 1774 |
struct mt792x_bss_conf *mconf; |
| 1775 |
struct sta_rec_phy *phy; |
| 1776 |
struct tlv *tlv; |
| 1777 |
u8 af = 0, mm = 0; |
| 1778 |
|
| 1779 |
link_conf = mt792x_vif_to_bss_conf(vif, link_sta->link_id); |
| 1780 |
mconf = mt792x_vif_to_link(mvif, link_sta->link_id); |
| 1781 |
chandef = mconf->mt76.ctx ? &mconf->mt76.ctx->def : |
| 1782 |
&link_conf->chanreq.oper; |
| 1783 |
|
| 1784 |
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_PHY, sizeof(*phy)); |
| 1785 |
phy = (struct sta_rec_phy *)tlv; |
| 1786 |
phy->phy_type = mt76_connac_get_phy_mode_v2(mvif->phy->mt76, vif, |
| 1787 |
chandef->chan->band, |
| 1788 |
link_sta); |
| 1789 |
phy->basic_rate = cpu_to_le16((u16)link_conf->basic_rates); |
| 1790 |
if (link_sta->ht_cap.ht_supported) { |
| 1791 |
af = link_sta->ht_cap.ampdu_factor; |
| 1792 |
mm = link_sta->ht_cap.ampdu_density; |
| 1793 |
} |
| 1794 |
|
| 1795 |
if (link_sta->vht_cap.vht_supported) { |
| 1796 |
u8 vht_af = FIELD_GET(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK, |
| 1797 |
link_sta->vht_cap.cap); |
| 1798 |
|
| 1799 |
af = max_t(u8, af, vht_af); |
| 1800 |
} |
| 1801 |
|
| 1802 |
if (link_sta->he_6ghz_capa.capa) { |
| 1803 |
af = le16_get_bits(link_sta->he_6ghz_capa.capa, |
| 1804 |
IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP); |
| 1805 |
mm = le16_get_bits(link_sta->he_6ghz_capa.capa, |
| 1806 |
IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START); |
| 1807 |
} |
| 1808 |
|
| 1809 |
phy->ampdu = FIELD_PREP(IEEE80211_HT_AMPDU_PARM_FACTOR, af) | |
| 1810 |
FIELD_PREP(IEEE80211_HT_AMPDU_PARM_DENSITY, mm); |
| 1811 |
phy->max_ampdu_len = af; |
| 1812 |
} |
| 1813 |
|
| 1814 |
static void |
| 1815 |
mt7925_mcu_sta_state_v2_tlv(struct mt76_phy *mphy, struct sk_buff *skb, |
| 1816 |
struct ieee80211_link_sta *link_sta, |
| 1817 |
struct ieee80211_vif *vif, |
| 1818 |
u8 rcpi, u8 sta_state) |
| 1819 |
{ |
| 1820 |
struct sta_rec_state_v2 { |
| 1821 |
__le16 tag; |
| 1822 |
__le16 len; |
| 1823 |
u8 state; |
| 1824 |
u8 rsv[3]; |
| 1825 |
__le32 flags; |
| 1826 |
u8 vht_opmode; |
| 1827 |
u8 action; |
| 1828 |
u8 rsv2[2]; |
| 1829 |
} __packed * state; |
| 1830 |
struct tlv *tlv; |
| 1831 |
|
| 1832 |
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_STATE, sizeof(*state)); |
| 1833 |
state = (struct sta_rec_state_v2 *)tlv; |
| 1834 |
state->state = sta_state; |
| 1835 |
|
| 1836 |
if (link_sta->vht_cap.vht_supported) { |
| 1837 |
state->vht_opmode = link_sta->bandwidth; |
| 1838 |
state->vht_opmode |= link_sta->rx_nss << |
| 1839 |
IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT; |
| 1840 |
} |
| 1841 |
} |
| 1842 |
|
| 1843 |
static void |
| 1844 |
mt7925_mcu_sta_rate_ctrl_tlv(struct sk_buff *skb, |
| 1845 |
struct ieee80211_vif *vif, |
| 1846 |
struct ieee80211_link_sta *link_sta) |
| 1847 |
{ |
| 1848 |
struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; |
| 1849 |
struct ieee80211_bss_conf *link_conf; |
| 1850 |
struct cfg80211_chan_def *chandef; |
| 1851 |
struct sta_rec_ra_info *ra_info; |
| 1852 |
struct mt792x_bss_conf *mconf; |
| 1853 |
enum nl80211_band band; |
| 1854 |
struct tlv *tlv; |
| 1855 |
u16 supp_rates; |
| 1856 |
|
| 1857 |
link_conf = mt792x_vif_to_bss_conf(vif, link_sta->link_id); |
| 1858 |
mconf = mt792x_vif_to_link(mvif, link_sta->link_id); |
| 1859 |
chandef = mconf->mt76.ctx ? &mconf->mt76.ctx->def : |
| 1860 |
&link_conf->chanreq.oper; |
| 1861 |
band = chandef->chan->band; |
| 1862 |
|
| 1863 |
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_RA, sizeof(*ra_info)); |
| 1864 |
ra_info = (struct sta_rec_ra_info *)tlv; |
| 1865 |
|
| 1866 |
supp_rates = link_sta->supp_rates[band]; |
| 1867 |
if (band == NL80211_BAND_2GHZ) |
| 1868 |
supp_rates = FIELD_PREP(RA_LEGACY_OFDM, supp_rates >> 4) | |
| 1869 |
FIELD_PREP(RA_LEGACY_CCK, supp_rates & 0xf); |
| 1870 |
else |
| 1871 |
supp_rates = FIELD_PREP(RA_LEGACY_OFDM, supp_rates); |
| 1872 |
|
| 1873 |
ra_info->legacy = cpu_to_le16(supp_rates); |
| 1874 |
|
| 1875 |
if (link_sta->ht_cap.ht_supported) |
| 1876 |
memcpy(ra_info->rx_mcs_bitmask, |
| 1877 |
link_sta->ht_cap.mcs.rx_mask, |
| 1878 |
HT_MCS_MASK_NUM); |
| 1879 |
} |
| 1880 |
|
| 1881 |
static void |
| 1882 |
mt7925_mcu_sta_eht_mld_tlv(struct sk_buff *skb, |
| 1883 |
struct ieee80211_vif *vif, struct ieee80211_sta *sta) |
| 1884 |
{ |
| 1885 |
struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; |
| 1886 |
struct wiphy *wiphy = mvif->phy->mt76->hw->wiphy; |
| 1887 |
const struct wiphy_iftype_ext_capab *ext_capa; |
| 1888 |
struct sta_rec_eht_mld *eht_mld; |
| 1889 |
struct tlv *tlv; |
| 1890 |
u16 eml_cap; |
| 1891 |
|
| 1892 |
if (!ieee80211_vif_is_mld(vif)) |
| 1893 |
return; |
| 1894 |
|
| 1895 |
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_EHT_MLD, sizeof(*eht_mld)); |
| 1896 |
eht_mld = (struct sta_rec_eht_mld *)tlv; |
| 1897 |
eht_mld->mld_type = 0xff; |
| 1898 |
|
| 1899 |
ext_capa = cfg80211_get_iftype_ext_capa(wiphy, |
| 1900 |
ieee80211_vif_type_p2p(vif)); |
| 1901 |
if (!ext_capa) |
| 1902 |
return; |
| 1903 |
|
| 1904 |
eml_cap = (vif->cfg.eml_cap & (IEEE80211_EML_CAP_EMLSR_SUPP | |
| 1905 |
IEEE80211_EML_CAP_TRANSITION_TIMEOUT)) | |
| 1906 |
(ext_capa->eml_capabilities & (IEEE80211_EML_CAP_EMLSR_PADDING_DELAY | |
| 1907 |
IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY)); |
| 1908 |
|
| 1909 |
if (eml_cap & IEEE80211_EML_CAP_EMLSR_SUPP) { |
| 1910 |
eht_mld->eml_cap[0] = u16_get_bits(eml_cap, GENMASK(7, 0)); |
| 1911 |
eht_mld->eml_cap[1] = u16_get_bits(eml_cap, GENMASK(15, 8)); |
| 1912 |
} else { |
| 1913 |
eht_mld->str_cap[0] = BIT(1); |
| 1914 |
} |
| 1915 |
} |
| 1916 |
|
| 1917 |
static void |
| 1918 |
mt7925_mcu_sta_mld_tlv(struct sk_buff *skb, |
| 1919 |
struct ieee80211_vif *vif, struct ieee80211_sta *sta) |
| 1920 |
{ |
| 1921 |
struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; |
| 1922 |
struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv; |
| 1923 |
unsigned long valid = mvif->valid_links; |
| 1924 |
struct mt792x_bss_conf *mconf; |
| 1925 |
struct mt792x_link_sta *mlink; |
| 1926 |
struct sta_rec_mld *mld; |
| 1927 |
struct tlv *tlv; |
| 1928 |
int i, cnt = 0; |
| 1929 |
|
| 1930 |
tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_MLD, sizeof(*mld)); |
| 1931 |
mld = (struct sta_rec_mld *)tlv; |
| 1932 |
memcpy(mld->mac_addr, sta->addr, ETH_ALEN); |
| 1933 |
mld->primary_id = cpu_to_le16(msta->deflink.wcid.idx); |
| 1934 |
mld->wlan_id = cpu_to_le16(msta->deflink.wcid.idx); |
| 1935 |
mld->link_num = min_t(u8, hweight16(mvif->valid_links), 2); |
| 1936 |
|
| 1937 |
for_each_set_bit(i, &valid, IEEE80211_MLD_MAX_NUM_LINKS) { |
| 1938 |
if (cnt == mld->link_num) |
| 1939 |
break; |
| 1940 |
|
| 1941 |
mconf = mt792x_vif_to_link(mvif, i); |
| 1942 |
mlink = mt792x_sta_to_link(msta, i); |
| 1943 |
mld->link[cnt].wlan_id = cpu_to_le16(mlink->wcid.idx); |
| 1944 |
mld->link[cnt++].bss_idx = mconf->mt76.idx; |
| 1945 |
|
| 1946 |
if (mlink != &msta->deflink) |
| 1947 |
mld->secondary_id = cpu_to_le16(mlink->wcid.idx); |
| 1948 |
} |
| 1949 |
} |
| 1950 |
|
| 1951 |
static void |
| 1952 |
mt7925_mcu_sta_remove_tlv(struct sk_buff *skb) |
| 1953 |
{ |
| 1954 |
struct sta_rec_remove *rem; |
| 1955 |
struct tlv *tlv; |
| 1956 |
|
| 1957 |
tlv = mt76_connac_mcu_add_tlv(skb, 0x25, sizeof(*rem)); |
| 1958 |
rem = (struct sta_rec_remove *)tlv; |
| 1959 |
rem->action = 0; |
| 1960 |
} |
| 1961 |
|
| 1962 |
static int |
| 1963 |
mt7925_mcu_sta_cmd(struct mt76_phy *phy, |
| 1964 |
struct mt76_sta_cmd_info *info) |
| 1965 |
{ |
| 1966 |
struct mt792x_vif *mvif = (struct mt792x_vif *)info->vif->drv_priv; |
| 1967 |
struct mt76_dev *dev = phy->dev; |
| 1968 |
struct mt792x_bss_conf *mconf; |
| 1969 |
struct sk_buff *skb; |
| 1970 |
int conn_state; |
| 1971 |
|
| 1972 |
mconf = mt792x_vif_to_link(mvif, info->wcid->link_id); |
| 1973 |
|
| 1974 |
skb = __mt76_connac_mcu_alloc_sta_req(dev, &mconf->mt76, info->wcid, |
| 1975 |
MT7925_STA_UPDATE_MAX_SIZE); |
| 1976 |
if (IS_ERR(skb)) |
| 1977 |
return PTR_ERR(skb); |
| 1978 |
|
| 1979 |
conn_state = info->enable ? CONN_STATE_PORT_SECURE : |
| 1980 |
CONN_STATE_DISCONNECT; |
| 1981 |
|
| 1982 |
if (info->enable && info->link_sta) { |
| 1983 |
mt76_connac_mcu_sta_basic_tlv(dev, skb, info->link_conf, |
| 1984 |
info->link_sta, |
| 1985 |
conn_state, info->newly); |
| 1986 |
mt7925_mcu_sta_phy_tlv(skb, info->vif, info->link_sta); |
| 1987 |
mt7925_mcu_sta_ht_tlv(skb, info->link_sta); |
| 1988 |
mt7925_mcu_sta_vht_tlv(skb, info->link_sta); |
| 1989 |
mt76_connac_mcu_sta_uapsd(skb, info->vif, info->link_sta->sta); |
| 1990 |
mt7925_mcu_sta_amsdu_tlv(skb, info->vif, info->link_sta); |
| 1991 |
mt7925_mcu_sta_he_tlv(skb, info->link_sta); |
| 1992 |
mt7925_mcu_sta_he_6g_tlv(skb, info->link_sta); |
| 1993 |
mt7925_mcu_sta_eht_tlv(skb, info->link_sta); |
| 1994 |
mt7925_mcu_sta_rate_ctrl_tlv(skb, info->vif, |
| 1995 |
info->link_sta); |
| 1996 |
mt7925_mcu_sta_state_v2_tlv(phy, skb, info->link_sta, |
| 1997 |
info->vif, info->rcpi, |
| 1998 |
info->state); |
| 1999 |
|
| 2000 |
if (info->state != MT76_STA_INFO_STATE_NONE) { |
| 2001 |
mt7925_mcu_sta_mld_tlv(skb, info->vif, info->link_sta->sta); |
| 2002 |
mt7925_mcu_sta_eht_mld_tlv(skb, info->vif, info->link_sta->sta); |
| 2003 |
} |
| 2004 |
} |
| 2005 |
|
| 2006 |
if (!info->enable) { |
| 2007 |
mt7925_mcu_sta_remove_tlv(skb); |
| 2008 |
mt76_connac_mcu_add_tlv(skb, STA_REC_MLD_OFF, |
| 2009 |
sizeof(struct tlv)); |
| 2010 |
} else { |
| 2011 |
mt7925_mcu_sta_hdr_trans_tlv(skb, info->vif, info->link_sta); |
| 2012 |
} |
| 2013 |
|
| 2014 |
return mt76_mcu_skb_send_msg(dev, skb, info->cmd, true); |
| 2015 |
} |
| 2016 |
|
| 2017 |
int mt7925_mcu_sta_update(struct mt792x_dev *dev, |
| 2018 |
struct ieee80211_link_sta *link_sta, |
| 2019 |
struct ieee80211_vif *vif, bool enable, |
| 2020 |
enum mt76_sta_info_state state) |
| 2021 |
{ |
| 2022 |
struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; |
| 2023 |
int rssi = -ewma_rssi_read(&mvif->bss_conf.rssi); |
| 2024 |
struct mt76_sta_cmd_info info = { |
| 2025 |
.link_sta = link_sta, |
| 2026 |
.vif = vif, |
| 2027 |
.link_conf = &vif->bss_conf, |
| 2028 |
.enable = enable, |
| 2029 |
.cmd = MCU_UNI_CMD(STA_REC_UPDATE), |
| 2030 |
.state = state, |
| 2031 |
.offload_fw = true, |
| 2032 |
.rcpi = to_rcpi(rssi), |
| 2033 |
}; |
| 2034 |
struct mt792x_sta *msta; |
| 2035 |
struct mt792x_link_sta *mlink; |
| 2036 |
|
| 2037 |
if (link_sta) { |
| 2038 |
msta = (struct mt792x_sta *)link_sta->sta->drv_priv; |
| 2039 |
mlink = mt792x_sta_to_link(msta, link_sta->link_id); |
| 2040 |
} |
| 2041 |
info.wcid = link_sta ? &mlink->wcid : &mvif->sta.deflink.wcid; |
| 2042 |
info.newly = state != MT76_STA_INFO_STATE_ASSOC; |
| 2043 |
|
| 2044 |
return mt7925_mcu_sta_cmd(&dev->mphy, &info); |
| 2045 |
} |
| 2046 |
|
| 2047 |
int mt7925_mcu_set_beacon_filter(struct mt792x_dev *dev, |
| 2048 |
struct ieee80211_vif *vif, |
| 2049 |
bool enable) |
| 2050 |
{ |
| 2051 |
#define MT7925_FIF_BIT_CLR BIT(1) |
| 2052 |
#define MT7925_FIF_BIT_SET BIT(0) |
| 2053 |
int err = 0; |
| 2054 |
|
| 2055 |
if (enable) { |
| 2056 |
err = mt7925_mcu_uni_bss_bcnft(dev, &vif->bss_conf, true); |
| 2057 |
if (err < 0) |
| 2058 |
return err; |
| 2059 |
|
| 2060 |
return mt7925_mcu_set_rxfilter(dev, 0, |
| 2061 |
MT7925_FIF_BIT_SET, |
| 2062 |
MT_WF_RFCR_DROP_OTHER_BEACON); |
| 2063 |
} |
| 2064 |
|
| 2065 |
err = mt7925_mcu_set_bss_pm(dev, &vif->bss_conf, false); |
| 2066 |
if (err < 0) |
| 2067 |
return err; |
| 2068 |
|
| 2069 |
return mt7925_mcu_set_rxfilter(dev, 0, |
| 2070 |
MT7925_FIF_BIT_CLR, |
| 2071 |
MT_WF_RFCR_DROP_OTHER_BEACON); |
| 2072 |
} |
| 2073 |
|
| 2074 |
int mt7925_get_txpwr_info(struct mt792x_dev *dev, u8 band_idx, struct mt7925_txpwr *txpwr) |
| 2075 |
{ |
| 2076 |
#define TX_POWER_SHOW_INFO 0x7 |
| 2077 |
#define TXPOWER_ALL_RATE_POWER_INFO 0x2 |
| 2078 |
struct mt7925_txpwr_event *event; |
| 2079 |
struct mt7925_txpwr_req req = { |
| 2080 |
.tag = cpu_to_le16(TX_POWER_SHOW_INFO), |
| 2081 |
.len = cpu_to_le16(sizeof(req) - 4), |
| 2082 |
.catg = TXPOWER_ALL_RATE_POWER_INFO, |
| 2083 |
.band_idx = band_idx, |
| 2084 |
}; |
| 2085 |
struct sk_buff *skb; |
| 2086 |
int ret; |
| 2087 |
|
| 2088 |
ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_UNI_CMD(TXPOWER), |
| 2089 |
&req, sizeof(req), true, &skb); |
| 2090 |
if (ret) |
| 2091 |
return ret; |
| 2092 |
|
| 2093 |
event = (struct mt7925_txpwr_event *)skb->data; |
| 2094 |
memcpy(txpwr, &event->txpwr, sizeof(event->txpwr)); |
| 2095 |
|
| 2096 |
dev_kfree_skb(skb); |
| 2097 |
|
| 2098 |
return 0; |
| 2099 |
} |
| 2100 |
|
| 2101 |
int mt7925_mcu_set_sniffer(struct mt792x_dev *dev, struct ieee80211_vif *vif, |
| 2102 |
bool enable) |
| 2103 |
{ |
| 2104 |
struct { |
| 2105 |
struct { |
| 2106 |
u8 band_idx; |
| 2107 |
u8 pad[3]; |
| 2108 |
} __packed hdr; |
| 2109 |
struct sniffer_enable_tlv { |
| 2110 |
__le16 tag; |
| 2111 |
__le16 len; |
| 2112 |
u8 enable; |
| 2113 |
u8 pad[3]; |
| 2114 |
} __packed enable; |
| 2115 |
} __packed req = { |
| 2116 |
.hdr = { |
| 2117 |
.band_idx = 0, |
| 2118 |
}, |
| 2119 |
.enable = { |
| 2120 |
.tag = cpu_to_le16(UNI_SNIFFER_ENABLE), |
| 2121 |
.len = cpu_to_le16(sizeof(struct sniffer_enable_tlv)), |
| 2122 |
.enable = enable, |
| 2123 |
}, |
| 2124 |
}; |
| 2125 |
|
| 2126 |
return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(SNIFFER), &req, sizeof(req), |
| 2127 |
true); |
| 2128 |
} |
| 2129 |
|
| 2130 |
int mt7925_mcu_config_sniffer(struct mt792x_vif *vif, |
| 2131 |
struct ieee80211_chanctx_conf *ctx) |
| 2132 |
{ |
| 2133 |
struct mt76_phy *mphy = vif->phy->mt76; |
| 2134 |
struct cfg80211_chan_def *chandef = ctx ? &ctx->def : &mphy->chandef; |
| 2135 |
int freq1 = chandef->center_freq1, freq2 = chandef->center_freq2; |
| 2136 |
|
| 2137 |
static const u8 ch_band[] = { |
| 2138 |
[NL80211_BAND_2GHZ] = 1, |
| 2139 |
[NL80211_BAND_5GHZ] = 2, |
| 2140 |
[NL80211_BAND_6GHZ] = 3, |
| 2141 |
}; |
| 2142 |
static const u8 ch_width[] = { |
| 2143 |
[NL80211_CHAN_WIDTH_20_NOHT] = 0, |
| 2144 |
[NL80211_CHAN_WIDTH_20] = 0, |
| 2145 |
[NL80211_CHAN_WIDTH_40] = 0, |
| 2146 |
[NL80211_CHAN_WIDTH_80] = 1, |
| 2147 |
[NL80211_CHAN_WIDTH_160] = 2, |
| 2148 |
[NL80211_CHAN_WIDTH_80P80] = 3, |
| 2149 |
[NL80211_CHAN_WIDTH_5] = 4, |
| 2150 |
[NL80211_CHAN_WIDTH_10] = 5, |
| 2151 |
[NL80211_CHAN_WIDTH_320] = 6, |
| 2152 |
}; |
| 2153 |
|
| 2154 |
struct { |
| 2155 |
struct { |
| 2156 |
u8 band_idx; |
| 2157 |
u8 pad[3]; |
| 2158 |
} __packed hdr; |
| 2159 |
struct config_tlv { |
| 2160 |
__le16 tag; |
| 2161 |
__le16 len; |
| 2162 |
u16 aid; |
| 2163 |
u8 ch_band; |
| 2164 |
u8 bw; |
| 2165 |
u8 control_ch; |
| 2166 |
u8 sco; |
| 2167 |
u8 center_ch; |
| 2168 |
u8 center_ch2; |
| 2169 |
u8 drop_err; |
| 2170 |
u8 pad[3]; |
| 2171 |
} __packed tlv; |
| 2172 |
} __packed req = { |
| 2173 |
.hdr = { |
| 2174 |
.band_idx = 0, |
| 2175 |
}, |
| 2176 |
.tlv = { |
| 2177 |
.tag = cpu_to_le16(UNI_SNIFFER_CONFIG), |
| 2178 |
.len = cpu_to_le16(sizeof(req.tlv)), |
| 2179 |
.control_ch = chandef->chan->hw_value, |
| 2180 |
.center_ch = ieee80211_frequency_to_channel(freq1), |
| 2181 |
.drop_err = 1, |
| 2182 |
}, |
| 2183 |
}; |
| 2184 |
|
| 2185 |
if (chandef->chan->band < ARRAY_SIZE(ch_band)) |
| 2186 |
req.tlv.ch_band = ch_band[chandef->chan->band]; |
| 2187 |
if (chandef->width < ARRAY_SIZE(ch_width)) |
| 2188 |
req.tlv.bw = ch_width[chandef->width]; |
| 2189 |
|
| 2190 |
if (freq2) |
| 2191 |
req.tlv.center_ch2 = ieee80211_frequency_to_channel(freq2); |
| 2192 |
|
| 2193 |
if (req.tlv.control_ch < req.tlv.center_ch) |
| 2194 |
req.tlv.sco = 1; /* SCA */ |
| 2195 |
else if (req.tlv.control_ch > req.tlv.center_ch) |
| 2196 |
req.tlv.sco = 3; /* SCB */ |
| 2197 |
|
| 2198 |
return mt76_mcu_send_msg(mphy->dev, MCU_UNI_CMD(SNIFFER), |
| 2199 |
&req, sizeof(req), true); |
| 2200 |
} |
| 2201 |
|
| 2202 |
int |
| 2203 |
mt7925_mcu_uni_add_beacon_offload(struct mt792x_dev *dev, |
| 2204 |
struct ieee80211_hw *hw, |
| 2205 |
struct ieee80211_vif *vif, |
| 2206 |
bool enable) |
| 2207 |
{ |
| 2208 |
struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; |
| 2209 |
struct ieee80211_mutable_offsets offs; |
| 2210 |
struct { |
| 2211 |
struct req_hdr { |
| 2212 |
u8 bss_idx; |
| 2213 |
u8 pad[3]; |
| 2214 |
} __packed hdr; |
| 2215 |
struct bcn_content_tlv { |
| 2216 |
__le16 tag; |
| 2217 |
__le16 len; |
| 2218 |
__le16 tim_ie_pos; |
| 2219 |
__le16 csa_ie_pos; |
| 2220 |
__le16 bcc_ie_pos; |
| 2221 |
/* 0: disable beacon offload |
| 2222 |
* 1: enable beacon offload |
| 2223 |
* 2: update probe respond offload |
| 2224 |
*/ |
| 2225 |
u8 enable; |
| 2226 |
/* 0: legacy format (TXD + payload) |
| 2227 |
* 1: only cap field IE |
| 2228 |
*/ |
| 2229 |
u8 type; |
| 2230 |
__le16 pkt_len; |
| 2231 |
u8 pkt[512]; |
| 2232 |
} __packed beacon_tlv; |
| 2233 |
} req = { |
| 2234 |
.hdr = { |
| 2235 |
.bss_idx = mvif->bss_conf.mt76.idx, |
| 2236 |
}, |
| 2237 |
.beacon_tlv = { |
| 2238 |
.tag = cpu_to_le16(UNI_BSS_INFO_BCN_CONTENT), |
| 2239 |
.len = cpu_to_le16(sizeof(struct bcn_content_tlv)), |
| 2240 |
.enable = enable, |
| 2241 |
.type = 1, |
| 2242 |
}, |
| 2243 |
}; |
| 2244 |
struct sk_buff *skb; |
| 2245 |
u8 cap_offs; |
| 2246 |
|
| 2247 |
/* support enable/update process only |
| 2248 |
* disable flow would be handled in bss stop handler automatically |
| 2249 |
*/ |
| 2250 |
if (!enable) |
| 2251 |
return -EOPNOTSUPP; |
| 2252 |
|
| 2253 |
skb = ieee80211_beacon_get_template(mt76_hw(dev), vif, &offs, 0); |
| 2254 |
if (!skb) |
| 2255 |
return -EINVAL; |
| 2256 |
|
| 2257 |
cap_offs = offsetof(struct ieee80211_mgmt, u.beacon.capab_info); |
| 2258 |
if (!skb_pull(skb, cap_offs)) { |
| 2259 |
dev_err(dev->mt76.dev, "beacon format err\n"); |
| 2260 |
dev_kfree_skb(skb); |
| 2261 |
return -EINVAL; |
| 2262 |
} |
| 2263 |
|
| 2264 |
if (skb->len > 512) { |
| 2265 |
dev_err(dev->mt76.dev, "beacon size limit exceed\n"); |
| 2266 |
dev_kfree_skb(skb); |
| 2267 |
return -EINVAL; |
| 2268 |
} |
| 2269 |
|
| 2270 |
memcpy(req.beacon_tlv.pkt, skb->data, skb->len); |
| 2271 |
req.beacon_tlv.pkt_len = cpu_to_le16(skb->len); |
| 2272 |
offs.tim_offset -= cap_offs; |
| 2273 |
req.beacon_tlv.tim_ie_pos = cpu_to_le16(offs.tim_offset); |
| 2274 |
|
| 2275 |
if (offs.cntdwn_counter_offs[0]) { |
| 2276 |
u16 csa_offs; |
| 2277 |
|
| 2278 |
csa_offs = offs.cntdwn_counter_offs[0] - cap_offs - 4; |
| 2279 |
req.beacon_tlv.csa_ie_pos = cpu_to_le16(csa_offs); |
| 2280 |
} |
| 2281 |
dev_kfree_skb(skb); |
| 2282 |
|
| 2283 |
return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(BSS_INFO_UPDATE), |
| 2284 |
&req, sizeof(req), true); |
| 2285 |
} |
| 2286 |
|
| 2287 |
static |
| 2288 |
void mt7925_mcu_bss_rlm_tlv(struct sk_buff *skb, struct mt76_phy *phy, |
| 2289 |
struct ieee80211_bss_conf *link_conf, |
| 2290 |
struct ieee80211_chanctx_conf *ctx) |
| 2291 |
{ |
| 2292 |
struct cfg80211_chan_def *chandef = ctx ? &ctx->def : |
| 2293 |
&link_conf->chanreq.oper; |
| 2294 |
int freq1 = chandef->center_freq1, freq2 = chandef->center_freq2; |
| 2295 |
enum nl80211_band band = chandef->chan->band; |
| 2296 |
struct bss_rlm_tlv *req; |
| 2297 |
struct tlv *tlv; |
| 2298 |
|
| 2299 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_BSS_INFO_RLM, sizeof(*req)); |
| 2300 |
req = (struct bss_rlm_tlv *)tlv; |
| 2301 |
req->control_channel = chandef->chan->hw_value; |
| 2302 |
req->center_chan = ieee80211_frequency_to_channel(freq1); |
| 2303 |
req->center_chan2 = 0; |
| 2304 |
req->tx_streams = hweight8(phy->antenna_mask); |
| 2305 |
req->ht_op_info = 4; /* set HT 40M allowed */ |
| 2306 |
req->rx_streams = hweight8(phy->antenna_mask); |
| 2307 |
req->center_chan2 = 0; |
| 2308 |
req->sco = 0; |
| 2309 |
req->band = 1; |
| 2310 |
|
| 2311 |
switch (band) { |
| 2312 |
case NL80211_BAND_2GHZ: |
| 2313 |
req->band = 1; |
| 2314 |
break; |
| 2315 |
case NL80211_BAND_5GHZ: |
| 2316 |
req->band = 2; |
| 2317 |
break; |
| 2318 |
case NL80211_BAND_6GHZ: |
| 2319 |
req->band = 3; |
| 2320 |
break; |
| 2321 |
default: |
| 2322 |
break; |
| 2323 |
} |
| 2324 |
|
| 2325 |
switch (chandef->width) { |
| 2326 |
case NL80211_CHAN_WIDTH_40: |
| 2327 |
req->bw = CMD_CBW_40MHZ; |
| 2328 |
break; |
| 2329 |
case NL80211_CHAN_WIDTH_80: |
| 2330 |
req->bw = CMD_CBW_80MHZ; |
| 2331 |
break; |
| 2332 |
case NL80211_CHAN_WIDTH_80P80: |
| 2333 |
req->bw = CMD_CBW_8080MHZ; |
| 2334 |
req->center_chan2 = ieee80211_frequency_to_channel(freq2); |
| 2335 |
break; |
| 2336 |
case NL80211_CHAN_WIDTH_160: |
| 2337 |
req->bw = CMD_CBW_160MHZ; |
| 2338 |
break; |
| 2339 |
case NL80211_CHAN_WIDTH_5: |
| 2340 |
req->bw = CMD_CBW_5MHZ; |
| 2341 |
break; |
| 2342 |
case NL80211_CHAN_WIDTH_10: |
| 2343 |
req->bw = CMD_CBW_10MHZ; |
| 2344 |
break; |
| 2345 |
case NL80211_CHAN_WIDTH_20_NOHT: |
| 2346 |
case NL80211_CHAN_WIDTH_20: |
| 2347 |
default: |
| 2348 |
req->bw = CMD_CBW_20MHZ; |
| 2349 |
req->ht_op_info = 0; |
| 2350 |
break; |
| 2351 |
} |
| 2352 |
|
| 2353 |
if (req->control_channel < req->center_chan) |
| 2354 |
req->sco = 1; /* SCA */ |
| 2355 |
else if (req->control_channel > req->center_chan) |
| 2356 |
req->sco = 3; /* SCB */ |
| 2357 |
} |
| 2358 |
|
| 2359 |
static struct sk_buff * |
| 2360 |
__mt7925_mcu_alloc_bss_req(struct mt76_dev *dev, struct mt76_vif_link *mvif, int len) |
| 2361 |
{ |
| 2362 |
struct bss_req_hdr hdr = { |
| 2363 |
.bss_idx = mvif->idx, |
| 2364 |
}; |
| 2365 |
struct sk_buff *skb; |
| 2366 |
|
| 2367 |
skb = mt76_mcu_msg_alloc(dev, NULL, len); |
| 2368 |
if (!skb) |
| 2369 |
return ERR_PTR(-ENOMEM); |
| 2370 |
|
| 2371 |
skb_put_data(skb, &hdr, sizeof(hdr)); |
| 2372 |
|
| 2373 |
return skb; |
| 2374 |
} |
| 2375 |
|
| 2376 |
static |
| 2377 |
void mt7925_mcu_bss_eht_tlv(struct sk_buff *skb, struct mt76_phy *phy, |
| 2378 |
struct ieee80211_bss_conf *link_conf, |
| 2379 |
struct ieee80211_chanctx_conf *ctx) |
| 2380 |
{ |
| 2381 |
struct cfg80211_chan_def *chandef = ctx ? &ctx->def : |
| 2382 |
&link_conf->chanreq.oper; |
| 2383 |
|
| 2384 |
struct bss_eht_tlv *req; |
| 2385 |
struct tlv *tlv; |
| 2386 |
|
| 2387 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_BSS_INFO_EHT, sizeof(*req)); |
| 2388 |
req = (struct bss_eht_tlv *)tlv; |
| 2389 |
req->is_eth_dscb_present = chandef->punctured ? 1 : 0; |
| 2390 |
req->eht_dis_sub_chan_bitmap = cpu_to_le16(chandef->punctured); |
| 2391 |
} |
| 2392 |
|
| 2393 |
int mt7925_mcu_set_eht_pp(struct mt76_phy *phy, struct mt76_vif_link *mvif, |
| 2394 |
struct ieee80211_bss_conf *link_conf, |
| 2395 |
struct ieee80211_chanctx_conf *ctx) |
| 2396 |
{ |
| 2397 |
struct sk_buff *skb; |
| 2398 |
|
| 2399 |
skb = __mt7925_mcu_alloc_bss_req(phy->dev, mvif, |
| 2400 |
MT7925_BSS_UPDATE_MAX_SIZE); |
| 2401 |
if (IS_ERR(skb)) |
| 2402 |
return PTR_ERR(skb); |
| 2403 |
|
| 2404 |
mt7925_mcu_bss_eht_tlv(skb, phy, link_conf, ctx); |
| 2405 |
|
| 2406 |
return mt76_mcu_skb_send_msg(phy->dev, skb, |
| 2407 |
MCU_UNI_CMD(BSS_INFO_UPDATE), true); |
| 2408 |
} |
| 2409 |
|
| 2410 |
int mt7925_mcu_set_chctx(struct mt76_phy *phy, struct mt76_vif_link *mvif, |
| 2411 |
struct ieee80211_bss_conf *link_conf, |
| 2412 |
struct ieee80211_chanctx_conf *ctx) |
| 2413 |
{ |
| 2414 |
struct sk_buff *skb; |
| 2415 |
|
| 2416 |
skb = __mt7925_mcu_alloc_bss_req(phy->dev, mvif, |
| 2417 |
MT7925_BSS_UPDATE_MAX_SIZE); |
| 2418 |
if (IS_ERR(skb)) |
| 2419 |
return PTR_ERR(skb); |
| 2420 |
|
| 2421 |
mt7925_mcu_bss_rlm_tlv(skb, phy, link_conf, ctx); |
| 2422 |
|
| 2423 |
return mt76_mcu_skb_send_msg(phy->dev, skb, |
| 2424 |
MCU_UNI_CMD(BSS_INFO_UPDATE), true); |
| 2425 |
} |
| 2426 |
|
| 2427 |
static u8 |
| 2428 |
mt7925_get_phy_mode_ext(struct mt76_phy *phy, struct ieee80211_vif *vif, |
| 2429 |
enum nl80211_band band, |
| 2430 |
struct ieee80211_link_sta *link_sta) |
| 2431 |
{ |
| 2432 |
struct ieee80211_he_6ghz_capa *he_6ghz_capa; |
| 2433 |
const struct ieee80211_sta_eht_cap *eht_cap; |
| 2434 |
__le16 capa = 0; |
| 2435 |
u8 mode = 0; |
| 2436 |
|
| 2437 |
if (link_sta) { |
| 2438 |
he_6ghz_capa = &link_sta->he_6ghz_capa; |
| 2439 |
eht_cap = &link_sta->eht_cap; |
| 2440 |
} else { |
| 2441 |
struct ieee80211_supported_band *sband; |
| 2442 |
|
| 2443 |
sband = phy->hw->wiphy->bands[band]; |
| 2444 |
capa = ieee80211_get_he_6ghz_capa(sband, vif->type); |
| 2445 |
he_6ghz_capa = (struct ieee80211_he_6ghz_capa *)&capa; |
| 2446 |
|
| 2447 |
eht_cap = ieee80211_get_eht_iftype_cap(sband, vif->type); |
| 2448 |
} |
| 2449 |
|
| 2450 |
switch (band) { |
| 2451 |
case NL80211_BAND_2GHZ: |
| 2452 |
if (eht_cap && eht_cap->has_eht) |
| 2453 |
mode |= PHY_MODE_BE_24G; |
| 2454 |
break; |
| 2455 |
case NL80211_BAND_5GHZ: |
| 2456 |
if (eht_cap && eht_cap->has_eht) |
| 2457 |
mode |= PHY_MODE_BE_5G; |
| 2458 |
break; |
| 2459 |
case NL80211_BAND_6GHZ: |
| 2460 |
if (he_6ghz_capa && he_6ghz_capa->capa) |
| 2461 |
mode |= PHY_MODE_AX_6G; |
| 2462 |
|
| 2463 |
if (eht_cap && eht_cap->has_eht) |
| 2464 |
mode |= PHY_MODE_BE_6G; |
| 2465 |
break; |
| 2466 |
default: |
| 2467 |
break; |
| 2468 |
} |
| 2469 |
|
| 2470 |
return mode; |
| 2471 |
} |
| 2472 |
|
| 2473 |
static void |
| 2474 |
mt7925_mcu_bss_basic_tlv(struct sk_buff *skb, |
| 2475 |
struct ieee80211_bss_conf *link_conf, |
| 2476 |
struct ieee80211_link_sta *link_sta, |
| 2477 |
struct ieee80211_chanctx_conf *ctx, |
| 2478 |
struct mt76_phy *phy, u16 wlan_idx, |
| 2479 |
bool enable) |
| 2480 |
{ |
| 2481 |
struct ieee80211_vif *vif = link_conf->vif; |
| 2482 |
struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); |
| 2483 |
struct cfg80211_chan_def *chandef = ctx ? &ctx->def : |
| 2484 |
&link_conf->chanreq.oper; |
| 2485 |
enum nl80211_band band = chandef->chan->band; |
| 2486 |
struct mt76_connac_bss_basic_tlv *basic_req; |
| 2487 |
struct mt792x_link_sta *mlink; |
| 2488 |
struct tlv *tlv; |
| 2489 |
int conn_type; |
| 2490 |
u8 idx; |
| 2491 |
|
| 2492 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_BSS_INFO_BASIC, sizeof(*basic_req)); |
| 2493 |
basic_req = (struct mt76_connac_bss_basic_tlv *)tlv; |
| 2494 |
|
| 2495 |
idx = mconf->mt76.omac_idx > EXT_BSSID_START ? HW_BSSID_0 : |
| 2496 |
mconf->mt76.omac_idx; |
| 2497 |
basic_req->hw_bss_idx = idx; |
| 2498 |
|
| 2499 |
basic_req->phymode_ext = mt7925_get_phy_mode_ext(phy, vif, band, |
| 2500 |
link_sta); |
| 2501 |
|
| 2502 |
if (band == NL80211_BAND_2GHZ) |
| 2503 |
basic_req->nonht_basic_phy = cpu_to_le16(PHY_TYPE_ERP_INDEX); |
| 2504 |
else |
| 2505 |
basic_req->nonht_basic_phy = cpu_to_le16(PHY_TYPE_OFDM_INDEX); |
| 2506 |
|
| 2507 |
memcpy(basic_req->bssid, link_conf->bssid, ETH_ALEN); |
| 2508 |
basic_req->phymode = mt76_connac_get_phy_mode(phy, vif, band, link_sta); |
| 2509 |
basic_req->bcn_interval = cpu_to_le16(link_conf->beacon_int); |
| 2510 |
basic_req->dtim_period = link_conf->dtim_period; |
| 2511 |
basic_req->bmc_tx_wlan_idx = cpu_to_le16(wlan_idx); |
| 2512 |
basic_req->link_idx = mconf->mt76.idx; |
| 2513 |
|
| 2514 |
if (link_sta) { |
| 2515 |
struct mt792x_sta *msta; |
| 2516 |
|
| 2517 |
msta = (struct mt792x_sta *)link_sta->sta->drv_priv; |
| 2518 |
mlink = mt792x_sta_to_link(msta, link_sta->link_id); |
| 2519 |
|
| 2520 |
} else { |
| 2521 |
mlink = &mconf->vif->sta.deflink; |
| 2522 |
} |
| 2523 |
|
| 2524 |
basic_req->sta_idx = cpu_to_le16(mlink->wcid.idx); |
| 2525 |
basic_req->omac_idx = mconf->mt76.omac_idx; |
| 2526 |
basic_req->band_idx = mconf->mt76.band_idx; |
| 2527 |
basic_req->wmm_idx = mconf->mt76.wmm_idx; |
| 2528 |
basic_req->conn_state = !enable; |
| 2529 |
|
| 2530 |
switch (vif->type) { |
| 2531 |
case NL80211_IFTYPE_MESH_POINT: |
| 2532 |
case NL80211_IFTYPE_AP: |
| 2533 |
if (vif->p2p) |
| 2534 |
conn_type = CONNECTION_P2P_GO; |
| 2535 |
else |
| 2536 |
conn_type = CONNECTION_INFRA_AP; |
| 2537 |
basic_req->conn_type = cpu_to_le32(conn_type); |
| 2538 |
basic_req->active = enable; |
| 2539 |
break; |
| 2540 |
case NL80211_IFTYPE_STATION: |
| 2541 |
if (vif->p2p) |
| 2542 |
conn_type = CONNECTION_P2P_GC; |
| 2543 |
else |
| 2544 |
conn_type = CONNECTION_INFRA_STA; |
| 2545 |
basic_req->conn_type = cpu_to_le32(conn_type); |
| 2546 |
basic_req->active = true; |
| 2547 |
break; |
| 2548 |
case NL80211_IFTYPE_ADHOC: |
| 2549 |
basic_req->conn_type = cpu_to_le32(CONNECTION_IBSS_ADHOC); |
| 2550 |
basic_req->active = true; |
| 2551 |
break; |
| 2552 |
default: |
| 2553 |
WARN_ON(1); |
| 2554 |
break; |
| 2555 |
} |
| 2556 |
} |
| 2557 |
|
| 2558 |
static void |
| 2559 |
mt7925_mcu_bss_sec_tlv(struct sk_buff *skb, |
| 2560 |
struct ieee80211_bss_conf *link_conf) |
| 2561 |
{ |
| 2562 |
struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); |
| 2563 |
struct mt76_vif_link *mvif = &mconf->mt76; |
| 2564 |
struct bss_sec_tlv { |
| 2565 |
__le16 tag; |
| 2566 |
__le16 len; |
| 2567 |
u8 mode; |
| 2568 |
u8 status; |
| 2569 |
u8 cipher; |
| 2570 |
u8 __rsv; |
| 2571 |
} __packed * sec; |
| 2572 |
struct tlv *tlv; |
| 2573 |
|
| 2574 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_BSS_INFO_SEC, sizeof(*sec)); |
| 2575 |
sec = (struct bss_sec_tlv *)tlv; |
| 2576 |
|
| 2577 |
switch (mvif->cipher) { |
| 2578 |
case CONNAC3_CIPHER_GCMP_256: |
| 2579 |
case CONNAC3_CIPHER_GCMP: |
| 2580 |
sec->mode = MODE_WPA3_SAE; |
| 2581 |
sec->status = 8; |
| 2582 |
break; |
| 2583 |
case CONNAC3_CIPHER_AES_CCMP: |
| 2584 |
sec->mode = MODE_WPA2_PSK; |
| 2585 |
sec->status = 6; |
| 2586 |
break; |
| 2587 |
case CONNAC3_CIPHER_TKIP: |
| 2588 |
sec->mode = MODE_WPA2_PSK; |
| 2589 |
sec->status = 4; |
| 2590 |
break; |
| 2591 |
case CONNAC3_CIPHER_WEP104: |
| 2592 |
case CONNAC3_CIPHER_WEP40: |
| 2593 |
sec->mode = MODE_SHARED; |
| 2594 |
sec->status = 0; |
| 2595 |
break; |
| 2596 |
default: |
| 2597 |
sec->mode = MODE_OPEN; |
| 2598 |
sec->status = 1; |
| 2599 |
break; |
| 2600 |
} |
| 2601 |
|
| 2602 |
sec->cipher = mvif->cipher; |
| 2603 |
} |
| 2604 |
|
| 2605 |
static void |
| 2606 |
mt7925_mcu_bss_bmc_tlv(struct sk_buff *skb, struct mt792x_phy *phy, |
| 2607 |
struct ieee80211_chanctx_conf *ctx, |
| 2608 |
struct ieee80211_bss_conf *link_conf) |
| 2609 |
{ |
| 2610 |
struct cfg80211_chan_def *chandef = ctx ? &ctx->def : |
| 2611 |
&link_conf->chanreq.oper; |
| 2612 |
struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); |
| 2613 |
enum nl80211_band band = chandef->chan->band; |
| 2614 |
struct mt76_vif_link *mvif = &mconf->mt76; |
| 2615 |
struct bss_rate_tlv *bmc; |
| 2616 |
struct tlv *tlv; |
| 2617 |
u8 idx = mvif->mcast_rates_idx ? |
| 2618 |
mvif->mcast_rates_idx : mvif->basic_rates_idx; |
| 2619 |
|
| 2620 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_BSS_INFO_RATE, sizeof(*bmc)); |
| 2621 |
|
| 2622 |
bmc = (struct bss_rate_tlv *)tlv; |
| 2623 |
|
| 2624 |
if (band == NL80211_BAND_2GHZ) |
| 2625 |
bmc->basic_rate = cpu_to_le16(HR_DSSS_ERP_BASIC_RATE); |
| 2626 |
else |
| 2627 |
bmc->basic_rate = cpu_to_le16(OFDM_BASIC_RATE); |
| 2628 |
|
| 2629 |
bmc->short_preamble = (band == NL80211_BAND_2GHZ); |
| 2630 |
bmc->bc_fixed_rate = idx; |
| 2631 |
bmc->mc_fixed_rate = idx; |
| 2632 |
} |
| 2633 |
|
| 2634 |
static void |
| 2635 |
mt7925_mcu_bss_mld_tlv(struct sk_buff *skb, |
| 2636 |
struct ieee80211_bss_conf *link_conf) |
| 2637 |
{ |
| 2638 |
struct ieee80211_vif *vif = link_conf->vif; |
| 2639 |
struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); |
| 2640 |
struct mt792x_vif *mvif = (struct mt792x_vif *)link_conf->vif->drv_priv; |
| 2641 |
struct mt792x_phy *phy = mvif->phy; |
| 2642 |
struct bss_mld_tlv *mld; |
| 2643 |
struct tlv *tlv; |
| 2644 |
bool is_mld; |
| 2645 |
|
| 2646 |
is_mld = ieee80211_vif_is_mld(link_conf->vif) || |
| 2647 |
(hweight16(mvif->valid_links) > 1); |
| 2648 |
|
| 2649 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_BSS_INFO_MLD, sizeof(*mld)); |
| 2650 |
mld = (struct bss_mld_tlv *)tlv; |
| 2651 |
|
| 2652 |
mld->link_id = is_mld ? link_conf->link_id : 0xff; |
| 2653 |
/* apply the index of the primary link */ |
| 2654 |
mld->group_mld_id = is_mld ? mvif->bss_conf.mt76.idx : 0xff; |
| 2655 |
mld->own_mld_id = mconf->mt76.idx + 32; |
| 2656 |
mld->remap_idx = 0xff; |
| 2657 |
|
| 2658 |
if (phy->chip_cap & MT792x_CHIP_CAP_MLO_EML_EN) { |
| 2659 |
mld->eml_enable = !!(link_conf->vif->cfg.eml_cap & |
| 2660 |
IEEE80211_EML_CAP_EMLSR_SUPP); |
| 2661 |
} else { |
| 2662 |
mld->eml_enable = 0; |
| 2663 |
} |
| 2664 |
|
| 2665 |
memcpy(mld->mac_addr, vif->addr, ETH_ALEN); |
| 2666 |
} |
| 2667 |
|
| 2668 |
static void |
| 2669 |
mt7925_mcu_bss_qos_tlv(struct sk_buff *skb, struct ieee80211_bss_conf *link_conf) |
| 2670 |
{ |
| 2671 |
struct mt76_connac_bss_qos_tlv *qos; |
| 2672 |
struct tlv *tlv; |
| 2673 |
|
| 2674 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_BSS_INFO_QBSS, sizeof(*qos)); |
| 2675 |
qos = (struct mt76_connac_bss_qos_tlv *)tlv; |
| 2676 |
qos->qos = link_conf->qos; |
| 2677 |
} |
| 2678 |
|
| 2679 |
static void |
| 2680 |
mt7925_mcu_bss_mbssid_tlv(struct sk_buff *skb, struct ieee80211_bss_conf *link_conf, |
| 2681 |
bool enable) |
| 2682 |
{ |
| 2683 |
struct bss_info_uni_mbssid *mbssid; |
| 2684 |
struct tlv *tlv; |
| 2685 |
|
| 2686 |
if (!enable && !link_conf->bssid_indicator) |
| 2687 |
return; |
| 2688 |
|
| 2689 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_BSS_INFO_11V_MBSSID, |
| 2690 |
sizeof(*mbssid)); |
| 2691 |
|
| 2692 |
mbssid = (struct bss_info_uni_mbssid *)tlv; |
| 2693 |
mbssid->max_indicator = link_conf->bssid_indicator; |
| 2694 |
mbssid->mbss_idx = link_conf->bssid_index; |
| 2695 |
mbssid->tx_bss_omac_idx = 0; |
| 2696 |
} |
| 2697 |
|
| 2698 |
static void |
| 2699 |
mt7925_mcu_bss_he_tlv(struct sk_buff *skb, struct ieee80211_bss_conf *link_conf, |
| 2700 |
struct mt792x_phy *phy) |
| 2701 |
{ |
| 2702 |
#define DEFAULT_HE_PE_DURATION 4 |
| 2703 |
#define DEFAULT_HE_DURATION_RTS_THRES 1023 |
| 2704 |
const struct ieee80211_sta_he_cap *cap; |
| 2705 |
struct bss_info_uni_he *he; |
| 2706 |
struct tlv *tlv; |
| 2707 |
|
| 2708 |
cap = mt76_connac_get_he_phy_cap(phy->mt76, link_conf->vif); |
| 2709 |
|
| 2710 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_BSS_INFO_HE_BASIC, sizeof(*he)); |
| 2711 |
|
| 2712 |
he = (struct bss_info_uni_he *)tlv; |
| 2713 |
he->he_pe_duration = link_conf->htc_trig_based_pkt_ext; |
| 2714 |
if (!he->he_pe_duration) |
| 2715 |
he->he_pe_duration = DEFAULT_HE_PE_DURATION; |
| 2716 |
|
| 2717 |
he->he_rts_thres = cpu_to_le16(link_conf->frame_time_rts_th); |
| 2718 |
if (!he->he_rts_thres) |
| 2719 |
he->he_rts_thres = cpu_to_le16(DEFAULT_HE_DURATION_RTS_THRES); |
| 2720 |
|
| 2721 |
he->max_nss_mcs[CMD_HE_MCS_BW80] = cap->he_mcs_nss_supp.tx_mcs_80; |
| 2722 |
he->max_nss_mcs[CMD_HE_MCS_BW160] = cap->he_mcs_nss_supp.tx_mcs_160; |
| 2723 |
he->max_nss_mcs[CMD_HE_MCS_BW8080] = cap->he_mcs_nss_supp.tx_mcs_80p80; |
| 2724 |
} |
| 2725 |
|
| 2726 |
static void |
| 2727 |
mt7925_mcu_bss_color_tlv(struct sk_buff *skb, struct ieee80211_bss_conf *link_conf, |
| 2728 |
bool enable) |
| 2729 |
{ |
| 2730 |
struct bss_info_uni_bss_color *color; |
| 2731 |
struct tlv *tlv; |
| 2732 |
|
| 2733 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_BSS_INFO_BSS_COLOR, sizeof(*color)); |
| 2734 |
color = (struct bss_info_uni_bss_color *)tlv; |
| 2735 |
|
| 2736 |
color->enable = enable ? |
| 2737 |
link_conf->he_bss_color.enabled : 0; |
| 2738 |
color->bss_color = enable ? |
| 2739 |
link_conf->he_bss_color.color : 0; |
| 2740 |
} |
| 2741 |
|
| 2742 |
static void |
| 2743 |
mt7925_mcu_bss_ifs_tlv(struct sk_buff *skb, |
| 2744 |
struct ieee80211_bss_conf *link_conf) |
| 2745 |
{ |
| 2746 |
struct mt792x_vif *mvif = (struct mt792x_vif *)link_conf->vif->drv_priv; |
| 2747 |
struct mt792x_phy *phy = mvif->phy; |
| 2748 |
struct bss_ifs_time_tlv *ifs_time; |
| 2749 |
struct tlv *tlv; |
| 2750 |
|
| 2751 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_BSS_INFO_IFS_TIME, sizeof(*ifs_time)); |
| 2752 |
ifs_time = (struct bss_ifs_time_tlv *)tlv; |
| 2753 |
ifs_time->slot_valid = true; |
| 2754 |
ifs_time->slot_time = cpu_to_le16(phy->slottime); |
| 2755 |
} |
| 2756 |
|
| 2757 |
int mt7925_mcu_set_timing(struct mt792x_phy *phy, |
| 2758 |
struct ieee80211_bss_conf *link_conf) |
| 2759 |
{ |
| 2760 |
struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); |
| 2761 |
struct mt792x_dev *dev = phy->dev; |
| 2762 |
struct sk_buff *skb; |
| 2763 |
|
| 2764 |
skb = __mt7925_mcu_alloc_bss_req(&dev->mt76, &mconf->mt76, |
| 2765 |
MT7925_BSS_UPDATE_MAX_SIZE); |
| 2766 |
if (IS_ERR(skb)) |
| 2767 |
return PTR_ERR(skb); |
| 2768 |
|
| 2769 |
mt7925_mcu_bss_ifs_tlv(skb, link_conf); |
| 2770 |
|
| 2771 |
return mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 2772 |
MCU_UNI_CMD(BSS_INFO_UPDATE), true); |
| 2773 |
} |
| 2774 |
|
| 2775 |
void mt7925_mcu_del_dev(struct mt76_dev *mdev, |
| 2776 |
struct ieee80211_vif *vif) |
| 2777 |
{ |
| 2778 |
struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; |
| 2779 |
struct { |
| 2780 |
struct { |
| 2781 |
u8 omac_idx; |
| 2782 |
u8 band_idx; |
| 2783 |
__le16 pad; |
| 2784 |
} __packed hdr; |
| 2785 |
struct req_tlv { |
| 2786 |
__le16 tag; |
| 2787 |
__le16 len; |
| 2788 |
u8 active; |
| 2789 |
u8 link_idx; /* hw link idx */ |
| 2790 |
u8 omac_addr[ETH_ALEN]; |
| 2791 |
} __packed tlv; |
| 2792 |
} dev_req = { |
| 2793 |
.tlv = { |
| 2794 |
.tag = cpu_to_le16(DEV_INFO_ACTIVE), |
| 2795 |
.len = cpu_to_le16(sizeof(struct req_tlv)), |
| 2796 |
.active = true, |
| 2797 |
}, |
| 2798 |
}; |
| 2799 |
struct { |
| 2800 |
struct { |
| 2801 |
u8 bss_idx; |
| 2802 |
u8 pad[3]; |
| 2803 |
} __packed hdr; |
| 2804 |
struct mt76_connac_bss_basic_tlv basic; |
| 2805 |
} basic_req = { |
| 2806 |
.basic = { |
| 2807 |
.tag = cpu_to_le16(UNI_BSS_INFO_BASIC), |
| 2808 |
.len = cpu_to_le16(sizeof(struct mt76_connac_bss_basic_tlv)), |
| 2809 |
.active = true, |
| 2810 |
.conn_state = 1, |
| 2811 |
}, |
| 2812 |
}; |
| 2813 |
|
| 2814 |
dev_req.hdr.omac_idx = mvif->omac_idx; |
| 2815 |
dev_req.hdr.band_idx = mvif->band_idx; |
| 2816 |
|
| 2817 |
basic_req.hdr.bss_idx = mvif->idx; |
| 2818 |
basic_req.basic.omac_idx = mvif->omac_idx; |
| 2819 |
basic_req.basic.band_idx = mvif->band_idx; |
| 2820 |
basic_req.basic.link_idx = mvif->link_idx; |
| 2821 |
|
| 2822 |
mt76_mcu_send_msg(mdev, MCU_UNI_CMD(BSS_INFO_UPDATE), |
| 2823 |
&basic_req, sizeof(basic_req), true); |
| 2824 |
|
| 2825 |
/* recovery omac address for the legacy interface */ |
| 2826 |
memcpy(dev_req.tlv.omac_addr, vif->addr, ETH_ALEN); |
| 2827 |
mt76_mcu_send_msg(mdev, MCU_UNI_CMD(DEV_INFO_UPDATE), |
| 2828 |
&dev_req, sizeof(dev_req), true); |
| 2829 |
} |
| 2830 |
|
| 2831 |
int mt7925_mcu_add_bss_info(struct mt792x_phy *phy, |
| 2832 |
struct ieee80211_chanctx_conf *ctx, |
| 2833 |
struct ieee80211_bss_conf *link_conf, |
| 2834 |
struct ieee80211_link_sta *link_sta, |
| 2835 |
int enable) |
| 2836 |
{ |
| 2837 |
struct mt792x_vif *mvif = (struct mt792x_vif *)link_conf->vif->drv_priv; |
| 2838 |
struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(link_conf); |
| 2839 |
struct mt792x_dev *dev = phy->dev; |
| 2840 |
struct mt792x_link_sta *mlink_bc; |
| 2841 |
struct sk_buff *skb; |
| 2842 |
|
| 2843 |
skb = __mt7925_mcu_alloc_bss_req(&dev->mt76, &mconf->mt76, |
| 2844 |
MT7925_BSS_UPDATE_MAX_SIZE); |
| 2845 |
if (IS_ERR(skb)) |
| 2846 |
return PTR_ERR(skb); |
| 2847 |
|
| 2848 |
mlink_bc = mt792x_sta_to_link(&mvif->sta, mconf->link_id); |
| 2849 |
|
| 2850 |
/* bss_basic must be first */ |
| 2851 |
mt7925_mcu_bss_basic_tlv(skb, link_conf, link_sta, ctx, phy->mt76, |
| 2852 |
mlink_bc->wcid.idx, enable); |
| 2853 |
mt7925_mcu_bss_sec_tlv(skb, link_conf); |
| 2854 |
mt7925_mcu_bss_bmc_tlv(skb, phy, ctx, link_conf); |
| 2855 |
mt7925_mcu_bss_qos_tlv(skb, link_conf); |
| 2856 |
mt7925_mcu_bss_mld_tlv(skb, link_conf); |
| 2857 |
mt7925_mcu_bss_ifs_tlv(skb, link_conf); |
| 2858 |
|
| 2859 |
if (link_conf->he_support) { |
| 2860 |
mt7925_mcu_bss_he_tlv(skb, link_conf, phy); |
| 2861 |
mt7925_mcu_bss_color_tlv(skb, link_conf, enable); |
| 2862 |
} |
| 2863 |
|
| 2864 |
if (enable) { |
| 2865 |
mt7925_mcu_bss_rlm_tlv(skb, phy->mt76, link_conf, ctx); |
| 2866 |
mt7925_mcu_bss_mbssid_tlv(skb, link_conf, enable); |
| 2867 |
} |
| 2868 |
|
| 2869 |
return mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 2870 |
MCU_UNI_CMD(BSS_INFO_UPDATE), true); |
| 2871 |
} |
| 2872 |
|
| 2873 |
int mt7925_mcu_set_dbdc(struct mt76_phy *phy, bool enable) |
| 2874 |
{ |
| 2875 |
struct mt76_dev *mdev = phy->dev; |
| 2876 |
|
| 2877 |
struct mbmc_conf_tlv *conf; |
| 2878 |
struct mbmc_set_req *hdr; |
| 2879 |
struct sk_buff *skb; |
| 2880 |
struct tlv *tlv; |
| 2881 |
int max_len, err; |
| 2882 |
|
| 2883 |
max_len = sizeof(*hdr) + sizeof(*conf); |
| 2884 |
skb = mt76_mcu_msg_alloc(mdev, NULL, max_len); |
| 2885 |
if (!skb) |
| 2886 |
return -ENOMEM; |
| 2887 |
|
| 2888 |
hdr = (struct mbmc_set_req *)skb_put(skb, sizeof(*hdr)); |
| 2889 |
|
| 2890 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_MBMC_SETTING, sizeof(*conf)); |
| 2891 |
conf = (struct mbmc_conf_tlv *)tlv; |
| 2892 |
|
| 2893 |
conf->mbmc_en = enable; |
| 2894 |
conf->band = 0; /* unused */ |
| 2895 |
|
| 2896 |
err = mt76_mcu_skb_send_msg(mdev, skb, MCU_UNI_CMD(SET_DBDC_PARMS), |
| 2897 |
true); |
| 2898 |
|
| 2899 |
return err; |
| 2900 |
} |
| 2901 |
|
| 2902 |
static void |
| 2903 |
mt7925_mcu_build_scan_ie_tlv(struct mt76_dev *mdev, |
| 2904 |
struct sk_buff *skb, |
| 2905 |
struct ieee80211_scan_ies *scan_ies) |
| 2906 |
{ |
| 2907 |
u32 max_len = sizeof(struct scan_ie_tlv) + MT76_CONNAC_SCAN_IE_LEN; |
| 2908 |
struct scan_ie_tlv *ie; |
| 2909 |
enum nl80211_band i; |
| 2910 |
struct tlv *tlv; |
| 2911 |
const u8 *ies; |
| 2912 |
u16 ies_len; |
| 2913 |
|
| 2914 |
for (i = 0; i <= NL80211_BAND_6GHZ; i++) { |
| 2915 |
if (i == NL80211_BAND_60GHZ) |
| 2916 |
continue; |
| 2917 |
|
| 2918 |
ies = scan_ies->ies[i]; |
| 2919 |
ies_len = scan_ies->len[i]; |
| 2920 |
|
| 2921 |
if (!ies || !ies_len) |
| 2922 |
continue; |
| 2923 |
|
| 2924 |
if (ies_len > max_len) |
| 2925 |
return; |
| 2926 |
|
| 2927 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_SCAN_IE, |
| 2928 |
sizeof(*ie) + ies_len); |
| 2929 |
ie = (struct scan_ie_tlv *)tlv; |
| 2930 |
|
| 2931 |
memcpy(ie->ies, ies, ies_len); |
| 2932 |
ie->ies_len = cpu_to_le16(ies_len); |
| 2933 |
|
| 2934 |
switch (i) { |
| 2935 |
case NL80211_BAND_2GHZ: |
| 2936 |
ie->band = 1; |
| 2937 |
break; |
| 2938 |
case NL80211_BAND_6GHZ: |
| 2939 |
ie->band = 3; |
| 2940 |
break; |
| 2941 |
default: |
| 2942 |
ie->band = 2; |
| 2943 |
break; |
| 2944 |
} |
| 2945 |
|
| 2946 |
max_len -= (sizeof(*ie) + ies_len); |
| 2947 |
} |
| 2948 |
} |
| 2949 |
|
| 2950 |
int mt7925_mcu_hw_scan(struct mt76_phy *phy, struct ieee80211_vif *vif, |
| 2951 |
struct ieee80211_scan_request *scan_req) |
| 2952 |
{ |
| 2953 |
struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; |
| 2954 |
struct cfg80211_scan_request *sreq = &scan_req->req; |
| 2955 |
int n_ssids = 0, err, i; |
| 2956 |
struct ieee80211_channel **scan_list = sreq->channels; |
| 2957 |
struct mt76_dev *mdev = phy->dev; |
| 2958 |
struct mt76_connac_mcu_scan_channel *chan; |
| 2959 |
struct sk_buff *skb; |
| 2960 |
struct scan_hdr_tlv *hdr; |
| 2961 |
struct scan_req_tlv *req; |
| 2962 |
struct scan_ssid_tlv *ssid; |
| 2963 |
struct scan_bssid_tlv *bssid; |
| 2964 |
struct scan_chan_info_tlv *chan_info; |
| 2965 |
struct scan_ie_tlv *ie; |
| 2966 |
struct scan_misc_tlv *misc; |
| 2967 |
struct tlv *tlv; |
| 2968 |
int max_len; |
| 2969 |
|
| 2970 |
if (test_bit(MT76_HW_SCANNING, &phy->state)) |
| 2971 |
return -EBUSY; |
| 2972 |
|
| 2973 |
max_len = sizeof(*hdr) + sizeof(*req) + sizeof(*ssid) + |
| 2974 |
sizeof(*bssid) * MT7925_RNR_SCAN_MAX_BSSIDS + |
| 2975 |
sizeof(*chan_info) + sizeof(*misc) + sizeof(*ie) + |
| 2976 |
MT76_CONNAC_SCAN_IE_LEN; |
| 2977 |
|
| 2978 |
skb = mt76_mcu_msg_alloc(mdev, NULL, max_len); |
| 2979 |
if (!skb) |
| 2980 |
return -ENOMEM; |
| 2981 |
|
| 2982 |
set_bit(MT76_HW_SCANNING, &phy->state); |
| 2983 |
mvif->scan_seq_num = (mvif->scan_seq_num + 1) & 0x7f; |
| 2984 |
|
| 2985 |
hdr = (struct scan_hdr_tlv *)skb_put(skb, sizeof(*hdr)); |
| 2986 |
hdr->seq_num = mvif->scan_seq_num | mvif->band_idx << 7; |
| 2987 |
hdr->bss_idx = mvif->idx; |
| 2988 |
|
| 2989 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_SCAN_REQ, sizeof(*req)); |
| 2990 |
req = (struct scan_req_tlv *)tlv; |
| 2991 |
req->scan_type = sreq->n_ssids ? 1 : 0; |
| 2992 |
req->probe_req_num = sreq->n_ssids ? 2 : 0; |
| 2993 |
|
| 2994 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_SCAN_SSID, sizeof(*ssid)); |
| 2995 |
ssid = (struct scan_ssid_tlv *)tlv; |
| 2996 |
for (i = 0; i < sreq->n_ssids; i++) { |
| 2997 |
if (!sreq->ssids[i].ssid_len) |
| 2998 |
continue; |
| 2999 |
if (i >= MT7925_RNR_SCAN_MAX_BSSIDS) |
| 3000 |
break; |
| 3001 |
|
| 3002 |
ssid->ssids[n_ssids].ssid_len = cpu_to_le32(sreq->ssids[i].ssid_len); |
| 3003 |
memcpy(ssid->ssids[n_ssids].ssid, sreq->ssids[i].ssid, |
| 3004 |
sreq->ssids[i].ssid_len); |
| 3005 |
n_ssids++; |
| 3006 |
} |
| 3007 |
ssid->ssid_type = n_ssids ? BIT(2) : BIT(0); |
| 3008 |
ssid->ssids_num = n_ssids; |
| 3009 |
|
| 3010 |
if (sreq->n_6ghz_params) { |
| 3011 |
u8 j; |
| 3012 |
|
| 3013 |
mt76_connac_mcu_build_rnr_scan_param(mdev, sreq); |
| 3014 |
|
| 3015 |
for (j = 0; j < mdev->rnr.bssid_num; j++) { |
| 3016 |
if (j >= MT7925_RNR_SCAN_MAX_BSSIDS) |
| 3017 |
break; |
| 3018 |
|
| 3019 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_SCAN_BSSID, |
| 3020 |
sizeof(*bssid)); |
| 3021 |
bssid = (struct scan_bssid_tlv *)tlv; |
| 3022 |
|
| 3023 |
ether_addr_copy(bssid->bssid, mdev->rnr.bssid[j]); |
| 3024 |
bssid->match_ch = mdev->rnr.channel[j]; |
| 3025 |
bssid->match_ssid_ind = MT7925_RNR_SCAN_MAX_BSSIDS; |
| 3026 |
bssid->match_short_ssid_ind = MT7925_RNR_SCAN_MAX_BSSIDS; |
| 3027 |
} |
| 3028 |
req->scan_func |= SCAN_FUNC_RNR_SCAN; |
| 3029 |
} else { |
| 3030 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_SCAN_BSSID, sizeof(*bssid)); |
| 3031 |
bssid = (struct scan_bssid_tlv *)tlv; |
| 3032 |
|
| 3033 |
ether_addr_copy(bssid->bssid, sreq->bssid); |
| 3034 |
} |
| 3035 |
|
| 3036 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_SCAN_CHANNEL, sizeof(*chan_info)); |
| 3037 |
chan_info = (struct scan_chan_info_tlv *)tlv; |
| 3038 |
chan_info->channels_num = min_t(u8, sreq->n_channels, |
| 3039 |
ARRAY_SIZE(chan_info->channels)); |
| 3040 |
for (i = 0; i < chan_info->channels_num; i++) { |
| 3041 |
chan = &chan_info->channels[i]; |
| 3042 |
|
| 3043 |
switch (scan_list[i]->band) { |
| 3044 |
case NL80211_BAND_2GHZ: |
| 3045 |
chan->band = 1; |
| 3046 |
break; |
| 3047 |
case NL80211_BAND_6GHZ: |
| 3048 |
chan->band = 3; |
| 3049 |
break; |
| 3050 |
default: |
| 3051 |
chan->band = 2; |
| 3052 |
break; |
| 3053 |
} |
| 3054 |
chan->channel_num = scan_list[i]->hw_value; |
| 3055 |
} |
| 3056 |
chan_info->channel_type = sreq->n_channels ? 4 : 0; |
| 3057 |
|
| 3058 |
req->scan_func |= SCAN_FUNC_SPLIT_SCAN; |
| 3059 |
|
| 3060 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_SCAN_MISC, sizeof(*misc)); |
| 3061 |
misc = (struct scan_misc_tlv *)tlv; |
| 3062 |
if (sreq->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 3063 |
get_random_mask_addr(misc->random_mac, sreq->mac_addr, |
| 3064 |
sreq->mac_addr_mask); |
| 3065 |
req->scan_func |= SCAN_FUNC_RANDOM_MAC; |
| 3066 |
} |
| 3067 |
|
| 3068 |
/* Append scan probe IEs as the last tlv */ |
| 3069 |
mt7925_mcu_build_scan_ie_tlv(mdev, skb, &scan_req->ies); |
| 3070 |
|
| 3071 |
err = mt76_mcu_skb_send_msg(mdev, skb, MCU_UNI_CMD(SCAN_REQ), |
| 3072 |
true); |
| 3073 |
if (err < 0) |
| 3074 |
clear_bit(MT76_HW_SCANNING, &phy->state); |
| 3075 |
|
| 3076 |
return err; |
| 3077 |
} |
| 3078 |
EXPORT_SYMBOL_GPL(mt7925_mcu_hw_scan); |
| 3079 |
|
| 3080 |
int mt7925_mcu_sched_scan_req(struct mt76_phy *phy, |
| 3081 |
struct ieee80211_vif *vif, |
| 3082 |
struct cfg80211_sched_scan_request *sreq, |
| 3083 |
struct ieee80211_scan_ies *ies) |
| 3084 |
{ |
| 3085 |
struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; |
| 3086 |
struct ieee80211_channel **scan_list = sreq->channels; |
| 3087 |
struct mt76_connac_mcu_scan_channel *chan; |
| 3088 |
struct mt76_dev *mdev = phy->dev; |
| 3089 |
struct cfg80211_match_set *cfg_match; |
| 3090 |
struct cfg80211_ssid *cfg_ssid; |
| 3091 |
|
| 3092 |
struct scan_hdr_tlv *hdr; |
| 3093 |
struct scan_sched_req *req; |
| 3094 |
struct scan_ssid_tlv *ssid; |
| 3095 |
struct scan_chan_info_tlv *chan_info; |
| 3096 |
struct scan_ie_tlv *ie; |
| 3097 |
struct scan_sched_ssid_match_sets *match; |
| 3098 |
struct sk_buff *skb; |
| 3099 |
struct tlv *tlv; |
| 3100 |
int i, max_len; |
| 3101 |
|
| 3102 |
max_len = sizeof(*hdr) + sizeof(*req) + sizeof(*ssid) + |
| 3103 |
sizeof(*chan_info) + sizeof(*ie) + |
| 3104 |
sizeof(*match); |
| 3105 |
|
| 3106 |
skb = mt76_mcu_msg_alloc(mdev, NULL, max_len); |
| 3107 |
if (!skb) |
| 3108 |
return -ENOMEM; |
| 3109 |
|
| 3110 |
mvif->scan_seq_num = (mvif->scan_seq_num + 1) & 0x7f; |
| 3111 |
|
| 3112 |
hdr = (struct scan_hdr_tlv *)skb_put(skb, sizeof(*hdr)); |
| 3113 |
hdr->seq_num = mvif->scan_seq_num | mvif->band_idx << 7; |
| 3114 |
hdr->bss_idx = mvif->idx; |
| 3115 |
|
| 3116 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_SCAN_SCHED_REQ, sizeof(*req)); |
| 3117 |
req = (struct scan_sched_req *)tlv; |
| 3118 |
req->version = 1; |
| 3119 |
|
| 3120 |
if (sreq->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) |
| 3121 |
req->scan_func |= SCAN_FUNC_RANDOM_MAC; |
| 3122 |
|
| 3123 |
req->intervals_num = sreq->n_scan_plans; |
| 3124 |
for (i = 0; i < req->intervals_num; i++) |
| 3125 |
req->intervals[i] = cpu_to_le16(sreq->scan_plans[i].interval); |
| 3126 |
|
| 3127 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_SCAN_SSID, sizeof(*ssid)); |
| 3128 |
ssid = (struct scan_ssid_tlv *)tlv; |
| 3129 |
|
| 3130 |
ssid->ssids_num = sreq->n_ssids; |
| 3131 |
ssid->ssid_type = BIT(2); |
| 3132 |
for (i = 0; i < ssid->ssids_num; i++) { |
| 3133 |
cfg_ssid = &sreq->ssids[i]; |
| 3134 |
memcpy(ssid->ssids[i].ssid, cfg_ssid->ssid, cfg_ssid->ssid_len); |
| 3135 |
ssid->ssids[i].ssid_len = cpu_to_le32(cfg_ssid->ssid_len); |
| 3136 |
} |
| 3137 |
|
| 3138 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_SCAN_SSID_MATCH_SETS, sizeof(*match)); |
| 3139 |
match = (struct scan_sched_ssid_match_sets *)tlv; |
| 3140 |
match->match_num = sreq->n_match_sets; |
| 3141 |
for (i = 0; i < match->match_num; i++) { |
| 3142 |
cfg_match = &sreq->match_sets[i]; |
| 3143 |
memcpy(match->match[i].ssid, cfg_match->ssid.ssid, |
| 3144 |
cfg_match->ssid.ssid_len); |
| 3145 |
match->match[i].rssi_th = cpu_to_le32(cfg_match->rssi_thold); |
| 3146 |
match->match[i].ssid_len = cfg_match->ssid.ssid_len; |
| 3147 |
} |
| 3148 |
|
| 3149 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_SCAN_CHANNEL, sizeof(*chan_info)); |
| 3150 |
chan_info = (struct scan_chan_info_tlv *)tlv; |
| 3151 |
chan_info->channels_num = min_t(u8, sreq->n_channels, |
| 3152 |
ARRAY_SIZE(chan_info->channels)); |
| 3153 |
for (i = 0; i < chan_info->channels_num; i++) { |
| 3154 |
chan = &chan_info->channels[i]; |
| 3155 |
|
| 3156 |
switch (scan_list[i]->band) { |
| 3157 |
case NL80211_BAND_2GHZ: |
| 3158 |
chan->band = 1; |
| 3159 |
break; |
| 3160 |
case NL80211_BAND_6GHZ: |
| 3161 |
chan->band = 3; |
| 3162 |
break; |
| 3163 |
default: |
| 3164 |
chan->band = 2; |
| 3165 |
break; |
| 3166 |
} |
| 3167 |
chan->channel_num = scan_list[i]->hw_value; |
| 3168 |
} |
| 3169 |
chan_info->channel_type = sreq->n_channels ? 4 : 0; |
| 3170 |
|
| 3171 |
/* Append scan probe IEs as the last tlv */ |
| 3172 |
mt7925_mcu_build_scan_ie_tlv(mdev, skb, ies); |
| 3173 |
|
| 3174 |
return mt76_mcu_skb_send_msg(mdev, skb, MCU_UNI_CMD(SCAN_REQ), |
| 3175 |
true); |
| 3176 |
} |
| 3177 |
EXPORT_SYMBOL_GPL(mt7925_mcu_sched_scan_req); |
| 3178 |
|
| 3179 |
int |
| 3180 |
mt7925_mcu_sched_scan_enable(struct mt76_phy *phy, |
| 3181 |
struct ieee80211_vif *vif, |
| 3182 |
bool enable) |
| 3183 |
{ |
| 3184 |
struct mt76_dev *mdev = phy->dev; |
| 3185 |
struct scan_sched_enable *req; |
| 3186 |
struct scan_hdr_tlv *hdr; |
| 3187 |
struct sk_buff *skb; |
| 3188 |
struct tlv *tlv; |
| 3189 |
int max_len; |
| 3190 |
|
| 3191 |
max_len = sizeof(*hdr) + sizeof(*req); |
| 3192 |
|
| 3193 |
skb = mt76_mcu_msg_alloc(mdev, NULL, max_len); |
| 3194 |
if (!skb) |
| 3195 |
return -ENOMEM; |
| 3196 |
|
| 3197 |
hdr = (struct scan_hdr_tlv *)skb_put(skb, sizeof(*hdr)); |
| 3198 |
hdr->seq_num = 0; |
| 3199 |
hdr->bss_idx = 0; |
| 3200 |
|
| 3201 |
tlv = mt76_connac_mcu_add_tlv(skb, UNI_SCAN_SCHED_ENABLE, sizeof(*req)); |
| 3202 |
req = (struct scan_sched_enable *)tlv; |
| 3203 |
req->active = !enable; |
| 3204 |
|
| 3205 |
if (enable) |
| 3206 |
set_bit(MT76_HW_SCHED_SCANNING, &phy->state); |
| 3207 |
else |
| 3208 |
clear_bit(MT76_HW_SCHED_SCANNING, &phy->state); |
| 3209 |
|
| 3210 |
return mt76_mcu_skb_send_msg(mdev, skb, MCU_UNI_CMD(SCAN_REQ), |
| 3211 |
true); |
| 3212 |
} |
| 3213 |
|
| 3214 |
int mt7925_mcu_cancel_hw_scan(struct mt76_phy *phy, |
| 3215 |
struct ieee80211_vif *vif) |
| 3216 |
{ |
| 3217 |
struct mt76_vif_link *mvif = (struct mt76_vif_link *)vif->drv_priv; |
| 3218 |
struct { |
| 3219 |
struct scan_hdr { |
| 3220 |
u8 seq_num; |
| 3221 |
u8 bss_idx; |
| 3222 |
u8 pad[2]; |
| 3223 |
} __packed hdr; |
| 3224 |
struct scan_cancel_tlv { |
| 3225 |
__le16 tag; |
| 3226 |
__le16 len; |
| 3227 |
u8 is_ext_channel; |
| 3228 |
u8 rsv[3]; |
| 3229 |
} __packed cancel; |
| 3230 |
} req = { |
| 3231 |
.hdr = { |
| 3232 |
.seq_num = mvif->scan_seq_num, |
| 3233 |
.bss_idx = mvif->idx, |
| 3234 |
}, |
| 3235 |
.cancel = { |
| 3236 |
.tag = cpu_to_le16(UNI_SCAN_CANCEL), |
| 3237 |
.len = cpu_to_le16(sizeof(struct scan_cancel_tlv)), |
| 3238 |
}, |
| 3239 |
}; |
| 3240 |
|
| 3241 |
if (test_and_clear_bit(MT76_HW_SCANNING, &phy->state)) { |
| 3242 |
struct cfg80211_scan_info info = { |
| 3243 |
.aborted = true, |
| 3244 |
}; |
| 3245 |
|
| 3246 |
ieee80211_scan_completed(phy->hw, &info); |
| 3247 |
} |
| 3248 |
|
| 3249 |
return mt76_mcu_send_msg(phy->dev, MCU_UNI_CMD(SCAN_REQ), |
| 3250 |
&req, sizeof(req), true); |
| 3251 |
} |
| 3252 |
EXPORT_SYMBOL_GPL(mt7925_mcu_cancel_hw_scan); |
| 3253 |
|
| 3254 |
int mt7925_mcu_set_channel_domain(struct mt76_phy *phy) |
| 3255 |
{ |
| 3256 |
int len, i, n_max_channels, n_2ch = 0, n_5ch = 0, n_6ch = 0; |
| 3257 |
struct { |
| 3258 |
struct { |
| 3259 |
u8 alpha2[4]; /* regulatory_request.alpha2 */ |
| 3260 |
u8 bw_2g; /* BW_20_40M 0 |
| 3261 |
* BW_20M 1 |
| 3262 |
* BW_20_40_80M 2 |
| 3263 |
* BW_20_40_80_160M 3 |
| 3264 |
* BW_20_40_80_8080M 4 |
| 3265 |
*/ |
| 3266 |
u8 bw_5g; |
| 3267 |
u8 bw_6g; |
| 3268 |
u8 pad; |
| 3269 |
} __packed hdr; |
| 3270 |
struct n_chan { |
| 3271 |
__le16 tag; |
| 3272 |
__le16 len; |
| 3273 |
u8 n_2ch; |
| 3274 |
u8 n_5ch; |
| 3275 |
u8 n_6ch; |
| 3276 |
u8 pad; |
| 3277 |
} __packed n_ch; |
| 3278 |
} req = { |
| 3279 |
.hdr = { |
| 3280 |
.bw_2g = 0, |
| 3281 |
.bw_5g = 3, /* BW_20_40_80_160M */ |
| 3282 |
.bw_6g = 3, |
| 3283 |
}, |
| 3284 |
.n_ch = { |
| 3285 |
.tag = cpu_to_le16(2), |
| 3286 |
}, |
| 3287 |
}; |
| 3288 |
struct mt76_connac_mcu_chan { |
| 3289 |
__le16 hw_value; |
| 3290 |
__le16 pad; |
| 3291 |
__le32 flags; |
| 3292 |
} __packed channel; |
| 3293 |
struct mt76_dev *dev = phy->dev; |
| 3294 |
struct ieee80211_channel *chan; |
| 3295 |
struct sk_buff *skb; |
| 3296 |
|
| 3297 |
n_max_channels = phy->sband_2g.sband.n_channels + |
| 3298 |
phy->sband_5g.sband.n_channels + |
| 3299 |
phy->sband_6g.sband.n_channels; |
| 3300 |
len = sizeof(req) + n_max_channels * sizeof(channel); |
| 3301 |
|
| 3302 |
skb = mt76_mcu_msg_alloc(dev, NULL, len); |
| 3303 |
if (!skb) |
| 3304 |
return -ENOMEM; |
| 3305 |
|
| 3306 |
skb_reserve(skb, sizeof(req)); |
| 3307 |
|
| 3308 |
for (i = 0; i < phy->sband_2g.sband.n_channels; i++) { |
| 3309 |
chan = &phy->sband_2g.sband.channels[i]; |
| 3310 |
if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3311 |
continue; |
| 3312 |
|
| 3313 |
channel.hw_value = cpu_to_le16(chan->hw_value); |
| 3314 |
channel.flags = cpu_to_le32(chan->flags); |
| 3315 |
channel.pad = 0; |
| 3316 |
|
| 3317 |
skb_put_data(skb, &channel, sizeof(channel)); |
| 3318 |
n_2ch++; |
| 3319 |
} |
| 3320 |
for (i = 0; i < phy->sband_5g.sband.n_channels; i++) { |
| 3321 |
chan = &phy->sband_5g.sband.channels[i]; |
| 3322 |
if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3323 |
continue; |
| 3324 |
|
| 3325 |
channel.hw_value = cpu_to_le16(chan->hw_value); |
| 3326 |
channel.flags = cpu_to_le32(chan->flags); |
| 3327 |
channel.pad = 0; |
| 3328 |
|
| 3329 |
skb_put_data(skb, &channel, sizeof(channel)); |
| 3330 |
n_5ch++; |
| 3331 |
} |
| 3332 |
for (i = 0; i < phy->sband_6g.sband.n_channels; i++) { |
| 3333 |
chan = &phy->sband_6g.sband.channels[i]; |
| 3334 |
if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3335 |
continue; |
| 3336 |
|
| 3337 |
channel.hw_value = cpu_to_le16(chan->hw_value); |
| 3338 |
channel.flags = cpu_to_le32(chan->flags); |
| 3339 |
channel.pad = 0; |
| 3340 |
|
| 3341 |
skb_put_data(skb, &channel, sizeof(channel)); |
| 3342 |
n_6ch++; |
| 3343 |
} |
| 3344 |
|
| 3345 |
BUILD_BUG_ON(sizeof(dev->alpha2) > sizeof(req.hdr.alpha2)); |
| 3346 |
memcpy(req.hdr.alpha2, dev->alpha2, sizeof(dev->alpha2)); |
| 3347 |
req.n_ch.n_2ch = n_2ch; |
| 3348 |
req.n_ch.n_5ch = n_5ch; |
| 3349 |
req.n_ch.n_6ch = n_6ch; |
| 3350 |
len = sizeof(struct n_chan) + (n_2ch + n_5ch + n_6ch) * sizeof(channel); |
| 3351 |
req.n_ch.len = cpu_to_le16(len); |
| 3352 |
memcpy(__skb_push(skb, sizeof(req)), &req, sizeof(req)); |
| 3353 |
|
| 3354 |
return mt76_mcu_skb_send_msg(dev, skb, MCU_UNI_CMD(SET_DOMAIN_INFO), |
| 3355 |
true); |
| 3356 |
} |
| 3357 |
EXPORT_SYMBOL_GPL(mt7925_mcu_set_channel_domain); |
| 3358 |
|
| 3359 |
static int |
| 3360 |
__mt7925_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, |
| 3361 |
enum environment_cap env_cap, |
| 3362 |
struct mt7925_clc *clc, u8 idx) |
| 3363 |
{ |
| 3364 |
struct mt7925_clc_segment *seg; |
| 3365 |
struct sk_buff *skb; |
| 3366 |
struct { |
| 3367 |
u8 rsv[4]; |
| 3368 |
__le16 tag; |
| 3369 |
__le16 len; |
| 3370 |
|
| 3371 |
u8 ver; |
| 3372 |
u8 pad0; |
| 3373 |
__le16 size; |
| 3374 |
u8 idx; |
| 3375 |
u8 env; |
| 3376 |
u8 acpi_conf; |
| 3377 |
u8 pad1; |
| 3378 |
u8 alpha2[2]; |
| 3379 |
u8 type[2]; |
| 3380 |
u8 rsvd[64]; |
| 3381 |
} __packed req = { |
| 3382 |
.tag = cpu_to_le16(0x3), |
| 3383 |
|
| 3384 |
.idx = idx, |
| 3385 |
.env = env_cap, |
| 3386 |
}; |
| 3387 |
int ret, valid_cnt = 0; |
| 3388 |
u8 *pos, *last_pos; |
| 3389 |
|
| 3390 |
if (!clc) |
| 3391 |
return 0; |
| 3392 |
|
| 3393 |
req.ver = clc->ver; |
| 3394 |
pos = clc->data + sizeof(*seg) * clc->t0.nr_seg; |
| 3395 |
last_pos = clc->data + le32_to_cpu(*(__le32 *)(clc->data + 4)); |
| 3396 |
while (pos < last_pos) { |
| 3397 |
struct mt7925_clc_rule *rule = (struct mt7925_clc_rule *)pos; |
| 3398 |
|
| 3399 |
pos += sizeof(*rule); |
| 3400 |
if (rule->alpha2[0] != alpha2[0] || |
| 3401 |
rule->alpha2[1] != alpha2[1]) |
| 3402 |
continue; |
| 3403 |
|
| 3404 |
seg = (struct mt7925_clc_segment *)clc->data |
| 3405 |
+ rule->seg_idx - 1; |
| 3406 |
|
| 3407 |
memcpy(req.alpha2, rule->alpha2, 2); |
| 3408 |
memcpy(req.type, rule->type, 2); |
| 3409 |
|
| 3410 |
req.size = cpu_to_le16(seg->len); |
| 3411 |
req.len = cpu_to_le16(sizeof(req) + seg->len - 4); |
| 3412 |
dev->phy.clc_chan_conf = clc->ver == 1 ? 0xff : rule->flag; |
| 3413 |
skb = __mt76_mcu_msg_alloc(&dev->mt76, &req, |
| 3414 |
le16_to_cpu(req.size) + sizeof(req), |
| 3415 |
sizeof(req), GFP_KERNEL); |
| 3416 |
if (!skb) |
| 3417 |
return -ENOMEM; |
| 3418 |
skb_put_data(skb, clc->data + seg->offset, seg->len); |
| 3419 |
|
| 3420 |
ret = mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 3421 |
MCU_UNI_CMD(SET_POWER_LIMIT), |
| 3422 |
true); |
| 3423 |
if (ret < 0) |
| 3424 |
return ret; |
| 3425 |
valid_cnt++; |
| 3426 |
} |
| 3427 |
|
| 3428 |
if (!valid_cnt) { |
| 3429 |
dev->phy.clc_chan_conf = 0xff; |
| 3430 |
return -ENOENT; |
| 3431 |
} |
| 3432 |
|
| 3433 |
return 0; |
| 3434 |
} |
| 3435 |
|
| 3436 |
int mt7925_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, |
| 3437 |
enum environment_cap env_cap) |
| 3438 |
{ |
| 3439 |
struct mt792x_phy *phy = (struct mt792x_phy *)&dev->phy; |
| 3440 |
int i, ret; |
| 3441 |
|
| 3442 |
if (!ARRAY_SIZE(phy->clc)) |
| 3443 |
return -ESRCH; |
| 3444 |
|
| 3445 |
/* submit all clc config */ |
| 3446 |
for (i = 0; i < ARRAY_SIZE(phy->clc); i++) { |
| 3447 |
if (i == MT792x_CLC_BE_CTRL) |
| 3448 |
continue; |
| 3449 |
|
| 3450 |
ret = __mt7925_mcu_set_clc(dev, alpha2, env_cap, |
| 3451 |
phy->clc[i], i); |
| 3452 |
|
| 3453 |
/* If no country found, set "00" as default */ |
| 3454 |
if (ret == -ENOENT) |
| 3455 |
ret = __mt7925_mcu_set_clc(dev, "00", |
| 3456 |
ENVIRON_INDOOR, |
| 3457 |
phy->clc[i], i); |
| 3458 |
if (ret < 0) |
| 3459 |
return ret; |
| 3460 |
} |
| 3461 |
return 0; |
| 3462 |
} |
| 3463 |
|
| 3464 |
int mt7925_mcu_fill_message(struct mt76_dev *mdev, struct sk_buff *skb, |
| 3465 |
int cmd, int *wait_seq) |
| 3466 |
{ |
| 3467 |
int txd_len, mcu_cmd = FIELD_GET(__MCU_CMD_FIELD_ID, cmd); |
| 3468 |
struct mt76_connac2_mcu_uni_txd *uni_txd; |
| 3469 |
struct mt76_connac2_mcu_txd *mcu_txd; |
| 3470 |
__le32 *txd; |
| 3471 |
u32 val; |
| 3472 |
u8 seq; |
| 3473 |
|
| 3474 |
/* TODO: make dynamic based on msg type */ |
| 3475 |
mdev->mcu.timeout = 20 * HZ; |
| 3476 |
|
| 3477 |
seq = ++mdev->mcu.msg_seq & 0xf; |
| 3478 |
if (!seq) |
| 3479 |
seq = ++mdev->mcu.msg_seq & 0xf; |
| 3480 |
|
| 3481 |
if (cmd == MCU_CMD(FW_SCATTER)) |
| 3482 |
goto exit; |
| 3483 |
|
| 3484 |
txd_len = cmd & __MCU_CMD_FIELD_UNI ? sizeof(*uni_txd) : sizeof(*mcu_txd); |
| 3485 |
txd = (__le32 *)skb_push(skb, txd_len); |
| 3486 |
|
| 3487 |
val = FIELD_PREP(MT_TXD0_TX_BYTES, skb->len) | |
| 3488 |
FIELD_PREP(MT_TXD0_PKT_FMT, MT_TX_TYPE_CMD) | |
| 3489 |
FIELD_PREP(MT_TXD0_Q_IDX, MT_TX_MCU_PORT_RX_Q0); |
| 3490 |
txd[0] = cpu_to_le32(val); |
| 3491 |
|
| 3492 |
val = FIELD_PREP(MT_TXD1_HDR_FORMAT, MT_HDR_FORMAT_CMD); |
| 3493 |
txd[1] = cpu_to_le32(val); |
| 3494 |
|
| 3495 |
if (cmd & __MCU_CMD_FIELD_UNI) { |
| 3496 |
uni_txd = (struct mt76_connac2_mcu_uni_txd *)txd; |
| 3497 |
uni_txd->len = cpu_to_le16(skb->len - sizeof(uni_txd->txd)); |
| 3498 |
uni_txd->cid = cpu_to_le16(mcu_cmd); |
| 3499 |
uni_txd->s2d_index = MCU_S2D_H2N; |
| 3500 |
uni_txd->pkt_type = MCU_PKT_ID; |
| 3501 |
uni_txd->seq = seq; |
| 3502 |
|
| 3503 |
if (cmd & __MCU_CMD_FIELD_QUERY) |
| 3504 |
uni_txd->option = MCU_CMD_UNI_QUERY_ACK; |
| 3505 |
else |
| 3506 |
uni_txd->option = MCU_CMD_UNI_EXT_ACK; |
| 3507 |
|
| 3508 |
if (cmd == MCU_UNI_CMD(HIF_CTRL) || |
| 3509 |
cmd == MCU_UNI_CMD(CHIP_CONFIG)) |
| 3510 |
uni_txd->option &= ~MCU_CMD_ACK; |
| 3511 |
|
| 3512 |
if (mcu_cmd == MCU_UNI_CMD_TESTMODE_CTRL || |
| 3513 |
mcu_cmd == MCU_UNI_CMD_TESTMODE_RX_STAT) { |
| 3514 |
if (cmd & __MCU_CMD_FIELD_QUERY) |
| 3515 |
uni_txd->option = 0x2; |
| 3516 |
else |
| 3517 |
uni_txd->option = 0x6; |
| 3518 |
} |
| 3519 |
|
| 3520 |
goto exit; |
| 3521 |
} |
| 3522 |
|
| 3523 |
mcu_txd = (struct mt76_connac2_mcu_txd *)txd; |
| 3524 |
mcu_txd->len = cpu_to_le16(skb->len - sizeof(mcu_txd->txd)); |
| 3525 |
mcu_txd->pq_id = cpu_to_le16(MCU_PQ_ID(MT_TX_PORT_IDX_MCU, |
| 3526 |
MT_TX_MCU_PORT_RX_Q0)); |
| 3527 |
mcu_txd->pkt_type = MCU_PKT_ID; |
| 3528 |
mcu_txd->seq = seq; |
| 3529 |
mcu_txd->cid = mcu_cmd; |
| 3530 |
mcu_txd->ext_cid = FIELD_GET(__MCU_CMD_FIELD_EXT_ID, cmd); |
| 3531 |
|
| 3532 |
if (mcu_txd->ext_cid || (cmd & __MCU_CMD_FIELD_CE)) { |
| 3533 |
if (cmd & __MCU_CMD_FIELD_QUERY) |
| 3534 |
mcu_txd->set_query = MCU_Q_QUERY; |
| 3535 |
else |
| 3536 |
mcu_txd->set_query = MCU_Q_SET; |
| 3537 |
mcu_txd->ext_cid_ack = !!mcu_txd->ext_cid; |
| 3538 |
} else { |
| 3539 |
mcu_txd->set_query = MCU_Q_NA; |
| 3540 |
} |
| 3541 |
|
| 3542 |
if (cmd & __MCU_CMD_FIELD_WA) |
| 3543 |
mcu_txd->s2d_index = MCU_S2D_H2C; |
| 3544 |
else |
| 3545 |
mcu_txd->s2d_index = MCU_S2D_H2N; |
| 3546 |
|
| 3547 |
exit: |
| 3548 |
if (wait_seq) |
| 3549 |
*wait_seq = seq; |
| 3550 |
|
| 3551 |
return 0; |
| 3552 |
} |
| 3553 |
EXPORT_SYMBOL_GPL(mt7925_mcu_fill_message); |
| 3554 |
|
| 3555 |
int mt7925_mcu_set_rts_thresh(struct mt792x_phy *phy, u32 val) |
| 3556 |
{ |
| 3557 |
struct { |
| 3558 |
u8 band_idx; |
| 3559 |
u8 _rsv[3]; |
| 3560 |
|
| 3561 |
__le16 tag; |
| 3562 |
__le16 len; |
| 3563 |
__le32 len_thresh; |
| 3564 |
__le32 pkt_thresh; |
| 3565 |
} __packed req = { |
| 3566 |
.band_idx = phy->mt76->band_idx, |
| 3567 |
.tag = cpu_to_le16(UNI_BAND_CONFIG_RTS_THRESHOLD), |
| 3568 |
.len = cpu_to_le16(sizeof(req) - 4), |
| 3569 |
.len_thresh = cpu_to_le32(val), |
| 3570 |
.pkt_thresh = cpu_to_le32(0x2), |
| 3571 |
}; |
| 3572 |
|
| 3573 |
return mt76_mcu_send_msg(&phy->dev->mt76, MCU_UNI_CMD(BAND_CONFIG), |
| 3574 |
&req, sizeof(req), true); |
| 3575 |
} |
| 3576 |
|
| 3577 |
int mt7925_mcu_set_radio_en(struct mt792x_phy *phy, bool enable) |
| 3578 |
{ |
| 3579 |
struct { |
| 3580 |
u8 band_idx; |
| 3581 |
u8 _rsv[3]; |
| 3582 |
|
| 3583 |
__le16 tag; |
| 3584 |
__le16 len; |
| 3585 |
u8 enable; |
| 3586 |
u8 _rsv2[3]; |
| 3587 |
} __packed req = { |
| 3588 |
.band_idx = phy->mt76->band_idx, |
| 3589 |
.tag = cpu_to_le16(UNI_BAND_CONFIG_RADIO_ENABLE), |
| 3590 |
.len = cpu_to_le16(sizeof(req) - 4), |
| 3591 |
.enable = enable, |
| 3592 |
}; |
| 3593 |
|
| 3594 |
return mt76_mcu_send_msg(&phy->dev->mt76, MCU_UNI_CMD(BAND_CONFIG), |
| 3595 |
&req, sizeof(req), true); |
| 3596 |
} |
| 3597 |
|
| 3598 |
static void |
| 3599 |
mt7925_mcu_build_sku(struct mt76_dev *dev, s8 *sku, |
| 3600 |
struct mt76_power_limits *limits, |
| 3601 |
enum nl80211_band band) |
| 3602 |
{ |
| 3603 |
int i, offset = sizeof(limits->cck); |
| 3604 |
|
| 3605 |
memset(sku, 127, MT_CONNAC3_SKU_POWER_LIMIT); |
| 3606 |
|
| 3607 |
if (band == NL80211_BAND_2GHZ) { |
| 3608 |
/* cck */ |
| 3609 |
memcpy(sku, limits->cck, sizeof(limits->cck)); |
| 3610 |
} |
| 3611 |
|
| 3612 |
/* ofdm */ |
| 3613 |
memcpy(&sku[offset], limits->ofdm, sizeof(limits->ofdm)); |
| 3614 |
offset += (sizeof(limits->ofdm) * 5); |
| 3615 |
|
| 3616 |
/* ht */ |
| 3617 |
for (i = 0; i < 2; i++) { |
| 3618 |
memcpy(&sku[offset], limits->mcs[i], 8); |
| 3619 |
offset += 8; |
| 3620 |
} |
| 3621 |
sku[offset++] = limits->mcs[0][0]; |
| 3622 |
|
| 3623 |
/* vht */ |
| 3624 |
for (i = 0; i < ARRAY_SIZE(limits->mcs); i++) { |
| 3625 |
memcpy(&sku[offset], limits->mcs[i], |
| 3626 |
ARRAY_SIZE(limits->mcs[i])); |
| 3627 |
offset += 12; |
| 3628 |
} |
| 3629 |
|
| 3630 |
/* he */ |
| 3631 |
for (i = 0; i < ARRAY_SIZE(limits->ru); i++) { |
| 3632 |
memcpy(&sku[offset], limits->ru[i], ARRAY_SIZE(limits->ru[i])); |
| 3633 |
offset += ARRAY_SIZE(limits->ru[i]); |
| 3634 |
} |
| 3635 |
|
| 3636 |
/* eht */ |
| 3637 |
for (i = 0; i < ARRAY_SIZE(limits->eht); i++) { |
| 3638 |
memcpy(&sku[offset], limits->eht[i], ARRAY_SIZE(limits->eht[i])); |
| 3639 |
offset += ARRAY_SIZE(limits->eht[i]); |
| 3640 |
} |
| 3641 |
} |
| 3642 |
|
| 3643 |
static int |
| 3644 |
mt7925_mcu_rate_txpower_band(struct mt76_phy *phy, |
| 3645 |
enum nl80211_band band) |
| 3646 |
{ |
| 3647 |
int tx_power, n_chan, last_ch, err = 0, idx = 0; |
| 3648 |
int i, sku_len, batch_size, batch_len = 3; |
| 3649 |
struct mt76_dev *dev = phy->dev; |
| 3650 |
static const u8 chan_list_2ghz[] = { |
| 3651 |
1, 2, 3, 4, 5, 6, 7, |
| 3652 |
8, 9, 10, 11, 12, 13, 14 |
| 3653 |
}; |
| 3654 |
static const u8 chan_list_5ghz[] = { |
| 3655 |
36, 38, 40, 42, 44, 46, 48, |
| 3656 |
50, 52, 54, 56, 58, 60, 62, |
| 3657 |
64, 100, 102, 104, 106, 108, 110, |
| 3658 |
112, 114, 116, 118, 120, 122, 124, |
| 3659 |
126, 128, 132, 134, 136, 138, 140, |
| 3660 |
142, 144, 149, 151, 153, 155, 157, |
| 3661 |
159, 161, 165, 167 |
| 3662 |
}; |
| 3663 |
static const u8 chan_list_6ghz[] = { |
| 3664 |
1, 3, 5, 7, 9, 11, 13, |
| 3665 |
15, 17, 19, 21, 23, 25, 27, |
| 3666 |
29, 33, 35, 37, 39, 41, 43, |
| 3667 |
45, 47, 49, 51, 53, 55, 57, |
| 3668 |
59, 61, 65, 67, 69, 71, 73, |
| 3669 |
75, 77, 79, 81, 83, 85, 87, |
| 3670 |
89, 91, 93, 97, 99, 101, 103, |
| 3671 |
105, 107, 109, 111, 113, 115, 117, |
| 3672 |
119, 121, 123, 125, 129, 131, 133, |
| 3673 |
135, 137, 139, 141, 143, 145, 147, |
| 3674 |
149, 151, 153, 155, 157, 161, 163, |
| 3675 |
165, 167, 169, 171, 173, 175, 177, |
| 3676 |
179, 181, 183, 185, 187, 189, 193, |
| 3677 |
195, 197, 199, 201, 203, 205, 207, |
| 3678 |
209, 211, 213, 215, 217, 219, 221, |
| 3679 |
225, 227, 229, 233 |
| 3680 |
}; |
| 3681 |
struct mt76_power_limits *limits; |
| 3682 |
struct mt7925_sku_tlv *sku_tlbv; |
| 3683 |
const u8 *ch_list; |
| 3684 |
|
| 3685 |
sku_len = sizeof(*sku_tlbv); |
| 3686 |
tx_power = 2 * phy->hw->conf.power_level; |
| 3687 |
if (!tx_power) |
| 3688 |
tx_power = 127; |
| 3689 |
|
| 3690 |
if (band == NL80211_BAND_2GHZ) { |
| 3691 |
n_chan = ARRAY_SIZE(chan_list_2ghz); |
| 3692 |
ch_list = chan_list_2ghz; |
| 3693 |
last_ch = chan_list_2ghz[ARRAY_SIZE(chan_list_2ghz) - 1]; |
| 3694 |
} else if (band == NL80211_BAND_6GHZ) { |
| 3695 |
n_chan = ARRAY_SIZE(chan_list_6ghz); |
| 3696 |
ch_list = chan_list_6ghz; |
| 3697 |
last_ch = chan_list_6ghz[ARRAY_SIZE(chan_list_6ghz) - 1]; |
| 3698 |
} else { |
| 3699 |
n_chan = ARRAY_SIZE(chan_list_5ghz); |
| 3700 |
ch_list = chan_list_5ghz; |
| 3701 |
last_ch = chan_list_5ghz[ARRAY_SIZE(chan_list_5ghz) - 1]; |
| 3702 |
} |
| 3703 |
batch_size = DIV_ROUND_UP(n_chan, batch_len); |
| 3704 |
|
| 3705 |
limits = devm_kmalloc(dev->dev, sizeof(*limits), GFP_KERNEL); |
| 3706 |
if (!limits) |
| 3707 |
return -ENOMEM; |
| 3708 |
|
| 3709 |
sku_tlbv = devm_kmalloc(dev->dev, sku_len, GFP_KERNEL); |
| 3710 |
if (!sku_tlbv) { |
| 3711 |
devm_kfree(dev->dev, limits); |
| 3712 |
return -ENOMEM; |
| 3713 |
} |
| 3714 |
|
| 3715 |
for (i = 0; i < batch_size; i++) { |
| 3716 |
struct mt7925_tx_power_limit_tlv *tx_power_tlv; |
| 3717 |
int j, msg_len, num_ch; |
| 3718 |
struct sk_buff *skb; |
| 3719 |
|
| 3720 |
num_ch = i == batch_size - 1 ? n_chan % batch_len : batch_len; |
| 3721 |
msg_len = sizeof(*tx_power_tlv) + num_ch * sku_len; |
| 3722 |
skb = mt76_mcu_msg_alloc(dev, NULL, msg_len); |
| 3723 |
if (!skb) { |
| 3724 |
err = -ENOMEM; |
| 3725 |
goto out; |
| 3726 |
} |
| 3727 |
|
| 3728 |
tx_power_tlv = (struct mt7925_tx_power_limit_tlv *) |
| 3729 |
skb_put(skb, sizeof(*tx_power_tlv)); |
| 3730 |
|
| 3731 |
BUILD_BUG_ON(sizeof(dev->alpha2) > sizeof(tx_power_tlv->alpha2)); |
| 3732 |
memcpy(tx_power_tlv->alpha2, dev->alpha2, sizeof(dev->alpha2)); |
| 3733 |
tx_power_tlv->n_chan = num_ch; |
| 3734 |
tx_power_tlv->tag = cpu_to_le16(0x1); |
| 3735 |
tx_power_tlv->len = cpu_to_le16(msg_len); |
| 3736 |
|
| 3737 |
switch (band) { |
| 3738 |
case NL80211_BAND_2GHZ: |
| 3739 |
tx_power_tlv->band = 1; |
| 3740 |
break; |
| 3741 |
case NL80211_BAND_6GHZ: |
| 3742 |
tx_power_tlv->band = 3; |
| 3743 |
break; |
| 3744 |
default: |
| 3745 |
tx_power_tlv->band = 2; |
| 3746 |
break; |
| 3747 |
} |
| 3748 |
|
| 3749 |
for (j = 0; j < num_ch; j++, idx++) { |
| 3750 |
struct ieee80211_channel chan = { |
| 3751 |
.hw_value = ch_list[idx], |
| 3752 |
.band = band, |
| 3753 |
}; |
| 3754 |
s8 reg_power, sar_power; |
| 3755 |
|
| 3756 |
reg_power = mt76_connac_get_ch_power(phy, &chan, |
| 3757 |
tx_power); |
| 3758 |
sar_power = mt76_get_sar_power(phy, &chan, reg_power); |
| 3759 |
|
| 3760 |
mt76_get_rate_power_limits(phy, &chan, limits, |
| 3761 |
sar_power); |
| 3762 |
|
| 3763 |
tx_power_tlv->last_msg = ch_list[idx] == last_ch; |
| 3764 |
sku_tlbv->channel = ch_list[idx]; |
| 3765 |
|
| 3766 |
mt7925_mcu_build_sku(dev, sku_tlbv->pwr_limit, |
| 3767 |
limits, band); |
| 3768 |
skb_put_data(skb, sku_tlbv, sku_len); |
| 3769 |
} |
| 3770 |
err = mt76_mcu_skb_send_msg(dev, skb, |
| 3771 |
MCU_UNI_CMD(SET_POWER_LIMIT), |
| 3772 |
true); |
| 3773 |
if (err < 0) |
| 3774 |
goto out; |
| 3775 |
} |
| 3776 |
|
| 3777 |
out: |
| 3778 |
devm_kfree(dev->dev, sku_tlbv); |
| 3779 |
devm_kfree(dev->dev, limits); |
| 3780 |
return err; |
| 3781 |
} |
| 3782 |
|
| 3783 |
int mt7925_mcu_set_rate_txpower(struct mt76_phy *phy) |
| 3784 |
{ |
| 3785 |
struct mt76_dev *mdev = phy->dev; |
| 3786 |
struct mt792x_dev *dev = mt792x_hw_dev(mdev->hw); |
| 3787 |
int err; |
| 3788 |
|
| 3789 |
if (phy->cap.has_2ghz) { |
| 3790 |
err = mt7925_mcu_rate_txpower_band(phy, |
| 3791 |
NL80211_BAND_2GHZ); |
| 3792 |
if (err < 0) |
| 3793 |
return err; |
| 3794 |
} |
| 3795 |
|
| 3796 |
if (phy->cap.has_5ghz) { |
| 3797 |
err = mt7925_mcu_rate_txpower_band(phy, |
| 3798 |
NL80211_BAND_5GHZ); |
| 3799 |
if (err < 0) |
| 3800 |
return err; |
| 3801 |
} |
| 3802 |
|
| 3803 |
if (phy->cap.has_6ghz && dev->phy.clc_chan_conf) { |
| 3804 |
err = mt7925_mcu_rate_txpower_band(phy, |
| 3805 |
NL80211_BAND_6GHZ); |
| 3806 |
if (err < 0) |
| 3807 |
return err; |
| 3808 |
} |
| 3809 |
|
| 3810 |
return 0; |
| 3811 |
} |
| 3812 |
|
| 3813 |
int mt7925_mcu_wf_rf_pin_ctrl(struct mt792x_phy *phy) |
| 3814 |
{ |
| 3815 |
#define UNI_CMD_RADIO_STATUS_GET 0 |
| 3816 |
struct mt792x_dev *dev = phy->dev; |
| 3817 |
struct sk_buff *skb; |
| 3818 |
int ret; |
| 3819 |
struct { |
| 3820 |
__le16 tag; |
| 3821 |
__le16 len; |
| 3822 |
u8 rsv[4]; |
| 3823 |
} __packed req = { |
| 3824 |
.tag = UNI_CMD_RADIO_STATUS_GET, |
| 3825 |
.len = cpu_to_le16(sizeof(req)), |
| 3826 |
}; |
| 3827 |
struct mt7925_radio_status_event { |
| 3828 |
__le16 tag; |
| 3829 |
__le16 len; |
| 3830 |
|
| 3831 |
u8 data; |
| 3832 |
u8 rsv[3]; |
| 3833 |
} __packed *status; |
| 3834 |
|
| 3835 |
ret = mt76_mcu_send_and_get_msg(&dev->mt76, |
| 3836 |
MCU_UNI_CMD(RADIO_STATUS), |
| 3837 |
&req, sizeof(req), true, &skb); |
| 3838 |
if (ret) |
| 3839 |
return ret; |
| 3840 |
|
| 3841 |
skb_pull(skb, sizeof(struct tlv)); |
| 3842 |
status = (struct mt7925_radio_status_event *)skb->data; |
| 3843 |
ret = status->data; |
| 3844 |
|
| 3845 |
dev_kfree_skb(skb); |
| 3846 |
|
| 3847 |
return ret; |
| 3848 |
} |
| 3849 |
|
| 3850 |
int mt7925_mcu_set_rxfilter(struct mt792x_dev *dev, u32 fif, |
| 3851 |
u8 bit_op, u32 bit_map) |
| 3852 |
{ |
| 3853 |
struct mt792x_phy *phy = &dev->phy; |
| 3854 |
struct { |
| 3855 |
u8 band_idx; |
| 3856 |
u8 rsv1[3]; |
| 3857 |
|
| 3858 |
__le16 tag; |
| 3859 |
__le16 len; |
| 3860 |
u8 mode; |
| 3861 |
u8 rsv2[3]; |
| 3862 |
__le32 fif; |
| 3863 |
__le32 bit_map; /* bit_* for bitmap update */ |
| 3864 |
u8 bit_op; |
| 3865 |
u8 pad[51]; |
| 3866 |
} __packed req = { |
| 3867 |
.band_idx = phy->mt76->band_idx, |
| 3868 |
.tag = cpu_to_le16(UNI_BAND_CONFIG_SET_MAC80211_RX_FILTER), |
| 3869 |
.len = cpu_to_le16(sizeof(req) - 4), |
| 3870 |
|
| 3871 |
.mode = fif ? 0 : 1, |
| 3872 |
.fif = cpu_to_le32(fif), |
| 3873 |
.bit_map = cpu_to_le32(bit_map), |
| 3874 |
.bit_op = bit_op, |
| 3875 |
}; |
| 3876 |
|
| 3877 |
return mt76_mcu_send_msg(&phy->dev->mt76, MCU_UNI_CMD(BAND_CONFIG), |
| 3878 |
&req, sizeof(req), true); |
| 3879 |
} |
| 3880 |
|
| 3881 |
int mt7925_mcu_set_rssimonitor(struct mt792x_dev *dev, struct ieee80211_vif *vif) |
| 3882 |
{ |
| 3883 |
struct mt792x_bss_conf *mconf = mt792x_link_conf_to_mconf(&vif->bss_conf); |
| 3884 |
struct { |
| 3885 |
struct { |
| 3886 |
u8 bss_idx; |
| 3887 |
u8 pad[3]; |
| 3888 |
} __packed hdr; |
| 3889 |
__le16 tag; |
| 3890 |
__le16 len; |
| 3891 |
u8 enable; |
| 3892 |
s8 cqm_rssi_high; |
| 3893 |
s8 cqm_rssi_low; |
| 3894 |
u8 rsv; |
| 3895 |
} req = { |
| 3896 |
.hdr = { |
| 3897 |
.bss_idx = mconf->mt76.idx, |
| 3898 |
}, |
| 3899 |
.tag = cpu_to_le16(UNI_CMD_RSSI_MONITOR_SET), |
| 3900 |
.len = cpu_to_le16(sizeof(req) - 4), |
| 3901 |
.enable = vif->cfg.assoc, |
| 3902 |
.cqm_rssi_high = (s8)(vif->bss_conf.cqm_rssi_thold + vif->bss_conf.cqm_rssi_hyst), |
| 3903 |
.cqm_rssi_low = (s8)(vif->bss_conf.cqm_rssi_thold - vif->bss_conf.cqm_rssi_hyst), |
| 3904 |
}; |
| 3905 |
|
| 3906 |
return mt76_mcu_send_msg(&dev->mt76, MCU_UNI_CMD(RSSI_MONITOR), &req, |
| 3907 |
sizeof(req), false); |
| 3908 |
} |