@@ -288,11 +288,29 @@ int mt76_connac_init_tx_queues(struct mt76_phy *phy, int idx, int n_desc,
288288}
289289EXPORT_SYMBOL_GPL (mt76_connac_init_tx_queues );
290290
291+ #define __bitrate_mask_check (_mcs , _mode ) \
292+ ({ \
293+ u8 i = 0; \
294+ for (nss = 0; i < ARRAY_SIZE(mask->control[band]._mcs); i++) { \
295+ if (!mask->control[band]._mcs[i]) \
296+ continue; \
297+ if (hweight16(mask->control[band]._mcs[i]) == 1) { \
298+ mode = MT_PHY_TYPE_##_mode; \
299+ rateidx = ffs(mask->control[band]._mcs[i]) - 1; \
300+ if (mode == MT_PHY_TYPE_HT) \
301+ rateidx += 8 * i; \
302+ else \
303+ nss = i + 1; \
304+ goto out; \
305+ } \
306+ } \
307+ })
308+
291309u16 mt76_connac2_mac_tx_rate_val (struct mt76_phy * mphy ,
292310 struct ieee80211_vif * vif ,
293311 bool beacon , bool mcast )
294312{
295- u8 mode = 0 , band = mphy -> chandef .chan -> band ;
313+ u8 nss = 0 , mode = 0 , band = mphy -> chandef .chan -> band ;
296314 int rateidx = 0 , mcast_rate ;
297315
298316 if (!vif )
@@ -307,19 +325,12 @@ u16 mt76_connac2_mac_tx_rate_val(struct mt76_phy *mphy,
307325 struct cfg80211_bitrate_mask * mask ;
308326
309327 mask = & vif -> bss_conf .beacon_tx_rate ;
310- if (hweight16 (mask -> control [band ].he_mcs [0 ]) == 1 ) {
311- rateidx = ffs (mask -> control [band ].he_mcs [0 ]) - 1 ;
312- mode = MT_PHY_TYPE_HE_SU ;
313- goto out ;
314- } else if (hweight16 (mask -> control [band ].vht_mcs [0 ]) == 1 ) {
315- rateidx = ffs (mask -> control [band ].vht_mcs [0 ]) - 1 ;
316- mode = MT_PHY_TYPE_VHT ;
317- goto out ;
318- } else if (hweight8 (mask -> control [band ].ht_mcs [0 ]) == 1 ) {
319- rateidx = ffs (mask -> control [band ].ht_mcs [0 ]) - 1 ;
320- mode = MT_PHY_TYPE_HT ;
321- goto out ;
322- } else if (hweight32 (mask -> control [band ].legacy ) == 1 ) {
328+
329+ __bitrate_mask_check (he_mcs , HE_SU );
330+ __bitrate_mask_check (vht_mcs , VHT );
331+ __bitrate_mask_check (ht_mcs , HT );
332+
333+ if (hweight32 (mask -> control [band ].legacy ) == 1 ) {
323334 rateidx = ffs (mask -> control [band ].legacy ) - 1 ;
324335 goto legacy ;
325336 }
@@ -335,9 +346,9 @@ u16 mt76_connac2_mac_tx_rate_val(struct mt76_phy *mphy,
335346 rateidx = mt76_calculate_default_rate (mphy , rateidx );
336347 mode = rateidx >> 8 ;
337348 rateidx &= GENMASK (7 , 0 );
338-
339349out :
340- return FIELD_PREP (MT_TX_RATE_IDX , rateidx ) |
350+ return FIELD_PREP (MT_TX_RATE_NSS , nss ) |
351+ FIELD_PREP (MT_TX_RATE_IDX , rateidx ) |
341352 FIELD_PREP (MT_TX_RATE_MODE , mode );
342353}
343354EXPORT_SYMBOL_GPL (mt76_connac2_mac_tx_rate_val );
0 commit comments