1 /* SPDX-License-Identifier: ISC */ 2 3 #include <linux/etherdevice.h> 4 #include <linux/platform_device.h> 5 #include <linux/pci.h> 6 #include <linux/module.h> 7 #include "mt7603.h" 8 #include "eeprom.h" 9 10 static int 11 mt7603_start(struct ieee80211_hw *hw) 12 { 13 struct mt7603_dev *dev = hw->priv; 14 15 mt7603_mac_start(dev); 16 dev->survey_time = ktime_get_boottime(); 17 set_bit(MT76_STATE_RUNNING, &dev->mt76.state); 18 mt7603_mac_work(&dev->mac_work.work); 19 20 return 0; 21 } 22 23 static void 24 mt7603_stop(struct ieee80211_hw *hw) 25 { 26 struct mt7603_dev *dev = hw->priv; 27 28 clear_bit(MT76_STATE_RUNNING, &dev->mt76.state); 29 cancel_delayed_work_sync(&dev->mac_work); 30 mt7603_mac_stop(dev); 31 } 32 33 static int 34 mt7603_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 35 { 36 struct mt7603_vif *mvif = (struct mt7603_vif *)vif->drv_priv; 37 struct mt7603_dev *dev = hw->priv; 38 struct mt76_txq *mtxq; 39 u8 bc_addr[ETH_ALEN]; 40 int idx; 41 int ret = 0; 42 43 mutex_lock(&dev->mt76.mutex); 44 45 mvif->idx = ffs(~dev->vif_mask) - 1; 46 if (mvif->idx >= MT7603_MAX_INTERFACES) { 47 ret = -ENOSPC; 48 goto out; 49 } 50 51 mt76_wr(dev, MT_MAC_ADDR0(mvif->idx), 52 get_unaligned_le32(vif->addr)); 53 mt76_wr(dev, MT_MAC_ADDR1(mvif->idx), 54 (get_unaligned_le16(vif->addr + 4) | 55 MT_MAC_ADDR1_VALID)); 56 57 if (vif->type == NL80211_IFTYPE_AP) { 58 mt76_wr(dev, MT_BSSID0(mvif->idx), 59 get_unaligned_le32(vif->addr)); 60 mt76_wr(dev, MT_BSSID1(mvif->idx), 61 (get_unaligned_le16(vif->addr + 4) | 62 MT_BSSID1_VALID)); 63 } 64 65 idx = MT7603_WTBL_RESERVED - 1 - mvif->idx; 66 dev->vif_mask |= BIT(mvif->idx); 67 mvif->sta.wcid.idx = idx; 68 mvif->sta.wcid.hw_key_idx = -1; 69 70 eth_broadcast_addr(bc_addr); 71 mt7603_wtbl_init(dev, idx, mvif->idx, bc_addr); 72 73 mtxq = (struct mt76_txq *)vif->txq->drv_priv; 74 mtxq->wcid = &mvif->sta.wcid; 75 mt76_txq_init(&dev->mt76, vif->txq); 76 rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid); 77 78 out: 79 mutex_unlock(&dev->mt76.mutex); 80 81 return ret; 82 } 83 84 static void 85 mt7603_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 86 { 87 struct mt7603_vif *mvif = (struct mt7603_vif *)vif->drv_priv; 88 struct mt7603_dev *dev = hw->priv; 89 int idx = mvif->sta.wcid.idx; 90 91 mt76_wr(dev, MT_MAC_ADDR0(mvif->idx), 0); 92 mt76_wr(dev, MT_MAC_ADDR1(mvif->idx), 0); 93 mt76_wr(dev, MT_BSSID0(mvif->idx), 0); 94 mt76_wr(dev, MT_BSSID1(mvif->idx), 0); 95 mt7603_beacon_set_timer(dev, mvif->idx, 0); 96 97 rcu_assign_pointer(dev->mt76.wcid[idx], NULL); 98 mt76_txq_remove(&dev->mt76, vif->txq); 99 100 mutex_lock(&dev->mt76.mutex); 101 dev->vif_mask &= ~BIT(mvif->idx); 102 mutex_unlock(&dev->mt76.mutex); 103 } 104 105 static void 106 mt7603_init_edcca(struct mt7603_dev *dev) 107 { 108 /* Set lower signal level to -65dBm */ 109 mt76_rmw_field(dev, MT_RXTD(8), MT_RXTD_8_LOWER_SIGNAL, 0x23); 110 111 /* clear previous energy detect monitor results */ 112 mt76_rr(dev, MT_MIB_STAT_ED); 113 114 if (dev->ed_monitor) 115 mt76_set(dev, MT_MIB_CTL, MT_MIB_CTL_ED_TIME); 116 else 117 mt76_clear(dev, MT_MIB_CTL, MT_MIB_CTL_ED_TIME); 118 119 dev->ed_strict_mode = 0xff; 120 dev->ed_strong_signal = 0; 121 dev->ed_time = ktime_get_boottime(); 122 123 mt7603_edcca_set_strict(dev, false); 124 } 125 126 static int 127 mt7603_set_channel(struct mt7603_dev *dev, struct cfg80211_chan_def *def) 128 { 129 u8 *rssi_data = (u8 *)dev->mt76.eeprom.data; 130 int idx, ret; 131 u8 bw = MT_BW_20; 132 bool failed = false; 133 134 cancel_delayed_work_sync(&dev->mac_work); 135 136 mutex_lock(&dev->mt76.mutex); 137 set_bit(MT76_RESET, &dev->mt76.state); 138 139 mt76_set_channel(&dev->mt76); 140 mt7603_mac_stop(dev); 141 142 if (def->width == NL80211_CHAN_WIDTH_40) 143 bw = MT_BW_40; 144 145 dev->mt76.chandef = *def; 146 mt76_rmw_field(dev, MT_AGG_BWCR, MT_AGG_BWCR_BW, bw); 147 ret = mt7603_mcu_set_channel(dev); 148 if (ret) { 149 failed = true; 150 goto out; 151 } 152 153 if (def->chan->band == NL80211_BAND_5GHZ) { 154 idx = 1; 155 rssi_data += MT_EE_RSSI_OFFSET_5G; 156 } else { 157 idx = 0; 158 rssi_data += MT_EE_RSSI_OFFSET_2G; 159 } 160 161 memcpy(dev->rssi_offset, rssi_data, sizeof(dev->rssi_offset)); 162 163 idx |= (def->chan - 164 mt76_hw(dev)->wiphy->bands[def->chan->band]->channels) << 1; 165 mt76_wr(dev, MT_WF_RMAC_CH_FREQ, idx); 166 mt7603_mac_set_timing(dev); 167 mt7603_mac_start(dev); 168 169 clear_bit(MT76_RESET, &dev->mt76.state); 170 171 mt76_txq_schedule_all(&dev->mt76); 172 173 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mac_work, 174 MT7603_WATCHDOG_TIME); 175 176 /* reset channel stats */ 177 mt76_clear(dev, MT_MIB_CTL, MT_MIB_CTL_READ_CLR_DIS); 178 mt76_set(dev, MT_MIB_CTL, 179 MT_MIB_CTL_CCA_NAV_TX | MT_MIB_CTL_PSCCA_TIME); 180 mt76_rr(dev, MT_MIB_STAT_PSCCA); 181 mt7603_cca_stats_reset(dev); 182 183 dev->survey_time = ktime_get_boottime(); 184 185 mt7603_init_edcca(dev); 186 187 out: 188 mutex_unlock(&dev->mt76.mutex); 189 190 if (failed) 191 mt7603_mac_work(&dev->mac_work.work); 192 193 return ret; 194 } 195 196 static int 197 mt7603_config(struct ieee80211_hw *hw, u32 changed) 198 { 199 struct mt7603_dev *dev = hw->priv; 200 int ret = 0; 201 202 if (changed & (IEEE80211_CONF_CHANGE_CHANNEL | 203 IEEE80211_CONF_CHANGE_POWER)) 204 ret = mt7603_set_channel(dev, &hw->conf.chandef); 205 206 if (changed & IEEE80211_CONF_CHANGE_MONITOR) { 207 mutex_lock(&dev->mt76.mutex); 208 209 if (!(hw->conf.flags & IEEE80211_CONF_MONITOR)) 210 dev->rxfilter |= MT_WF_RFCR_DROP_OTHER_UC; 211 else 212 dev->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_UC; 213 214 mt76_wr(dev, MT_WF_RFCR, dev->rxfilter); 215 216 mutex_unlock(&dev->mt76.mutex); 217 } 218 219 return ret; 220 } 221 222 static void 223 mt7603_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags, 224 unsigned int *total_flags, u64 multicast) 225 { 226 struct mt7603_dev *dev = hw->priv; 227 u32 flags = 0; 228 229 #define MT76_FILTER(_flag, _hw) do { \ 230 flags |= *total_flags & FIF_##_flag; \ 231 dev->rxfilter &= ~(_hw); \ 232 dev->rxfilter |= !(flags & FIF_##_flag) * (_hw); \ 233 } while (0) 234 235 dev->rxfilter &= ~(MT_WF_RFCR_DROP_OTHER_BSS | 236 MT_WF_RFCR_DROP_OTHER_BEACON | 237 MT_WF_RFCR_DROP_FRAME_REPORT | 238 MT_WF_RFCR_DROP_PROBEREQ | 239 MT_WF_RFCR_DROP_MCAST_FILTERED | 240 MT_WF_RFCR_DROP_MCAST | 241 MT_WF_RFCR_DROP_BCAST | 242 MT_WF_RFCR_DROP_DUPLICATE | 243 MT_WF_RFCR_DROP_A2_BSSID | 244 MT_WF_RFCR_DROP_UNWANTED_CTL | 245 MT_WF_RFCR_DROP_STBC_MULTI); 246 247 MT76_FILTER(OTHER_BSS, MT_WF_RFCR_DROP_OTHER_TIM | 248 MT_WF_RFCR_DROP_A3_MAC | 249 MT_WF_RFCR_DROP_A3_BSSID); 250 251 MT76_FILTER(FCSFAIL, MT_WF_RFCR_DROP_FCSFAIL); 252 253 MT76_FILTER(CONTROL, MT_WF_RFCR_DROP_CTS | 254 MT_WF_RFCR_DROP_RTS | 255 MT_WF_RFCR_DROP_CTL_RSV | 256 MT_WF_RFCR_DROP_NDPA); 257 258 *total_flags = flags; 259 mt76_wr(dev, MT_WF_RFCR, dev->rxfilter); 260 } 261 262 static void 263 mt7603_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 264 struct ieee80211_bss_conf *info, u32 changed) 265 { 266 struct mt7603_dev *dev = hw->priv; 267 struct mt7603_vif *mvif = (struct mt7603_vif *)vif->drv_priv; 268 269 mutex_lock(&dev->mt76.mutex); 270 271 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BSSID)) { 272 if (info->assoc || info->ibss_joined) { 273 mt76_wr(dev, MT_BSSID0(mvif->idx), 274 get_unaligned_le32(info->bssid)); 275 mt76_wr(dev, MT_BSSID1(mvif->idx), 276 (get_unaligned_le16(info->bssid + 4) | 277 MT_BSSID1_VALID)); 278 } else { 279 mt76_wr(dev, MT_BSSID0(mvif->idx), 0); 280 mt76_wr(dev, MT_BSSID1(mvif->idx), 0); 281 } 282 } 283 284 if (changed & BSS_CHANGED_ERP_SLOT) { 285 int slottime = info->use_short_slot ? 9 : 20; 286 287 if (slottime != dev->slottime) { 288 dev->slottime = slottime; 289 mt7603_mac_set_timing(dev); 290 } 291 } 292 293 if (changed & (BSS_CHANGED_BEACON_ENABLED | BSS_CHANGED_BEACON_INT)) { 294 int beacon_int = !!info->enable_beacon * info->beacon_int; 295 296 tasklet_disable(&dev->pre_tbtt_tasklet); 297 mt7603_beacon_set_timer(dev, mvif->idx, beacon_int); 298 tasklet_enable(&dev->pre_tbtt_tasklet); 299 } 300 301 mutex_unlock(&dev->mt76.mutex); 302 } 303 304 int 305 mt7603_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, 306 struct ieee80211_sta *sta) 307 { 308 struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76); 309 struct mt7603_sta *msta = (struct mt7603_sta *)sta->drv_priv; 310 struct mt7603_vif *mvif = (struct mt7603_vif *)vif->drv_priv; 311 int idx; 312 int ret = 0; 313 314 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7603_WTBL_STA - 1); 315 if (idx < 0) 316 return -ENOSPC; 317 318 __skb_queue_head_init(&msta->psq); 319 msta->ps = ~0; 320 msta->smps = ~0; 321 msta->wcid.sta = 1; 322 msta->wcid.idx = idx; 323 mt7603_wtbl_init(dev, idx, mvif->idx, sta->addr); 324 mt7603_wtbl_set_ps(dev, msta, false); 325 326 if (vif->type == NL80211_IFTYPE_AP) 327 set_bit(MT_WCID_FLAG_CHECK_PS, &msta->wcid.flags); 328 329 return ret; 330 } 331 332 void 333 mt7603_sta_assoc(struct mt76_dev *mdev, struct ieee80211_vif *vif, 334 struct ieee80211_sta *sta) 335 { 336 struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76); 337 338 mt7603_wtbl_update_cap(dev, sta); 339 } 340 341 void 342 mt7603_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, 343 struct ieee80211_sta *sta) 344 { 345 struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76); 346 struct mt7603_sta *msta = (struct mt7603_sta *)sta->drv_priv; 347 struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv; 348 349 spin_lock_bh(&dev->ps_lock); 350 __skb_queue_purge(&msta->psq); 351 mt7603_filter_tx(dev, wcid->idx, true); 352 spin_unlock_bh(&dev->ps_lock); 353 354 mt7603_wtbl_clear(dev, wcid->idx); 355 } 356 357 static void 358 mt7603_ps_tx_list(struct mt7603_dev *dev, struct sk_buff_head *list) 359 { 360 struct sk_buff *skb; 361 362 while ((skb = __skb_dequeue(list)) != NULL) 363 mt76_tx_queue_skb_raw(dev, skb_get_queue_mapping(skb), 364 skb, 0); 365 } 366 367 void 368 mt7603_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta, bool ps) 369 { 370 struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76); 371 struct mt7603_sta *msta = (struct mt7603_sta *)sta->drv_priv; 372 struct sk_buff_head list; 373 374 mt76_stop_tx_queues(&dev->mt76, sta, false); 375 mt7603_wtbl_set_ps(dev, msta, ps); 376 if (ps) 377 return; 378 379 __skb_queue_head_init(&list); 380 381 spin_lock_bh(&dev->ps_lock); 382 skb_queue_splice_tail_init(&msta->psq, &list); 383 spin_unlock_bh(&dev->ps_lock); 384 385 mt7603_ps_tx_list(dev, &list); 386 } 387 388 static void 389 mt7603_release_buffered_frames(struct ieee80211_hw *hw, 390 struct ieee80211_sta *sta, 391 u16 tids, int nframes, 392 enum ieee80211_frame_release_type reason, 393 bool more_data) 394 { 395 struct mt7603_dev *dev = hw->priv; 396 struct mt7603_sta *msta = (struct mt7603_sta *)sta->drv_priv; 397 struct sk_buff_head list; 398 struct sk_buff *skb, *tmp; 399 400 __skb_queue_head_init(&list); 401 402 spin_lock_bh(&dev->ps_lock); 403 skb_queue_walk_safe(&msta->psq, skb, tmp) { 404 if (!nframes) 405 break; 406 407 if (!(tids & BIT(skb->priority))) 408 continue; 409 410 skb_set_queue_mapping(skb, MT_TXQ_PSD); 411 __skb_unlink(skb, &msta->psq); 412 __skb_queue_tail(&list, skb); 413 nframes--; 414 } 415 spin_unlock_bh(&dev->ps_lock); 416 417 mt7603_ps_tx_list(dev, &list); 418 419 if (nframes) 420 mt76_release_buffered_frames(hw, sta, tids, nframes, reason, 421 more_data); 422 } 423 424 static int 425 mt7603_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 426 struct ieee80211_vif *vif, struct ieee80211_sta *sta, 427 struct ieee80211_key_conf *key) 428 { 429 struct mt7603_dev *dev = hw->priv; 430 struct mt7603_vif *mvif = (struct mt7603_vif *)vif->drv_priv; 431 struct mt7603_sta *msta = sta ? (struct mt7603_sta *)sta->drv_priv : 432 &mvif->sta; 433 struct mt76_wcid *wcid = &msta->wcid; 434 int idx = key->keyidx; 435 436 /* fall back to sw encryption for unsupported ciphers */ 437 switch (key->cipher) { 438 case WLAN_CIPHER_SUITE_TKIP: 439 case WLAN_CIPHER_SUITE_CCMP: 440 break; 441 default: 442 return -EOPNOTSUPP; 443 } 444 445 /* 446 * The hardware does not support per-STA RX GTK, fall back 447 * to software mode for these. 448 */ 449 if ((vif->type == NL80211_IFTYPE_ADHOC || 450 vif->type == NL80211_IFTYPE_MESH_POINT) && 451 (key->cipher == WLAN_CIPHER_SUITE_TKIP || 452 key->cipher == WLAN_CIPHER_SUITE_CCMP) && 453 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) 454 return -EOPNOTSUPP; 455 456 if (cmd == SET_KEY) { 457 key->hw_key_idx = wcid->idx; 458 wcid->hw_key_idx = idx; 459 } else { 460 if (idx == wcid->hw_key_idx) 461 wcid->hw_key_idx = -1; 462 463 key = NULL; 464 } 465 mt76_wcid_key_setup(&dev->mt76, wcid, key); 466 467 return mt7603_wtbl_set_key(dev, wcid->idx, key); 468 } 469 470 static int 471 mt7603_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue, 472 const struct ieee80211_tx_queue_params *params) 473 { 474 struct mt7603_dev *dev = hw->priv; 475 u16 cw_min = (1 << 5) - 1; 476 u16 cw_max = (1 << 10) - 1; 477 u32 val; 478 479 queue = dev->mt76.q_tx[queue].hw_idx; 480 481 if (params->cw_min) 482 cw_min = params->cw_min; 483 if (params->cw_max) 484 cw_max = params->cw_max; 485 486 mutex_lock(&dev->mt76.mutex); 487 mt7603_mac_stop(dev); 488 489 val = mt76_rr(dev, MT_WMM_TXOP(queue)); 490 val &= ~(MT_WMM_TXOP_MASK << MT_WMM_TXOP_SHIFT(queue)); 491 val |= params->txop << MT_WMM_TXOP_SHIFT(queue); 492 mt76_wr(dev, MT_WMM_TXOP(queue), val); 493 494 val = mt76_rr(dev, MT_WMM_AIFSN); 495 val &= ~(MT_WMM_AIFSN_MASK << MT_WMM_AIFSN_SHIFT(queue)); 496 val |= params->aifs << MT_WMM_AIFSN_SHIFT(queue); 497 mt76_wr(dev, MT_WMM_AIFSN, val); 498 499 val = mt76_rr(dev, MT_WMM_CWMIN); 500 val &= ~(MT_WMM_CWMIN_MASK << MT_WMM_CWMIN_SHIFT(queue)); 501 val |= cw_min << MT_WMM_CWMIN_SHIFT(queue); 502 mt76_wr(dev, MT_WMM_CWMIN, val); 503 504 val = mt76_rr(dev, MT_WMM_CWMAX(queue)); 505 val &= ~(MT_WMM_CWMAX_MASK << MT_WMM_CWMAX_SHIFT(queue)); 506 val |= cw_max << MT_WMM_CWMAX_SHIFT(queue); 507 mt76_wr(dev, MT_WMM_CWMAX(queue), val); 508 509 mt7603_mac_start(dev); 510 mutex_unlock(&dev->mt76.mutex); 511 512 return 0; 513 } 514 515 static void 516 mt7603_sw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 517 const u8 *mac) 518 { 519 struct mt7603_dev *dev = hw->priv; 520 521 set_bit(MT76_SCANNING, &dev->mt76.state); 522 mt7603_beacon_set_timer(dev, -1, 0); 523 } 524 525 static void 526 mt7603_sw_scan_complete(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 527 { 528 struct mt7603_dev *dev = hw->priv; 529 530 clear_bit(MT76_SCANNING, &dev->mt76.state); 531 mt7603_beacon_set_timer(dev, -1, dev->beacon_int); 532 } 533 534 static void 535 mt7603_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 536 u32 queues, bool drop) 537 { 538 } 539 540 static int 541 mt7603_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 542 struct ieee80211_ampdu_params *params) 543 { 544 enum ieee80211_ampdu_mlme_action action = params->action; 545 struct mt7603_dev *dev = hw->priv; 546 struct ieee80211_sta *sta = params->sta; 547 struct ieee80211_txq *txq = sta->txq[params->tid]; 548 struct mt7603_sta *msta = (struct mt7603_sta *)sta->drv_priv; 549 u16 tid = params->tid; 550 u16 *ssn = ¶ms->ssn; 551 u8 ba_size = params->buf_size; 552 struct mt76_txq *mtxq; 553 554 if (!txq) 555 return -EINVAL; 556 557 mtxq = (struct mt76_txq *)txq->drv_priv; 558 559 switch (action) { 560 case IEEE80211_AMPDU_RX_START: 561 mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, *ssn, 562 params->buf_size); 563 mt7603_mac_rx_ba_reset(dev, sta->addr, tid); 564 break; 565 case IEEE80211_AMPDU_RX_STOP: 566 mt76_rx_aggr_stop(&dev->mt76, &msta->wcid, tid); 567 break; 568 case IEEE80211_AMPDU_TX_OPERATIONAL: 569 mtxq->aggr = true; 570 mtxq->send_bar = false; 571 mt7603_mac_tx_ba_reset(dev, msta->wcid.idx, tid, *ssn, ba_size); 572 break; 573 case IEEE80211_AMPDU_TX_STOP_FLUSH: 574 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 575 mtxq->aggr = false; 576 ieee80211_send_bar(vif, sta->addr, tid, mtxq->agg_ssn); 577 mt7603_mac_tx_ba_reset(dev, msta->wcid.idx, tid, *ssn, -1); 578 break; 579 case IEEE80211_AMPDU_TX_START: 580 mtxq->agg_ssn = *ssn << 4; 581 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); 582 break; 583 case IEEE80211_AMPDU_TX_STOP_CONT: 584 mtxq->aggr = false; 585 mt7603_mac_tx_ba_reset(dev, msta->wcid.idx, tid, *ssn, -1); 586 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); 587 break; 588 } 589 590 return 0; 591 } 592 593 static void 594 mt7603_sta_rate_tbl_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 595 struct ieee80211_sta *sta) 596 { 597 struct mt7603_dev *dev = hw->priv; 598 struct mt7603_sta *msta = (struct mt7603_sta *)sta->drv_priv; 599 struct ieee80211_sta_rates *sta_rates = rcu_dereference(sta->rates); 600 int i; 601 602 spin_lock_bh(&dev->mt76.lock); 603 for (i = 0; i < ARRAY_SIZE(msta->rates); i++) { 604 msta->rates[i].idx = sta_rates->rate[i].idx; 605 msta->rates[i].count = sta_rates->rate[i].count; 606 msta->rates[i].flags = sta_rates->rate[i].flags; 607 608 if (msta->rates[i].idx < 0 || !msta->rates[i].count) 609 break; 610 } 611 msta->n_rates = i; 612 mt7603_wtbl_set_rates(dev, msta, NULL, msta->rates); 613 msta->rate_probe = false; 614 mt7603_wtbl_set_smps(dev, msta, 615 sta->smps_mode == IEEE80211_SMPS_DYNAMIC); 616 spin_unlock_bh(&dev->mt76.lock); 617 } 618 619 static void 620 mt7603_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class) 621 { 622 struct mt7603_dev *dev = hw->priv; 623 624 dev->coverage_class = coverage_class; 625 mt7603_mac_set_timing(dev); 626 } 627 628 static void mt7603_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, 629 struct sk_buff *skb) 630 { 631 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 632 struct ieee80211_vif *vif = info->control.vif; 633 struct mt7603_dev *dev = hw->priv; 634 struct mt76_wcid *wcid = &dev->global_sta.wcid; 635 636 if (control->sta) { 637 struct mt7603_sta *msta; 638 639 msta = (struct mt7603_sta *)control->sta->drv_priv; 640 wcid = &msta->wcid; 641 } else if (vif) { 642 struct mt7603_vif *mvif; 643 644 mvif = (struct mt7603_vif *)vif->drv_priv; 645 wcid = &mvif->sta.wcid; 646 } 647 648 mt76_tx(&dev->mt76, control->sta, wcid, skb); 649 } 650 651 static int 652 mt7603_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set) 653 { 654 return 0; 655 } 656 657 const struct ieee80211_ops mt7603_ops = { 658 .tx = mt7603_tx, 659 .start = mt7603_start, 660 .stop = mt7603_stop, 661 .add_interface = mt7603_add_interface, 662 .remove_interface = mt7603_remove_interface, 663 .config = mt7603_config, 664 .configure_filter = mt7603_configure_filter, 665 .bss_info_changed = mt7603_bss_info_changed, 666 .sta_state = mt76_sta_state, 667 .set_key = mt7603_set_key, 668 .conf_tx = mt7603_conf_tx, 669 .sw_scan_start = mt7603_sw_scan, 670 .sw_scan_complete = mt7603_sw_scan_complete, 671 .flush = mt7603_flush, 672 .ampdu_action = mt7603_ampdu_action, 673 .get_txpower = mt76_get_txpower, 674 .wake_tx_queue = mt76_wake_tx_queue, 675 .sta_rate_tbl_update = mt7603_sta_rate_tbl_update, 676 .release_buffered_frames = mt7603_release_buffered_frames, 677 .set_coverage_class = mt7603_set_coverage_class, 678 .set_tim = mt7603_set_tim, 679 .get_survey = mt76_get_survey, 680 }; 681 682 MODULE_LICENSE("Dual BSD/GPL"); 683 684 static int __init mt7603_init(void) 685 { 686 int ret; 687 688 ret = platform_driver_register(&mt76_wmac_driver); 689 if (ret) 690 return ret; 691 692 #ifdef CONFIG_PCI 693 ret = pci_register_driver(&mt7603_pci_driver); 694 if (ret) 695 platform_driver_unregister(&mt76_wmac_driver); 696 #endif 697 return ret; 698 } 699 700 static void __exit mt7603_exit(void) 701 { 702 #ifdef CONFIG_PCI 703 pci_unregister_driver(&mt7603_pci_driver); 704 #endif 705 platform_driver_unregister(&mt76_wmac_driver); 706 } 707 708 module_init(mt7603_init); 709 module_exit(mt7603_exit); 710