Skip to content

Commit c8e370f

Browse files
LorenzoBianconinbd168
authored andcommitted
mt76: connac: move more mt7921/mt7915 mac shared code in connac lib
Move the following routines in mt76-connac lib since they are shared between mt7915 and mt7921: - mt76_connac2_tx_check_aggr - mt76_connac2_txwi_free - mt76_connac2_tx_token_put Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Signed-off-by: Felix Fietkau <nbd@nbd.name>
1 parent ef591d7 commit c8e370f

File tree

9 files changed

+96
-166
lines changed

9 files changed

+96
-166
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,5 +419,10 @@ int mt76_connac2_mac_fill_rx_rate(struct mt76_dev *dev,
419419
struct mt76_rx_status *status,
420420
struct ieee80211_supported_band *sband,
421421
__le32 *rxv, u8 *mode);
422+
void mt76_connac2_tx_check_aggr(struct ieee80211_sta *sta, __le32 *txwi);
423+
void mt76_connac2_txwi_free(struct mt76_dev *dev, struct mt76_txwi_cache *t,
424+
struct ieee80211_sta *sta,
425+
struct list_head *free_list);
426+
void mt76_connac2_tx_token_put(struct mt76_dev *dev);
422427

423428
#endif /* __MT76_CONNAC_H */

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,3 +1112,85 @@ int mt76_connac2_mac_fill_rx_rate(struct mt76_dev *dev,
11121112
return 0;
11131113
}
11141114
EXPORT_SYMBOL_GPL(mt76_connac2_mac_fill_rx_rate);
1115+
1116+
void mt76_connac2_tx_check_aggr(struct ieee80211_sta *sta, __le32 *txwi)
1117+
{
1118+
struct mt76_wcid *wcid;
1119+
u16 fc, tid;
1120+
u32 val;
1121+
1122+
if (!sta ||
1123+
!(sta->deflink.ht_cap.ht_supported || sta->deflink.he_cap.has_he))
1124+
return;
1125+
1126+
tid = le32_get_bits(txwi[1], MT_TXD1_TID);
1127+
if (tid >= 6) /* skip VO queue */
1128+
return;
1129+
1130+
val = le32_to_cpu(txwi[2]);
1131+
fc = FIELD_GET(MT_TXD2_FRAME_TYPE, val) << 2 |
1132+
FIELD_GET(MT_TXD2_SUB_TYPE, val) << 4;
1133+
if (unlikely(fc != (IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA)))
1134+
return;
1135+
1136+
wcid = (struct mt76_wcid *)sta->drv_priv;
1137+
if (!test_and_set_bit(tid, &wcid->ampdu_state))
1138+
ieee80211_start_tx_ba_session(sta, tid, 0);
1139+
}
1140+
EXPORT_SYMBOL_GPL(mt76_connac2_tx_check_aggr);
1141+
1142+
void mt76_connac2_txwi_free(struct mt76_dev *dev, struct mt76_txwi_cache *t,
1143+
struct ieee80211_sta *sta,
1144+
struct list_head *free_list)
1145+
{
1146+
struct mt76_wcid *wcid;
1147+
__le32 *txwi;
1148+
u16 wcid_idx;
1149+
1150+
mt76_connac_txp_skb_unmap(dev, t);
1151+
if (!t->skb)
1152+
goto out;
1153+
1154+
txwi = (__le32 *)mt76_get_txwi_ptr(dev, t);
1155+
if (sta) {
1156+
wcid = (struct mt76_wcid *)sta->drv_priv;
1157+
wcid_idx = wcid->idx;
1158+
} else {
1159+
wcid_idx = le32_get_bits(txwi[1], MT_TXD1_WLAN_IDX);
1160+
wcid = rcu_dereference(dev->wcid[wcid_idx]);
1161+
1162+
if (wcid && wcid->sta) {
1163+
sta = container_of((void *)wcid, struct ieee80211_sta,
1164+
drv_priv);
1165+
spin_lock_bh(&dev->sta_poll_lock);
1166+
if (list_empty(&wcid->poll_list))
1167+
list_add_tail(&wcid->poll_list,
1168+
&dev->sta_poll_list);
1169+
spin_unlock_bh(&dev->sta_poll_lock);
1170+
}
1171+
}
1172+
1173+
if (sta && likely(t->skb->protocol != cpu_to_be16(ETH_P_PAE)))
1174+
mt76_connac2_tx_check_aggr(sta, txwi);
1175+
1176+
__mt76_tx_complete_skb(dev, wcid_idx, t->skb, free_list);
1177+
out:
1178+
t->skb = NULL;
1179+
mt76_put_txwi(dev, t);
1180+
}
1181+
EXPORT_SYMBOL_GPL(mt76_connac2_txwi_free);
1182+
1183+
void mt76_connac2_tx_token_put(struct mt76_dev *dev)
1184+
{
1185+
struct mt76_txwi_cache *txwi;
1186+
int id;
1187+
1188+
spin_lock_bh(&dev->token_lock);
1189+
idr_for_each_entry(&dev->token, txwi, id) {
1190+
mt76_connac2_txwi_free(dev, txwi, NULL, NULL);
1191+
dev->token_count--;
1192+
}
1193+
spin_unlock_bh(&dev->token_lock);
1194+
idr_destroy(&dev->token);
1195+
}
1196+
EXPORT_SYMBOL_GPL(mt76_connac2_tx_token_put);

