2 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include "mt76x2_dma.h"
20 struct beacon_bc_data {
21 struct mt76x2_dev *dev;
22 struct sk_buff_head q;
23 struct sk_buff *tail[8];
26 int mt76x2_tx_prepare_skb(struct mt76_dev *mdev, void *txwi,
27 struct sk_buff *skb, struct mt76_queue *q,
28 struct mt76_wcid *wcid, struct ieee80211_sta *sta,
31 struct mt76x2_dev *dev = container_of(mdev, struct mt76x2_dev, mt76);
32 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
33 int qsel = MT_QSEL_EDCA;
36 if (q == &dev->mt76.q_tx[MT_TXQ_PSD] && wcid && wcid->idx < 128)
37 mt76x2_mac_wcid_set_drop(dev, wcid->idx, false);
39 mt76x2_mac_write_txwi(dev, txwi, skb, wcid, sta, skb->len);
41 ret = mt76x2_insert_hdr_pad(skb);
45 if (info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)
48 *tx_info = FIELD_PREP(MT_TXD_INFO_QSEL, qsel) |
51 if (!wcid || wcid->hw_key_idx == 0xff || wcid->sw_iv)
52 *tx_info |= MT_TXD_INFO_WIV;
58 mt76x2_update_beacon_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
60 struct mt76x2_dev *dev = (struct mt76x2_dev *) priv;
61 struct mt76x2_vif *mvif = (struct mt76x2_vif *) vif->drv_priv;
62 struct sk_buff *skb = NULL;
64 if (!(dev->beacon_mask & BIT(mvif->idx)))
67 skb = ieee80211_beacon_get(mt76_hw(dev), vif);
71 mt76x2_mac_set_beacon(dev, mvif->idx, skb);
75 mt76x2_add_buffered_bc(void *priv, u8 *mac, struct ieee80211_vif *vif)
77 struct beacon_bc_data *data = priv;
78 struct mt76x2_dev *dev = data->dev;
79 struct mt76x2_vif *mvif = (struct mt76x2_vif *) vif->drv_priv;
80 struct ieee80211_tx_info *info;
83 if (!(dev->beacon_mask & BIT(mvif->idx)))
86 skb = ieee80211_get_buffered_bc(mt76_hw(dev), vif);
90 info = IEEE80211_SKB_CB(skb);
91 info->control.vif = vif;
92 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
93 mt76_skb_set_moredata(skb, true);
94 __skb_queue_tail(&data->q, skb);
95 data->tail[mvif->idx] = skb;
99 mt76x2_resync_beacon_timer(struct mt76x2_dev *dev)
101 u32 timer_val = dev->beacon_int << 4;
106 * Beacon timer drifts by 1us every tick, the timer is configured
107 * in 1/16 TU (64us) units.
109 if (dev->tbtt_count < 62)
112 if (dev->tbtt_count >= 64) {
118 * The updated beacon interval takes effect after two TBTT, because
119 * at this point the original interval has already been loaded into
120 * the next TBTT_TIMER value
122 if (dev->tbtt_count == 62)
125 mt76_rmw_field(dev, MT_BEACON_TIME_CFG,
126 MT_BEACON_TIME_CFG_INTVAL, timer_val);
129 void mt76x2_pre_tbtt_tasklet(unsigned long arg)
131 struct mt76x2_dev *dev = (struct mt76x2_dev *) arg;
132 struct mt76_queue *q = &dev->mt76.q_tx[MT_TXQ_PSD];
133 struct beacon_bc_data data = {};
137 mt76x2_resync_beacon_timer(dev);
140 __skb_queue_head_init(&data.q);
142 ieee80211_iterate_active_interfaces_atomic(mt76_hw(dev),
143 IEEE80211_IFACE_ITER_RESUME_ALL,
144 mt76x2_update_beacon_iter, dev);
147 nframes = skb_queue_len(&data.q);
148 ieee80211_iterate_active_interfaces_atomic(mt76_hw(dev),
149 IEEE80211_IFACE_ITER_RESUME_ALL,
150 mt76x2_add_buffered_bc, &data);
151 } while (nframes != skb_queue_len(&data.q));
156 for (i = 0; i < ARRAY_SIZE(data.tail); i++) {
160 mt76_skb_set_moredata(data.tail[i], false);
163 spin_lock_bh(&q->lock);
164 while ((skb = __skb_dequeue(&data.q)) != NULL) {
165 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
166 struct ieee80211_vif *vif = info->control.vif;
167 struct mt76x2_vif *mvif = (struct mt76x2_vif *) vif->drv_priv;
169 mt76_dma_tx_queue_skb(&dev->mt76, q, skb, &mvif->group_wcid,
172 spin_unlock_bh(&q->lock);