Path: blob/main/sys/contrib/dev/mediatek/mt76/mt76x02_util.c
48378 views
// SPDX-License-Identifier: ISC1/*2* Copyright (C) 2018 Stanislaw Gruszka <[email protected]>3* Copyright (C) 2016 Felix Fietkau <[email protected]>4*/56#include <linux/module.h>7#include "mt76x02.h"89#define MT76x02_CCK_RATE(_idx, _rate) { \10.bitrate = _rate, \11.flags = IEEE80211_RATE_SHORT_PREAMBLE, \12.hw_value = (MT_PHY_TYPE_CCK << 8) | (_idx), \13.hw_value_short = (MT_PHY_TYPE_CCK << 8) | (8 + (_idx)), \14}1516struct ieee80211_rate mt76x02_rates[] = {17MT76x02_CCK_RATE(0, 10),18MT76x02_CCK_RATE(1, 20),19MT76x02_CCK_RATE(2, 55),20MT76x02_CCK_RATE(3, 110),21OFDM_RATE(0, 60),22OFDM_RATE(1, 90),23OFDM_RATE(2, 120),24OFDM_RATE(3, 180),25OFDM_RATE(4, 240),26OFDM_RATE(5, 360),27OFDM_RATE(6, 480),28OFDM_RATE(7, 540),29};30EXPORT_SYMBOL_GPL(mt76x02_rates);3132static const struct ieee80211_iface_limit mt76x02_if_limits[] = {33{34.max = 1,35.types = BIT(NL80211_IFTYPE_ADHOC)36}, {37.max = 8,38.types = BIT(NL80211_IFTYPE_STATION) |39#ifdef CONFIG_MAC80211_MESH40BIT(NL80211_IFTYPE_MESH_POINT) |41#endif42BIT(NL80211_IFTYPE_P2P_CLIENT) |43BIT(NL80211_IFTYPE_P2P_GO) |44BIT(NL80211_IFTYPE_AP)45},46};4748static const struct ieee80211_iface_limit mt76x02u_if_limits[] = {49{50.max = 1,51.types = BIT(NL80211_IFTYPE_ADHOC)52}, {53.max = 2,54.types = BIT(NL80211_IFTYPE_STATION) |55#ifdef CONFIG_MAC80211_MESH56BIT(NL80211_IFTYPE_MESH_POINT) |57#endif58BIT(NL80211_IFTYPE_P2P_CLIENT) |59BIT(NL80211_IFTYPE_P2P_GO) |60BIT(NL80211_IFTYPE_AP)61},62};6364static const struct ieee80211_iface_combination mt76x02_if_comb[] = {65{66.limits = mt76x02_if_limits,67.n_limits = ARRAY_SIZE(mt76x02_if_limits),68.max_interfaces = 8,69.num_different_channels = 1,70.beacon_int_infra_match = true,71.radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |72BIT(NL80211_CHAN_WIDTH_20) |73BIT(NL80211_CHAN_WIDTH_40) |74BIT(NL80211_CHAN_WIDTH_80),75}76};7778static const struct ieee80211_iface_combination mt76x02u_if_comb[] = {79{80.limits = mt76x02u_if_limits,81.n_limits = ARRAY_SIZE(mt76x02u_if_limits),82.max_interfaces = 2,83.num_different_channels = 1,84.beacon_int_infra_match = true,85}86};8788static void89mt76x02_led_set_config(struct mt76_phy *mphy, u8 delay_on, u8 delay_off)90{91struct mt76x02_dev *dev = container_of(mphy->dev, struct mt76x02_dev,92mt76);93u32 val;9495val = FIELD_PREP(MT_LED_STATUS_DURATION, 0xff) |96FIELD_PREP(MT_LED_STATUS_OFF, delay_off) |97FIELD_PREP(MT_LED_STATUS_ON, delay_on);9899mt76_wr(dev, MT_LED_S0(mphy->leds.pin), val);100mt76_wr(dev, MT_LED_S1(mphy->leds.pin), val);101102val = MT_LED_CTRL_REPLAY(mphy->leds.pin) |103MT_LED_CTRL_KICK(mphy->leds.pin);104if (mphy->leds.al)105val |= MT_LED_CTRL_POLARITY(mphy->leds.pin);106mt76_wr(dev, MT_LED_CTRL, val);107}108109static int110mt76x02_led_set_blink(struct led_classdev *led_cdev,111unsigned long *delay_on,112unsigned long *delay_off)113{114struct mt76_phy *mphy = container_of(led_cdev, struct mt76_phy,115leds.cdev);116u8 delta_on, delta_off;117118delta_off = max_t(u8, *delay_off / 10, 1);119delta_on = max_t(u8, *delay_on / 10, 1);120121mt76x02_led_set_config(mphy, delta_on, delta_off);122123return 0;124}125126static void127mt76x02_led_set_brightness(struct led_classdev *led_cdev,128enum led_brightness brightness)129{130struct mt76_phy *mphy = container_of(led_cdev, struct mt76_phy,131leds.cdev);132133if (!brightness)134mt76x02_led_set_config(mphy, 0, 0xff);135else136mt76x02_led_set_config(mphy, 0xff, 0);137}138139int mt76x02_init_device(struct mt76x02_dev *dev)140{141struct ieee80211_hw *hw = mt76_hw(dev);142struct wiphy *wiphy = hw->wiphy;143144INIT_DELAYED_WORK(&dev->mphy.mac_work, mt76x02_mac_work);145146hw->queues = 4;147hw->max_rates = 1;148hw->max_report_rates = 7;149hw->max_rate_tries = 1;150hw->extra_tx_headroom = 2;151152if (mt76_is_usb(&dev->mt76)) {153hw->extra_tx_headroom += sizeof(struct mt76x02_txwi) +154MT_DMA_HDR_LEN;155wiphy->iface_combinations = mt76x02u_if_comb;156wiphy->n_iface_combinations = ARRAY_SIZE(mt76x02u_if_comb);157} else {158INIT_DELAYED_WORK(&dev->wdt_work, mt76x02_wdt_work);159160mt76x02_dfs_init_detector(dev);161162wiphy->reg_notifier = mt76x02_regd_notifier;163wiphy->iface_combinations = mt76x02_if_comb;164wiphy->n_iface_combinations = ARRAY_SIZE(mt76x02_if_comb);165166/* init led callbacks */167if (IS_ENABLED(CONFIG_MT76_LEDS)) {168dev->mphy.leds.cdev.brightness_set =169mt76x02_led_set_brightness;170dev->mphy.leds.cdev.blink_set = mt76x02_led_set_blink;171}172}173174wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS);175176hw->sta_data_size = sizeof(struct mt76x02_sta);177hw->vif_data_size = sizeof(struct mt76x02_vif);178179ieee80211_hw_set(hw, SUPPORTS_HT_CCK_RATES);180ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING);181ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);182183dev->mt76.global_wcid.idx = 255;184dev->mt76.global_wcid.hw_key_idx = -1;185dev->slottime = 9;186187if (is_mt76x2(dev)) {188dev->mphy.sband_2g.sband.ht_cap.cap |=189IEEE80211_HT_CAP_LDPC_CODING;190dev->mphy.sband_5g.sband.ht_cap.cap |=191IEEE80211_HT_CAP_LDPC_CODING;192dev->mphy.chainmask = 0x202;193dev->mphy.antenna_mask = 3;194} else {195dev->mphy.chainmask = 0x101;196dev->mphy.antenna_mask = 1;197}198199return 0;200}201EXPORT_SYMBOL_GPL(mt76x02_init_device);202203void mt76x02_configure_filter(struct ieee80211_hw *hw,204unsigned int changed_flags,205unsigned int *total_flags, u64 multicast)206{207struct mt76x02_dev *dev = hw->priv;208u32 flags = 0;209210#define MT76_FILTER(_flag, _hw) do { \211flags |= *total_flags & FIF_##_flag; \212dev->mt76.rxfilter &= ~(_hw); \213dev->mt76.rxfilter |= !(flags & FIF_##_flag) * (_hw); \214} while (0)215216mutex_lock(&dev->mt76.mutex);217218dev->mt76.rxfilter &= ~MT_RX_FILTR_CFG_OTHER_BSS;219220MT76_FILTER(FCSFAIL, MT_RX_FILTR_CFG_CRC_ERR);221MT76_FILTER(PLCPFAIL, MT_RX_FILTR_CFG_PHY_ERR);222MT76_FILTER(CONTROL, MT_RX_FILTR_CFG_ACK |223MT_RX_FILTR_CFG_CTS |224MT_RX_FILTR_CFG_CFEND |225MT_RX_FILTR_CFG_CFACK |226MT_RX_FILTR_CFG_BA |227MT_RX_FILTR_CFG_CTRL_RSV);228MT76_FILTER(PSPOLL, MT_RX_FILTR_CFG_PSPOLL);229230*total_flags = flags;231mt76_wr(dev, MT_RX_FILTR_CFG, dev->mt76.rxfilter);232233mutex_unlock(&dev->mt76.mutex);234}235EXPORT_SYMBOL_GPL(mt76x02_configure_filter);236237int mt76x02_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,238struct ieee80211_sta *sta)239{240struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76);241struct mt76x02_sta *msta = (struct mt76x02_sta *)sta->drv_priv;242struct mt76x02_vif *mvif = (struct mt76x02_vif *)vif->drv_priv;243int idx = 0;244245memset(msta, 0, sizeof(*msta));246247idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT76x02_N_WCIDS);248if (idx < 0)249return -ENOSPC;250251msta->vif = mvif;252msta->wcid.sta = 1;253msta->wcid.idx = idx;254msta->wcid.hw_key_idx = -1;255mt76x02_mac_wcid_setup(dev, idx, mvif->idx, sta->addr);256mt76x02_mac_wcid_set_drop(dev, idx, false);257ewma_pktlen_init(&msta->pktlen);258259if (vif->type == NL80211_IFTYPE_AP)260set_bit(MT_WCID_FLAG_CHECK_PS, &msta->wcid.flags);261262return 0;263}264EXPORT_SYMBOL_GPL(mt76x02_sta_add);265266void mt76x02_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,267struct ieee80211_sta *sta)268{269struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76);270struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;271int idx = wcid->idx;272273mt76x02_mac_wcid_set_drop(dev, idx, true);274mt76x02_mac_wcid_setup(dev, idx, 0, NULL);275}276EXPORT_SYMBOL_GPL(mt76x02_sta_remove);277278static void279mt76x02_vif_init(struct mt76x02_dev *dev, struct ieee80211_vif *vif,280unsigned int idx)281{282struct mt76x02_vif *mvif = (struct mt76x02_vif *)vif->drv_priv;283struct mt76_txq *mtxq;284285memset(mvif, 0, sizeof(*mvif));286287mvif->idx = idx;288mvif->group_wcid.idx = MT_VIF_WCID(idx);289mt76_wcid_init(&mvif->group_wcid, 0);290291mtxq = (struct mt76_txq *)vif->txq->drv_priv;292rcu_assign_pointer(dev->mt76.wcid[MT_VIF_WCID(idx)], &mvif->group_wcid);293mtxq->wcid = MT_VIF_WCID(idx);294}295296int297mt76x02_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)298{299struct mt76x02_dev *dev = hw->priv;300unsigned int idx = 0;301302/* Allow to change address in HW if we create first interface. */303if (!dev->mt76.vif_mask &&304(((vif->addr[0] ^ dev->mphy.macaddr[0]) & ~GENMASK(4, 1)) ||305memcmp(vif->addr + 1, dev->mphy.macaddr + 1, ETH_ALEN - 1)))306mt76x02_mac_setaddr(dev, vif->addr);307308if (vif->addr[0] & BIT(1))309idx = 1 + (((dev->mphy.macaddr[0] ^ vif->addr[0]) >> 2) & 7);310311/*312* Client mode typically only has one configurable BSSID register,313* which is used for bssidx=0. This is linked to the MAC address.314* Since mac80211 allows changing interface types, and we cannot315* force the use of the primary MAC address for a station mode316* interface, we need some other way of configuring a per-interface317* remote BSSID.318* The hardware provides an AP-Client feature, where bssidx 0-7 are319* used for AP mode and bssidx 8-15 for client mode.320* We shift the station interface bss index by 8 to force the321* hardware to recognize the BSSID.322* The resulting bssidx mismatch for unicast frames is ignored by hw.323*/324if (vif->type == NL80211_IFTYPE_STATION)325idx += 8;326327/* vif is already set or idx is 8 for AP/Mesh/... */328if (dev->mt76.vif_mask & BIT_ULL(idx) ||329(vif->type != NL80211_IFTYPE_STATION && idx > 7))330return -EBUSY;331332dev->mt76.vif_mask |= BIT_ULL(idx);333334mt76x02_vif_init(dev, vif, idx);335return 0;336}337EXPORT_SYMBOL_GPL(mt76x02_add_interface);338339void mt76x02_remove_interface(struct ieee80211_hw *hw,340struct ieee80211_vif *vif)341{342struct mt76x02_dev *dev = hw->priv;343struct mt76x02_vif *mvif = (struct mt76x02_vif *)vif->drv_priv;344345dev->mt76.vif_mask &= ~BIT_ULL(mvif->idx);346rcu_assign_pointer(dev->mt76.wcid[mvif->group_wcid.idx], NULL);347mt76_wcid_cleanup(&dev->mt76, &mvif->group_wcid);348}349EXPORT_SYMBOL_GPL(mt76x02_remove_interface);350351int mt76x02_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,352struct ieee80211_ampdu_params *params)353{354enum ieee80211_ampdu_mlme_action action = params->action;355struct ieee80211_sta *sta = params->sta;356struct mt76x02_dev *dev = hw->priv;357struct mt76x02_sta *msta = (struct mt76x02_sta *)sta->drv_priv;358struct ieee80211_txq *txq = sta->txq[params->tid];359u16 tid = params->tid;360u16 ssn = params->ssn;361struct mt76_txq *mtxq;362int ret = 0;363364if (!txq)365return -EINVAL;366367mtxq = (struct mt76_txq *)txq->drv_priv;368369mutex_lock(&dev->mt76.mutex);370switch (action) {371case IEEE80211_AMPDU_RX_START:372mt76_rx_aggr_start(&dev->mt76, &msta->wcid, tid,373ssn, params->buf_size);374mt76_set(dev, MT_WCID_ADDR(msta->wcid.idx) + 4, BIT(16 + tid));375break;376case IEEE80211_AMPDU_RX_STOP:377mt76_rx_aggr_stop(&dev->mt76, &msta->wcid, tid);378mt76_clear(dev, MT_WCID_ADDR(msta->wcid.idx) + 4,379BIT(16 + tid));380break;381case IEEE80211_AMPDU_TX_OPERATIONAL:382mtxq->aggr = true;383mtxq->send_bar = false;384ieee80211_send_bar(vif, sta->addr, tid, mtxq->agg_ssn);385break;386case IEEE80211_AMPDU_TX_STOP_FLUSH:387case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:388mtxq->aggr = false;389break;390case IEEE80211_AMPDU_TX_START:391mtxq->agg_ssn = IEEE80211_SN_TO_SEQ(ssn);392ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;393break;394case IEEE80211_AMPDU_TX_STOP_CONT:395mtxq->aggr = false;396ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);397break;398}399mutex_unlock(&dev->mt76.mutex);400401return ret;402}403EXPORT_SYMBOL_GPL(mt76x02_ampdu_action);404405int mt76x02_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,406struct ieee80211_vif *vif, struct ieee80211_sta *sta,407struct ieee80211_key_conf *key)408{409struct mt76x02_dev *dev = hw->priv;410struct mt76x02_vif *mvif = (struct mt76x02_vif *)vif->drv_priv;411struct mt76x02_sta *msta;412struct mt76_wcid *wcid;413int idx = key->keyidx;414int ret;415416/* fall back to sw encryption for unsupported ciphers */417switch (key->cipher) {418case WLAN_CIPHER_SUITE_WEP40:419case WLAN_CIPHER_SUITE_WEP104:420case WLAN_CIPHER_SUITE_TKIP:421case WLAN_CIPHER_SUITE_CCMP:422break;423default:424return -EOPNOTSUPP;425}426427/*428* The hardware does not support per-STA RX GTK, fall back429* to software mode for these.430*/431if ((vif->type == NL80211_IFTYPE_ADHOC ||432vif->type == NL80211_IFTYPE_MESH_POINT) &&433(key->cipher == WLAN_CIPHER_SUITE_TKIP ||434key->cipher == WLAN_CIPHER_SUITE_CCMP) &&435!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))436return -EOPNOTSUPP;437438/*439* In USB AP mode, broadcast/multicast frames are setup in beacon440* data registers and sent via HW beacons engine, they require to441* be already encrypted.442*/443if (mt76_is_usb(&dev->mt76) &&444vif->type == NL80211_IFTYPE_AP &&445!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))446return -EOPNOTSUPP;447448/* MT76x0 GTK offloading does not work with more than one VIF */449if (is_mt76x0(dev) && !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))450return -EOPNOTSUPP;451452msta = sta ? (struct mt76x02_sta *)sta->drv_priv : NULL;453wcid = msta ? &msta->wcid : &mvif->group_wcid;454455if (cmd != SET_KEY) {456if (idx == wcid->hw_key_idx) {457wcid->hw_key_idx = -1;458wcid->sw_iv = false;459}460461return 0;462}463464key->hw_key_idx = wcid->idx;465wcid->hw_key_idx = idx;466if (key->flags & IEEE80211_KEY_FLAG_RX_MGMT) {467key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;468wcid->sw_iv = true;469}470mt76_wcid_key_setup(&dev->mt76, wcid, key);471472if (!msta) {473if (key || wcid->hw_key_idx == idx) {474ret = mt76x02_mac_wcid_set_key(dev, wcid->idx, key);475if (ret)476return ret;477}478479return mt76x02_mac_shared_key_setup(dev, mvif->idx, idx, key);480}481482return mt76x02_mac_wcid_set_key(dev, msta->wcid.idx, key);483}484EXPORT_SYMBOL_GPL(mt76x02_set_key);485486int mt76x02_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,487unsigned int link_id, u16 queue,488const struct ieee80211_tx_queue_params *params)489{490struct mt76x02_dev *dev = hw->priv;491u8 cw_min = 5, cw_max = 10, qid;492u32 val;493494qid = dev->mphy.q_tx[queue]->hw_idx;495496if (params->cw_min)497cw_min = fls(params->cw_min);498if (params->cw_max)499cw_max = fls(params->cw_max);500501val = FIELD_PREP(MT_EDCA_CFG_TXOP, params->txop) |502FIELD_PREP(MT_EDCA_CFG_AIFSN, params->aifs) |503FIELD_PREP(MT_EDCA_CFG_CWMIN, cw_min) |504FIELD_PREP(MT_EDCA_CFG_CWMAX, cw_max);505mt76_wr(dev, MT_EDCA_CFG_AC(qid), val);506507val = mt76_rr(dev, MT_WMM_TXOP(qid));508val &= ~(MT_WMM_TXOP_MASK << MT_WMM_TXOP_SHIFT(qid));509val |= params->txop << MT_WMM_TXOP_SHIFT(qid);510mt76_wr(dev, MT_WMM_TXOP(qid), val);511512val = mt76_rr(dev, MT_WMM_AIFSN);513val &= ~(MT_WMM_AIFSN_MASK << MT_WMM_AIFSN_SHIFT(qid));514val |= params->aifs << MT_WMM_AIFSN_SHIFT(qid);515mt76_wr(dev, MT_WMM_AIFSN, val);516517val = mt76_rr(dev, MT_WMM_CWMIN);518val &= ~(MT_WMM_CWMIN_MASK << MT_WMM_CWMIN_SHIFT(qid));519val |= cw_min << MT_WMM_CWMIN_SHIFT(qid);520mt76_wr(dev, MT_WMM_CWMIN, val);521522val = mt76_rr(dev, MT_WMM_CWMAX);523val &= ~(MT_WMM_CWMAX_MASK << MT_WMM_CWMAX_SHIFT(qid));524val |= cw_max << MT_WMM_CWMAX_SHIFT(qid);525mt76_wr(dev, MT_WMM_CWMAX, val);526527return 0;528}529EXPORT_SYMBOL_GPL(mt76x02_conf_tx);530531void mt76x02_set_tx_ackto(struct mt76x02_dev *dev)532{533u8 ackto, sifs, slottime = dev->slottime;534535/* As defined by IEEE 802.11-2007 17.3.8.6 */536slottime += 3 * dev->coverage_class;537mt76_rmw_field(dev, MT_BKOFF_SLOT_CFG,538MT_BKOFF_SLOT_CFG_SLOTTIME, slottime);539540sifs = mt76_get_field(dev, MT_XIFS_TIME_CFG,541MT_XIFS_TIME_CFG_OFDM_SIFS);542543ackto = slottime + sifs;544mt76_rmw_field(dev, MT_TX_TIMEOUT_CFG,545MT_TX_TIMEOUT_CFG_ACKTO, ackto);546}547EXPORT_SYMBOL_GPL(mt76x02_set_tx_ackto);548549void mt76x02_set_coverage_class(struct ieee80211_hw *hw,550int radio_idx, s16 coverage_class)551{552struct mt76x02_dev *dev = hw->priv;553554mutex_lock(&dev->mt76.mutex);555dev->coverage_class = max_t(s16, coverage_class, 0);556mt76x02_set_tx_ackto(dev);557mutex_unlock(&dev->mt76.mutex);558}559EXPORT_SYMBOL_GPL(mt76x02_set_coverage_class);560561int mt76x02_set_rts_threshold(struct ieee80211_hw *hw, int radio_idx, u32 val)562{563struct mt76x02_dev *dev = hw->priv;564565if (val != ~0 && val > 0xffff)566return -EINVAL;567568mutex_lock(&dev->mt76.mutex);569mt76x02_mac_set_rts_thresh(dev, val);570mutex_unlock(&dev->mt76.mutex);571572return 0;573}574EXPORT_SYMBOL_GPL(mt76x02_set_rts_threshold);575576void mt76x02_sta_rate_tbl_update(struct ieee80211_hw *hw,577struct ieee80211_vif *vif,578struct ieee80211_sta *sta)579{580struct mt76x02_dev *dev = hw->priv;581struct mt76x02_sta *msta = (struct mt76x02_sta *)sta->drv_priv;582struct ieee80211_sta_rates *rates = rcu_dereference(sta->rates);583struct ieee80211_tx_rate rate = {};584585if (!rates)586return;587588rate.idx = rates->rate[0].idx;589rate.flags = rates->rate[0].flags;590mt76x02_mac_wcid_set_rate(dev, &msta->wcid, &rate);591}592EXPORT_SYMBOL_GPL(mt76x02_sta_rate_tbl_update);593594void mt76x02_remove_hdr_pad(struct sk_buff *skb, int len)595{596int hdrlen;597598if (!len)599return;600601hdrlen = ieee80211_get_hdrlen_from_skb(skb);602memmove(skb->data + len, skb->data, hdrlen);603skb_pull(skb, len);604}605EXPORT_SYMBOL_GPL(mt76x02_remove_hdr_pad);606607void mt76x02_sw_scan_complete(struct ieee80211_hw *hw,608struct ieee80211_vif *vif)609{610struct mt76x02_dev *dev = hw->priv;611612clear_bit(MT76_SCANNING, &dev->mphy.state);613if (dev->cal.gain_init_done) {614/* Restore AGC gain and resume calibration after scanning. */615dev->cal.low_gain = -1;616ieee80211_queue_delayed_work(hw, &dev->cal_work, 0);617}618}619EXPORT_SYMBOL_GPL(mt76x02_sw_scan_complete);620621void mt76x02_sta_ps(struct mt76_dev *mdev, struct ieee80211_sta *sta,622bool ps)623{624struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76);625struct mt76x02_sta *msta = (struct mt76x02_sta *)sta->drv_priv;626int idx = msta->wcid.idx;627628mt76_stop_tx_queues(&dev->mphy, sta, true);629if (mt76_is_mmio(mdev))630mt76x02_mac_wcid_set_drop(dev, idx, ps);631}632EXPORT_SYMBOL_GPL(mt76x02_sta_ps);633634void mt76x02_bss_info_changed(struct ieee80211_hw *hw,635struct ieee80211_vif *vif,636struct ieee80211_bss_conf *info,637u64 changed)638{639struct mt76x02_vif *mvif = (struct mt76x02_vif *)vif->drv_priv;640struct mt76x02_dev *dev = hw->priv;641642mutex_lock(&dev->mt76.mutex);643644if (changed & BSS_CHANGED_BSSID)645mt76x02_mac_set_bssid(dev, mvif->idx, info->bssid);646647if (changed & BSS_CHANGED_HT || changed & BSS_CHANGED_ERP_CTS_PROT)648mt76x02_mac_set_tx_protection(dev, info->use_cts_prot,649info->ht_operation_mode);650651if (changed & BSS_CHANGED_BEACON_INT) {652mt76_rmw_field(dev, MT_BEACON_TIME_CFG,653MT_BEACON_TIME_CFG_INTVAL,654info->beacon_int << 4);655dev->mt76.beacon_int = info->beacon_int;656}657658if (changed & BSS_CHANGED_BEACON_ENABLED)659mt76x02_mac_set_beacon_enable(dev, vif, info->enable_beacon);660661if (changed & BSS_CHANGED_ERP_PREAMBLE)662mt76x02_mac_set_short_preamble(dev, info->use_short_preamble);663664if (changed & BSS_CHANGED_ERP_SLOT) {665int slottime = info->use_short_slot ? 9 : 20;666667dev->slottime = slottime;668mt76x02_set_tx_ackto(dev);669}670671mutex_unlock(&dev->mt76.mutex);672}673EXPORT_SYMBOL_GPL(mt76x02_bss_info_changed);674675void mt76x02_config_mac_addr_list(struct mt76x02_dev *dev)676{677struct ieee80211_hw *hw = mt76_hw(dev);678struct wiphy *wiphy = hw->wiphy;679int i;680681for (i = 0; i < ARRAY_SIZE(dev->macaddr_list); i++) {682u8 *addr = dev->macaddr_list[i].addr;683684memcpy(addr, dev->mphy.macaddr, ETH_ALEN);685686if (!i)687continue;688689addr[0] |= BIT(1);690addr[0] ^= ((i - 1) << 2);691}692wiphy->addresses = dev->macaddr_list;693wiphy->n_addresses = ARRAY_SIZE(dev->macaddr_list);694}695EXPORT_SYMBOL_GPL(mt76x02_config_mac_addr_list);696697MODULE_DESCRIPTION("MediaTek MT76x02 helpers");698MODULE_LICENSE("Dual BSD/GPL");699700701