drivers/net/wireless/mediatek/mt76/mt7915/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ static void mt7915_unregister_ext_phy(struct mt7915_dev *dev)
11661166
static void mt7915_stop_hardware(struct mt7915_dev *dev)
11671167
{
11681168
mt7915_mcu_exit(dev);
1169-
mt7915_tx_token_put(dev);
1169+
mt76_connac2_tx_token_put(&dev->mt76);
11701170
mt7915_dma_cleanup(dev);
11711171
tasklet_disable(&dev->mt76.irq_tasklet);
11721172

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

Lines changed: 4 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -842,75 +842,6 @@ u32 mt7915_wed_init_buf(void *ptr, dma_addr_t phys, int token_id)
842842
return MT_TXD_SIZE + sizeof(*txp);
843843
}
844844

845-
static void
846-
mt7915_tx_check_aggr(struct ieee80211_sta *sta, __le32 *txwi)
847-
{
848-
struct mt7915_sta *msta;
849-
u16 fc, tid;
850-
u32 val;
851-
852-
if (!sta || !(sta->deflink.ht_cap.ht_supported || sta->deflink.he_cap.has_he))
853-
return;
854-
855-
tid = le32_get_bits(txwi[1], MT_TXD1_TID);
856-
if (tid >= 6) /* skip VO queue */
857-
return;
858-
859-
val = le32_to_cpu(txwi[2]);
860-
fc = FIELD_GET(MT_TXD2_FRAME_TYPE, val) << 2 |
861-
FIELD_GET(MT_TXD2_SUB_TYPE, val) << 4;
862-
if (unlikely(fc != (IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA)))
863-
return;
864-
865-
msta = (struct mt7915_sta *)sta->drv_priv;
866-
if (!test_and_set_bit(tid, &msta->wcid.ampdu_state))
867-
ieee80211_start_tx_ba_session(sta, tid, 0);
868-
}
869-
870-
static void
871-
mt7915_txwi_free(struct mt7915_dev *dev, struct mt76_txwi_cache *t,
872-
struct ieee80211_sta *sta, struct list_head *free_list)
873-
{
874-
struct mt76_dev *mdev = &dev->mt76;
875-
struct mt7915_sta *msta;
876-
struct mt76_wcid *wcid;
877-
__le32 *txwi;
878-
u16 wcid_idx;
879-
880-
mt76_connac_txp_skb_unmap(mdev, t);
881-
if (!t->skb)
882-
goto out;
883-
884-
txwi = (__le32 *)mt76_get_txwi_ptr(mdev, t);
885-
if (sta) {
886-
wcid = (struct mt76_wcid *)sta->drv_priv;
887-
wcid_idx = wcid->idx;
888-
} else {
889-
wcid_idx = le32_get_bits(txwi[1], MT_TXD1_WLAN_IDX);
890-
wcid = rcu_dereference(dev->mt76.wcid[wcid_idx]);
891-
892-
if (wcid && wcid->sta) {
893-
msta = container_of(wcid, struct mt7915_sta, wcid);
894-
sta = container_of((void *)msta, struct ieee80211_sta,
895-
drv_priv);
896-
spin_lock_bh(&mdev->sta_poll_lock);
897-
if (list_empty(&msta->wcid.poll_list))
898-
list_add_tail(&msta->wcid.poll_list,
899-
&mdev->sta_poll_list);
900-
spin_unlock_bh(&mdev->sta_poll_lock);
901-
}
902-
}
903-
904-
if (sta && likely(t->skb->protocol != cpu_to_be16(ETH_P_PAE)))
905-
mt7915_tx_check_aggr(sta, txwi);
906-
907-
__mt76_tx_complete_skb(mdev, wcid_idx, t->skb, free_list);
908-
909-
out:
910-
t->skb = NULL;
911-
mt76_put_txwi(mdev, t);
912-
}
913-
914845
static void
915846
mt7915_mac_tx_free_prepare(struct mt7915_dev *dev)
916847
{
@@ -1031,7 +962,7 @@ mt7915_mac_tx_free(struct mt7915_dev *dev, void *data, int len)
1031962
if (!txwi)
1032963
continue;
1033964

1034-
mt7915_txwi_free(dev, txwi, sta, &free_list);
965+
mt76_connac2_txwi_free(mdev, txwi, sta, &free_list);
1035966
}
1036967
}
1037968

