mt76: move mt76x02_mac_write_txwi in mt76x02-lib module
authorLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Mon, 1 Oct 2018 16:58:19 +0000 (18:58 +0200)
committerFelix Fietkau <nbd@nbd.name>
Fri, 5 Oct 2018 18:05:44 +0000 (20:05 +0200)
Move mt76x02_mac_write_txwi in mt76x02_mac.c since it is shared between
mt76x0 and mt76x2 drivers. This is a preliminary patch to unify txwi
configuration between mt76x0 and mt76x2 drivers

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt76x02_mac.c
drivers/net/wireless/mediatek/mt76/mt76x02_mac.h
drivers/net/wireless/mediatek/mt76/mt76x2/mac.c
drivers/net/wireless/mediatek/mt76/mt76x2/mac.h
drivers/net/wireless/mediatek/mt76/mt76x2/pci_mac.c
drivers/net/wireless/mediatek/mt76/mt76x2/pci_tx.c
drivers/net/wireless/mediatek/mt76/mt76x2/usb_core.c

index df4366a702c9c0a3672c4518e63430d898ab8c41..71d677a6b88a90404153e9f0e63445a518f3d371 100644 (file)
@@ -18,6 +18,7 @@
 #include "mt76.h"
 #include "mt76x02_regs.h"
 #include "mt76x02_mac.h"
+#include "mt76x02_util.h"
 
 enum mt76x02_cipher_type
 mt76x02_mac_get_key_info(struct ieee80211_key_conf *key, u8 *key_data)
@@ -341,6 +342,68 @@ mt76x02_mac_process_tx_rate(struct ieee80211_tx_rate *txrate, u16 rate,
        return 0;
 }
 
