blob: ae9b7c02a8769c7aff39dfb65bd1854fbc95abf3 [file] [log] [blame]
From b6184a94736ddea3277b1bea374686edb9aef6b4 Mon Sep 17 00:00:00 2001
From: Sujuan Chen <sujuan.chen@mediatek.com>
Date: Fri, 6 Jan 2023 18:18:50 +0800
Subject: [PATCH 2005/2015] wifi: mt76: mt7915: wed: add rxwi for further in
chip rro
Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
---
dma.c | 93 +++++++++++++++++++++++++------------------------
mac80211.c | 2 +-
mt76.h | 24 ++++++++-----
mt7915/dma.c | 2 --
mt7915/mmio.c | 3 +-
mt7915/mt7915.h | 1 +
tx.c | 16 ++++-----
wed.c | 26 +++++++-------
8 files changed, 87 insertions(+), 80 deletions(-)
diff --git a/dma.c b/dma.c
index 185c6f12..9cd97d24 100644
--- a/dma.c
+++ b/dma.c
@@ -64,17 +64,17 @@ mt76_alloc_txwi(struct mt76_dev *dev)
return t;
}
-static struct mt76_txwi_cache *
+static struct mt76_rxwi_cache *
mt76_alloc_rxwi(struct mt76_dev *dev)
{
- struct mt76_txwi_cache *t;
+ struct mt76_rxwi_cache *r;
- t = kzalloc(L1_CACHE_ALIGN(sizeof(*t)), GFP_ATOMIC);
- if (!t)
+ r = kzalloc(L1_CACHE_ALIGN(sizeof(*r)), GFP_ATOMIC);
+ if (!r)
return NULL;
- t->ptr = NULL;
- return t;
+ r->ptr = NULL;
+ return r;
}
static struct mt76_txwi_cache *
@@ -93,20 +93,20 @@ __mt76_get_txwi(struct mt76_dev *dev)
return t;
}
-static struct mt76_txwi_cache *
+static struct mt76_rxwi_cache *
__mt76_get_rxwi(struct mt76_dev *dev)
{
- struct mt76_txwi_cache *t = NULL;
+ struct mt76_rxwi_cache *r = NULL;
- spin_lock_bh(&dev->wed_lock);
+ spin_lock_bh(&dev->lock);
if (!list_empty(&dev->rxwi_cache)) {
- t = list_first_entry(&dev->rxwi_cache, struct mt76_txwi_cache,
+ r = list_first_entry(&dev->rxwi_cache, struct mt76_rxwi_cache,
list);
- list_del(&t->list);
+ list_del(&r->list);
}
- spin_unlock_bh(&dev->wed_lock);
+ spin_unlock_bh(&dev->lock);
- return t;
+ return r;
}
static struct mt76_txwi_cache *
@@ -120,13 +120,13 @@ mt76_get_txwi(struct mt76_dev *dev)
return mt76_alloc_txwi(dev);
}
-struct mt76_txwi_cache *
+struct mt76_rxwi_cache *
mt76_get_rxwi(struct mt76_dev *dev)
{
- struct mt76_txwi_cache *t = __mt76_get_rxwi(dev);
+ struct mt76_rxwi_cache *r = __mt76_get_rxwi(dev);
- if (t)
- return t;
+ if (r)
+ return r;
return mt76_alloc_rxwi(dev);
}
@@ -145,14 +145,14 @@ mt76_put_txwi(struct mt76_dev *dev, struct mt76_txwi_cache *t)
EXPORT_SYMBOL_GPL(mt76_put_txwi);
void
-mt76_put_rxwi(struct mt76_dev *dev, struct mt76_txwi_cache *t)
+mt76_put_rxwi(struct mt76_dev *dev, struct mt76_rxwi_cache *r)
{
- if (!t)
+ if (!r)
return;
- spin_lock_bh(&dev->wed_lock);
- list_add(&t->list, &dev->rxwi_cache);
- spin_unlock_bh(&dev->wed_lock);
+ spin_lock_bh(&dev->lock);
+ list_add(&r->list, &dev->rxwi_cache);
+ spin_unlock_bh(&dev->lock);
}
EXPORT_SYMBOL_GPL(mt76_put_rxwi);
@@ -173,13 +173,13 @@ mt76_free_pending_txwi(struct mt76_dev *dev)
void
mt76_free_pending_rxwi(struct mt76_dev *dev)
{
- struct mt76_txwi_cache *t;
+ struct mt76_rxwi_cache *r;
local_bh_disable();
- while ((t = __mt76_get_rxwi(dev)) != NULL) {
- if (t->ptr)
- skb_free_frag(t->ptr);
- kfree(t);
+ while ((r = __mt76_get_rxwi(dev)) != NULL) {
+ if (r->ptr)
+ skb_free_frag(r->ptr);
+ kfree(r);
}
local_bh_enable();
}
@@ -228,7 +228,7 @@ mt76_dma_add_rx_buf(struct mt76_dev *dev, struct mt76_queue *q,
struct mt76_queue_buf *buf, void *data)
{
struct mt76_queue_entry *entry = &q->entry[q->head];
- struct mt76_txwi_cache *txwi = NULL;
+ struct mt76_rxwi_cache *rxwi = NULL;
struct mt76_desc *desc;
int idx = q->head;
u32 buf1 = 0, ctrl;
@@ -249,13 +249,13 @@ mt76_dma_add_rx_buf(struct mt76_dev *dev, struct mt76_queue *q,
#endif
if (mt76_queue_is_wed_rx(q)) {
- txwi = mt76_get_rxwi(dev);
- if (!txwi)
+ rxwi = mt76_get_rxwi(dev);
+ if (!rxwi)
return -ENOMEM;
- rx_token = mt76_rx_token_consume(dev, data, txwi, buf->addr);
+ rx_token = mt76_rx_token_consume(dev, data, rxwi, buf->addr);
if (rx_token < 0) {
- mt76_put_rxwi(dev, txwi);
+ mt76_put_rxwi(dev, rxwi);
return -ENOMEM;
}
@@ -271,7 +271,7 @@ mt76_dma_add_rx_buf(struct mt76_dev *dev, struct mt76_queue *q,
done:
entry->dma_addr[0] = buf->addr;
entry->dma_len[0] = buf->len;
- entry->txwi = txwi;
+ entry->rxwi = rxwi;
entry->buf = data;
entry->wcid = 0xffff;
entry->skip_buf1 = true;
@@ -284,7 +284,7 @@ done:
static int
mt76_dma_add_buf(struct mt76_dev *dev, struct mt76_queue *q,
struct mt76_queue_buf *buf, int nbufs, u32 info,
- struct sk_buff *skb, void *txwi)
+ struct sk_buff *skb, void *txwi, void *rxwi)
{
struct mt76_queue_entry *entry;
struct mt76_desc *desc;
@@ -344,6 +344,7 @@ mt76_dma_add_buf(struct mt76_dev *dev, struct mt76_queue *q,
}
q->entry[idx].txwi = txwi;
+ q->entry[idx].rxwi = rxwi;
q->entry[idx].skb = skb;
q->entry[idx].wcid = 0xffff;
@@ -446,13 +447,13 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx,
if (mt76_queue_is_wed_rx(q)) {
u32 id, find = 0;
u32 token = FIELD_GET(MT_DMA_CTL_TOKEN, buf1);
- struct mt76_txwi_cache *t;
+ struct mt76_rxwi_cache *r;
if (*more) {
spin_lock_bh(&dev->rx_token_lock);
- idr_for_each_entry(&dev->rx_token, t, id) {
- if (t->dma_addr == le32_to_cpu(desc->buf0)) {
+ idr_for_each_entry(&dev->rx_token, r, id) {
+ if (r->dma_addr == le32_to_cpu(desc->buf0)) {
find = 1;
token = id;
@@ -469,19 +470,19 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx,
return NULL;
}
- t = mt76_rx_token_release(dev, token);
- if (!t)
+ r = mt76_rx_token_release(dev, token);
+ if (!r)
return NULL;
- dma_unmap_single(dev->dma_dev, t->dma_addr,
+ dma_unmap_single(dev->dma_dev, r->dma_addr,
SKB_WITH_OVERHEAD(q->buf_size),
DMA_FROM_DEVICE);
- buf = t->ptr;
- t->dma_addr = 0;
- t->ptr = NULL;
+ buf = r->ptr;
+ r->dma_addr = 0;
+ r->ptr = NULL;
- mt76_put_rxwi(dev, t);
+ mt76_put_rxwi(dev, r);
if (drop)
*drop |= !!(buf1 & MT_DMA_CTL_WO_DROP);
} else {
@@ -547,7 +548,7 @@ mt76_dma_tx_queue_skb_raw(struct mt76_dev *dev, struct mt76_queue *q,
buf.len = skb->len;
spin_lock_bh(&q->lock);
- mt76_dma_add_buf(dev, q, &buf, 1, tx_info, skb, NULL);
+ mt76_dma_add_buf(dev, q, &buf, 1, tx_info, skb, NULL, NULL);
mt76_dma_kick_queue(dev, q);
spin_unlock_bh(&q->lock);
@@ -628,7 +629,7 @@ mt76_dma_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q,
goto unmap;
return mt76_dma_add_buf(dev, q, tx_info.buf, tx_info.nbuf,
- tx_info.info, tx_info.skb, t);
+ tx_info.info, tx_info.skb, t, NULL);
unmap:
for (n--; n > 0; n--)
diff --git a/mac80211.c b/mac80211.c
index 750a642a..e50c68f8 100644
--- a/mac80211.c
+++ b/mac80211.c
@@ -619,7 +619,6 @@ mt76_alloc_device(struct device *pdev, unsigned int size,
spin_lock_init(&dev->lock);
spin_lock_init(&dev->cc_lock);
spin_lock_init(&dev->status_lock);
- spin_lock_init(&dev->wed_lock);
mutex_init(&dev->mutex);
init_waitqueue_head(&dev->tx_wait);
@@ -652,6 +651,7 @@ mt76_alloc_device(struct device *pdev, unsigned int size,
INIT_LIST_HEAD(&dev->txwi_cache);
INIT_LIST_HEAD(&dev->rxwi_cache);
dev->token_size = dev->drv->token_size;
+ dev->rx_token_size = dev->drv->rx_token_size;
for (i = 0; i < ARRAY_SIZE(dev->q_rx); i++)
skb_queue_head_init(&dev->rx_skb[i]);
diff --git a/mt76.h b/mt76.h
index 411a9576..40884fd8 100644
--- a/mt76.h
+++ b/mt76.h
@@ -193,6 +193,7 @@ struct mt76_queue_entry {
};
union {
struct mt76_txwi_cache *txwi;
+ struct mt76_rxwi_cache *rxwi;
struct urb *urb;
int buf_sz;
};
@@ -413,10 +414,15 @@ struct mt76_txwi_cache {
u8 phy_idx;
unsigned long jiffies;
- union {
- struct sk_buff *skb;
- void *ptr;
- };
+ struct sk_buff *skb;
+};
+
+struct mt76_rxwi_cache {
+ struct list_head list;
+ dma_addr_t dma_addr;
+
+ void *ptr;
+ u32 token;
};
struct mt76_rx_tid {
@@ -511,6 +517,7 @@ struct mt76_driver_ops {
u16 txwi_size;
u16 token_size;
u8 mcs_rates;
+ u16 rx_token_size;
void (*update_survey)(struct mt76_phy *phy);
@@ -903,7 +910,6 @@ struct mt76_dev {
struct ieee80211_hw *hw;
- spinlock_t wed_lock;
spinlock_t lock;
spinlock_t cc_lock;
@@ -1639,8 +1645,8 @@ mt76_tx_status_get_hw(struct mt76_dev *dev, struct sk_buff *skb)
}
void mt76_put_txwi(struct mt76_dev *dev, struct mt76_txwi_cache *t);
-void mt76_put_rxwi(struct mt76_dev *dev, struct mt76_txwi_cache *t);
-struct mt76_txwi_cache *mt76_get_rxwi(struct mt76_dev *dev);
+void mt76_put_rxwi(struct mt76_dev *dev, struct mt76_rxwi_cache *r);
+struct mt76_rxwi_cache *mt76_get_rxwi(struct mt76_dev *dev);
void mt76_free_pending_rxwi(struct mt76_dev *dev);
void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,
struct napi_struct *napi);
@@ -1831,9 +1837,9 @@ mt76_token_release(struct mt76_dev *dev, int token, bool *wake);
int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi,
u8 phy_idx);
void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked);
-struct mt76_txwi_cache *mt76_rx_token_release(struct mt76_dev *dev, int token);
+struct mt76_rxwi_cache *mt76_rx_token_release(struct mt76_dev *dev, int token);
int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr,
- struct mt76_txwi_cache *r, dma_addr_t phys);
+ struct mt76_rxwi_cache *r, dma_addr_t phys);
static inline void mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked)
{
diff --git a/mt7915/dma.c b/mt7915/dma.c
index 0baa82c8..552410aa 100644
--- a/mt7915/dma.c
+++ b/mt7915/dma.c
@@ -512,7 +512,6 @@ int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2)
mtk_wed_get_rx_capa(&mdev->mmio.wed)) {
mdev->q_rx[MT_RXQ_MAIN].flags =
MT_WED_Q_RX(MT7915_RXQ_BAND0);
- dev->mt76.rx_token_size += MT7915_RX_RING_SIZE;
mdev->q_rx[MT_RXQ_MAIN].wed = &mdev->mmio.wed;
}
@@ -551,7 +550,6 @@ int mt7915_dma_init(struct mt7915_dev *dev, struct mt7915_phy *phy2)
mtk_wed_get_rx_capa(&mdev->mmio.wed)) {
mdev->q_rx[MT_RXQ_BAND1].flags =
MT_WED_Q_RX(MT7915_RXQ_BAND1);
- dev->mt76.rx_token_size += MT7915_RX_RING_SIZE;
mdev->q_rx[MT_RXQ_BAND1].wed = &mdev->mmio.wed;
}
diff --git a/mt7915/mmio.c b/mt7915/mmio.c
index 53648212..baf35a53 100644
--- a/mt7915/mmio.c
+++ b/mt7915/mmio.c
@@ -725,7 +725,7 @@ int mt7915_mmio_wed_init(struct mt7915_dev *dev, void *pdev_ptr,
wed->wlan.reset = mt7915_mmio_wed_reset;
wed->wlan.reset_complete = mt76_wed_reset_complete;
- dev->mt76.rx_token_size = wed->wlan.rx_npkt;
+ dev->mt76.rx_token_size += wed->wlan.rx_npkt;
if (mtk_wed_device_attach(wed))
return 0;
@@ -933,6 +933,7 @@ struct mt7915_dev *mt7915_mmio_probe(struct device *pdev,
SURVEY_INFO_TIME_RX |
SURVEY_INFO_TIME_BSS_RX,
.token_size = MT7915_TOKEN_SIZE,
+ .rx_token_size = MT7915_RX_TOKEN_SIZE,
.tx_prepare_skb = mt7915_tx_prepare_skb,
.tx_complete_skb = mt76_connac_tx_complete_skb,
.rx_skb = mt7915_queue_rx_skb,
diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
index 9ea30f1d..55af5c8c 100644
--- a/mt7915/mt7915.h
+++ b/mt7915/mt7915.h
@@ -64,6 +64,7 @@
#define MT7915_EEPROM_BLOCK_SIZE 16
#define MT7915_HW_TOKEN_SIZE 7168
#define MT7915_TOKEN_SIZE 8192
+#define MT7915_RX_TOKEN_SIZE 4096
#define MT7915_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */
#define MT7915_CFEND_RATE_11B 0x03 /* 11B LP, 11M */
diff --git a/tx.c b/tx.c
index db0d4df5..92afbf5d 100644
--- a/tx.c
+++ b/tx.c
@@ -864,16 +864,16 @@ int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi,
EXPORT_SYMBOL_GPL(mt76_token_consume);
int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr,
- struct mt76_txwi_cache *t, dma_addr_t phys)
+ struct mt76_rxwi_cache *r, dma_addr_t phys)
{
int token;
spin_lock_bh(&dev->rx_token_lock);
- token = idr_alloc(&dev->rx_token, t, 0, dev->rx_token_size,
+ token = idr_alloc(&dev->rx_token, r, 0, dev->rx_token_size,
GFP_ATOMIC);
if (token >= 0) {
- t->ptr = ptr;
- t->dma_addr = phys;
+ r->ptr = ptr;
+ r->dma_addr = phys;
}
spin_unlock_bh(&dev->rx_token_lock);
@@ -912,15 +912,15 @@ mt76_token_release(struct mt76_dev *dev, int token, bool *wake)
}
EXPORT_SYMBOL_GPL(mt76_token_release);
-struct mt76_txwi_cache *
+struct mt76_rxwi_cache *
mt76_rx_token_release(struct mt76_dev *dev, int token)
{
- struct mt76_txwi_cache *t;
+ struct mt76_rxwi_cache *r;
spin_lock_bh(&dev->rx_token_lock);
- t = idr_remove(&dev->rx_token, token);
+ r = idr_remove(&dev->rx_token, token);
spin_unlock_bh(&dev->rx_token_lock);
- return t;
+ return r;
}
EXPORT_SYMBOL_GPL(mt76_rx_token_release);
diff --git a/wed.c b/wed.c
index 47c81a28..c03b52f9 100644
--- a/wed.c
+++ b/wed.c
@@ -16,18 +16,18 @@ void mt76_wed_release_rx_buf(struct mtk_wed_device *wed)
sizeof(struct skb_shared_info));
for (i = 0; i < dev->rx_token_size; i++) {
- struct mt76_txwi_cache *t;
+ struct mt76_rxwi_cache *r;
- t = mt76_rx_token_release(dev, i);
- if (!t || !t->ptr)
+ r = mt76_rx_token_release(dev, i);
+ if (!r || !r->ptr)
continue;
- dma_unmap_single(dev->dma_dev, t->dma_addr,
+ dma_unmap_single(dev->dma_dev, r->dma_addr,
wed->wlan.rx_size, DMA_FROM_DEVICE);
- __free_pages(virt_to_page(t->ptr), get_order(length));
- t->ptr = NULL;
+ __free_pages(virt_to_page(r->ptr), get_order(length));
+ r->ptr = NULL;
- mt76_put_rxwi(dev, t);
+ mt76_put_rxwi(dev, r);
}
mt76_free_pending_rxwi(dev);
@@ -46,18 +46,18 @@ u32 mt76_wed_init_rx_buf(struct mtk_wed_device *wed, int size)
sizeof(struct skb_shared_info));
for (i = 0; i < size; i++) {
- struct mt76_txwi_cache *t = mt76_get_rxwi(dev);
+ struct mt76_rxwi_cache *r = mt76_get_rxwi(dev);
dma_addr_t phy_addr;
struct page *page;
int token;
void *ptr;
- if (!t)
+ if (!r)
goto unmap;
page = __dev_alloc_pages(GFP_KERNEL, get_order(length));
if (!page) {
- mt76_put_rxwi(dev, t);
+ mt76_put_rxwi(dev, r);
goto unmap;
}
@@ -67,17 +67,17 @@ u32 mt76_wed_init_rx_buf(struct mtk_wed_device *wed, int size)
DMA_TO_DEVICE);
if (unlikely(dma_mapping_error(dev->dev, phy_addr))) {
__free_pages(page, get_order(length));
- mt76_put_rxwi(dev, t);
+ mt76_put_rxwi(dev, r);
goto unmap;
}
desc->buf0 = cpu_to_le32(phy_addr);
- token = mt76_rx_token_consume(dev, ptr, t, phy_addr);
+ token = mt76_rx_token_consume(dev, ptr, r, phy_addr);
if (token < 0) {
dma_unmap_single(dev->dma_dev, phy_addr,
wed->wlan.rx_size, DMA_TO_DEVICE);
__free_pages(page, get_order(length));
- mt76_put_rxwi(dev, t);
+ mt76_put_rxwi(dev, r);
goto unmap;
}
--
2.18.0