@@ -1063,7 +994,7 @@ mt7915_mac_tx_free_v0(struct mt7915_dev *dev, void *data, int len)
1063994
if (!txwi)
1064995
continue;
1065996

1066-
mt7915_txwi_free(dev, txwi, NULL, &free_list);
997+
mt76_connac2_txwi_free(mdev, txwi, NULL, &free_list);
1067998
}
1068999

10691000
mt7915_mac_tx_free_done(dev, &free_list, wake);
@@ -1378,20 +1309,6 @@ mt7915_update_beacons(struct mt7915_dev *dev)
13781309
mt7915_update_vif_beacon, mphy_ext->hw);
13791310
}
13801311

1381-
void mt7915_tx_token_put(struct mt7915_dev *dev)
1382-
{
1383-
struct mt76_txwi_cache *txwi;
1384-
int id;
1385-
1386-
spin_lock_bh(&dev->mt76.token_lock);
1387-
idr_for_each_entry(&dev->mt76.token, txwi, id) {
1388-
mt7915_txwi_free(dev, txwi, NULL, NULL);
1389-
dev->mt76.token_count--;
1390-
}
1391-
spin_unlock_bh(&dev->mt76.token_lock);
1392-
idr_destroy(&dev->mt76.token);
1393-
}
1394-
13951312
static int
13961313
mt7915_mac_restart(struct mt7915_dev *dev)
13971314
{
@@ -1440,7 +1357,7 @@ mt7915_mac_restart(struct mt7915_dev *dev)
14401357
napi_disable(&dev->mt76.tx_napi);
14411358

14421359
/* token reinit */
1443-
mt7915_tx_token_put(dev);
1360+
mt76_connac2_tx_token_put(&dev->mt76);
14441361
idr_init(&dev->mt76.token);
14451362

14461363
mt7915_dma_reset(dev, true);
@@ -1633,7 +1550,7 @@ void mt7915_mac_reset_work(struct work_struct *work)
16331550
if (mt7915_wait_reset_state(dev, MT_MCU_CMD_RESET_DONE)) {
16341551
mt7915_dma_reset(dev, false);
16351552

1636-
mt7915_tx_token_put(dev);
1553+
mt76_connac2_tx_token_put(&dev->mt76);
16371554
idr_init(&dev->mt76.token);
16381555

16391556
mt76_wr(dev, MT_MCU_INT_EVENT, MT_MCU_INT_EVENT_DMA_INIT);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,6 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
555555
enum mt76_txq_id qid, struct mt76_wcid *wcid,
556556
struct ieee80211_sta *sta,
557557
struct mt76_tx_info *tx_info);
558-
void mt7915_tx_token_put(struct mt7915_dev *dev);
559558
void mt7915_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
560559
struct sk_buff *skb, u32 *info);
561560
bool mt7915_rx_check(struct mt76_dev *mdev, void *data, int len);

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

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -511,30 +511,6 @@ mt7921_mac_fill_rx(struct mt7921_dev *dev, struct sk_buff *skb)
511511
return 0;
512512
}
513513