+void mt76x02_mac_write_txwi(struct mt76_dev *dev, struct mt76x02_txwi *txwi,
+                           struct sk_buff *skb, struct mt76_wcid *wcid,
+                           struct ieee80211_sta *sta, int len)
+{
+       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+       struct ieee80211_tx_rate *rate = &info->control.rates[0];
+       struct ieee80211_key_conf *key = info->control.hw_key;
+       u16 rate_ht_mask = FIELD_PREP(MT_RXWI_RATE_PHY, BIT(1) | BIT(2));
+       u8 nss;
+       s8 txpwr_adj, max_txpwr_adj;
+       u8 ccmp_pn[8], nstreams = dev->chainmask & 0xf;
+
+       memset(txwi, 0, sizeof(*txwi));
+
+       if (wcid)
+               txwi->wcid = wcid->idx;
+       else
+               txwi->wcid = 0xff;
+
+       txwi->pktid = 1;
+
+       if (wcid && wcid->sw_iv && key) {
+               u64 pn = atomic64_inc_return(&key->tx_pn);
+               ccmp_pn[0] = pn;
+               ccmp_pn[1] = pn >> 8;
+               ccmp_pn[2] = 0;
+               ccmp_pn[3] = 0x20 | (key->keyidx << 6);
+               ccmp_pn[4] = pn >> 16;
+               ccmp_pn[5] = pn >> 24;
+               ccmp_pn[6] = pn >> 32;
+               ccmp_pn[7] = pn >> 40;
+               txwi->iv = *((__le32 *)&ccmp_pn[0]);
+               txwi->eiv = *((__le32 *)&ccmp_pn[1]);
+       }
+
+       spin_lock_bh(&dev->lock);
+       if (wcid && (rate->idx < 0 || !rate->count)) {
+               txwi->rate = wcid->tx_rate;
+               max_txpwr_adj = wcid->max_txpwr_adj;
+               nss = wcid->tx_rate_nss;
+       } else {
+               txwi->rate = mt76x02_mac_tx_rate_val(dev, rate, &nss);
+               max_txpwr_adj = mt76x02_tx_get_max_txpwr_adj(dev, rate);
+       }
+       spin_unlock_bh(&dev->lock);
+
+       if (dev->drv->get_tx_txpwr_adj) {
+               txpwr_adj = dev->drv->get_tx_txpwr_adj(dev, dev->txpower_conf,
+                                                      max_txpwr_adj);
+               txwi->ctl2 = FIELD_PREP(MT_TX_PWR_ADJ, txpwr_adj);
+       }
+
+       if (nstreams > 1 && mt76_rev(dev) >= MT76XX_REV_E4)
+               txwi->txstream = 0x13;
+       else if (nstreams > 1 && mt76_rev(dev) >= MT76XX_REV_E3 &&
+                !(txwi->rate & cpu_to_le16(rate_ht_mask)))
+               txwi->txstream = 0x93;
+
+       mt76x02_mac_fill_txwi(txwi, skb, sta, len, nss);
+}
+EXPORT_SYMBOL_GPL(mt76x02_mac_write_txwi);
+
 static void
 mt76x02_mac_fill_tx_status(struct mt76_dev *dev,
                          struct ieee80211_tx_info *info,
index 62072291e416b42bb6d26a9cfcad8bca07ca2c6f..ddc8057fbbabdd3ec7b1442076fb0eccd357669b 100644 (file)
@@ -203,4 +203,7 @@ void mt76x02_send_tx_status(struct mt76_dev *dev,
 int
 mt76x02_mac_process_rate(struct mt76_rx_status *status, u16 rate);
 void mt76x02_mac_setaddr(struct mt76_dev *dev, u8 *addr);
+void mt76x02_mac_write_txwi(struct mt76_dev *dev, struct mt76x02_txwi *txwi,
+                           struct sk_buff *skb, struct mt76_wcid *wcid,
+                           struct ieee80211_sta *sta, int len);
 #endif
index 0791fa11875c10cafc99c4a92a62338ff745d815..c98ce1582aec7ecdddf034b401bf31f7444edc25 100644 (file)
@@ -54,66 +54,6 @@ void mt76x2_mac_stop(struct mt76x2_dev *dev, bool force)
 }
 EXPORT_SYMBOL_GPL(mt76x2_mac_stop);
 
-void mt76x2_mac_write_txwi(struct mt76x2_dev *dev, struct mt76x02_txwi *txwi,
-                          struct sk_buff *skb, struct mt76_wcid *wcid,
-                          struct ieee80211_sta *sta, int len)
-{
-       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-       struct ieee80211_tx_rate *rate = &info->control.rates[0];
-       struct ieee80211_key_conf *key = info->control.hw_key;
-       u16 rate_ht_mask = FIELD_PREP(MT_RXWI_RATE_PHY, BIT(1) | BIT(2));
-       u8 nss;
-       s8 txpwr_adj, max_txpwr_adj;
-       u8 ccmp_pn[8];
-
-       memset(txwi, 0, sizeof(*txwi));
-
-       if (wcid)
-               txwi->wcid = wcid->idx;
-       else
-               txwi->wcid = 0xff;
-
-       txwi->pktid = 1;
-
-       if (wcid && wcid->sw_iv && key) {
-               u64 pn = atomic64_inc_return(&key->tx_pn);
-               ccmp_pn[0] = pn;
-               ccmp_pn[1] = pn >> 8;
-               ccmp_pn[2] = 0;
-               ccmp_pn[3] = 0x20 | (key->keyidx << 6);
-               ccmp_pn[4] = pn >> 16;
-               ccmp_pn[5] = pn >> 24;
-               ccmp_pn[6] = pn >> 32;
-               ccmp_pn[7] = pn >> 40;
-               txwi->iv = *((__le32 *)&ccmp_pn[0]);
-               txwi->eiv = *((__le32 *)&ccmp_pn[1]);
-       }
-
-       spin_lock_bh(&dev->mt76.lock);
-       if (wcid && (rate->idx < 0 || !rate->count)) {
-               txwi->rate = wcid->tx_rate;
-               max_txpwr_adj = wcid->max_txpwr_adj;
-               nss = wcid->tx_rate_nss;
-       } else {
-               txwi->rate = mt76x02_mac_tx_rate_val(&dev->mt76, rate, &nss);
-               max_txpwr_adj = mt76x02_tx_get_max_txpwr_adj(&dev->mt76, rate);
-       }
-       spin_unlock_bh(&dev->mt76.lock);
-
-       txpwr_adj = mt76x2_tx_get_txpwr_adj(&dev->mt76, dev->mt76.txpower_conf,
-                                           max_txpwr_adj);
-       txwi->ctl2 = FIELD_PREP(MT_TX_PWR_ADJ, txpwr_adj);
-
-       if (mt76xx_rev(dev) >= MT76XX_REV_E4)
-               txwi->txstream = 0x13;
-       else if (mt76xx_rev(dev) >= MT76XX_REV_E3 &&
-                !(txwi->rate & cpu_to_le16(rate_ht_mask)))
-               txwi->txstream = 0x93;
-
-       mt76x02_mac_fill_txwi(txwi, skb, sta, len, nss);
-}
-EXPORT_SYMBOL_GPL(mt76x2_mac_write_txwi);
-
 int mt76x2_mac_get_rssi(struct mt76x2_dev *dev, s8 rssi, int chain)
 {
        struct mt76x2_rx_freq_cal *cal = &dev->cal.rx;
index b2176f9a661a32cc279590ce4d2bfffe64b8dcca..95ad5eea4274dc3fc902ebaea2040f14dfdd49ab 100644 (file)
@@ -48,9 +48,6 @@ void mt76x2_mac_set_bssid(struct mt76x2_dev *dev, u8 idx, const u8 *addr);
 
 int mt76x2_mac_process_rx(struct mt76x2_dev *dev, struct sk_buff *skb,
                          void *rxi);
-void mt76x2_mac_write_txwi(struct mt76x2_dev *dev, struct mt76x02_txwi *txwi,
-                          struct sk_buff *skb, struct mt76_wcid *wcid,
-                          struct ieee80211_sta *sta, int len);
 
 int mt76x2_mac_set_beacon(struct mt76x2_dev *dev, u8 vif_idx,
                          struct sk_buff *skb);
index c1be3fe8cc90fe5f560d43d7a6b25e923619a026..8037bfb515559c54323c2a81c86506da7558b1f9 100644 (file)
@@ -106,7 +106,7 @@ mt76_write_beacon(struct mt76x2_dev *dev, int offset, struct sk_buff *skb)
        if (WARN_ON_ONCE(beacon_len < skb->len + sizeof(struct mt76x02_txwi)))
                return -ENOSPC;
 
-       mt76x2_mac_write_txwi(dev, &txwi, skb, NULL, NULL, skb->len);
+       mt76x02_mac_write_txwi(&dev->mt76, &txwi, skb, NULL, NULL, skb->len);
 
        mt76_wr_copy(dev, offset, &txwi, sizeof(txwi));
        offset += sizeof(txwi);
index 69dc1f368f525231d23d17a95877743004794a8c..bef28d57bfcca72b4c7509e91e916fa021b49716 100644 (file)
@@ -37,7 +37,7 @@ int mt76x2_tx_prepare_skb(struct mt76_dev *mdev, void *txwi,
        if (q == &dev->mt76.q_tx[MT_TXQ_PSD] && wcid && wcid->idx < 128)
                mt76x02_mac_wcid_set_drop(&dev->mt76, wcid->idx, false);
 
-       mt76x2_mac_write_txwi(dev, txwi, skb, wcid, sta, skb->len);
+       mt76x02_mac_write_txwi(mdev, txwi, skb, wcid, sta, skb->len);
 
        ret = mt76x02_insert_hdr_pad(skb);
        if (ret < 0)
index 6eb7b28d102fb26274ab4f40b83bb5706c474ed3..a740f059e8e1accdd70b1227e0b7e20918e30720 100644 (file)
@@ -36,7 +36,6 @@ int mt76x2u_tx_prepare_skb(struct mt76_dev *mdev, void *data,
                           struct mt76_wcid *wcid, struct ieee80211_sta *sta,
                           u32 *tx_info)
 {
-       struct mt76x2_dev *dev = container_of(mdev, struct mt76x2_dev, mt76);
        struct mt76x02_txwi *txwi;
        int err, len = skb->len;
 
@@ -47,7 +46,7 @@ int mt76x2u_tx_prepare_skb(struct mt76_dev *mdev, void *data,
        mt76x02_insert_hdr_pad(skb);
 
        txwi = skb_push(skb, sizeof(struct mt76x02_txwi));
-       mt76x2_mac_write_txwi(dev, txwi, skb, wcid, sta, len);
+       mt76x02_mac_write_txwi(mdev, txwi, skb, wcid, sta, len);
 
        return mt76x02u_set_txinfo(skb, wcid, q2ep(q->hw_idx));
 }