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 "../mt76x02_util.h"
19 #include "../mt76x02_dma.h"
21 struct beacon_bc_data {
22 struct mt76x2_dev *dev;
23 struct sk_buff_head q;
24 struct sk_buff *tail[8];
27 int mt76x2_tx_prepare_skb(struct mt76_dev *mdev, void *txwi,
28 struct sk_buff *skb, struct mt76_queue *q,
29 struct mt76_wcid *wcid, struct ieee80211_sta *sta,
32 struct mt76x2_dev *dev = container_of(mdev, struct mt76x2_dev, mt76);
33 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
34 int qsel = MT_QSEL_EDCA;
37 if (q == &dev->mt76.q_tx[MT_TXQ_PSD] && wcid && wcid->idx < 128)
38 mt76x02_mac_wcid_set_drop(&dev->mt76, wcid->idx, false);
40 mt76x2_mac_write_txwi(dev, txwi, skb, wcid, sta, skb->len);
42 ret = mt76x02_insert_hdr_pad(skb);
46 if (info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)
49 *tx_info = FIELD_PREP(MT_TXD_INFO_QSEL, qsel) |
52 if (!wcid || wcid->hw_key_idx == 0xff || wcid->sw_iv)
53 *tx_info |= MT_TXD_INFO_WIV;
59 mt76x2_update_beacon_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
61 struct mt76x2_dev *dev = (struct mt76x2_dev *) priv;
62 struct mt76x02_vif *mvif = (struct mt76x02_vif *) vif->drv_priv;
63 struct sk_buff *skb = NULL;
65 if (!(dev->beacon_mask & BIT(mvif->idx)))
68 skb = ieee80211_beacon_get(mt76_hw(dev), vif);
72 mt76x2_mac_set_beacon(dev, mvif->idx, skb);
76 mt76x2_add_buffered_bc(void *priv, u8 *mac, struct ieee80211_vif *vif)
78 struct beacon_bc_data *data = priv;
79 struct mt76x2_dev *dev = data->dev;
80 struct mt76x02_vif *mvif = (struct mt76x02_vif *) vif->drv_priv;
81 struct ieee80211_tx_info *info;
84 if (!(dev->beacon_mask & BIT(mvif->idx)))
87 skb = ieee80211_get_buffered_bc(mt76_hw(dev), vif);
91 info = IEEE80211_SKB_CB(skb);
92 info->control.vif = vif;
93 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
94 mt76_skb_set_moredata(skb, true);
95 __skb_queue_tail(&data->q, skb);
96 data->tail[mvif->idx] = skb;
100 mt76x2_resync_beacon_timer(struct mt76x2_dev *dev)
102 u32 timer_val = dev->beacon_int << 4;
107 * Beacon timer drifts by 1us every tick, the timer is configured
108 * in 1/16 TU (64us) units.
110 if (dev->tbtt_count < 62)
113 if (dev->tbtt_count >= 64) {
119 * The updated beacon interval takes effect after two TBTT, because
120 * at this point the original interval has already been loaded into
121 * the next TBTT_TIMER value
123 if (dev->tbtt_count == 62)
126 mt76_rmw_field(dev, MT_BEACON_TIME_CFG,
127 MT_BEACON_TIME_CFG_INTVAL, timer_val);
130 void mt76x2_pre_tbtt_tasklet(unsigned long arg)
132 struct mt76x2_dev *dev = (struct mt76x2_dev *) arg;
133 struct mt76_queue *q = &dev->mt76.q_tx[MT_TXQ_PSD];
134 struct beacon_bc_data data = {};
138 mt76x2_resync_beacon_timer(dev);
141 __skb_queue_head_init(&data.q);
143 ieee80211_iterate_active_interfaces_atomic(mt76_hw(dev),
144 IEEE80211_IFACE_ITER_RESUME_ALL,
145 mt76x2_update_beacon_iter, dev);
148 nframes = skb_queue_len(&data.q);
149 ieee80211_iterate_active_interfaces_atomic(mt76_hw(dev),
150 IEEE80211_IFACE_ITER_RESUME_ALL,
151 mt76x2_add_buffered_bc, &data);
152 } while (nframes != skb_queue_len(&data.q));
157 for (i = 0; i < ARRAY_SIZE(data.tail); i++) {
161 mt76_skb_set_moredata(data.tail[i], false);
164 spin_lock_bh(&q->lock);
165 while ((skb = __skb_dequeue(&data.q)) != NULL) {
166 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
167 struct ieee80211_vif *vif = info->control.vif;
168 struct mt76x02_vif *mvif = (struct mt76x02_vif *) vif->drv_priv;
170 mt76_dma_tx_queue_skb(&dev->mt76, q, skb, &mvif->group_wcid,
173 spin_unlock_bh(&q->lock);