514-
static void mt7921_tx_check_aggr(struct ieee80211_sta *sta, __le32 *txwi)
515-
{
516-
struct mt7921_sta *msta;
517-
u16 fc, tid;
518-
u32 val;
519-
520-
if (!sta || !(sta->deflink.ht_cap.ht_supported || sta->deflink.he_cap.has_he))
521-
return;
522-
523-
tid = le32_get_bits(txwi[1], MT_TXD1_TID);
524-
if (tid >= 6) /* skip VO queue */
525-
return;
526-
527-
val = le32_to_cpu(txwi[2]);
528-
fc = FIELD_GET(MT_TXD2_FRAME_TYPE, val) << 2 |
529-
FIELD_GET(MT_TXD2_SUB_TYPE, val) << 4;
530-
if (unlikely(fc != (IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA)))
531-
return;
532-
533-
msta = (struct mt7921_sta *)sta->drv_priv;
534-
if (!test_and_set_bit(tid, &msta->wcid.ampdu_state))
535-
ieee80211_start_tx_ba_session(sta, tid, 0);
536-
}
537-
538514
void mt7921_mac_add_txs(struct mt7921_dev *dev, void *data)
539515
{
540516
struct mt7921_sta *msta = NULL;
@@ -576,37 +552,6 @@ void mt7921_mac_add_txs(struct mt7921_dev *dev, void *data)
576552
rcu_read_unlock();
577553
}
578554

579-
void mt7921_txwi_free(struct mt7921_dev *dev, struct mt76_txwi_cache *t,
580-
struct ieee80211_sta *sta, bool clear_status,
581-
struct list_head *free_list)
582-
{
583-
struct mt76_dev *mdev = &dev->mt76;
584-
__le32 *txwi;
585-
u16 wcid_idx;
586-
587-
mt76_connac_txp_skb_unmap(mdev, t);
588-
if (!t->skb)
589-
goto out;
590-
591-
txwi = (__le32 *)mt76_get_txwi_ptr(mdev, t);
592-
if (sta) {
593-
struct mt76_wcid *wcid = (struct mt76_wcid *)sta->drv_priv;
594-
595-
if (likely(t->skb->protocol != cpu_to_be16(ETH_P_PAE)))
596-
mt7921_tx_check_aggr(sta, txwi);
597-
598-
wcid_idx = wcid->idx;
599-
} else {
600-
wcid_idx = le32_get_bits(txwi[1], MT_TXD1_WLAN_IDX);
601-
}
602-
603-
__mt76_tx_complete_skb(mdev, wcid_idx, t->skb, free_list);
604-
out:
605-
t->skb = NULL;
606-
mt76_put_txwi(mdev, t);
607-
}
608-
EXPORT_SYMBOL_GPL(mt7921_txwi_free);
609-
610555
static void mt7921_mac_tx_free(struct mt7921_dev *dev, void *data, int len)
611556
{
612557
struct mt76_connac_tx_free *free = data;
@@ -669,7 +614,7 @@ static void mt7921_mac_tx_free(struct mt7921_dev *dev, void *data, int len)
669614
if (!txwi)
670615
continue;
671616

672-
mt7921_txwi_free(dev, txwi, sta, stat, &free_list);
617+
mt76_connac2_txwi_free(mdev, txwi, sta, &free_list);
673618
}
674619

