Skip to content

Commit db9f11d

Browse files
committed
mt76: store wcid tx rate info in one u32 reduce locking
Signed-off-by: Felix Fietkau <[email protected]>
1 parent 2fe30dc commit db9f11d

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

drivers/net/wireless/mediatek/mt76/mt76.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ enum mt76_wcid_flags {
188188

189189
DECLARE_EWMA(signal, 10, 8);
190190

191+
#define MT_WCID_TX_INFO_RATE GENMASK(15, 0)
192+
#define MT_WCID_TX_INFO_NSS GENMASK(17, 16)
193+
#define MT_WCID_TX_INFO_TXPWR_ADJ GENMASK(25, 18)
194+
#define MT_WCID_TX_INFO_SET BIT(31)
195+
191196
struct mt76_wcid {
192197
struct mt76_rx_tid __rcu *aggr[IEEE80211_NUM_TIDS];
193198

@@ -206,10 +211,7 @@ struct mt76_wcid {
206211
u8 rx_check_pn;
207212
u8 rx_key_pn[IEEE80211_NUM_TIDS][6];
208213

209-
__le16 tx_rate;
210-
bool tx_rate_set;
211-
u8 tx_rate_nss;
212-
s8 max_txpwr_adj;
214+
u32 tx_info;
213215
bool sw_iv;
214216

215217
u8 packet_id;

drivers/net/wireless/mediatek/mt76/mt7603/mac.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,11 @@ void mt7603_wtbl_set_rates(struct mt7603_dev *dev, struct mt7603_sta *sta,
717717
MT_WTBL_UPDATE_RATE_UPDATE |
718718
MT_WTBL_UPDATE_TX_COUNT_CLEAR);
719719

720-
if (!sta->wcid.tx_rate_set)
720+
if (!(sta->wcid.tx_info & MT_WCID_TX_INFO_SET))
721721
mt76_poll(dev, MT_WTBL_UPDATE, MT_WTBL_UPDATE_BUSY, 0, 5000);
722722

723723
sta->rate_count = 2 * MT7603_RATE_RETRY * n_rates;
724-
sta->wcid.tx_rate_set = true;
724+
sta->wcid.tx_info |= MT_WCID_TX_INFO_SET;
725725
}
726726

727727
static enum mt7603_cipher_type

drivers/net/wireless/mediatek/mt76/mt76x02_mac.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,17 @@ mt76x02_mac_tx_rate_val(struct mt76x02_dev *dev,
218218
void mt76x02_mac_wcid_set_rate(struct mt76x02_dev *dev, struct mt76_wcid *wcid,
219219
const struct ieee80211_tx_rate *rate)
220220
{
221-
spin_lock_bh(&dev->mt76.lock);
222-
wcid->tx_rate = mt76x02_mac_tx_rate_val(dev, rate, &wcid->tx_rate_nss);
223-
wcid->tx_rate_set = true;
224-
spin_unlock_bh(&dev->mt76.lock);
221+
s8 max_txpwr_adj = mt76x02_tx_get_max_txpwr_adj(dev, rate);
222+
__le16 rateval;
223+
u32 tx_info;
224+
s8 nss;
225+
226+
rateval = mt76x02_mac_tx_rate_val(dev, rate, &nss);
227+
tx_info = FIELD_PREP(MT_WCID_TX_INFO_RATE, rateval) |
228+
FIELD_PREP(MT_WCID_TX_INFO_NSS, nss) |
229+
FIELD_PREP(MT_WCID_TX_INFO_TXPWR_ADJ, max_txpwr_adj) |
230+
MT_WCID_TX_INFO_SET;
231+
wcid->tx_info = tx_info;
225232
}
226233

227234
void mt76x02_mac_set_short_preamble(struct mt76x02_dev *dev, bool enable)
@@ -323,6 +330,7 @@ void mt76x02_mac_write_txwi(struct mt76x02_dev *dev, struct mt76x02_txwi *txwi,
323330
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
324331
struct ieee80211_tx_rate *rate = &info->control.rates[0];
325332
struct ieee80211_key_conf *key = info->control.hw_key;
333+
u32 wcid_tx_info;
326334
u16 rate_ht_mask = FIELD_PREP(MT_RXWI_RATE_PHY, BIT(1) | BIT(2));
327335
u16 txwi_flags = 0;
328336
u8 nss;
@@ -357,16 +365,16 @@ void mt76x02_mac_write_txwi(struct mt76x02_dev *dev, struct mt76x02_txwi *txwi,
357365
txwi->eiv = *((__le32 *)&ccmp_pn[4]);
358366
}
359367

360-
spin_lock_bh(&dev->mt76.lock);
361368
if (wcid && (rate->idx < 0 || !rate->count)) {
362-
txwi->rate = wcid->tx_rate;
363-
max_txpwr_adj = wcid->max_txpwr_adj;
364-
nss = wcid->tx_rate_nss;
369+
wcid_tx_info = wcid->tx_info;
370+
txwi->rate = FIELD_GET(MT_WCID_TX_INFO_RATE, wcid_tx_info);
371+
max_txpwr_adj = FIELD_GET(MT_WCID_TX_INFO_TXPWR_ADJ,
372+
wcid_tx_info);
373+
nss = FIELD_GET(MT_WCID_TX_INFO_NSS, wcid_tx_info);
365374
} else {
366375
txwi->rate = mt76x02_mac_tx_rate_val(dev, rate, &nss);
367376
max_txpwr_adj = mt76x02_tx_get_max_txpwr_adj(dev, rate);
368377
}
369-
spin_unlock_bh(&dev->mt76.lock);
370378

371379
txpwr_adj = mt76x02_tx_get_txpwr_adj(dev, dev->mt76.txpower_conf,
372380
max_txpwr_adj);

drivers/net/wireless/mediatek/mt76/mt76x02_util.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,6 @@ void mt76x02_sta_rate_tbl_update(struct ieee80211_hw *hw,
572572
rate.idx = rates->rate[0].idx;
573573
rate.flags = rates->rate[0].flags;
574574
mt76x02_mac_wcid_set_rate(dev, &msta->wcid, &rate);
575-
msta->wcid.max_txpwr_adj = mt76x02_tx_get_max_txpwr_adj(dev, &rate);
576575
}
577576
EXPORT_SYMBOL_GPL(mt76x02_sta_rate_tbl_update);
578577

drivers/net/wireless/mediatek/mt76/tx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ mt76_tx(struct mt76_dev *dev, struct ieee80211_sta *sta,
266266
skb_set_queue_mapping(skb, qid);
267267
}
268268

269-
if (!wcid->tx_rate_set)
269+
if (!(wcid->tx_info & MT_WCID_TX_INFO_SET))
270270
ieee80211_get_tx_rates(info->control.vif, sta, skb,
271271
info->control.rates, 1);
272272

@@ -412,7 +412,7 @@ mt76_txq_send_burst(struct mt76_dev *dev, struct mt76_sw_queue *sq,
412412
}
413413

414414
info = IEEE80211_SKB_CB(skb);
415-
if (!wcid->tx_rate_set)
415+
if (!(wcid->tx_info & MT_WCID_TX_INFO_SET))
416416
ieee80211_get_tx_rates(txq->vif, txq->sta, skb,
417417
info->control.rates, 1);
418418
tx_rate = info->control.rates[0];

0 commit comments

Comments
 (0)