1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2019 MediaTek Inc.
4 * Author: Roy Luo <royluo@google.com>
5 * Ryder Lee <ryder.lee@mediatek.com>
6 * Felix Fietkau <nbd@nbd.name>
9 #include <linux/etherdevice.h>
10 #include <linux/platform_device.h>
11 #include <linux/pci.h>
12 #include <linux/module.h>
16 static bool mt7615_dev_running(struct mt7615_dev *dev)
18 struct mt7615_phy *phy;
20 if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state))
23 phy = mt7615_ext_phy(dev);
25 return phy && test_bit(MT76_STATE_RUNNING, &phy->mt76->state);
28 static int mt7615_start(struct ieee80211_hw *hw)
30 struct mt7615_dev *dev = mt7615_hw_dev(hw);
31 struct mt7615_phy *phy = mt7615_hw_phy(hw);
34 if (!mt7615_wait_for_mcu_init(dev))
37 mutex_lock(&dev->mt76.mutex);
39 running = mt7615_dev_running(dev);
42 mt7615_mcu_set_pm(dev, 0, 0);
43 mt7615_mcu_set_mac_enable(dev, 0, true);
44 mt7615_mac_enable_nf(dev, 0);
47 if (phy != &dev->phy) {
48 mt7615_mcu_set_pm(dev, 1, 0);
49 mt7615_mcu_set_mac_enable(dev, 1, true);
50 mt7615_mac_enable_nf(dev, 1);
53 mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD_SET_RX_PATH);
55 set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
60 mt7615_mac_reset_counters(dev);
62 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mt76.mac_work,
63 MT7615_WATCHDOG_TIME);
66 mutex_unlock(&dev->mt76.mutex);
71 static void mt7615_stop(struct ieee80211_hw *hw)
73 struct mt7615_dev *dev = mt7615_hw_dev(hw);
74 struct mt7615_phy *phy = mt7615_hw_phy(hw);
76 mutex_lock(&dev->mt76.mutex);
78 clear_bit(MT76_STATE_RUNNING, &phy->mt76->state);
80 if (phy != &dev->phy) {
81 mt7615_mcu_set_pm(dev, 1, 1);
82 mt7615_mcu_set_mac_enable(dev, 1, false);
85 if (!mt7615_dev_running(dev)) {
86 cancel_delayed_work_sync(&dev->mt76.mac_work);
88 mt7615_mcu_set_pm(dev, 0, 1);
89 mt7615_mcu_set_mac_enable(dev, 0, false);
92 mutex_unlock(&dev->mt76.mutex);
95 static int get_omac_idx(enum nl80211_iftype type, u32 mask)
100 case NL80211_IFTYPE_MONITOR:
101 case NL80211_IFTYPE_AP:
102 case NL80211_IFTYPE_MESH_POINT:
103 case NL80211_IFTYPE_ADHOC:
104 /* ap use hw bssid 0 and ext bssid */
105 if (~mask & BIT(HW_BSSID_0))
108 for (i = EXT_BSSID_1; i < EXT_BSSID_END; i++)
113 case NL80211_IFTYPE_STATION:
114 /* sta use hw bssid other than 0 */
115 for (i = HW_BSSID_1; i < HW_BSSID_MAX; i++)
128 static int mt7615_add_interface(struct ieee80211_hw *hw,
129 struct ieee80211_vif *vif)
131 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
132 struct mt7615_dev *dev = mt7615_hw_dev(hw);
133 struct mt7615_phy *phy = mt7615_hw_phy(hw);
134 struct mt76_txq *mtxq;
135 bool ext_phy = phy != &dev->phy;
138 mutex_lock(&dev->mt76.mutex);
140 mvif->idx = ffs(~dev->vif_mask) - 1;
141 if (mvif->idx >= MT7615_MAX_INTERFACES) {
146 idx = get_omac_idx(vif->type, dev->omac_mask);
151 mvif->omac_idx = idx;
153 mvif->band_idx = ext_phy;
154 if (mt7615_ext_phy(dev))
155 mvif->wmm_idx = ext_phy * (MT7615_MAX_WMM_SETS / 2) +
156 mvif->idx % (MT7615_MAX_WMM_SETS / 2);
158 mvif->wmm_idx = mvif->idx % MT7615_MAX_WMM_SETS;
160 ret = mt7615_mcu_add_dev_info(dev, vif, true);
164 dev->vif_mask |= BIT(mvif->idx);
165 dev->omac_mask |= BIT(mvif->omac_idx);
166 phy->omac_mask |= BIT(mvif->omac_idx);
168 mt7615_mcu_set_dbdc(dev);
170 idx = MT7615_WTBL_RESERVED - mvif->idx;
172 INIT_LIST_HEAD(&mvif->sta.poll_list);
173 mvif->sta.wcid.idx = idx;
174 mvif->sta.wcid.ext_phy = mvif->band_idx;
175 mvif->sta.wcid.hw_key_idx = -1;
176 mt7615_mac_wtbl_update(dev, idx,
177 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
179 rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid);
181 mtxq = (struct mt76_txq *)vif->txq->drv_priv;
182 mtxq->wcid = &mvif->sta.wcid;
183 mt76_txq_init(&dev->mt76, vif->txq);
187 mutex_unlock(&dev->mt76.mutex);
192 static void mt7615_remove_interface(struct ieee80211_hw *hw,
193 struct ieee80211_vif *vif)
195 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
196 struct mt7615_sta *msta = &mvif->sta;
197 struct mt7615_dev *dev = mt7615_hw_dev(hw);
198 struct mt7615_phy *phy = mt7615_hw_phy(hw);
199 int idx = msta->wcid.idx;
201 /* TODO: disable beacon for the bss */
203 mt7615_mcu_add_dev_info(dev, vif, false);
205 rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
207 mt76_txq_remove(&dev->mt76, vif->txq);
209 mutex_lock(&dev->mt76.mutex);
210 dev->vif_mask &= ~BIT(mvif->idx);
211 dev->omac_mask &= ~BIT(mvif->omac_idx);
212 phy->omac_mask &= ~BIT(mvif->omac_idx);
213 mutex_unlock(&dev->mt76.mutex);
215 spin_lock_bh(&dev->sta_poll_lock);
216 if (!list_empty(&msta->poll_list))
217 list_del_init(&msta->poll_list);
218 spin_unlock_bh(&dev->sta_poll_lock);
221 static void mt7615_init_dfs_state(struct mt7615_phy *phy)
223 struct mt76_phy *mphy = phy->mt76;
224 struct ieee80211_hw *hw = mphy->hw;
225 struct cfg80211_chan_def *chandef = &hw->conf.chandef;
227 if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
230 if (!(chandef->chan->flags & IEEE80211_CHAN_RADAR))
233 if (mphy->chandef.chan->center_freq == chandef->chan->center_freq &&
234 mphy->chandef.width == chandef->width)
240 static int mt7615_set_channel(struct mt7615_phy *phy)
242 struct mt7615_dev *dev = phy->dev;
243 bool ext_phy = phy != &dev->phy;
246 cancel_delayed_work_sync(&dev->mt76.mac_work);
248 mutex_lock(&dev->mt76.mutex);
249 set_bit(MT76_RESET, &phy->mt76->state);
251 mt7615_init_dfs_state(phy);
252 mt76_set_channel(phy->mt76);
254 ret = mt7615_mcu_set_chan_info(phy, MCU_EXT_CMD_CHANNEL_SWITCH);
258 mt7615_mac_set_timing(phy);
259 ret = mt7615_dfs_init_radar_detector(phy);
260 mt7615_mac_cca_stats_reset(phy);
261 mt7615_mcu_set_sku_en(phy, true);
263 mt7615_mac_reset_counters(dev);
265 phy->chfreq = mt76_rr(dev, MT_CHFREQ(ext_phy));
268 clear_bit(MT76_RESET, &phy->mt76->state);
269 mutex_unlock(&dev->mt76.mutex);
271 mt76_txq_schedule_all(phy->mt76);
272 ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mt76.mac_work,
273 MT7615_WATCHDOG_TIME);
277 static int mt7615_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
278 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
279 struct ieee80211_key_conf *key)
281 struct mt7615_dev *dev = mt7615_hw_dev(hw);
282 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
283 struct mt7615_sta *msta = sta ? (struct mt7615_sta *)sta->drv_priv :
285 struct mt76_wcid *wcid = &msta->wcid;
286 int idx = key->keyidx;
288 /* The hardware does not support per-STA RX GTK, fallback
289 * to software mode for these.
291 if ((vif->type == NL80211_IFTYPE_ADHOC ||
292 vif->type == NL80211_IFTYPE_MESH_POINT) &&
293 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
294 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
295 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
298 /* fall back to sw encryption for unsupported ciphers */
299 switch (key->cipher) {
300 case WLAN_CIPHER_SUITE_AES_CMAC:
301 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIE;
303 case WLAN_CIPHER_SUITE_WEP40:
304 case WLAN_CIPHER_SUITE_WEP104:
305 case WLAN_CIPHER_SUITE_TKIP:
306 case WLAN_CIPHER_SUITE_CCMP:
307 case WLAN_CIPHER_SUITE_CCMP_256:
308 case WLAN_CIPHER_SUITE_GCMP:
309 case WLAN_CIPHER_SUITE_GCMP_256:
310 case WLAN_CIPHER_SUITE_SMS4:
316 if (cmd == SET_KEY) {
317 key->hw_key_idx = wcid->idx;
318 wcid->hw_key_idx = idx;
319 } else if (idx == wcid->hw_key_idx) {
320 wcid->hw_key_idx = -1;
322 mt76_wcid_key_setup(&dev->mt76, wcid,
323 cmd == SET_KEY ? key : NULL);
325 return mt7615_mac_wtbl_set_key(dev, wcid, key, cmd);
328 static int mt7615_config(struct ieee80211_hw *hw, u32 changed)
330 struct mt7615_dev *dev = mt7615_hw_dev(hw);
331 struct mt7615_phy *phy = mt7615_hw_phy(hw);
332 bool band = phy != &dev->phy;
335 if (changed & (IEEE80211_CONF_CHANGE_CHANNEL |
336 IEEE80211_CONF_CHANGE_POWER)) {
337 ieee80211_stop_queues(hw);
338 ret = mt7615_set_channel(phy);
339 ieee80211_wake_queues(hw);
342 mutex_lock(&dev->mt76.mutex);
344 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
345 if (!(hw->conf.flags & IEEE80211_CONF_MONITOR))
346 phy->rxfilter |= MT_WF_RFCR_DROP_OTHER_UC;
348 phy->rxfilter &= ~MT_WF_RFCR_DROP_OTHER_UC;
350 mt76_wr(dev, MT_WF_RFCR(band), phy->rxfilter);
353 mutex_unlock(&dev->mt76.mutex);
359 mt7615_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
360 const struct ieee80211_tx_queue_params *params)
362 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
363 struct mt7615_dev *dev = mt7615_hw_dev(hw);
365 queue += mvif->wmm_idx * MT7615_MAX_WMM_SETS;
367 return mt7615_mcu_set_wmm(dev, queue, params);
370 static void mt7615_configure_filter(struct ieee80211_hw *hw,
371 unsigned int changed_flags,
372 unsigned int *total_flags,
375 struct mt7615_dev *dev = mt7615_hw_dev(hw);
376 struct mt7615_phy *phy = mt7615_hw_phy(hw);
377 bool band = phy != &dev->phy;
379 u32 ctl_flags = MT_WF_RFCR1_DROP_ACK |
380 MT_WF_RFCR1_DROP_BF_POLL |
381 MT_WF_RFCR1_DROP_BA |
382 MT_WF_RFCR1_DROP_CFEND |
383 MT_WF_RFCR1_DROP_CFACK;
386 #define MT76_FILTER(_flag, _hw) do { \
387 flags |= *total_flags & FIF_##_flag; \
388 phy->rxfilter &= ~(_hw); \
389 phy->rxfilter |= !(flags & FIF_##_flag) * (_hw); \
392 phy->rxfilter &= ~(MT_WF_RFCR_DROP_OTHER_BSS |
393 MT_WF_RFCR_DROP_OTHER_BEACON |
394 MT_WF_RFCR_DROP_FRAME_REPORT |
395 MT_WF_RFCR_DROP_PROBEREQ |
396 MT_WF_RFCR_DROP_MCAST_FILTERED |
397 MT_WF_RFCR_DROP_MCAST |
398 MT_WF_RFCR_DROP_BCAST |
399 MT_WF_RFCR_DROP_DUPLICATE |
400 MT_WF_RFCR_DROP_A2_BSSID |
401 MT_WF_RFCR_DROP_UNWANTED_CTL |
402 MT_WF_RFCR_DROP_STBC_MULTI);
404 MT76_FILTER(OTHER_BSS, MT_WF_RFCR_DROP_OTHER_TIM |
405 MT_WF_RFCR_DROP_A3_MAC |
406 MT_WF_RFCR_DROP_A3_BSSID);
408 MT76_FILTER(FCSFAIL, MT_WF_RFCR_DROP_FCSFAIL);
410 MT76_FILTER(CONTROL, MT_WF_RFCR_DROP_CTS |
411 MT_WF_RFCR_DROP_RTS |
412 MT_WF_RFCR_DROP_CTL_RSV |
413 MT_WF_RFCR_DROP_NDPA);
415 *total_flags = flags;
416 mt76_wr(dev, MT_WF_RFCR(band), phy->rxfilter);
418 if (*total_flags & FIF_CONTROL)
419 mt76_clear(dev, MT_WF_RFCR1(band), ctl_flags);
421 mt76_set(dev, MT_WF_RFCR1(band), ctl_flags);
424 static void mt7615_bss_info_changed(struct ieee80211_hw *hw,
425 struct ieee80211_vif *vif,
426 struct ieee80211_bss_conf *info,
429 struct mt7615_dev *dev = mt7615_hw_dev(hw);
431 mutex_lock(&dev->mt76.mutex);
433 if (changed & BSS_CHANGED_ASSOC)
434 mt7615_mcu_add_bss_info(dev, vif, info->assoc);
436 if (changed & BSS_CHANGED_ERP_SLOT) {
437 int slottime = info->use_short_slot ? 9 : 20;
438 struct mt7615_phy *phy = mt7615_hw_phy(hw);
440 if (slottime != phy->slottime) {
441 phy->slottime = slottime;
442 mt7615_mac_set_timing(phy);
446 if (changed & BSS_CHANGED_BEACON_ENABLED) {
447 mt7615_mcu_add_bss_info(dev, vif, info->enable_beacon);
448 mt7615_mcu_sta_add(dev, vif, NULL, info->enable_beacon);
451 if (changed & (BSS_CHANGED_BEACON |
452 BSS_CHANGED_BEACON_ENABLED))
453 mt7615_mcu_add_beacon(dev, hw, vif, info->enable_beacon);
455 mutex_unlock(&dev->mt76.mutex);
459 mt7615_channel_switch_beacon(struct ieee80211_hw *hw,
460 struct ieee80211_vif *vif,
461 struct cfg80211_chan_def *chandef)
463 struct mt7615_dev *dev = mt7615_hw_dev(hw);
465 mutex_lock(&dev->mt76.mutex);
466 mt7615_mcu_add_beacon(dev, hw, vif, true);
467 mutex_unlock(&dev->mt76.mutex);
470 int mt7615_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
471 struct ieee80211_sta *sta)
473 struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
474 struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
475 struct mt7615_vif *mvif = (struct mt7615_vif *)vif->drv_priv;
478 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7615_WTBL_STA - 1);
482 INIT_LIST_HEAD(&msta->poll_list);
485 msta->wcid.idx = idx;
486 msta->wcid.ext_phy = mvif->band_idx;
488 mt7615_mac_wtbl_update(dev, idx,
489 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
491 mt7615_mcu_sta_add(dev, vif, sta, true);
496 void mt7615_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
497 struct ieee80211_sta *sta)
499 struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
500 struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
502 mt7615_mcu_sta_add(dev, vif, sta, false);
503 mt7615_mac_wtbl_update(dev, msta->wcid.idx,
504 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
506 spin_lock_bh(&dev->sta_poll_lock);
507 if (!list_empty(&msta->poll_list))
508 list_del_init(&msta->poll_list);
509 spin_unlock_bh(&dev->sta_poll_lock);
512 static void mt7615_sta_rate_tbl_update(struct ieee80211_hw *hw,
513 struct ieee80211_vif *vif,
514 struct ieee80211_sta *sta)
516 struct mt7615_dev *dev = mt7615_hw_dev(hw);
517 struct mt7615_phy *phy = mt7615_hw_phy(hw);
518 struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
519 struct ieee80211_sta_rates *sta_rates = rcu_dereference(sta->rates);
522 spin_lock_bh(&dev->mt76.lock);
523 for (i = 0; i < ARRAY_SIZE(msta->rates); i++) {
524 msta->rates[i].idx = sta_rates->rate[i].idx;
525 msta->rates[i].count = sta_rates->rate[i].count;
526 msta->rates[i].flags = sta_rates->rate[i].flags;
528 if (msta->rates[i].idx < 0 || !msta->rates[i].count)
532 mt7615_mac_set_rates(phy, msta, NULL, msta->rates);
533 msta->rate_probe = false;
534 spin_unlock_bh(&dev->mt76.lock);
537 static void mt7615_tx(struct ieee80211_hw *hw,
538 struct ieee80211_tx_control *control,
541 struct mt7615_dev *dev = mt7615_hw_dev(hw);
542 struct mt76_phy *mphy = hw->priv;
543 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
544 struct ieee80211_vif *vif = info->control.vif;
545 struct mt76_wcid *wcid = &dev->mt76.global_wcid;
548 struct mt7615_sta *sta;
550 sta = (struct mt7615_sta *)control->sta->drv_priv;
554 if (vif && !control->sta) {
555 struct mt7615_vif *mvif;
557 mvif = (struct mt7615_vif *)vif->drv_priv;
558 wcid = &mvif->sta.wcid;
561 mt76_tx(mphy, control->sta, wcid, skb);
564 static int mt7615_set_rts_threshold(struct ieee80211_hw *hw, u32 val)
566 struct mt7615_dev *dev = mt7615_hw_dev(hw);
567 struct mt7615_phy *phy = mt7615_hw_phy(hw);
569 mutex_lock(&dev->mt76.mutex);
570 mt7615_mcu_set_rts_thresh(phy, val);
571 mutex_unlock(&dev->mt76.mutex);
577 mt7615_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
578 struct ieee80211_ampdu_params *params)
580 enum ieee80211_ampdu_mlme_action action = params->action;
581 struct mt7615_dev *dev = mt7615_hw_dev(hw);
582 struct ieee80211_sta *sta = params->sta;
583 struct ieee80211_txq *txq = sta->txq[params->tid];
584 struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
585 u16 tid = params->tid;
586 u16 ssn = params->ssn;
587 struct mt76_txq *mtxq;
593 mtxq = (struct mt76_txq *)txq->drv_priv;
595 mutex_lock(&dev->mt76.mutex);
597 case IEEE80211_AMPDU_RX_START:
598 mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid, ssn,
600 mt7615_mcu_add_rx_ba(dev, params, true);
602 case IEEE80211_AMPDU_RX_STOP:
603 mt76_rx_aggr_stop(&dev->mt76, &msta->wcid, tid);
604 mt7615_mcu_add_rx_ba(dev, params, false);
606 case IEEE80211_AMPDU_TX_OPERATIONAL:
608 mtxq->send_bar = false;
609 mt7615_mcu_add_tx_ba(dev, params, true);
611 case IEEE80211_AMPDU_TX_STOP_FLUSH:
612 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
614 mt7615_mcu_add_tx_ba(dev, params, false);
616 case IEEE80211_AMPDU_TX_START:
617 mtxq->agg_ssn = IEEE80211_SN_TO_SEQ(ssn);
618 ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
620 case IEEE80211_AMPDU_TX_STOP_CONT:
622 mt7615_mcu_add_tx_ba(dev, params, false);
623 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
626 mutex_unlock(&dev->mt76.mutex);
632 mt7615_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
633 struct ieee80211_sta *sta)
635 return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NOTEXIST,
640 mt7615_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
641 struct ieee80211_sta *sta)
643 return mt76_sta_state(hw, vif, sta, IEEE80211_STA_NONE,
644 IEEE80211_STA_NOTEXIST);
648 mt7615_get_stats(struct ieee80211_hw *hw,
649 struct ieee80211_low_level_stats *stats)
651 struct mt7615_phy *phy = mt7615_hw_phy(hw);
652 struct mib_stats *mib = &phy->mib;
654 stats->dot11RTSSuccessCount = mib->rts_cnt;
655 stats->dot11RTSFailureCount = mib->rts_retries_cnt;
656 stats->dot11FCSErrorCount = mib->fcs_err_cnt;
657 stats->dot11ACKFailureCount = mib->ack_fail_cnt;
663 mt7615_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
665 struct mt7615_dev *dev = mt7615_hw_dev(hw);
671 mutex_lock(&dev->mt76.mutex);
673 mt76_set(dev, MT_LPON_T0CR, MT_LPON_T0CR_MODE); /* TSF read */
674 tsf.t32[0] = mt76_rr(dev, MT_LPON_UTTR0);
675 tsf.t32[1] = mt76_rr(dev, MT_LPON_UTTR1);
677 mutex_unlock(&dev->mt76.mutex);
683 mt7615_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class)
685 struct mt7615_phy *phy = mt7615_hw_phy(hw);
687 phy->coverage_class = max_t(s16, coverage_class, 0);
688 mt7615_mac_set_timing(phy);
692 mt7615_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
694 struct mt7615_dev *dev = mt7615_hw_dev(hw);
695 struct mt7615_phy *phy = mt7615_hw_phy(hw);
696 int max_nss = hweight8(hw->wiphy->available_antennas_tx);
697 bool ext_phy = phy != &dev->phy;
699 if (!tx_ant || tx_ant != rx_ant || ffs(tx_ant) > max_nss)
702 if ((BIT(hweight8(tx_ant)) - 1) != tx_ant)
703 tx_ant = BIT(ffs(tx_ant) - 1) - 1;
705 mutex_lock(&dev->mt76.mutex);
707 phy->mt76->antenna_mask = tx_ant;
709 if (dev->chainmask == 0xf)
714 phy->chainmask = tx_ant;
716 mt76_set_stream_caps(&dev->mt76, true);
718 mutex_unlock(&dev->mt76.mutex);
723 const struct ieee80211_ops mt7615_ops = {
725 .start = mt7615_start,
727 .add_interface = mt7615_add_interface,
728 .remove_interface = mt7615_remove_interface,
729 .config = mt7615_config,
730 .conf_tx = mt7615_conf_tx,
731 .configure_filter = mt7615_configure_filter,
732 .bss_info_changed = mt7615_bss_info_changed,
733 .sta_add = mt7615_sta_add,
734 .sta_remove = mt7615_sta_remove,
735 .sta_pre_rcu_remove = mt76_sta_pre_rcu_remove,
736 .set_key = mt7615_set_key,
737 .ampdu_action = mt7615_ampdu_action,
738 .set_rts_threshold = mt7615_set_rts_threshold,
739 .wake_tx_queue = mt76_wake_tx_queue,
740 .sta_rate_tbl_update = mt7615_sta_rate_tbl_update,
741 .sw_scan_start = mt76_sw_scan,
742 .sw_scan_complete = mt76_sw_scan_complete,
743 .release_buffered_frames = mt76_release_buffered_frames,
744 .get_txpower = mt76_get_txpower,
745 .channel_switch_beacon = mt7615_channel_switch_beacon,
746 .get_stats = mt7615_get_stats,
747 .get_tsf = mt7615_get_tsf,
748 .get_survey = mt76_get_survey,
749 .get_antenna = mt76_get_antenna,
750 .set_antenna = mt7615_set_antenna,
751 .set_coverage_class = mt7615_set_coverage_class,
754 static int __init mt7615_init(void)
758 ret = pci_register_driver(&mt7615_pci_driver);
762 if (IS_ENABLED(CONFIG_MT7622_WMAC)) {
763 ret = platform_driver_register(&mt7622_wmac_driver);
765 pci_unregister_driver(&mt7615_pci_driver);
771 static void __exit mt7615_exit(void)
773 if (IS_ENABLED(CONFIG_MT7622_WMAC))
774 platform_driver_unregister(&mt7622_wmac_driver);
775 pci_unregister_driver(&mt7615_pci_driver);
778 module_init(mt7615_init);
779 module_exit(mt7615_exit);
780 MODULE_LICENSE("Dual BSD/GPL");