675620
if (wake)
@@ -1235,7 +1180,7 @@ void mt7921_usb_sdio_tx_complete_skb(struct mt76_dev *mdev,
12351180
sta = wcid_to_sta(wcid);
12361181

12371182
if (sta && likely(e->skb->protocol != cpu_to_be16(ETH_P_PAE)))
1238-
mt7921_tx_check_aggr(sta, txwi);
1183+
mt76_connac2_tx_check_aggr(sta, txwi);
12391184

12401185
skb_pull(e->skb, headroom);
12411186
mt76_tx_complete_skb(mdev, e->wcid, e->skb);

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ int mt7921e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
442442
struct mt76_tx_info *tx_info);
443443

444444
void mt7921_tx_worker(struct mt76_worker *w);
445-
void mt7921_tx_token_put(struct mt7921_dev *dev);
446445
bool mt7921_rx_check(struct mt76_dev *mdev, void *data, int len);
447446
void mt7921_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
448447
struct sk_buff *skb, u32 *info);
@@ -475,9 +474,6 @@ int mt7921_testmode_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
475474
void *data, int len);
476475
int mt7921_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *msg,
477476
struct netlink_callback *cb, void *data, int len);
478-
void mt7921_txwi_free(struct mt7921_dev *dev, struct mt76_txwi_cache *t,
479-
struct ieee80211_sta *sta, bool clear_status,
480-
struct list_head *free_list);
481477
int mt7921_mcu_parse_response(struct mt76_dev *mdev, int cmd,
482478
struct sk_buff *skb, int seq);
483479

drivers/net/wireless/mediatek/mt76/mt7921/pci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static void mt7921e_unregister_device(struct mt7921_dev *dev)
115115
cancel_work_sync(&pm->wake_work);
116116
cancel_work_sync(&dev->reset_work);
117117

118-
mt7921_tx_token_put(dev);
118+
mt76_connac2_tx_token_put(&dev->mt76);
119119
__mt7921_mcu_drv_pmctrl(dev);
120120
mt7921_dma_cleanup(dev);
121121
mt7921_wfsys_reset(dev);

drivers/net/wireless/mediatek/mt76/mt7921/pci_mac.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,6 @@ int mt7921e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
5353
return 0;
5454
}
5555

56-
void mt7921_tx_token_put(struct mt7921_dev *dev)
57-
{
58-
struct mt76_txwi_cache *txwi;
59-
int id;
60-
61-
spin_lock_bh(&dev->mt76.token_lock);
62-
idr_for_each_entry(&dev->mt76.token, txwi, id) {
63-
mt7921_txwi_free(dev, txwi, NULL, false, NULL);
64-
dev->mt76.token_count--;
65-
}
66-
spin_unlock_bh(&dev->mt76.token_lock);
67-
idr_destroy(&dev->mt76.token);
68-
}
69-
7056
int mt7921e_mac_reset(struct mt7921_dev *dev)
7157
{
7258
int i, err;
@@ -91,7 +77,7 @@ int mt7921e_mac_reset(struct mt7921_dev *dev)
9177
napi_disable(&dev->mt76.napi[MT_RXQ_MCU_WA]);
9278
napi_disable(&dev->mt76.tx_napi);
9379

94-
mt7921_tx_token_put(dev);
80+
mt76_connac2_tx_token_put(&dev->mt76);
9581
idr_init(&dev->mt76.token);
9682

9783
mt7921_wpdma_reset(dev, true);

0 commit comments

Comments
 (0)